View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Help with “prompt” command in a script

Gabriel wrote on Feb 23, 2009

Hello,

I'm learning how to write scripts, and I can't get the script below to actually prompt me for the "image" parameter. This is the error code I get:

ecl> prueba
ERROR: Attempt to access undefined local variable `imname'.

"imname = image"
line 12: /home/iraf/noao/casleored/prueba.cl
called as: `prueba ()'

The "prueba" task is defined in the "loginuser.cl" file like this:

# LOGINUSER.CL -- Customization of LOGIN.CL

task $casleored = /home/iraf/noao/casleored/casleored.cl

task $prueba = /home/iraf/noao/casleored/prueba.cl

keep

Script:

#PRUEBA

procedure prueba (image)

file image {prompt="Ingrese nombre de imagen .fit"}

begin

string imname
int k

imname = image

k = strlen(imname)
if (substr (imname, k-3, k) == ".fit"){
imname = substr (imname, 1, k-4)
}

print ('Nombre original: ' // imname)
print ('--------------------------')
print ('display (imname), 1: ')
display ((imname), 1)

end

Thanks!

Mike Fitzpatrick wrote on Feb 23, 2009

A '$' in front of the task name when you declare it means that the task as no parameters, and so you don't see the prompt. Try declaring as

task prueba = /home/iraf/noao/casleored/prueba.cl


-Mike

Gabriel wrote on Feb 23, 2009

Great, it works now.
Thanks!

Gabriel wrote on Feb 23, 2009

Since we're on the subject of script writing, a couple more of questions if you don't mind:

1) Is there a command to halt the script and return to IRAF command line? (I need to put it inside an "is" structure)

2) Is there a "pause" command (this for debugging purposes)?

3) Is there a "goto" or "call" or "jumpto" or similar command?

4) Is there a guide where I can find these things so I don't bother you every three seconds?

Cheers :)

Jason Quinn wrote on Feb 23, 2009

Gaba_p

Since we're on the subject of script writing, a couple more of questions if you don't mind:

1) Is there a command to halt the script and return to IRAF command line? (I need to put it inside an "is" structure)

2) Is there a "pause" command (this for debugging purposes)?

3) Is there a "goto" or "call" or "jumpto" or similar command?

4) Is there a guide where I can find these things so I don't bother you every three seconds?

Cheers :)


There is a script guide at http://iraf.net/irafdocs/script/

Never halted a script.... the only relevant commands I know are sleep and wait but they don't do exactly what you want. Personally I would avoid "goto"-type statements except for perhaps switch statements like the plague. IRAF has a goto statement (help "goto") but there's surely another way to write your code.

Jason

Gabriel wrote on Feb 23, 2009

There's a typo in: "1) Is there a command to halt the script and return to IRAF command line? (I need to put it inside an "is" structure) "; it's an "IF" structure, not an "is".

Thank you Jason, I already have that guide, but it doesn't provide a list of commands (at list I didn't find one). The "goto" is in case there is no "halt" command (so I can "goto" the end of the script).

Cheers!

Jason Quinn wrote on Feb 23, 2009

Gaba_p

There's a typo in: "1) Is there a command to halt the script and return to IRAF command line? (I need to put it inside an "is" structure) "; it's an "IF" structure, not an "is".

Thank you Jason, I already have that guide, but it doesn't provide a list of commands (at list I didn't find one). The "goto" is in case there is no "halt" command (so I can "goto" the end of the script).

Cheers!


Ah.... in that case, you are probably looking for the "bye" command... I often use this structure in my scripts:


if ( some_condition )
	{
	print("ERROR: An error has occured.")
	bye()
	}

Gabriel wrote on Feb 23, 2009

Thanks Jason! The "bye()" command was what I was looking for.
Now one more thing. I'm trying to run this script:

noao
imred
ccdred

int k

scan (k)
if (k == 1) {
hedit (images="flatu*.fit", fields="FILTERS", value="1", add=yes, addonly=no,
delete=no, verify=no, show=yes, update=yes)
}
else {
hedit (images="skyu*.fit", fields="FILTERS", value="U", add=yes, addonly=yes,
delete=no, verify=no, show=yes, update=yes)
}

It's defined as: task $casleored = /home/iraf/noao/casleored/casleored.cl
in the loginuser.cl file.
The "hedit (....)" works fine OUTSIDE the IF structure, but it won't work INSIDE IT. I also tried this way (using goto):

scan (k)
if (k == 1) {
print ('') #This is just so it will go to the "hedit (...)" statement below
}
else {
goto choice2
}
hedit (images="flatu*.fit", fields="FILTERS", value="1", add=yes, addonly=no,
delete=no, verify=no, show=yes, update=yes)

choice2:
if (k == 2) {
print ('') #This is just so it will go to the "hedit (...)" statement below
}
else {
goto exit
}
hedit (images="skyu*.fit", fields="FILTERS", value="U", add=yes, addonly=yes,
delete=no, verify=no, show=yes, update=yes)

exit:
bye()

if k=1 it works fine, but the goto command won't work when k=2 or k!=2.

I hope I'm being clear as to what I'm trying to achieve here. Any help will be much appreciated!

Gabriel wrote on Feb 23, 2009

Scratch the last. What I posted works, the problem appears when I add more "hedit" inside the If structure, like this:

noao
imred
ccdred

int k

print('ingresar k')
scan (k)
if (k == 1) {
hedit (images="flatu*.fit", fields="FILTERS", value="1", add=yes, addonly=no,
delete=no, verify=no, show=yes, update=yes)

hedit (images="flatb*.fit", fields="FILTERS", value="2", add=yes, addonly=no,
delete=no, verify=no, show=yes, update=yes)

hedit (images="flatv*.fit", fields="FILTERS", value="3", add=yes, addonly=no,
delete=no, verify=no, show=yes, update=yes)

hedit (images="flati*.fit", fields="FILTERS", value="5", add=yes, addonly=no,
delete=no, verify=no, show=yes, update=yes)

hedit (images="flat*.fit", fields="IMAGETYP", value="flat", add=yes, addonly=no,
delete=no, verify=no, show=yes, update=yes)
}
else {
hedit (images="skyu*.fit", fields="FILTERS", value="U", add=yes, addonly=yes,
delete=no, verify=no, show=yes, update=yes)

hedit (images="skyb*.fit", fields="FILTERS", value="B", add=yes, addonly=yes,
delete=no, verify=no, show=yes, update=yes)

hedit (images="skyv*.fit", fields="FILTERS", value="V", add=yes, addonly=yes,
delete=no, verify=no, show=yes, update=yes)

hedit (images="skyi*.fit", fields="FILTERS", value="I", add=yes, addonly=yes,
delete=no, verify=no, show=yes, update=yes)

hedit (images="sky*.fit", fields="IMAGETYP", value="flat", add=yes, addonly=yes,
delete=no, verify=no, show=yes, update=yes)
}

Gabriel wrote on Feb 23, 2009

Well, fixed it. I'm sorry, I'm posting before I try thoroughly. Won't happen again.

The problem was the jumps between "hedit's". It works fine like this:

noao
imred
ccdred

int k

print('ingresar k')
scan (k)
if (k == 1) {
hedit (images="flatu*.fit", fields="FILTERS", value="1", add=yes, addonly=no, delete=no, verify=no, show=yes, update=yes)
hedit (images="flatb*.fit", fields="FILTERS", value="2", add=yes, addonly=no, delete=no, verify=no, show=yes, update=yes)
hedit (images="flatv*.fit", fields="FILTERS", value="3", add=yes, addonly=no, delete=no, verify=no, show=yes, update=yes)
hedit (images="flati*.fit", fields="FILTERS", value="5", add=yes, addonly=no, delete=no, verify=no, show=yes, update=yes)
hedit (images="flat*.fit", fields="IMAGETYP", value="flat", add=yes, addonly=no, delete=no, verify=no, show=yes, update=yes)
}
else {
hedit (images="skyu*.fit", fields="FILTERS", value="U", add=yes, addonly=yes, delete=no, verify=no, show=yes, update=yes)
hedit (images="skyb*.fit", fields="FILTERS", value="B", add=yes, addonly=yes, delete=no, verify=no, show=yes, update=yes)
hedit (images="skyv*.fit", fields="FILTERS", value="V", add=yes, addonly=yes, delete=no, verify=no, show=yes, update=yes)
hedit (images="skyi*.fit", fields="FILTERS", value="I", add=yes, addonly=yes, delete=no, verify=no, show=yes, update=yes)
hedit (images="sky*.fit", fields="IMAGETYP", value="flat", add=yes, addonly=yes, delete=no, verify=no, show=yes, update=yes)
}

Last post on Feb 23, 2009