Welcome to iraf.net Friday, May 03 2024 @ 07:17 AM GMT


 Forum Index > Help Desk > Applications New Topic Post Reply
 Help with "prompt" command in a script
   
Gaba_p
 02/23/2009 01:59PM (Read 4625 times)  
++++-
Regular Member

Status: offline


Registered: 10/10/2008
Posts: 104
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.cltask $prueba = /home/iraf/noao/casleored/prueba.clkeep
[b:300247966f]Script:[/b:300247966f]#PRUEBAprocedure prueba (image)file image {prompt="Ingrese nombre de imagen .fit"}beginstring imname
int kimname = 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)endThanks!

 
Profile Email Website
 Quote
fitz
 02/23/2009 01:59PM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
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[code:1:dbedf73a4b]task prueba = /home/iraf/noao/casleored/prueba.cl[/code:1:dbedf73a4b]-Mike

 
Profile Email
 Quote
Gaba_p
 02/23/2009 01:59PM  
++++-
Regular Member

Status: offline


Registered: 10/10/2008
Posts: 104
Great, it works now.
Thanks!

 
Profile Email Website
 Quote
Gaba_p
 02/23/2009 01:59PM  
++++-
Regular Member

Status: offline


Registered: 10/10/2008
Posts: 104
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 Smile

 
Profile Email Website
 Quote
Jason Quinn
 02/23/2009 01:59PM  
+++++
Active Member

Status: offline


Registered: 04/07/2006
Posts: 175
[quote:7ed031f632="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 Smile[/quote:7ed031f632]There is a script guide at https://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

 
Profile Email
 Quote
Gaba_p
 02/23/2009 01:59PM  
++++-
Regular Member

Status: offline


Registered: 10/10/2008
Posts: 104
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!

 
Profile Email Website
 Quote
Jason Quinn
 02/23/2009 01:59PM  
+++++
Active Member

Status: offline


Registered: 04/07/2006
Posts: 175
[quote:02b008136d="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![/quote:02b008136d]Ah.... in that case, you are probably looking for the "bye" command... I often use this structure in my scripts:[code:1:02b008136d]
if ( some_condition )
{
print("ERROR: An error has occured.")
bye()
}
[/code:1:02b008136d]

 
Profile Email
 Quote
Gaba_p
 02/23/2009 01:59PM  
++++-
Regular Member

Status: offline


Registered: 10/10/2008
Posts: 104
Thanks Jason! The "bye()" command was what I was looking for.
Now one more thing. I'm trying to run this script:noao
imred
ccdredint kscan (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!

 
Profile Email Website
 Quote
Gaba_p
 02/23/2009 01:59PM  
++++-
Regular Member

Status: offline


Registered: 10/10/2008
Posts: 104
Scratch the last. What I posted works, the problem appears when I add more "hedit" inside the If structure, like this:noao
imred
ccdredint kprint('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)
}

 
Profile Email Website
 Quote
Gaba_p
 02/23/2009 01:59PM  
++++-
Regular Member

Status: offline


Registered: 10/10/2008
Posts: 104
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
ccdredint kprint('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)
}

 
Profile Email Website
 Quote
   
Content generated in: 0.23 seconds
New Topic Post Reply

Normal Topic Normal Topic
Sticky Topic Sticky Topic
Locked Topic Locked Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Anonymous users can post 
Filtered HTML Allowed 
Censored Content 
dog allergies remedies cialis 20 mg chilblain remedies


Privacy Policy
Terms of Use

User Functions

Login