View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

IRAF script

Robert Janusz wrote on Jan 05, 2011

(A) I have a script a.cl
...
scan(s1)
...
and when I run
cl < a.cl
the script is not waiting for input; how can I make the script to wait?

(B) I have a task TSK which is reading a list of data
data1
data2
...
The data comes from external (not IRAF) program PRO.
How can I make the TSK wait for data? Now, it simply reads the last dataN and exits without waiting for the PRO to send its last line of data.

Mike Fitzpatrick wrote on Jan 05, 2011

You need to turn the script into a procedure script (see the Script Guide at http://iraf.net/irafdocs/script/ ). By running with redirection, you are redirecting ALL standard input, and so the scan() in your script is actually reading the next line of the script itself.

Robert Janusz wrote on Jan 05, 2011

And what about the problem (B) of the post above?

PS

Here is a small example of how can we get "scan" break within "cl <" construction; it is not elegant, but works. The script "z" is:
s1=""
print("OK")
!read x; echo $x > z.tmp
cat z.tmp | scan s1; del z.tmp
print("END "//s1)

and now
cl < z
waits for input.

Mike Fitzpatrick wrote on Jan 05, 2011

There's not enough information in your post for me to understand exactly what you're doing. If PRO is producing a data file you read from TSK after the fact, you would do something like


list = "data.txt"
while (fscan (list, s1) != EOF) {
     .... do something
}


If instead you mean that you want to pipe the output of PRO to TSK then you need to first convert your script to a procedure script so it can be declared as a task, then use scan() to read from stdin within the task. In order pipe the output from one task to another you'll need to declare the non-iraf PRO as a 'foreign task", e.g.


cl> task $pro = $foreign
cl> task  tsk  = /path/tsk.cl
cl> pro | tsk


where the '$' in front of PRO means it has no parameters, and that its missing fromt he TSK declarations means your tsk.cl procedure script DOES has parameters (i.e. variables defined between the 'procedure' and 'begin' statements). Of course you could also just run PRO and redirect the output to a file and do the first suggestion.

If you still have problems you'll need to post more than one line of a script and tell me more about how you are calling it, are you reading from files or stdin, etc.

Robert Janusz wrote on Jan 05, 2011

I have an IRAF task (i.e.: procedure... parameters... begin... end) and I use the structure like this
list = "output.lst"
while (fscan(list,s1)!=EOF) {
     print(s1)
     ...
}
The external program PRO is very slow: it writes one line to the "output.lst" in 2-3 sec. because it has ca. 10000 stars to elaborate. It writes the star it has done and continues its calculation with another star. In the meantime the IRAF task is supposed to make IRAF analysis of the star in "s1". But the situation is: when PRO has written lets say 10 stars to "output.lst", I start the IRAF task and it works nicely with this 10 stars and does not wait for another but simply quits. How to force IRAF task to wait for all stars the PRO is elaborating?
Regards, rj

PS
The situation is similar to the IRAF "display" on the ds9: IRAF is able to wait to elaborate coordinates from ds9; and waits until the Q-pressed.

Mike Fitzpatrick wrote on Jan 05, 2011

A cursor read is completely different, it actually involves communications between the two tasks and not simply reading whatever the other task happens to spit out.

If you plan to use fscan() to process the list, you need to let the PRO task run until it is finished so all the values are in the file before you run TSK. Otherwise, you need to pipe the output of PRO into TSK (e.g. "cl> pro | tsk") and use scan() so TSK is reading from the standard input stream which is open as a long as PRO is running. There is no way in a CL script to check whether some new output has appeared in a file.

Last post on Jan 05, 2011