View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Using Imstat in script

smp wrote on Apr 21, 2009

Hi,

If I run the following script, I get the error message:

ERROR on line 16: FXF: number is not a decimal
mean ()


Script is:

procedure mean (input)

string input
int max_lines

begin

  file means_left
  int i

  for(i=1;i<=max_lines;i=i+1)
    {
       imstat(input//"[1:60,i:i]",fields="mean",format=no) | scan(means_left)
    }

end


please tell what is going wrong?
Thanks

Mike Fitzpatrick wrote on Apr 21, 2009

You need to construct the image section so it is a valid string, e.g.

imstat (input//"[1:60,"//i//":"//i//"]", fields="mean", .....


This concatenates the image name with some literal strings and the 'i' variable to create the image section.

-Mike

smp wrote on Apr 21, 2009

Thanks Mike.
It helped.

Now I have following doubts:
(1) Regarding this
imstat(input_copy//"[1:60,"//i//":"//i//"]",.....


is there any rule for when to use slashes (//) and when to use double quotes(") ?

(2) In following segment:

imstat(input_copy//"[1:60,"//i//":"//i//"]",fields="mean",format=no) | scan(x)
print (x,>"means_left")


I get the error:
ERROR on line 27: cannot open `means_left' for writing


But if I use >> operation, I do not get the error. I suppose that >> is meant for appending the new thing to previously existing thing.

(3) If I use following statement instead :

imstat(input_copy//"[1:60,"//i//":"//i//"]",fields="mean",format=no) | scan("means_left")


I do not get any error, but the file "means_left" is not created.

Regards
smp

Mike Fitzpatrick wrote on Apr 21, 2009


(1) Regarding this
Code:
imstat(input_copy//"[1:60,"//i//":"//i//"]",.....

is there any rule for when to use slashes (//) and when to use double quotes(") ?


Literal strings must be in double quotes, the '//' operator simply concatenates strings. In this example, 'input_copy' is a string variable and 'i' is an int variable, but the 'i' variable is converted internally so the entire operation is one big set of string concatenations.


ERROR on line 27: cannot open `means_left' for writing


By default, IRAF won't let you overwrite an existing file. The '>>' is a file append, if you want to overwrite you need to either explicitly delete the file first, or else do a

cl> set clobber = yes


where the 'clobber' environment variable says to let you overwrite.

As for the last example, a scan() to a literal string can't be done, the first two answers should be all you need.

-Mike

[/quote]

Mike Fitzpatrick wrote on Apr 21, 2009


(1) Regarding this
Code:
imstat(input_copy//"[1:60,"//i//":"//i//"]",.....

is there any rule for when to use slashes (//) and when to use double quotes(") ?


Literal strings must be in double quotes, the '//' operator simply concatenates strings. In this example, 'input_copy' is a string variable and 'i' is an int variable, but the 'i' variable is converted internally so the entire operation is one big set of string concatenations.


ERROR on line 27: cannot open `means_left' for writing


By default, IRAF won't let you overwrite an existing file. The '>>' is a file append, if you want to overwrite you need to either explicitly delete the file first, or else do a

cl> set clobber = yes


where the 'clobber' environment variable says to let you overwrite.

As for the last example, a scan() to a literal string can't be done, the first two answers should be all you need.

-Mike

smp wrote on Apr 21, 2009

when I say

file means_left
int i


Is it not that meas_left is a variable of data type file, as i is a variable of data type integer.

I mean, can't I save different file names in this variable - means_left - if it is one?

Mike Fitzpatrick wrote on Apr 21, 2009

I mean, can't I save different file names in this variable - means_left - if it is one?


Yes. A 'file' type is effectively a string variable, but you need to use it as a variable, i.e. do not put it in quotes so the value of the variable is used and not the literal string "means_left".

-Mike

smp wrote on Apr 21, 2009

thanks

Regards
smp

Last post on Apr 21, 2009