#!/bin/csh -f #+ # calib -- acquire calibration data for DEIMOS slitmask(s) # # Purpose: # With no argument, acquire calibration data for the current # slitmask. With arguments, acquire calibrations for the named # masks. # # Usage: # calib [-q] [-nofcs] [-pid] [-arctime ] [-flattime ] \ # [-n_arcs ] [-n_flats ] [-lamps values] \ # [ ... ] # # Arguments: # maskN = name of slitmask to observe [default=current] # # Switches: # -q = quiet mode; suppress certain output # -pid = print process ID # -nofcs = do not wait for FCS updates. This is useful when # calibrating in a configuration with no FCS setup defined # -arctime = specify an xposure time to use for arcs [integer, default=1] # -flattime = specify an exposure time to use for flats # [integer, default=12] # -n_arcs = number of arc exposures to take [integer; default=1] # -n_flats = number of quartz flat exposures to take [integer; default=3] # -lamps = specify a comma-separated list of arc lamps to use # for arc exposures [default is Ne,Ar,Kr,Xe] # # Output: # Acquires one calibration lamp exposure (using NeArKrXe lamps) # and three quartz flats per slitmask. A report on the exposures # is written to STDOUT on completion. # # Side Effects: # Will close the hatch if required. And leave it closed. # # Exit values: # 0 = normal completion # 1 = wrong number of arguments # 2 = FCS is not ready to track # # Example: # 1) calibrate the current mask using default exposure times: # calib # # 2) calibrate the masks 4208.W and 5205.E using the default # exposure time for arcs and 6 seconds for the flats. # calib -flattime 6 4208.W 5205.E # # 3) calibrate the masks 4208.W and 5205.E using a non-standard set of # arc lamps (Zn, Cd, and Hg): # calib -lamps "Zn,Cd,Hg" 4208.W 5205.E #- # Modification history: # 2002-Sep-25 GDW Original version # 2003-Mar-04 GDW Improved logic to (1) move slitmasks # before waiting from lamps to warm up # and FCS updates; (2) skip warming up # the arc lamps if they are already on # 2003-May-27 GDW Enable disk write # 2003-May-30 GDW Change default lamp warmup time from # 30 sec to 5sec # 2003-Aug-25 GDW Close hatch if required, instead of aborting # 2005-Aug-25 GDW Add use of "cycle_shutter" # 2014-Jun-13 GDW Add -pid flag # 2014-Jun-17 GDW Add -q flag #----------------------------------------------------------------------- # define defaults... set buf = $0 set cmd = $buf:t set usage = "Usage: $cmd [-q] [-nofcs] [-pid] [-arctime ] [-flattime ] [-n_arcs ]\n[-n_flats ] [-lamps ]\n\t[mask1 mask2 ... maskN]" set arctime = 1 set flattime = 12 @ n_arcs = 1 @ n_flats = 3 set lamps = ( Ne Ar Kr Xe ) set good_lamps = (Ar Kr Xe Cd Ne Zn Hg ) set lamps_needing_warmup = (Cd Zn Hg) set logfile = ${cmd}.log.$$ set use_fcs = 1 set quiet = 0 set goi_flags = "" set nsleep = 5 # default is to let lamps warm up for 5 sec set image1 = NONE set image2 = NONE set image3 = NONE # default is the current mask... set masks = ( `slitmask` ) # parse flags... while ( $#argv > 0 ) # check for quiet flag... if ( "$1" == "-q" ) then shift printf "Quiet mode enabled\n" set quiet = 1 set goi_flags = "-q" continue endif # check for pid flag... if ( "$1" == "-pid" ) then shift printf "PID=%d\n" $$ continue endif # check for nofcs flag... if ( "$1" == "-nofcs" ) then set use_fcs = 0 shift printf "Ignoring FCS\n" continue endif # check for arctime flag... if ( "$1" == "-arctime" ) then shift set arctime = $1 shift printf "Using requested arctime of $arctime\n" continue endif # check for flattime flag... if ( "$1" == "-flattime" ) then shift set flattime = $1 shift printf "Using requested flattime of $flattime\n" continue endif # check for n_arcs flag... if ( "$1" == "-n_arcs" ) then shift @ n_arcs = $1 shift printf "Acquiring $n_arcs arc exposures\n" continue endif # check for n_flats flag... if ( "$1" == "-n_flats" ) then shift @ n_flats = $1 shift printf "Acquiring $n_flats flat exposures\n" continue endif # check for lamp list... if ( "$1" == "-lamps" ) then if ( $#argv < 2 ) then printf "$usage\n" exit 1 endif set list = `echo $2 | sed "s/,/ /g"` set lamps = ( $list ) shift shift continue endif # no flags found; so quit processing flags... break end # parse args... if ( $#argv >= 1 ) then set masks = ( $* ) endif # complain if a purported mask name begins with "-" (probably a syntax error) foreach mask ( $masks ) echo $mask | grep "^-" >& /dev/null if ( $status == 0 ) then printf "$usage\n" exit 1 endif end # complain if FCS is not available... if ( $use_fcs ) then fcs_status if ( $status ) then exit 2 endif endif # validate lamp request... set lampstring = "" foreach lamp ( $lamps ) set lampstring = ${lampstring}$lamp set bad = 1 foreach good_lamp ( $good_lamps ) if ( "$lamp" == "$good_lamp" ) then set bad = 0 endif end if ( $bad == 1 ) then printf "ERROR -- $lamp is not a valid choice for an arc lamp\n" printf "\tValid selections are:" foreach good_lamp ( $good_lamps ) printf " %s" $good_lamp end printf "\n" exit 1 endif # check whether warmup required... foreach test ( $lamps_needing_warmup ) if ( "$lamp" == "$test" ) then set nsleep = 180 endif end end # check slider... set slider = `slider` if ( "$slider" != "3" && "$slider" != "4" ) then beep 3 printf "ERROR -- must be on slider 3 or 4\n" exit 1 endif # verify logfile... touch $logfile >& /dev/null if ( $status != 0 ) then set logfile = /tmp/$logfile touch $logfile >& /dev/null if ( $status != 0 ) then printf "ERROR -- cannot open logfile $logfile\n" beep 3 exit 1 endif endif printf "%-12s %-16s %s\n" "Mask" "Arc" "Flats" >> $logfile printf "%-12s %-16s %s\n" "------------" "----------------" "-----------------------------------" >> $logfile # close hatch if required... set hatch = `show -s deimot -terse hatchpos` if ( "$hatch" != "closed" ) then printf "WARNING -- hatch is open, so I'm going to close it...\n" modify -s deimot hatchpos=closed if ( $status ) then printf "ERROR while attempting to close hatch -- abort\n" exit 1 endif endif # cycle the shutter to avoid air pressure failure... cycle_shutter -10 if ( $status != 0 ) then printf "ERROR while attempting to exercise shutter -- abort\n" exit 1 endif # loop over masks... onintr aborting set abort # save the todisk state... set todisk_old = `show -s deiccd -terse todisk` modify -s deiccd todisk=t # initialize variables... set bad_masks = () set good_masks = () set current_lamps = "" foreach mask ( $masks ) # close main shutter to protect CCD while slitmask changes... modify -s deiccd cshutter=f # select the specified mask... slitmask $mask if ( $status != 0 ) then printf "ERROR selecting mask $mask --- skipping\n" beep 3 set bad_masks = ( $bad_masks $mask) continue endif # wait for FCS to track... if ( $use_fcs == 1 ) then lamps off set current_lamps = off modify -s deiccd cshutter=t # open shutter for FCS printf "Waiting for FCS to track..." waitfor -s deifcs fcssta = Tracking endif modify -s deiccd cshutter=f # close main shutter to allow lamps to turn on if ( $status != 0 ) then printf "ERROR closing shutter -- you may need to interrupt FCS in order to continue\n" beep 3 exit 1 endif # turn on arc lamps... if ( $n_arcs > 0 && "$current_lamps" != "arcs" ) then modify -s deimot lamps="$lamps" if ( $status != 0 ) then printf "ERROR turning arc lamps on --- skipping\n" beep 3 set bad_masks = ( $bad_masks $mask) continue endif set current_lamps = arcs printf "Waiting $nsleep seconds for lamps to warm up" if ( $quiet ) then printf "\n" else sleepdots $nsleep endif endif # acquire arc images... if ( $n_arcs > 0 ) then tint $arctime set description = "$lampstring arc $mask" object $description spectral modify -s deiccd obstype="Line" set image1 = `nextimage -tail` goi $goi_flags $n_arcs endif # acquire flats... if ( $n_flats > 0 ) then modify -s deimot lamps="Qz" if ( $status != 0 ) then printf "ERROR turning Qz lamp on --- skipping\n" beep 3 continue endif set current_lamps = qz tint $flattime sleep 5 set description = "IntFlat $mask" object $description spectral modify -s deiccd obstype="IntFlat" set image2 = `nextimage -tail` goi $goi_flags $n_flats waitfor -s deiccd wdisk=f set image3 = `lastimage -tail` endif # log results... printf "%-12s %-16s %s\n" "$mask" "$image1" "$image2 - $image3" >> $logfile # add to list of good masks... set good_masks = ( $good_masks $mask) end unset abort aborting: if ( $?abort ) then printf "Aborting!\n\a" endif # restore state... modify -s deiccd todisk=$todisk_old lamps off # print report... printf "Log of observations:\n\n" cat < $logfile printf "\n" \rm $logfile printf "The following masks were completed successfully:\n" if ( $#good_masks > 0 ) then foreach mask ( $good_masks ) printf "\t%s" $mask end else printf "\t%s" NONE endif printf "\n" if ( $#bad_masks > 0 ) then printf "The following masks were NOT completed due to errors:\n" foreach mask ( $bad_masks ) printf "\t%s" $mask end printf "\n" else printf "There were no errors reported --- all masks completed OK.\n" endif # script_done exit