PRO HDFDUMP_ATT_PRINT, OUTLUN, SD_ID, VARNAME, ATTNAME, $ GLOBAL=GLOBAL, NOTRUNCATE=NOTRUNCATE, FULL=FULL ;- Print all attributes for this variable ;- Get attribute information attinfo = hdf_sd_attinfo(sd_id, varname, attname, global=keyword_set(global)) attdata = attinfo.data ;- Convert attribute data to string if (size(attdata, /tname) eq 'BYTE') then attdata = fix(attdata) if (size(attdata, /tname) ne 'STRING') then begin attdata = string(attdata) nelems = n_elements(attdata) if (nelems gt 1) then attdata[0:nelems-2] = attdata[0:nelems-2] + ',' endif ;- Truncate long data strings truncate = 0 if (keyword_set(notruncate) eq 0) then begin maxlen = 160 truncloc = where(strlen(attdata) gt maxlen, count) if (count gt 0) then begin truncate = 1 attdata[truncloc] = strmid(attdata[truncloc], 0, maxlen) endif endif ;- Print the attribute name and data nelem = strcompress(n_elements(attinfo.data), /remove_all) if ((truncate eq 1) and keyword_set(full)) then begin printf, outlun, attname, ': ', attinfo.type, ' [', nelem, ']', ' (output truncated)', $ format='(8x, 7a)' endif else begin printf, outlun, attname, ': ', attinfo.type, ' [', nelem, ']', $ format='(8x, 6a)' endelse if keyword_set(full) then printf, outlun, attdata, format='(12x, 5a)' END ;------------------------------------------------------------------------------- PRO HDFDUMP, FILENAME, NOSORT=NOSORT, NOTRUNCATE=NOTRUNCATE, FULL=FULL, $ OUTFILE=OUTFILE ;- Check arguments if (n_params() ne 1) then message, 'Usage: HDFDUMP, FILENAME' if (n_elements(filename) eq 0) then message, 'Argument FILENAME is undefined' ;- Set output logical unit number to stdout or file if (n_elements(outfile) eq 0) then begin outlun = -1 endif else begin openw, outlun, outfile, /get_lun endelse ;------------------------------------------------------------------------------- ;- GET FILE STATUS ;------------------------------------------------------------------------------- ;- Get file information finfo = fileinfo(filename[0]) ;- Check file existence if (finfo.exist ne 1) then begin text = string(filename, format='("File does not exist: ", a)') message, text, /continue return endif ;- Check read access if (finfo.read ne 1) then begin text = string(filename, format='("File does not allow read access: ", a)') message, text, /continue return endif ;- Check HDF format if (finfo.hdf ne 1) then begin text = string(filename, format='("File is not HDF: ", a)') message, text, /continue return endif ;- Get HDF version number hdfid = hdf_open(finfo.name) hdf_lib_info, hdfid, version=file_version hdf_close, hdfid ;- Get IDL HDF version number hdf_lib_info, version=idl_version ;- Print file information printf, outlun, '' printf, outlun, '---------- FILE INFORMATION ----------' fmt = '(/, "File : ", a)' printf, outlun, finfo.name, format=fmt fmt = '("Size (bytes) : ", a)' printf, outlun, strcompress(finfo.size, /remove_all), format=fmt fmt = '("HDF Version : ", a)' printf, outlun, file_version, format=fmt fmt = '("IDL Version : ", a, " for ", a)' printf, outlun, !version.release, !version.os, format=fmt fmt = '("IDL HDF Version: ", a)' printf, outlun, idl_version, format=fmt ;------------------------------------------------------------------------------- ;- GET SCIENTIFIC DATASET INFORMATION ;------------------------------------------------------------------------------- ;- Open the file in SDS mode sd_id = hdf_sd_start(finfo.name) ;- Get list of SDS variable names varlist = hdf_sd_varlist(sd_id) ;- Print number of SDS variables printf, outlun, '' printf, outlun, '---------- SCIENTIFIC DATASETS ----------' fmt = '(/, "NUMBER OF VARIABLES: ", a, /) printf, outlun, strcompress(varlist.nvars, /remove_all), format=fmt ;- Sort the list of variable names if ((varlist.nvars gt 0) and (keyword_set(nosort) eq 0)) then $ varlist.varnames = varlist.varnames[sort(varlist.varnames)] ;------------------------------------------------------------------------------- ;- PRINT INFORMATION FOR EACH VARIABLE ;------------------------------------------------------------------------------- ;- Loop through each variable varindex = 0 while (varindex lt varlist.nvars) do begin ;- Get information for this variable varname = varlist.varnames[varindex] varinfo = hdf_sd_varinfo(sd_id, varname) ;- Save dimension information if (varindex eq 0) then begin dimnam_save = varinfo.dimnames dimval_save = varinfo.dims endif else begin dimnam_save = [dimnam_save, varinfo.dimnames] dimval_save = [dimval_save, varinfo.dims] endelse ;- Extract unique dimension names and values uniq_index = uniq(dimnam_save, sort(dimnam_save)) dimnam_save = dimnam_save(uniq_index) dimval_save = dimval_save(uniq_index) ;- Construct dimension name list dimnames = '' ndims = varinfo.ndims if (ndims gt 0) then begin dimnames = varinfo.dimnames if (ndims gt 1) then begin dimnames[0 : ndims - 2] = dimnames[0 : ndims - 2] + ', ' endif dimnames = ['[', dimnames, ']'] endif ;- Print information for this variable printf, outlun, varinfo.name, ": ", varinfo.type, ' ', dimnames, $ format='(4x, 50a)' ;- Get attribute information for this variable attlist = hdf_sd_attlist(sd_id, varname) natts = attlist.natts ;- Sort the attribute names if (keyword_set(nosort) eq 0) then begin sort_index = sort(attlist.attnames) attlist.attnames = attlist.attnames[sort_index] endif ;- Print name and value for each attribute if (natts gt 0) then for attindex = 0, natts - 1 do $ hdfdump_att_print, outlun, sd_id, varname, attlist.attnames[attindex], $ notruncate=keyword_set(notruncate), full=keyword_set(full) ;- Increment index varindex = varindex + 1 endwhile ;------------------------------------------------------------------------------- ;- PRINT INFORMATION FOR EACH DIMENSION ;------------------------------------------------------------------------------- ;- Print dimension information if (n_elements(dimnam_save) gt 0) then begin ;- Sort dimension names and values if (keyword_set(nosort) eq 0) then begin sort_index = sort(dimnam_save) dimnam_save = dimnam_save(sort_index) dimval_save = dimval_save(sort_index) endif ;- Print information for each dimension printf, outlun, '' fmt = '("NUMBER OF DIMENSIONS: ", a, /)' printf, outlun, strcompress(n_elements(dimnam_save), /remove_all), format=fmt for index = 0, n_elements(dimnam_save) - 1 do begin printf, outlun, dimnam_save[index], strcompress(dimval_save[index], /remove_all), $ format='(4x, a, " = ", a)' endfor endif ;------------------------------------------------------------------------------- ;- GET GLOBAL ATTRIBUTE INFORMATION ;------------------------------------------------------------------------------- ;- Get global attribute information attlist = hdf_sd_attlist(sd_id, '', /global) natts = attlist.natts ;- Print global attribute information printf, outlun, '' printf, outlun, '---------- GLOBAL ATTRIBUTES ----------' fmt ='(/, "NUMBER OF GLOBAL ATTRIBUTES: ", a, /)' printf, outlun, strcompress(attlist.natts, /remove_all), format=fmt ;- Sort the attribute names if (keyword_set(nosort) eq 0) then begin sort_index = sort(attlist.attnames) attlist.attnames = attlist.attnames[sort_index] endif ;- Print name and value for each attribute if (natts gt 0) then for attindex = 0, natts - 1 do $ hdfdump_att_print, outlun, sd_id, '', attlist.attnames[attindex], $ /global, notruncate=keyword_set(notruncate), full=keyword_set(full) ;- Close the file in SDS mode hdf_sd_end, sd_id ;------------------------------------------------------------------------------- ;- GET VDATA INFORMATION ;------------------------------------------------------------------------------- ;- Open the input file in HDF mode hdfid = hdf_open(finfo.name) ;- Get vdata list vdatalist = hdf_vd_vdatalist(hdfid, /nullclass) ;- Print global attribute information printf, outlun, '' printf, outlun, '---------- VDATAS ----------' fmt ='(/, "NUMBER OF VDATAS: ", a, /)' printf, outlun, strcompress(vdatalist.nvdatas, /remove_all), format=fmt ;- Sort the list of variable names if ((vdatalist.nvdatas gt 0) and (keyword_set(nosort) eq 0)) then $ vdatalist.vdatanames = vdatalist.vdatanames[sort(vdatalist.vdatanames)] ;- Loop through each variable vdataindex = 0 while (vdataindex lt vdatalist.nvdatas) do begin ;- Get information for this variable vdataname = vdatalist.vdatanames[vdataindex] vdatainfo = hdf_vd_vdatainfo(hdfid, vdataname) printf, outlun, vdatainfo.name, ' [', strcompress(vdatainfo.nrecords, /remove_all), ']', $ format='(4x, 4a)' ;- Sort the field names if (keyword_set(nosort) eq 0) and (vdatainfo.nfields gt 0) then $ vdatainfo.fieldnames = vdatainfo.fieldnames[sort(vdatainfo.fieldnames)] ;- If this vdata contains fields, print each field fieldindex = 0 while (fieldindex lt vdatainfo.nfields) do begin ;- Read this field if number of records is greater than zero fieldname = vdatainfo.fieldnames[fieldindex] if (vdatainfo.nrecords gt 0) then begin hdf_vd_vdataread, hdfid, vdataname, fieldname, data typename = size(data, /tname) endif else begin typename = 'UNKNOWN' endelse ;- Convert attribute data to string if (vdatainfo.nrecords gt 0) then begin if (size(data, /tname) eq 'BYTE') then data = fix(data) if (size(data, /tname) ne 'STRING') then begin data = string(data) nelems = n_elements(data) if (nelems gt 1) then data[0:nelems-2] = data[0:nelems-2] + ',' endif endif ;- Print this field printf, outlun, vdatainfo.fieldnames[fieldindex], ': ', typename, $ format='(8x, 3a)' if keyword_set(full) and (vdatainfo.nrecords gt 0) then $ printf, outlun, data, format='(12x, 5a)' ;- Increment field index fieldindex = fieldindex + 1 endwhile ;- Increment vdata index vdataindex = vdataindex + 1 endwhile ;- Close the input file in HDF mode hdf_close, hdfid ;- Close the output file if required if (n_elements(outfile) ne 0) then free_lun, outlun END