function mg_hdf_dump_typedecl, type, dims
compile_opt strictarr
return, string(type, strjoin(strtrim(dims, 2), ', '), format='(%"%s[%s]")')
end
pro mg_hdf_dump_an, file_id
compile_opt strictarr
an_id = hdf_an_start(file_id)
status = hdf_an_fileinfo(an_id, nFileLabels, nFileDescs, nDataLabels, nDataDescs)
help, nFileLabels, nFileDescs, nDataLabels, nDataDescs
for fl = 0L, nFileLabels - 1L do begin
id = hdf_an_select(an_id, fl, 2)
status = hdf_an_readann(id, annotation)
help, annotation
endfor
hdf_an_end, an_id
end
pro mg_hdf_dump_sd, file_id
compile_opt strictarr
hdf_sd_fileinfo, file_id, ndatasets, nattributes
for a = 0L, nattributes - 1L do begin
hdf_sd_attrinfo, file_id, a, name=attname, count=count, type=atttype
atttypedecl = mg_hdf_dump_typedecl(atttype, count)
print, '', atttypedecl, attname, format='(%"%sATTRIBUTE %s %s")'
endfor
for d = 0L, ndatasets - 1L do begin
sds_id = hdf_sd_select(file_id, d)
hdf_sd_getinfo, sds_id, name=name, natts=natts, type=type, dims=dims
typedecl = mg_hdf_dump_typedecl(type, dims)
print, typedecl, name, format='(%"SD DATASET %s %s")'
for a = 0L, natts - 1L do begin
hdf_sd_attrinfo, sds_id, a, name=attname, count=count, type=atttype
atttypedecl = mg_hdf_dump_typedecl(atttype, count)
print, ' ', atttypedecl, attname, format='(%"%sATTRIBUTE %s %s")'
endfor
endfor
end
pro mg_hdf_dump, filename
compile_opt strictarr
file_id = hdf_sd_start(expand_path(filename))
mg_hdf_dump_sd, file_id
hdf_sd_end, file_id
end
filename = '~/data/modis/MOD021KM.A2010019.1235.005.2010259102219.hdf'
mg_hdf_dump, filename
mg_hdf_dump, filepath('vattr_example.hdf', subdir=['examples', 'data'])
end