Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
Writing a structure containing empty strings
This message and the next one address long-standing problems I've had with IDL software to handle the FITS data format used in astronomy. When writing an IDL structure, str, to FITS format, the following simple code *almost* works. openw,lun, 'output.dat',/get_lun writeu,lun, str free_lun, lun The only problem occurs if one of the structure tags contains an empty string. What I want is for IDL to write a zeroed byte (0b), but IDL simply ignores the tag and doesn't write anything. Note that IDL does understand 0b as the byte representation of an empty string: IDL> print,strlen(string(0b)) 0 IDL> print,byte('') 0 but it simply skip over an empty string when performing I/O. So my first thought is to convert the string tags to bytes, but this has two problems: (1) one can't directly change the data type of a structure tag and (2) converting a string array to byte forces everything to a fixed length. So right now, I loop over every element and every tag of the structure and write it to disk:, if it is a string tag I test for the presence of an empty string, and then further loop over the string array to convert every element to a byte array before writing to disk. So simple code that *almost* works, requires a major revision to completely work. Or am I missing a simpler solution?