Script Problem
craigswenson wrote on Aug 14, 2007
I was having problems with nstar not placing stars that wander off the frame in the .nrj file and posted a question which nobody responded to, so I ended up writing a little script to try and insert the missing stars into the files myself. Unfortunately, it's getting hung up. Here's the code:
The problem seems to be on this line:
When the script reaches that point I get the error "cannot open star-1.joined for writing". But if I manually enter the exact same code at the cl prompt and then continue the script starting on the next line, everything runs just fine and the .lst files are created just the way I want them to be.
Any ideas? I don't really understand why I'm getting a "writing" error, since I'm not trying to write anything to a file.
-Craig
#Declare all necessary variables
string s1 = ""
string s2 = ""
string s3 = ""
string s4 = ""
string s5 = ""
string id
string mag
string otime
string xairmass
string ifilter
int starid
int n = 1
int l = 1
struct *list1
struct *list2
struct *list3
#Combine .nst and .nrj files together into a .concat file, and psort id in .concat
sections ("a-*.fits", opt="fullname", > "datalistfits")
match (".fits.","datalistfits",stop+,>"datalistimages")
sed 's/.fits/.fits.nst.1/g' "datalistimages" > "datalistnst"
sed 's/.fits/.fits.nrj.1/g' "datalistimages" > "datalistnrj"
sed 's/.fits/.concat/g' "datalistimages" > "datalistconcat"
joinlines ("datalistimages"//","//"datalistnst"//","//"datalistnrj"//","//"datalistconcat", > "datalistfull")
list = "datalistfull"
while(fscan(list,s1,s2,s3,s4) != EOF){
pconcat (s2//","//s3, s4)
psort (s4,"ID")
}
del data*
#Pull out the columns from .concat files needed for use in varstar into files called star*.joined
sections ("*.concat", opt="fullname", > "datalistconcat")
list1 = "datalistconcat"
while(fscan(list1,s1) != EOF){
for(l=1;l<=sections.nimages; l+=1){
txdump (s1, "id"//","//"mag"//","//"otime"//","//"xairmass"//","//"ifilter", yes, > "star-"//(l)//".joined")
}
}
#Add missing stars into star*.joined files and create .lst files for varstar
sections ("*.joined", opt="fullname", > "dataliststarfiles")
list2 = "dataliststarfiles"
while(fscan(list2,s5) != EOF){
list3 = (s5)
while(fscan(list3,id,mag,otime,xairmass,ifilter) != EOF){
starid = int(id)
while(starid>=n){
if(starid==n){
print(starid,>>"datalistid")
print(mag,>>"datalistmag")
print(otime,>>"datalistotime")
print(xairmass,>>"datalistairmass")
print(ifilter,>>"datalistfilter")
};
if(starid!=n){
print(n,>>"datalistid")
print("INDEF",>>"datalistmag")
print(otime,>>"datalistotime")
print(xairmass,>>"datalistairmass")
print(ifilter,>>"datalistfilter")
};
n=n+1
}
}
joinlines ("datalistid"//","//"datalistmag"//","//"datalistotime"//","//"datalistairmass"//","//"datalistfilter", > (s5)//".lst")
del data*
n = 1
}
The problem seems to be on this line:
sections ("*.joined", opt="fullname", > "dataliststarfiles")
When the script reaches that point I get the error "cannot open star-1.joined for writing". But if I manually enter the exact same code at the cl prompt and then continue the script starting on the next line, everything runs just fine and the .lst files are created just the way I want them to be.
Any ideas? I don't really understand why I'm getting a "writing" error, since I'm not trying to write anything to a file.
-Craig
Mike Fitzpatrick wrote on Aug 14, 2007
Craig,
I suspect the problem is in the TXDUMP call earlier in the script where star-1.joined is created. This is done in a loop and with a single '>' for the redirection meaning it gets overwritten. If you really want to overwrite, you should set the 'clobber' variable to allow this, otherwise use '>>' to append within the loop.
I looked briefly at your earlier post but couldn't think of a reason why the star wouldn't appear in the reject file as advertised. If you could put together a small test dataset and example of how it fails I'd be happy to look again.
Cheers,
-Mike
I suspect the problem is in the TXDUMP call earlier in the script where star-1.joined is created. This is done in a loop and with a single '>' for the redirection meaning it gets overwritten. If you really want to overwrite, you should set the 'clobber' variable to allow this, otherwise use '>>' to append within the loop.
I looked briefly at your earlier post but couldn't think of a reason why the star wouldn't appear in the reject file as advertised. If you could put together a small test dataset and example of how it fails I'd be happy to look again.
Cheers,
-Mike
craigswenson wrote on Aug 14, 2007
Thanks, Mike. That's something Paul and I didn't know. I guess you learn something new every day.
Last post on Aug 14, 2007