View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

programming nuances

Sean wrote on Sep 19, 2007

Hello,
I have been writing a procedure script to automatically reduce some optical data, and I have a few questions about the iraf programming language which don't seem to be addressed in "An Introductory Guide to IRAF Scripts". First of all, I have many coordinate files (text files) that I would like to input into psfmeasure. However, not all of the coordinate files necessarily have coordinates in them (some are blank because there was nothing in the frame of interest). So, I was wondering if there is an easy way of checking if a file is blank before inputting it into a task?
A related question is, is there a way of calling fscan on a file/parameter that is not stored as a list parameter? And finally, also kind of related, is there a way to manually define the scope of your variables in the iraf programming language? I know that it is not possible to define a list variable locally, but is there a way to access a global list variable from inside a local block of code without the list variable being included in the function call that creates the block?

Thank you very much for your time.

~Sean

Mike Fitzpatrick wrote on Sep 19, 2007

So, I was wondering if there is an easy way of checking if a file is blank before inputting it into a task?


You might try the COUNT task, e.g. "count (filename) | scan (nlines)" and see whether 'nlines' is then zero.

A related question is, is there a way of calling fscan on a file/parameter that is not stored as a list parameter?


If I understand your question correctly, then no. Could you elaborate on what you're trying to do?

And finally, also kind of related, is there a way to manually define the scope of your variables in the iraf programming language? I know that it is not possible to define a list variable locally, but is there a way to access a global list variable from inside a local block of code without the list variable being included in the function call that creates the block?


Sort of. You can use package parameters or the CL 'list' parameter as a type of global variable and use it within the script, but within the script it isn't possible to define a local scope. Hope this helps.

Cheers,
-Mike[/quote]

Sean wrote on Sep 19, 2007

That does help a bunch, thank you. I do have one more question, though (just came up). Contrary to what is says in the manual, the task psfmeasure prints the average fwhm at the end of its logfile. I have been redirecting the output from psfmeasure to a text file, and then using a while(fscan != EOF) style loop to try and get the last number (the average) out of the file. However, the loop always terminates before it gets there. Am I doing something wrong, or does psfmeasure print an EOF before the actual end of file? Is there some other way to get the last number from a file easily? I am trying to get that number for direct input into another task (phot).

Thank you so very much
~Sean

Mike Fitzpatrick wrote on Sep 19, 2007

It may just be your usage but you didn't post the code snippet. Are you scanning individual words or the entire line?

In any case, a simpler method is to use the 'logfile' directly, e.g.

 match ("Average", "logfile") | fields ("STDIN", 9) | scan (avg_fwhm)


and the variable 'avg_fwhm' will have the value.

Cheers,
-Mike

Sean wrote on Sep 19, 2007

I see what that code is supposed to do, but when I put it in, I get the message:
ERROR: Error in line specification
"match("Average", "log")|fields("STDIN",9)|scan(y)"

Here is the code:

procedure ulttask (filterlist)

string filterlist
struct *flist

begin
	struct line
	file coords
	flist = filterlist
	while(fscan(flist, line) != EOF)
	{
		i = 0
		coords = line//".coo.3"
		count(coords)|scan(i)
		if(i > 1)
		{
			y = 0
			psfmeasure.imagecur = coords
			psfmeasure(line)
			match("Average","log")|fields("STDIN",9)|scan(y)
			photpars.aperture = y
			datapars.fwhmpsf = y
			phot.image = line
			phot(mode='h')
			delete("log")
		}
		else
		{
			print("No PSF for ",line, >> "errors.txt")
		}
	}
end


I think this is somehow related to the other problem. Maybe psfmeasure isn't storing its files correctly?

~Sean[/code]

Last post on Sep 19, 2007