View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

while creating script..

Andrea Cardullo wrote on Jun 21, 2007

Hi, this is my problem:
I would like to write a script which allows me to use rimcursor, with the output in a file, different each time I use the script... (the script will do other operation too)
If I write, in command line:

rimcursor > filename

it does work.
I want to do something like this, in the script:
[...]
string TABB = "" {prompt='the name of the output file'}
begin
[...]
rimcursor > TABB
[...]

but in this way rimcursor creates the output named TABB, and doesn't use the filename I put as parameter...

How to do??

Mike Fitzpatrick wrote on Jun 21, 2007

You need to use the "program mode" syntax, i.e. with the parenthesis. For example,


procedure rcur ()

string curfile = ""     { prompt="cursor filename"      }

begin
    string fname

    # save param to local variable so we're not prompted each time
    # we use it.
    fname = curfile

    # Read image cursor, append result to filename.  Delete existing
    # file first.
    if (access (fname) == yes)
        delete (fname, verify-)
    rimcursor (>> fname)
end


Note the use of '>>' to append results instead of '>' that would overwrite.

-Mike

Andrea Cardullo wrote on Jun 21, 2007

Perfect, now it works!!
Thanks a lot!
Only a doubt:
if I delete the file every time, why I use >> to append? I just create a new file every time... or not?
Also I have another question:
if I would like to execute a command outside iraf, but using a variable defined in iraf...?
for example:
I need to open an image in ds9 but I can't use 'disp' because i need the world coordinate, so I'm interested if exists something like this, in a script:

[...]
string filename = "" {prompt = " the name of the file to be opened"}
[...]
!ds9 filename
[...]

Mike Fitzpatrick wrote on Jun 21, 2007

if I delete the file every time, why I use >> to append? I just create a new file every time... or not?


In this example, the '>>' isn't strictly needed. In real scripts however, you may be looping over multiple images and marking the same star in each image (so you'd delete the file before this loop). Anyway, it was just to point out the difference between > and >> for redirection


Also I have another question:
if I would like to execute a command outside iraf, but using a variable defined in iraf...?
for example:
I need to open an image in ds9 but I can't use 'disp' because i need the world coordinate, so I'm interested if exists something like this, in a script:


You could create a command string and pipe it to the CL for execution, e.g.

printf ("!ds9 %s &\n", filename) | cl()


Note the '&' so it runs in the background and won't block the script.

-Mike

Andrea Cardullo wrote on Jun 21, 2007

Thank you very much!!!!
Exactly what I was looking for!!
Now I have just a little problem:
the script is faster than the ds9 startup...
in the script first I open the ds9 with the image to be loaded (if is it not open yet), and then I run rimcurs. But rimcurs try to work earlier, when the ds9 is not yet opened, so it gives me the error:

ERROR: Cannot open device (node!imtool,,2048,2048)
called as: `rimcursor ()'

How can I solve this problem? (Insterting a pause, how??)

Mike Fitzpatrick wrote on Jun 21, 2007

You can either start DS9 manually before running the script, or else use the sleep() command to wait a specified number of seconds, e.g.


print ("ds9 &") | cl()          # start ds9
sleep (5)                           # wait for it
rimcur( .....)                      # read the cursor


Just be sure the sleep is "long enough".....

-Mike

Andrea Cardullo wrote on Jun 21, 2007

Mike, you are the best!

Radom wrote on Jun 21, 2007

fitz

You can either start DS9 manually before running the script, or else use the sleep() command to wait a specified number of seconds, e.g.


print ("ds9 &") | cl()          # start ds9
sleep (5)                           # wait for it
rimcur( .....)                      # read the cursor


Just be sure the sleep is "long enough".....

-Mike

I think I have similar problem. I want to edit some regions on image. I Load image and regions properly but I don't know how to edit them and save inside cl script. Is it possible?

Mike Fitzpatrick wrote on Jun 21, 2007

Could you say a little more about what kind of regions you're loading and what kind of editing? Tasks like IMEDIT and FIXPIX could be used to edit an image and would either use the display directly, or you could construct image sections using the cursor readback. Do you want to save the edited image, or the region, or both???

-Mike

Radom wrote on Jun 21, 2007

NVMD I've write a walkaround.

Thanks

Last post on Jun 21, 2007