0

I am fairly new to IDL, and I am trying to write a code that will take a MODIS HDF file (level three data MOD14A1 and MYD14A1 to be specific), read the array, and then write the data from the array preferably to a csv file, but ASCII would work, too. I have code that will allow me to do this for one file, but I want to be able to do this for multiple files. Essentially, I want it to read one HDF array, write it to a csv, move to the next HDF file, and then write that array to the same csv file in the next row. Any help here would be greatly appreciated. I've supplied the code I have so far to do this with one file.

filename = dialog_pickfile(filter = filter, path = path, title = title)
csv_file = 'Data.csv'

sd_id = HDF_SD_START(filename, /READ)

; read "FirePix", "MaxT21"

attr_index = HDF_SD_ATTRFIND(sd_id, 'FirePix')
HDF_SD_ATTRINFO, sd_id, attr_index, DATA = FirePix


attr_index = HDF_SD_ATTRFIND(sd_id, 'MaxT21')
HDF_SD_ATTRINFO, sd_id, attr_index, DATA = MaxT21


index = HDF_SD_NAMETOINDEX(sd_id, 'FireMask')
sds_id = HDF_SD_SELECT(sd_id, index)
HDF_SD_GETDATA, sds_id, FireMask
HDF_SD_ENDACCESS, sds_id

index = HDF_SD_NAMETOINDEX(sd_id, 'MaxFRP')
sds_id = HDF_SD_SELECT(sd_id, index)
HDF_SD_GETDATA, sds_id, MaxFRP
HDF_SD_ENDACCESS, sds_id


HDF_SD_END, sd_id

help, FirePix
print, FirePix, format = '(8I8)'
print, MaxT21, format = '("MaxT21:", F6.1, " K")'
help, FireMask, MaxFRP


WRITE_CSV, csv_file, FirePix

After I run this, and choose the correct file, this is the output I am getting:

FIREPIX         LONG      = Array[8]
   0       4       0       0       3      12       3       0
MaxT21: 402.1 K
FIREMASK        BYTE      = Array[1200, 1200, 8]
MAXFRP          LONG      = Array[1200, 1200, 8]

The "FIREPIX" array is the one I want stored into a csv.

Thanks in advance for any help!

asynchronos
  • 583
  • 2
  • 14
wbeck
  • 1
  • 2

1 Answers1

0

Instead of using WRITE_CSV, it is fairly simple to use the primitive IO routines to write a comma-separated array, i.e.:

openw, lun, csv_file, /get_lun

; the following line produces a single line the output CSV file
printf, lun, strjoin(strtrim(firepix, 2), ', ')

; TODO: do the above line as many times as necessary

free_lun, sun
mgalloy
  • 2,356
  • 1
  • 12
  • 10