function list_hdf_field_names, file_name, COUNT=count list = "" command = "vshow "+ '"'+file_name+'"' + " | grep entries | grep Var" spawn, command, lines ;breaki if lines[0] eq '' then begin ; this is perhaps an unpacked hdf5 format ? print, 'trying h5ls next' command = 'h5ls ' + '"' +file_name+'"' spawn, command, lines if N_elements(lines) eq 1 then begin ; don't know what to do print, 'could not find field names in file:', file_name print, ' do you have vshow (part of hdf4) and h5ls in your path ? ' breaki return, ["no fields found"] endif for i=0,N_elements(lines)-1 do begin hl = strmid(lines[i],0,strpos(lines[i], ' ')+1) if hl ne '' and total(hl eq list) eq 0 then list = [list, hl] print, '>'+hl+'<' endfor endif else begin for i=0,N_elements(lines)-1 do begin lines[i] = strmid(lines[i],strpos(lines[i], '(')+1) curis = strpos(lines[i], '{') hl = strtrim(strmid(lines[i], 0, curis),2) if hl ne '' and total(hl eq list) eq 0 then list = [list, hl] print, '>'+hl+'<' endfor endelse list = list[1:*] if ARG_PRESENT(COUNT) then count=N_elements(list) print, 'read ', N_elements(list), ' data labels from ', file_name ;breaki if N_elements(list) gt 0 then return, list ; else try more conventional way ; return list of strings of labels in hdf file ; if count is a named variable it returns the number of data sets list = '' print, 'list:', file_name dummy = FindFile(file_name , COUNT = exist) if dummy(0) eq '' then BEGIN print, 'read_hdf: the file "', file_name, '" does not exist!' RETURN, list ENDIF sd_id = HDF_SD_START(file_name[0], /READ) HDF_SD_FILEINFO, sd_id, NumSDS, attributes count = 0L n = 0L FOR i=1L,NumSDS DO BEGIN r=0. & l=0. sds_id = HDF_SD_SELECT(sd_id, n) WHILE (HDF_SD_ISCOORDVAR(sds_id)) DO BEGIN HDF_SD_ENDACCESS, sds_id n = n + 1 sds_id = HDF_SD_SELECT(sd_id, n) ENDWHILE n = n + 1 HDF_SD_GETINFO, sds_id, label = l, dims=d, type=t print, i, ' ', l, size(l) if (l NE '') then begin list = [list, l] count = count + 1 endif HDF_SD_ENDACCESS, sds_id ENDFOR HDF_SD_END, sd_id if (N_ELEMENTS(list) gt 1) THEN $ RETURN, list[1:*] $ ELSE BEGIN print, 'having trouble reading labels in ',file_name print, 'returning dummy list' list = 'No labels read ...'; ENDELSE return, '' END