View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

if….else….

ranisb wrote on Nov 17, 2008

Hi,
I am writing procedure script.In this i am using if...else loop.But it is giving syntax error with else....loop only.But I checked it and it is all right. I written it like this,
procedure reduction1 (biasimage)
string biasimage # {prompt="List of bias images"}
pset zerotest
struct *bslist
begin
int i
string bsfile, bias, biasmaster
if (!defpac("noao") || !defpac("imred")) {
bye()
}
bias = biasimage
if(bias != "") {
bsfile = mktemp("tmp$red")
section(bias, option = "fullname", > bsfile)
}
else {
print("No biasframes defined")
bye()
}
. ..........
...........
end

And giving syntax error with else loop,like following
cc> reduction1
** Syntax error, line 37
**: else {
^
** Syntax error, line 40
**: }
^
** Syntax error, line 93
**: else {
^
** Syntax error, line 95
**: }

Does you have an idea of how I could write this into my code or where I am wrong?
:(
Kindly write me solution

Regards,
Rani

Jason Quinn wrote on Nov 17, 2008

ranisb

Hi,
Does you have an idea of how I could write this into my code or where I am wrong?
:(
Kindly write me solution

Regards,
Rani


Your script executes for me without syntax error. I'm using IRAF 2.14.1. Try deleting the parameter file for the task and restarting IRAF.

Another idea: on rare occasion (about once a year) I get invisible whitespace control characters that screw up source code. I copy and paste the text into a new file when this happens and the problem usually goes away. You could try this.

Jason

PS I learned a new variable type "pset" because of your post. Is this yet another "string" variable Mike?

Mike Fitzpatrick wrote on Nov 17, 2008

Like Jason, I was able to run your script without error. Aside from the strange-character rarity, another CL quirk is that in some cases the if-else statements need to be terminated by a ';' in order to avoid an ambiguity, e.g.


if (something) {
    do this
}
;                                  <----------- dummy statement

if (something_else) {
    do that
}


I didn't see this problem specifically with your script but errors happening with an 'else' clause always remind me of it.

PS I learned a new variable type "pset" because of your post. Is this yet another "string" variable Mike?


A PSET is like a global data structure for storing parameters, more specifically it is a "named parameter set". These have been around quite a while and are used in e.g. the photometry packages to set parameters for the data or detection that may be common to several tasks. Details are available in the iraf$docs/pset.ms file in your system or online at http://docs.iraf.net/pset

-Mike

Last post on Nov 17, 2008