mainiacjoe |
06/04/2007 08:25PM (Read 7853 times)
|
|
|
Status: offline
Registered: 06/04/2007
Posts: 2
|
I am new to writing IRAF scripts and have three questions about variable declarations:The first is fairly general: In procedure scripts, when should you put variable declarations before the [i:7548ffb82b]begin[/i:7548ffb82b] and when in the body of the code immediately before they are used? I see examples of both in the Introductory Users Guide, and I'm not sure how they behave differently.The second question involves debugging. Having run a task once and made changes to its script file, how do you delete existing declarations so you can run your task again without getting illegal variable declarations?The third question concerns the modes of the variables. There are query, auto, and hidden, and I think one more, but what exactly do they do? For instance, when I try to run a script below to change the IMAGETYP header field based on the first four letters of the filename I unexpectedly get queried for the value to assign to the variable extension. Why isn't the scan taking care of that?Any other suggestions you can give me on my code will be appreciated as well, of course.Thanks,Joe Childers
Ball State[code:1:7548ffb82b]procedure fiximagetypestring extension # the extension on the image files
string *imagelist # the list of image files in the directory
struct imagefile # the filename of each file as the list is traversedbegin# --------------------------------------------------------------------# Delete all existing lists because of the appends coming laterdelete ("*.lst")# --------------------------------------------------------------------# figure out what extension the raw image files are usingdir ("*.fits") | scan(extension)
if (extension == "no")
extension = "fit"
else
extension = "fits"# --------------------------------------------------------------------# Create a list of all images in the directoryls ("*." // extension // " > images.lst")# --------------------------------------------------------------------# Set DARKTIME = (exposure) for all images, adding as necessaryunlearn hedit
hedit.add = !(defpar("hedit.DARKTIME"))
hedit ("@image.lst","DARKTIME","(exposure)",ver-)# --------------------------------------------------------------------# Update IMAGETYP on all image files based on the first four letters
# of the file name
# Add each image file to the appropriate processing listimagelist = "images.lst"hedit.add = nowhile (fscan (imagelist,imagefile) != EOF) { if (substr(imagefile,1,4) == "bias") {
hedit (imagefile,"IMAGETYP","bias")
print (imagefile,>>"bias.lst") } else { if (substr(imagefile,1,4) == "dark") {
hedit (imagefile,"IMAGETYP","dark")
print (imagefile,>>"dark.lst") } else { if (substr(imagefile,1,4) == "flat") {
hedit (imagefile,"IMAGETYP","flat")
print (imagefile,>>"flat.lst") } else {
hedit (imagefile,"IMAGETYP","object")
print (imagefile,>>"object.lst") } } }}end[/code:1:7548ffb82b]
|
|
|
|
fitz |
06/04/2007 08:25PM
|
|
|
Status: offline
Registered: 09/30/2005
Posts: 4040
|
[quote:8ffa81cd8b]
The first is fairly general: In procedure scripts, when should you put variable declarations before the begin and when in the body of the code immediately before they are used? I see examples of both in the Introductory Users Guide, and I'm not sure how they behave differently.[/quote:8ffa81cd8b]Any variables declared between the 'procedure' and the 'begin' are considered to be parameters of that task. Moreover, variables declared as arguments in the 'procedure' statement are 'query parameters', the rest are 'hidden' (i.e. can be epar/lpar but will use a default value if supplied). Variables declared after the 'begin' are just variables.[quote:8ffa81cd8b]
The second question involves debugging. Having run a task once and made changes to its script file, how do you delete existing declarations so you can run your task again without getting illegal variable declarations?
[/quote:8ffa81cd8b]You need to "unlearn" the task to remove any stored parameters from your uparm directory, e.g. "cl> unlearn mytask" to pick up new parameters.[quote:8ffa81cd8b]
The third question concerns the modes of the variables. There are query, auto, and hidden, and I think one more, but what exactly do they do? For instance, when I try to run a script below to change the IMAGETYP header field based on the first four letters of the filename I unexpectedly get queried for the value to assign to the variable extension. Why isn't the scan taking care of that? [/quote:8ffa81cd8b]Since you don't supply a default value you are prompted for it each time the param is queried (even if it is hidden). Normal practice for query params is to store them to local script variables once at the top of the script to avoid repeated prompts. If you want to supply a default extension but not actually make it a query param, declare it as e.g.[code:1:8ffa81cd8b]
string extension = "fits" { prompt="Filename extension" }
[/code:1:8ffa81cd8b]Cheers,
-Mike
|
|
|
|
mainiacjoe |
06/04/2007 08:25PM
|
|
|
Status: offline
Registered: 06/04/2007
Posts: 2
|
Thank you for those tips. I'm running into another problem, I'm getting an illegal variable declaration on line 15. I'm including just the first part of the script up to where I think the error is, as I've changed it to reflect the above.First of all, there is no variable declaration at line 15 of the .cl file, counting from the top. With line 1 being the line that starts with [i:201dc99894]procedure[/i:201dc99894] then it is the [i:201dc99894]struct extensiontest = "junk"[/i:201dc99894] that is at line 15. Do the error reports ignore leading blank or commented lines for line numbering?Second, I don't understand why I'm getting an error, if this is indeed where it's happening. Typing the same exact thing into the CL as a terminal script performs correctly. Can someone please advise what I am doing wrong?Thanks, Joe[code:1:201dc99894]######################################################################
# #
# fiximagetype.cl #
# #
# Joe Childers June 2007 #
# Ball State University #
# #
# This script will use the first four letters of an image's filename #
# to set its IMAGETYP #
# This script will add DARKTIME = (exposure) #
# #
# Run this script in the directory of the files you want to change #
# #
######################################################################procedure fiximagetypebegin# --------------------------------------------------------------------# Delete all existing lists because of the appends coming laterdelete ("*.lst")# --------------------------------------------------------------------# Create a list of all images in the directorystruct extensiontest = "junk"
dir ("*.fit") | scan (extensiontest)
if (extensiontest == "no files found")
ls ("*.fits",>"images.lst")
else
ls ("*.fit",>"images.lst") # --------------------------------------------------------------------# etc. the rest of the script follows essentially as in my previous post[/code:1:201dc99894]
|
|
|
|
fitz |
06/04/2007 08:25PM
|
|
|
Status: offline
Registered: 09/30/2005
Posts: 4040
|
Joe,I think the error is actually in the ordering of the code, i.e. having the variable declaration following the delete() command. This command execution puts the parse into a different state where it isn't expecting variable declarations and so you get the error, you don't see it from the command line because the parser treats the interactive interpreter a little differently. Try putting all the variable declarations immediately following the 'begin' statement and before you start executing tasks.Cheers,
-Mike
|
|
|
|
| |
|