View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

trouble with txdump!

H.J. van Heerden wrote on Nov 16, 2006

Hi all

I have a little trouble getting txdump to do what I want it to do.
After running the batch psf photometry script and thus generating (for 60 images) a .pst file for every image with values for the five stars measured, I wanted to txdump the xcen,ycen,mag for the stars into individual textfiles.

I.E. For 60 .pst files, and 5 stars' measured, I want to create 5 stardata files (nl. star1, star2, star3, ...) which contain that stars' xcen,ycen,mag and when I figure out how the obs. time.

The thing is I want to do it in a script (like automated stuff, don't like typing :wink: ). The way I thought to go about it is to run through the list of .pst files and write the data out to the appr. file. Thus for 5 stars it will load the .pst file and then run through a loop from i = 1:5, dumping the data to the files, or vice versa.

# Do the txdump. The rest of the code is cutoff. 
int i, j
string starfile, pst

struct = *pstlist #Contain the list of stars

i = 5
for (j = 1; j <= i; j+=1) {
      starfile = "star" // j         #Create the data file
      while (fscan (pstlist, pst) != EOF) {      #Scan through the list
               txdump pst xcenter,ycenter,mag 'id == j' >> starfile  #Dump the data
      }
}




I suspect that there might be quite a few errors in the code, and how I call txdump.

Advice would be nice :D

ThanX

Regards
Pat

H.J. van Heerden wrote on Nov 16, 2006

Hi all

I sorted the trouble with txdump. Called it wrongly. Now I have a new problem with my stardump script. I build in a choice function, i.e. if the user wants to dump an specific stars' data or all the stars (nl star- 4 or star- 1:5) If the user wants to dump 1:5, he enters 5 else if he wants 4 he enters 4'. Might be simple but it works for a short test script. The trouble is my final script gives me an error at the if - else statement. It says that there is a syntax error at the "else" statment, line 40.

Somehow I just can't see the source of the error. If someone can mybe help me solve it. Much appreciated!! :D

Here's the script

i = strlen (nstars)
	if (substr (nstars, i, i) == "'" )
		n = int(substr (nstars, 1, i-1))
		
		# Do the txdump. The textfiles containing the data will
		# appear in the same directory as the source files!
		starfile = "star" // n
		expr = "id ==" // n
		while (fscan (pstlist, pst) != EOF ) {
			txdump (pst, "xcenter,ycenter,mag", expr, >> starfile)
		} 
	else
		n = int(nstars)
		
		# Do the txdump. The textfiles containing the data will
		# appear in the same directory as the source files!
		for (k = 1; k <= n; k+=1) {
			starfile = "star" // k
			expr = "id ==" // k
			while (fscan (pstlist, pst) != EOF ) {
				txdump (pst, "xcenter,ycenter,mag", expr, >> starfile)
			}
		}
	


Thanx

Regards
Pat

Mike Fitzpatrick wrote on Nov 16, 2006

You've apparently been corrupted by Python, braces are required around the if statement (and while, and for....) compound-statement blocks. With no brace, only a single statement is used, so you're else appears out of nowhere as far as the parser is concerned.

-Mike

H.J. van Heerden wrote on Nov 16, 2006

Hi Mike

Sorry for the "bad coding". :oops: I am not a full time software devol. I know just enough to write bad code.

Thus far I have coded in VB6, C++, Matlab M-files, and now "Csh"/Iraf.

Hard to keep track of all the diff. conventions!!! :wink:

Anyway! The stardump script now work correctly. (Just had to swap the for and while loops in the else statement). Now I just have to include the UT - OBSTIME from the im-header in the star files as well. Then I can start to do some graphing for analysis. :D

ThanX for ALL the help!!

Regards
Pat

H.J. van Heerden wrote on Nov 16, 2006

Hi

Picked up some error again! :?

The Script worked a couple of days ago. I then proceeded to include a code section to display the stars' id's that the daophot package write into the .pst. files. So the user can see what id's to use when he wants to dump the data.

Now all of a sudden the code does not want to work. Up until the end of the scan part. The error seems to occur with the "nscan" part. I think. :?

Here is the code.


procedure stardump (pst_temp, pst_files, num_stars)	# Define procedure

# Define procedure variables

string	pst_temp	{prompt="The pstfile template for the star id's"}
string	pst_files	{prompt="The pstfiles containing the calculated magnitudes"}
string	num_stars	{prompt="The number of stars, or the starnumber to be dumped"}

struct	*pstlist

begin

	# Define script variables
	int	i, n, k
	string	pststar, pst, nstars, starfile, expr, starid, pstid
	
	# Make sure the nessecary packages are installed
	if ( ! defpac ("daophot")) {
		bye()
	}
	;
	
	# Get the star id's from the pst file, and display them for the user to choose.
	pstid	= pst_temp
	starid = mktemp ("tmp$pst")
	txdump (pstid, "id", yes, > starid)
	print ("Measured stars' id's!")
	type (starid)
	
	# Expand the image template into a text file list
	pststar = mktemp ("tmp$pst")
	sections (pst_files, option="fullname" , > pststar)
	
	# Get the rest of the parameters
	nstars	= num_stars
	pstlist = pststar
		
	# Scan through nstars to get the starnumber
	scan (nstars)
	if (nscan () != 0) {
	
		# If there is a starnumber do the textdump
		i = strlen (nstars)
		
		if (substr (nstars, i, i) == "'" ) {		# Check for specific stars
			n = int(substr (nstars, 1, i-1))
					
			# Do the txdump. The textfiles containing the data will
			# appear in the same directory as the source files!
			
			starfile = "star" // n
			expr = "id ==" // n
			while (fscan (pstlist, pst) != EOF ) {
				txdump (pst, "ifilter,otime,xairmass,xcenter,ycenter,mag,msky", expr, >> starfile)
			}
			;
		}
		else {
			n = int(nstars)		# Dump all the stars in order, if numbered from 1 to n
			
			# Do the txdump. The textfiles containing the data will
			# appear in the same directory as the source files!
			
			while (fscan (pstlist, pst) != EOF ) {
				for (k = 1; k <= n; k+=1) {
					starfile = "star" // k
					expr = "id ==" // k
					txdump (pst, "ifilter,otime,xairmass,xcenter,ycenter,mag,msky", expr, >> starfile)
				}
				;
			}
			;
		}
		;
	}
	;
			
	# Clean up
	delete (pststar, ver-, >& "dev$null")
	delete (starid, ver-, >& "dev$null")
		
end



Hope U can help

Regards
Pat

Mike Fitzpatrick wrote on Nov 16, 2006

Hi Pat,

I'm not quite sure what your intent is, or what specifically you changed other than to make this a procedure script. The scan() function reads from the stdin, so a statement like "scan(nstars)" means to take a number typed at the keyboard (or redirected) and store it in the 'nstars' variable. But, you set 'nstars' a few lines before that so it already has a value.

-Mike

H.J. van Heerden wrote on Nov 16, 2006

Hi Mike

The scan part is just to check for a non-zero value for nstars. I.E. dit the user enter a value. I expect that I could do it in a different way. But it did work a week ago, before I added the extra code,


# Get the star id's from the pst file, and display them for the user to choose.
   pstid   = pst_temp
   starid = mktemp ("tmp$pst")
   txdump (pstid, "id", yes, > starid)
   print ("Measured stars' id's!")
   type (starid) 

and relevant variables, declarations, enc...

Hope that answers your Q.

Thanx
Pat

Mike Fitzpatrick wrote on Nov 16, 2006

Pat,

I'm not as psychic as I used to be and "It used to work" isn't a helpful report, what exactly is the error message or problem with the new code?

-Mike

H.J. van Heerden wrote on Nov 16, 2006

Sorry Mike :oops:

Before I edited it, it gave me the correct output. That is. If I entered as input the .pst. files, with a star id of either 5 (to dump all stars from 1:5) or 4' (Dump star number 4), then it created the data files. (star1, star2, star3, ... or star4) With the relevant data included. When I used it on some test data (that i'm using the work out the bugs in the pipeline i'm building), it created the data files without error, to the extend that I could afterwards plot some prelimanary light curves.

What it does now is that it does not give any final output. It prints the message, and the star id file. The it prompts for the rest of the input. After I have entered the relevant files, and star id, the script just seem to do nothing. A blank line appear after the prompt, and when I press enter after a while, it exits.

When I ls the dir. The data file does not appear, i.e. it was not created. It seems that the script does not enter the part where it dumps the text. I think. :?

I tried doing a mkiraf, but did not work. I tried to convert it back to the way it was, but it did not work. The code seem correct. It shouldn't give an error. It can't be that it does not access the files?? I do not specify that it should look for specific files. :cry:

These kind of errors is my death. Seems that nothing is wrong, but still they exits.

Please Help

Thanx
Pat

Mike Fitzpatrick wrote on Nov 16, 2006

Hi Pat,

I still think the problem is with the "scan(nstars)" statement, i.e. that's where it's waiting for the input. If you replace this with something like "print (nstars) | scan(s1)" you'll still be able to check for a value the way I think you want. I copied your script and (think) I got it to run doing this.

Before running the script you can type "cl> d_trace" to toggle the trace flag, at least that will tell you where the script appears to "hang". Hope this helps.

Cheers,
-Mike

H.J. van Heerden wrote on Nov 16, 2006

Hi Mike

It now works. Thanx. It seems that even though I have almost completed a full package for our photometry pipeline, I still need to learn a lott when it comes to coding in Csh.

Regards

Pat :D

Last post on Nov 16, 2006