import sys import os import casac import string import inspect import pdb from parameter_check import * def tget(taskname=None, outfile=''): """ Get last input values from file on disk for a specified task: taskname -- Name of task default: ; example: taskname='bandpass' outfile -- Output file for the task inputs default: taskname.last then taskname.saved example: outfile=taskname.orion """ try: a=inspect.stack() stacklevel=0 for k in range(len(a)): if (string.find(a[k][1], 'ipython console') > 0): stacklevel=k break myf=sys._getframe(stacklevel).f_globals if taskname==None: taskname=myf['taskname'] myf['taskname']=taskname myf['taskname']=taskname if type(taskname)!=str: taskname=taskname.__name__ myf['taskname']=taskname myf['taskname']=taskname parameter_checktype(['taskname','outfile'],[taskname,outfile],[str,str]) parameter_checkmenu('taskname',taskname,['sdcal','sdfit','sdplot','sdstat']) parameter_checkmenu('taskname',taskname,['accum','almasimmos','bandpass','blcal','clean','clearplot','clrstat','concat','contsub','correct','deconvolve','exportfits','exportuvfits','feather','flagautocorr','flagdata','flagxy','fluxscale','fringecal','ft','gaincal','imhead','immoments','importvla','importasdm','importfits','importuvfits','clearcal','invert','listhistory','listobs','makemask','mosaic','mosaicmem','plotants','plotcal','plotxy','pointcal','regridimage','sdcal','sdfit','sdlist','sdplot','sdstat','smooth','setjy','split','uvmodelfit','viewer','browsetable','restore','initial']) ###Check if task exists by checking if task_defaults is defined if (myf.has_key(taskname+'_defaults') == False): raise TypeError, "task %s is not defined " %taskname if taskname==None: taskname=myf['taskname'] myf['taskname']=taskname f=zip(myf[taskname].func_code.co_varnames,myf[taskname].func_defaults) for j in range(len(f)): k=f[j][0] stst = myf[k] if ( type(stst) == str ): sex = k+"='"+stst+"'" else: sex = k+"="+str(stst) exec(sex) if outfile=='': outfile=taskname+'.last' try: taskparameterfile=open(outfile,'r') except: outfile=taskname+'.saved' try: taskparameterfile=open(outfile,'r') except: print "ERROR - no taskname.last or .saved" return taskparameterfile.close() execfile(outfile) # Put the task parameters back into the global namespace f=zip(myf[taskname].func_code.co_varnames,myf[taskname].func_defaults) for j in range(len(f)): k=f[j][0] myf[k] = eval(k) print "Restored parameters from file "+outfile except TypeError, e: print "tget --error: ", e