#----------------------------------------------------------------------- procedure deep2iraf( in) #----------------------------------------------------------------------- # NAME: # deep2iraf # # PURPOSE: # Convert DEEP2 data to IRAF-compatible format # # TYPE: # IRAF CL script # # AUTHOR: # Gregory D. Wirth, W. M. Keck Observatory # # INSTALLATION: # 1) install this file in your home iraf directory # 2) execute (or add to your loginuser.cl file) this line: # task deep2iraf = home$deep2iraf.cl # # EXAMPLES: # 1) Convert DEEP2 spectrum into IRAF-compatible image koo.fits: # deep2iraf spec1d.KTRS02.031.1833.fits out=koo.fits # # 2) Run "mysplot" on the DEEP2 spectrum without leaving a new file behind: # deep2iraf spec1d.KTRS02.031.1833.fits domysplot+ # # RESTRICTIONS: # Must be run from a directory in which the user has access to # generate temporary files. # # SIDE EFFECTS: # The resulting spectrum is linearized and hence REBINNED from what # one would get in zspec: CAVEAT EMPTOR!!! # #----------------------------------------------------------------------- # Modification history: # 2003-Sep-06 GDW Original version # 2003-Sep-07 GDW Changed n=1 to nlist=1 #----------------------------------------------------------------------- string in { prompt="Name of input DEEP2 spec1d file" } string out { "", prompt="Name of output IRAF spectrum (optional)" } int blue_extn { 1, prompt="Extension containing blue data" } int red_extn { 2, prompt="Extension containing red data" } bool domysplot { no, prompt="Run mysplot on spectrum?" } begin string i_in # internal copy of in string i_out # internal copy of in #----- string tmpprefix # prefix for temp files string tempfile # name of temp file containing data string tempspec # name of temp image string extn # name of input extension string title # image title string buf # string buffer int i # last character of dirname int l # last character of dirname int m # index position of string # check required packages... if( !deftask("rspectext")) error( 1, "Must load ONEDSPEC package first") if( !deftask("tinfo")) error( 1, "Must load TABLES package first") if( domysplot && !deftask("mysplot")) error( 1, "Must load MTOOLS package first") # prompt... i_in = in i_out = out if ( i_out == "" && ! domysplot ) error( 1, "No action selected! Either specify an output file or set domysplot=yes") # allocate temp files... tmpprefix = "deep2iraf" tempfile = mktemp( tmpprefix) tempspec = mktemp( tmpprefix) # check for access to input file... if( ! access( i_in)) error( 1, "Cannot access input file "//i_in) # check for access to output file... if( i_out != "" ){ if( access( i_out)) error( 1, "Operation would clobber existing file "//i_out) } # verify that the input file is in DEEP2 format... tinfo( i_in, ttout-) if( tinfo.nrows != 1 || tinfo.ncols != 15 || tinfo.tbltype != "fits" || tinfo.subtype != "binary" ) error( 1, "File does not appear to be in DEEP2 spec1d format: "//i_in) tlcol( i_in, nlist=1) | match( "SPEC") | scan( buf) if( nscan() != 1) error( 1, "SPEC entry not found in file "//i_in) tlcol( i_in, nlist=1) | match( "LAMBDA") | scan( buf) if( nscan() != 1) error( 1, "LAMBDA entry not found in file "//i_in) # generate output... extn = i_in // "[" // str(blue_extn) // "]" tprint( extn, prpar-, prdat+, pwidth=80, plength=0, showrow-, orig_row-, showhdr-, showunit-, columns="LAMBDA SPEC", rows="-", opt="plain", align-, sp_col="", lgroup=0, >tempfile) extn = i_in // "[" // str(red_extn) // "]" tprint( extn, prpar-, prdat+, pwidth=80, plength=0, showrow-, orig_row-, showhdr-, showunit-, columns="LAMBDA SPEC", rows="-", opt="plain", align-, sp_col="", lgroup=0, >>tempfile) # locate last character in directory string = i i = 0 l = strlen( i_in) buf = i_in m = stridx( "$/", buf) while( m>0){ i += m buf = substr( i_in, i+1, l) m = stridx( "$/", buf) } title = substr( i_in, i+1, l) # load into image... rspectext( tempfile, tempspec, title=title, flux-, dtype="interp") # copy... if( i_out == "" ) i_out = tempspec else imcopy( tempspec, i_out) # run mysplot if desired... if( domysplot) mysplot( i_out, mode="h") # clean up... if( access( tempfile)) delete( tempfile, ver-) if( imaccess( tempspec)) imdelete( tempspec, ver-) end