Search code examples
formatidl

IDL read RA and Dec format


i would like to read some RA and Dec values from a file to find only the unique ones. This will then be printed to a new file with only unique information associated with each RA and Dec.

The file contains starId, RA, Dec, Mag, Temp, ....

0001, 19:20:21.22, 37:40:43.5, 14.6, 5432, ...

readcol,'/filepath/filename.txt',starId,RA,DEC,Mag, Temp, format='L,A,A,D,D',/silent
idx = uniq(starId)

when i try to write the unique list to a file

openw,2,'/filepath/uniqlist.txt'
printf,2,[transpose([starId[idx]), transpose(RA[idx]), transpose(Dec[idx])]
close,2

I only get the first value of the RA and Dec

Can anyone help, what format specifiers can i use to read or write the correct information to the file


Solution

  • I didn't find a solution, but i did find a work around

    It turns out that it was the array brackets '[ ]' in the printf statement that seem to cause the problem.

    The work around is printing to file the old fashioned way using a loop

    idx = uniq(starId)
    openw,2,'/filepath/uniqlist.txt'
    for i = 0, n_elements(idx)-1 do begin
        printf,2, starId[idx[i]],'   ',RA[idx[i]],'  ',DEC[idx[i]],
    endfor
    close, 2
    

    Not ideal, but it does work.

    I would still be interested in a better solution if someone has one.