View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Hopefully just a basic syntax problem..

Andrew Staunton wrote on Nov 30, 2010

Hi there

I am trying a most basic step of grouping images by their JD keyword (from within a script)..the values often end one digit after the decimal place ie. 123.4 or 456.7 and for my purposes I have assigned these values to the integer variable i to eliminate this final digit when reading from a file so the two example numbers become 123 and 456 respectively..
The problem I am having is with the hselect command and here is the relevant code:

list="uniquedate.txt"

while (fscan(list,i) != EOF){
s1=str(i)
hselect ("@all.txt",
"(JD == s1*)", missing="INDEF",>>s1//".txt")
}

explanation of the above code:
all.txt holds a list of all the fits files
uniquedate.txt holds all the unique dates, one date per line so the first few lines of the file might read:
2452713.3
2452713.4
2452714.5
2452714.6
2452714.7
as I said earlier I am only interesting in grouping by the integer part of the date so the teo groups I want to create are:
2452713
2452714
So to truncate the dates I read it with integer variable i converted to string mainly so I could name my textfile as in the very final bit of the code:
s1//".txt".
what I want to do then is "(JD == i*)". hopefully that means that if JD = (i + anything else appended to the end) the it will write that to the file s1//".txt". I am gettin an error "image head parameter not found. I have tried inserting my string variable instead as in: "(JD == s1*)" but get the same error...it seems like this should work.. Note I want the metacharacter '*' because as I said my s1 value for the date was truncated however the value that hselect is reading will be the full value as in 456.7 and so I think 456.7 == s1* is like saying 456.7 == 456* and so any 456 date with any decimal place will fall into that category..I hope I am being clear here.

Would appreciate any advice

Andrew

Mike Fitzpatrick wrote on Nov 30, 2010

I think the problem is simply in the expression: The '?=' is the string comparator operator and works differently than '==' which is an exact equality. You'll also want to construct the expression to use the value of the 's1' script variable and quote the value. For example,

"(JD ?= '"//s1//"*')"


This creates the expression

"(JD ?= '2452713*')"


to be used.

Andrew Staunton wrote on Nov 30, 2010

Thanks for the helpful feedback.

I since discovered that the following lines of code might be better for dealing with the final digit than what I was looking at yesterday :
cat ("uniquedate.txt") | translit ("STDIN",".", " ", delete=no, collapse=no) |fields ("STDIN","1", lines="1-", quit_if_miss=no, print_file_n=no,>"temp.txt")
sort ("temp.txt",column=0, ignore_white=no, numeric_sort=no, reverse_sort=no) | unique (>"night.txt" )

so the code that I queried you with yesterday has reduced to:

list="night.txt"
while (fscan(list,i) != EOF){
s1=str(i)
hselect ("@all.txt", "$I", "JD ?= "//s1//"", missing="",>>s1//".txt")
}

where night.txt holds the integer values of the relevant dates in my case:
2452713
2452714
2452715
2452716

I am now having trouble with the boolean expression "JD ?= "//s1//""
With the current syntax, the script runs, and creates the files: 2452713.txt to 2452716.txt however it is not inserting the names of the fits files whose JD keywords are a match..ie all the .txt files are created but are blank..
I am guessing the the problem is that the boolean expression is looking at "//s1//" as a string instead of using the value of s1 (which is what I want).

I believe that the metacharacter "*" can be done away with as using the '?=' comparison operator means the digits after the decimal point will be ignored (but I may be wrong)..
I also tried: "JD ?= ' "//s1//"*' " but I am getting error: operands have incompatible types called as: 'cl ()'

All this is within a script (.cl) file by the way in case that changes things in any way..

Any advice would be appreciated

Andrew

Mike Fitzpatrick wrote on Nov 30, 2010

You're right that the '?=' operator will match a substring and so the '*' in the expression isn't needed. However, the '?=' operator is only valid if the JD keyword is actually a string, i.e. is the value in the header quoted? If not, then try and expression like

"int(JD) == "//s1


This will truncate the floating point value to integer and then compare against the value in the 's1' variable.

Last post on Nov 30, 2010