View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

scripts and strings

Guest wrote on Nov 12, 2008

Hello everybody out there

Question # 1
I got a list of binary tables to be converted to iraf fits images. I've written the procedure script, tab2spec (infile, outfile) which is modified from Dr. Jerry Kriss' website. The first lines are

procedure tab2spec (fusefile, iraffile)

file fusefile {prompt="Name of calibrated Fuse ttag file"}
file iraffile {prompt="Name of output Iraf image file"}

When I run it, I got
tt> tab2spec F02001010021bsic4ttagfcal.fit F02001010021bsic.fit
tmp$flux.fits4383k --> F02001010021bsic.fit
add F02001010021bsic.fit,exptime = 1495.
F02001010021bsic.fit updated
The output can be plotted with splot which is what I want, but I am wondering why the messages in the prompt doesn't show up. Does anyone know?

Question # 2
I got a whole list of images such as
F02001010012alif4ttagfcal.fit F02001010022bsic4ttagfcal.fit
F02001010012asic4ttagfcal.fit F02001010012bsic4ttagfcal.fit
F02001010031alif4ttagfcal.fit F02001010031asic4ttagfcal.fit
F02001010021alif4ttagfcal.fit F02001010031blif4ttagfcal.fit
F02001010021asic4ttagfcal.fit F02001010031bsic4ttagfcal.fit
etc
I would like to process a list of files to make it automatic.
tab2spec (@infile, @outfile)
where @infile, and @outfile contain the list of input and output files.
I created @infile using the images.imutil.sections task. I don't know how to
create the @outlist from the names in the @infile. I want for example:
infile = F02001010021asic4ttagfcal.fit, outfile = F02001010021asic.fit
According to phelp, the sys.fmtio contains some string manipulations but I cannot find fmtio in my Iraf v2.14.1 after loading the systems package. I have run out of ideas on what to do.

Thanks for your suggestions.

Siti :roll:

Mike Fitzpatrick wrote on Nov 12, 2008


Question # 1
:
The output can be plotted with splot which is what I want, but I am wondering why the messages in the prompt doesn't show up. Does anyone know?


Because you specified the arguments on the commandline, they aren't prompted for. Run with just the task name and you'll see the prompts.


Question # 2
I got a whole list of images such as
F02001010012alif4ttagfcal.fit F02001010022bsic4ttagfcal.fit
F02001010012asic4ttagfcal.fit F02001010012bsic4ttagfcal.fit
F02001010031alif4ttagfcal.fit F02001010031asic4ttagfcal.fit
F02001010021alif4ttagfcal.fit F02001010031blif4ttagfcal.fit
F02001010021asic4ttagfcal.fit F02001010031bsic4ttagfcal.fit


These need to be specified one-per-line.....


I would like to process a list of files to make it automatic.
tab2spec (@infile, @outfile)


You can use an editor to create the 'outfile' with the desired image names, if what you want is to generate the output list on the commandline then use a command like


cl> tab2spec F0200101*.fit F0200101*%ttagfcal%%.fit


The '%' operator does a string substitution inline and the above command will remove the 'ttagfcal' part of the filename from each of the input filenames.

-Mike

Guest wrote on Nov 12, 2008

Hello Mike,

For my Q 1, If I don't specify the arguments on the command line,

ct> tab2spec
ERROR on line 51: Header file name not found or ambiguous ([0])
tab2spec ()

Line 51 above refers to the end statement in the procedure below:
procedure tab2spec (fusefile, iraffile)

file fusefile {prompt="Name of calibrated Fuse ttag file"}
file iraffile {prompt="Name of output Iraf image file"}

begin
file infile, outfile, fluxtemp, wavetemp
int naxis2
real exptime

# Make sure that ttools and ctools packages are loaded
if (! defpac ("ttools") || ! defpac ("ctools"))
bye

infile = fusefile
outfile = iraffile

# get exposure time
keypar (infile//"[0]", "exptime")
exptime = real(keypar.value)
if (exptime == 0) {
print ("file ", infile, " is empty")
delete (infile)
bye
}

# get number of rows in fits table
keypar (infile//"[1]", "naxis2")
naxis = int(keypar.value)

# make temporary images
fluxtemp = mktemp ("tmp$flux.fits")
wavetemp = mktemp ("tmp$wave.fits")

# extract flux and wavelength and construct 1-dim IRAF images
tabim(infile, fluxtemp, "flux", 1, naxis2)
tabim(infile, wavetemp, "wave", 1, naxis2)

# create a 1-dim spectra
unlearn mkmultispec
mkmultispec (fluxtemp, wavetemp, outfile, function="spline3", nterms=7)

# put in the exposure time
unlearn hedit
hedit (outfile, "exptime", exptime, add+, verify-)

imdel (fluxtemp, ver-, >& "dev$null")
imdel (wavetemp, ver-, >& "dev$null")

end

For my Q 2, could you show me how to use an editor to create an @outfile from @infile? I really appreciate your help.

Thank you.Siti :)

Guest wrote on Nov 12, 2008

Hello Mike,

continue...........the line below:
naxis = int(keypar.value) should read
naxis2 = int(keypar.value)

this is an error when I cut and paste into this forum. Thanks.
Siti:)

Mike Fitzpatrick wrote on Nov 12, 2008


For my Q 1, If I don't specify the arguments on the command line,

ct> tab2spec
ERROR on line 51: Header file name not found or ambiguous ([0])
tab2spec ()


The fact you don't get the prompt makes me wonder how you declared the task, i.e. if it was something like "task $tab2spec = ...." then the '$' says the task has no parameters. Since you *do* have parameters, you shouldn't be using the '$' before the task name. If you change this, you'll need to unlearn the task before running it again.

The error indicates that the 'infile' local variable is empty rather than coming from the parameter, and so when you call keypar it sees only the '[0]' extension. If you type 'd_trace' before running your script, you'll toggle on a debug flag that will print detailed info as the script executes that might help us figure out what's going on.


For my Q 2, could you show me how to use an editor to create an @outfile from @infile? I really appreciate your help.


It depends on which editor you use: what I meant was that you would copy the input list to an output list, then e.g. use "vi" on the output list and issue the command ":1,$s/ttagfcal//g" to remove the string from the filename. You could do this all at once using the command

cat inlist | sed -e "s/ttagfcal//" > outlist


Cheers,
-Mike

Guest wrote on Nov 12, 2008

Dear Mike,

The prompts work as expected after I put inside my loginuser.cl:
task tab2spec = home$bin/tab2spec.cl

Inside my login.cl is: set home = "/home/siti/" and iraf home directory is /scisoft/share/iraf/iraf
I have no problem to apply this procedure to 1 file. However, if I do:
tt> tab2spec F020010100*.fit F020010100*%4ttagfcal%%.fit

528+12: pushconst `F020010100*%4ttagfcal%%.fit'
540+3: posargset 1
543+2: exec
----- exec script tab2spec (home$bin/tab2spec.cl) -----
----- task tab2spec -----
547+7: pushconst `ttools'
554+5: pushconst 1
559+4: intrinsic defpac
563+2: not
565+7: pushconst `ctools'
572+5: pushconst 1
577+4: intrinsic defpac
581+2: not
583+2: or
585+3: biff +5
593+5: pushparam fusefile
598+4: assign infile
602+5: pushparam iraffile
607+4: assign outfile
611+4: call keypar
615+4: pushparam infile
619+6: pushconst `[0]'
625+2: concat
627+3: posargset 0
630+7: pushconst `exptime'
637+3: posargset 1
640+2: exec
----- exec external task keypar -----
keypar\ninput="F020010100*.fit[0]"\nkeyword="exptime"\n
silent=no\nvalue="7693"\nfound=yes\nmode="al"\n$nargs=2\n
--------------------------------
----- task keypar -----
1091+4: call error
1095+5: pushconst 1
1100+3: posargset 0
1103+21: pushconst `Header file name not found or ambiguous (F020010100*.fit[0])'
1124+3: posargset 1
1127+2: exec
----- exec builtin error -----
ERROR on line 51: Header file name not found or ambiguous (F020010100*.fit[0])
tab2spec (fusefile=F020010100*.fit, iraffile=F020010100*%4ttagfcal%%.fit)

Another question, after doing “d_trace”, how do I get out without having to logout? By the way, the vi tip is really useful. Thanks.

Siti :)

Mike Fitzpatrick wrote on Nov 12, 2008

From the help page and the task source it appears that the KEYPAR task does not allow an input list of images, but prefers a single imaage as the argument. As such, you will need to modify your script to handle one image at a time rather than using the '*' wildcard to create a list.

Another question, after doing “d_trace”, how do I get out without having to logout......


The 'd_trace' is a toggle, i.e. type it again to disable the debug-output in the same CL session.

-Mike

Guest wrote on Nov 12, 2008

Dear Mike,

I want to confirm with you that my task is not interpreting the wildcard '*' correctly. I cut my procedure short and added a line to see what value is being read as the input file.

Procedure tab2spec1(fusefile, iraffile)

file fusefile {prompt="Name of calibrated Fuse ttag file"}
file iraffile {prompt="Name of output Iraf image file"}

begin

file infile, outfile, fluxtemp, wavetemp
int naxis2
real exptime

# Make sure that ttools and ctools packages are loaded
if (! defpac ("ttools") || ! defpac ("ctools"))
bye

infile = fusefile
outfile = iraffile

# Check the input file
print ("Input file is ", infile)

end
~
ct> tab2spec1 F*ttagfcal.fit F*%ttagfcal%%.fit
Input file is F*ttagfcal.fit

I mean it is not supposed to literally interpret it as “F*ttagfcal.fit”, right? Thanks for help so far.

Siti :?

Last post on Nov 12, 2008