string matching with where using data from binary FITS
Dear Lajos,
I have an IDL code suite that we are testing under FL.
I am finding a different result in the following case.
I use the function ‘where’ to compare an array of strings to a reference string. The reference string is originally extracted from a FITS file. IDL finds a match and returns the correct array index, but FL returns -1 (i.e. no match found).
It is not obvious why since FL seems to indicate that the strings are the same when I query the variable using print/help.
When I run a simplified version of the code using values that I define in the code itself (i.e. without extracting the reference string from the FITS file), then the matching under FL produces the same output as IDL.
Here is the code snippet that fails under FL:
FITS_RIMO = mrdfits( 'my_rimo_fits.fits', 1, HDR_RIMO )
REF_BOLO=strmid( fits_rimo[ 0 ].detector, 0, 3 ) + '_' + strmid( fits_rimo[ 0 ].detector, 4 )
PRINT,REF_BOLO
HELP,REF_BOLO
BOLO_ID_TMP = [ '00_100_1a', '01_100_1b', '20_100_2a', '21_100_2b', '40_100_3a']
Q_NAME = where( strmid( bolo_id_tmp, 3) eq REF_BOLO )
PRINT,Q_NAME
This produces the following output
MRDFITS: Binary table. 15 columns by 52 rows.
100_1a
REF_BOLO STRING = '100_1a'
-1
Here is the code snippet that functions correctly:
FITS_RIMO = mrdfits( 'my_rimo_fits.fits', 1, HDR_RIMO )
REF_BOLO='100_1a'
PRINT,REF_BOLO
HELP,REF_BOLO
BOLO_ID_TMP = [ '00_100_1a', '01_100_1b', '20_100_2a', '21_100_2b', '40_100_3a']
Q_NAME = where( strmid( bolo_id_tmp, 3) eq REF_BOLO )
PRINT,Q_NAME
This produces the following output
MRDFITS: Binary table. 15 columns by 52 rows.
100_1a
REF_BOLO STRING = '100_1a'
0
I suspect that it is related to the way the information is encoded in the FITS file (first/last bit?).
I have attached the culprit FITS file.
Many thanks fo your help,
Comments (3)
-
repo owner -
repo owner Fixed for the next snapshot.
-
repo owner - changed status to resolved
Closed.
- Log in to comment
Confirmed. Thank you for the report.
I get two extra zero bytes in the string read from the fits file
REF_BOLO STRING = '100_1a^@^@'
This comes probably from reading textual data in binary mode with READU.
There is a simple temporary workaround: convert the string to byte and then to string, again. This removes the extra zeros at the end:
REF_BOLO=STRING(BYTE(REF_BOLO))