Antonio Kanaan's script hsp_nd

# script to do final light curve reduction starting from list of images
procedure hsp_nd_new(list_file,base_outfile,follow,diaf_unit,diaf_beg,diaf_end,diaf_stp,annulus,dannulus,mark_int,photpars, centerpars, datapars, fitskypars, phot, ccdred, setjd,immatch, crosscor, minmax, taperedge,lista)

file  list_file{prompt = 'File '}
char  base_outfile {prompt = 'Base name for output file'}
char  follow   {"cross",enum="cross|2dcross|previous",prompt="Method to follow stars on the CCD"}
char  diaf_unit {"pixel",enum="pixel|fwhm",prompt="Unit for diaphragm radius"}
real  diaf_beg {2,min=0.1,max=30, prompt = 'First diaphragm radius in pixels: '}
real  diaf_end {7,min=0.2,max=40, prompt = 'Last diaphragm radius in pixels: '}
real  diaf_stp {1,min=0.1,max=10, prompt = 'Step in diaphragm radius: '}
real  annulus  {8,min=1,prompt = 'Internal radius for sky annulus '}
real  dannulus {8,min=1,prompt = 'Width of sky annulus '}
bool  mark_int {yes,prompt = 'Want to mark stars interactively?'}
pset photpars
pset centerpars
pset datapars
pset fitskypars
pset phot
pset ccdred
pset setjd
pset immatch
pset crosscor
pset minmax
pset taperedge
struct *lista

begin

# the following are the mirror variables used because IRAF may get 
# confused whenever one uses the task parameters to do anything:

file nlist_file
char nbase_outfile
char nnome,nnome_old
char nfollow
char ndiaf_unit
real ndiaf_beg
real ndiaf_end
real ndiaf_stp
real nannulus
real ndannulus
bool nmark_int
real nreadnoi
real nepadu

int ii

char first_image="l"
char tapered_first_image
int nimages=1
int x0,y0
real naperture
int nstars              # number of stars marked with imexamine
int   write_time = 10   # time it takes to write an image on disk
int contador
real diaf
int   stop
char  dummy,dummy2
real xaux , yaux
char  aux_name
char  outfile
char  outfile2
char  outfile3
real   seeing
bool   answer=no
int   i

file temp

ii=0

# satisfying IRAF - it doesn't like to have the parameters
# used during execution so a copy should be made for each

nlist_file = list_file
nbase_outfile = base_outfile
ndiaf_unit = diaf_unit
ndiaf_beg = diaf_beg
ndiaf_end = diaf_end
ndiaf_stp = diaf_stp
nfollow   = follow
naperture = ndiaf_beg
nannulus = annulus
ndannulus = dannulus
nmark_int = mark_int
nreadnoi = 5.0
nepadu = 5.0




#*****************************************************************************
# Startup procedures.  
# Declarations, creation, initialization of:
#   scripts
#   table formats
#   parameter initialization


if ( (ndiaf_unit=="fwhm") && (nfollow=="previous") )
   {
   print("fwhm units only work if you use cross correlations to follow")
   beep
   sleep(1)
   beep
   sleep(1)
   beep
   return
   }

set clobber='yes'
tinfo.ttout = no

do_tables(nlist_file,nimages,first_image)
nimages = do_tables.images
	
print ("u have ",nimages,"images")

first_image = do_tables.first_image
tapered_first_image = "tapered_first_image"
if ( imaccess(tapered_first_image) )
   imdelete(tapered_first_image)
taperedge(input=first_image,output=tapered_first_image)


do_awk()

photpars.aperture = naperture
fitskypars.annulus  = nannulus
fitskypars.dannulus = dannulus


#
# I now call IMEXAMINE to mark the target and the other comparison
# stars
#

if (nmark_int) 
   mark_stars(first_image,lista)
else
   copy(input="phot_coords.orig",output="phot_coords",verbose=no)

tinfo('phot_coords')
nstars = tinfo.nrows

# reads the phot_coords file to get the seeing
# the seeing value is used by IMMATCH.
# we may need to update the seeing value every time we loop around
# in which case we will move this line into the loop
lista = "phot_coords"
dummy2 = fscan(lista,dummy,dummy,seeing)

#
# This string ("nnome_temp") holds the name of the temporary file
# copy of the image that will be ccdproced.  It gets overwritten
# every time we loop
#

if ( imaccess("nnome_temp") )
   imdelete("nnome_temp",verify=no)
if ( imaccess("nnome_old") )
   imdelete("nnome_old",verify=no)
imcopy(first_image,"nnome_old",verbose=no)

# 
# The real code starts here.
# Everything else was setup.
# This part is relatively clean, the previous is a big mess

for (diaf=ndiaf_beg ; diaf<=ndiaf_end ; diaf=diaf+ndiaf_stp)
   {
   cache("phot")
   photpars.apertur = diaf		# aperture size is set here
   #
   # lc.tmp - is the file to store the light curves
   # lc.tmp2 - stores light curves with sky info
   #
   if ( access("lc.tmp") )
      delete("lc.tmp",verify=no)
   !cat /dev/null > lc.tmp
   if ( access("lc.tmp2") )
      delete("lc.tmp2",verify=no)
   !cat /dev/null > lc.tmp2
   if ( access("lc.tmp3") )
      delete("lc.tmp3",verify=no)
   !cat /dev/null > lc.tmp3
#  the following lines are used to generate a filename for this aperture
# 
# this should be replaced by:
# outfile = giveaname(nnome)
# a new parameter has been added to tabpar as of 
# tables version ????
   tabpar(table='imas',column='file',row=1,format=no)
   nnome = str(tabpar.value)
   setjd(images=nnome,listonly=yes,>>& "date_out")
   outfile = nbase_outfile // str(diaf)
   outfile2 = outfile // ".star-sky"
   outfile3 = outfile // ".info"
   # we now start looping through the images
   for (contador=1; contador<=nimages ; contador=contador+1)
      {
      tabpar(table='imas',column='file',row=contador,format=no)
      nnome = str(tabpar.value)
      print("Working on image ",nnome," Aperture = ",diaf)
      if ( contador!=1)
         {
   	 if ( nfollow == "cross" )
   	    {
	    if ( access("phot_coords.off") )
		delete("phot_coords.off",verify=no)
            immatch (images=nnome,refer=first_image,output="phot_coords.off")
#                  width=1.,interac=no,imshift=no)
#                  width=2.0*seeing,interac=no,imshift=no)
#                 graphic="stdgraph",cursor="")
#   	    imcentroid (nnome,first_image,coords="phot_coords.orig",
#		     shifts="", boxsize=3.0*seeing+1,bigbox=6.0*seeing+1,
#		     negative=no,niterate=3,toleran=0,
#		     verbose=no,>> "phot_coords.off")
   	    # this reads phot_coords and phot_coords.off, adding them together
   	    # and finally replacing phot_coords with the sum
   	    !gawk -f "offset.awk" < "phot_coords.orig" > "temp"
   	    rename("temp","phot_coords",field="all")
#           this is used to get the seeing value
            lista = "phot_coords"
            dummy2 = fscan(lista,dummy,dummy,seeing)
#           if we are using fwhm as unit of aperture size (variable apertures)
#           then we multiply diaf by the seeing value
            if ( ndiaf_unit == "fwhm" )
               photpars.apertur = seeing * diaf  
   	    }
 
     else if ( nfollow == "2dcross" )
         {
         if ( access("phot_coords.off") )
            delete("phot_coords.off",verify=no)
         if ( imaccess("taperedima") )
            imdelete("taperedima")
         taperedge(input=nnome,output="taperedima",width="10 %",
                   subtract="edge",function="cosbell",verbose=no)
         if ( imaccess("ccima" ) )
            imdelete("ccima",verify=no)
         crosscor(input1=tapered_first_image,
                  input2="taperedima",output="ccima")
         minmax("ccima",>"phot_coords.off")
# lixo33 [92,52] -0.002085051266476512 [92,83] 21305.998046875
         # this reads phot_coords.orig and phot_coords.off, adding them together
         # and finally replacing phot_coords with the sum
	 hselect(images=nnome,fields="i_naxis[12]",
                 expr=yes,>>"phot_coords.off")
         !gawk -f "2doffset.awk" < "phot_coords.orig" > "temp"
         !gawk -f "2doffset.awk" < "phot_coords.orig" 
         rename("temp","phot_coords",field="all")
#        this is used to get the seeing value
         lista = "phot_coords"
         dummy2 = fscan(lista,dummy,dummy,seeing)
#        if we are using fwhm as unit of aperture size (variable apertures)
#        then we multiply diaf by the seeing value
         if ( ndiaf_unit == "fwhm" )
            photpars.apertur = seeing * naperture
         }

   	 else if ( follow == "previous" )
   	    {
   	    # I am currently using the "contagem.awk" script to extract the
   	    # photometry information as well as the position information
   	    # (which gets stored in the file "phot_coords.li")
   	    # if using another method to follow stars this is a waste, but 
   	    # it seemed to be the easiest way to do this.  otherwise it would
   	    # involve re-reading the outfile from phot twice when I decided
   	    # I wanted to follow stars by only using their last position on
   	    # the chip.
   	    rename("phot_coords.li","phot_coords",field="all")
   	    }
         }
      if ( access("date_out") )
         delete("date_out",verify=no)
      if ( access("contagem.tmp") )
         delete("contagem.tmp",verify=no)
      setjd(images=nnome,listonly=yes,>>& "date_out")
      if ( access("julian_date") )
         delete("julian_date",verify=no)
      !gawk '{if (++i==4) print $2}' < date_out > julian_date
# The "most real thing" is done here      
      phot(nnome,>>& "display.lixo")
# The file phot_out2 keeps:
# jd, star1, sky1, star2, sky2, ...
# I need copying phot_out into phot_out2 because I need doing some
# arithmetic (see the pcalc line down)
      if ( access("phot_out2") )
         delete("phot_out2",verify=no)
      copy("phot_out","phot_out2",verbose=no)
      pcalc(infile="phot_out2",field="msky",value="msky*area")
      pdump(infiles="phot_out2",fields="flux,msky",expr=yes,headers=no,
            paramet=yes,> "phot_out.star-sky")
      !cat julian_date phot_out.star-sky > contagem.tmp
      !gawk -f allin1line.awk < contagem.tmp >> lc.tmp2
      delete("contagem.tmp",verify=no)
      delete("phot_out.star-sky",verify=no)
# now I will get the auxiliary file which carries:
# JD,IMAGE,XCENTER,YCENTER,XAIRMASS,PFWHM
      if ( access("phot_coords.1") )
         delete("phot_coords.1",verify=no)
      !head -1 phot_coords > phot_coords.1
      if ( access("radprof.out") )
         delete("radprof.out",verify=no)
      radprof(image=nnome,coords="phot_coords.1",output="radprof.out")
      if ( access("lixo") )
         delete("lixo",verify=no)
      pdump(infiles="radprof.out",fields="IMAGE,XCENTER,YCENTER,XAIRMASS,PFWHM",
            expr=yes,>"lixo")
      !cat julian_date lixo > lixo2
      !gawk -f allin1line.awk < lixo2 >> lc.tmp3
      delete("julian_date",verify=no)
      delete("lixo2",verify=no)
# In this part I do the basic photometry which will be saved to lc.tmp
      !cat date_out phot_out > contagem.tmp
      !gawk -f contagem.awk < contagem.tmp >> lc.tmp
      nnome_old = nnome
      }
   if ( access(outfile) )
      delete(outfile,verify=no)
   rename("lc.tmp",outfile,field="all")
   if ( access(outfile2) )
      delete(outfile2,verify=no)
   rename("lc.tmp2",outfile2,field="all")
   if ( access(outfile3) )
      delete(outfile3,verify=no)
   rename("lc.tmp3",outfile3,field="all")
   }
   
# deletes all temporary files

delete("phot_coords",verify=no)
delete("contagem.awk",verify=no)
delete("phot_coords.awk",verify=no)
delete("display.lixo",verify=no)
delete("date_out",verify=no)
end
Volta Astronomia e Astrofísica
Volta Lista de Exercício