[ncl-talk] Writing attributes to variables in HDF5 files
David Jones
jonesd647 at yahoo.ca
Tue Jul 18 12:22:13 MDT 2017
Dear NCL talk,
I was wondering how one can write variables with attributes to HDF5 files. Following the examples on the NCL website I can successfully write variables to HDF5 files, however the variable's attributes are always missing when I perform ncl_filedump or h5dump on the resulting file.
I've pasted a simple script at the end of this mail to illustrate the problem.
Any suggestions would be greatly appreciated!
Best wishes,Dave.
=====================================================================================
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
begin
; Step 1: Make variable
variable = new((/20,20/),"double")
variable = 7.
variable at units = "m"
variable at comment = "this is a comment"
variable at _FillValue = default_fillvalue(typeof(variable))
variable!0 = "y"
variable!1 = "x"
dim_y = dimsizes(variable(:,0))
dim_x = dimsizes(variable(0,:))
; Step 2: Now write this stuff to a HDF5 file with group "Results"
ofile = "hdf5_test_ncl.h5"
system("if [[ -e "+ofile+" ]] ; then rm -f "+ofile+" ; fi")
setfileoption("h5", "FileStructure", "Advanced")
hdf5_data = addfile(ofile,"c")
groupnames = (/"Results"/)
filegrpdef(hdf5_data, groupnames)
g1 = hdf5_data=>/Results
dimNames = (/"y","x"/)
dim_Sizes = (/dim_y,dim_x/)
dimUnlim = (/False,False/)
filedimdef(g1,dimNames,dim_Sizes,dimUnlim)
my = dim_y/2
mx = dim_x/2
chunkSizes = (/my,mx/)
filechunkdimdef(g1,dimNames,chunkSizes,dimUnlim)
filevardef(g1, "OUTVAR", typeof(variable), getvardims(variable))
filevarattdef(g1,"OUTVAR", variable) ; copying the attributes
filevarchunkdef(g1, "OUTVAR", chunkSizes)
filevarcompressleveldef(g1, "OUTVAR", 2)
g1->OUTVAR = (/variable/)
printVarSummary(variable)
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170718/755fc55e/attachment.html
More information about the ncl-talk
mailing list