; ; The purpose of this script is to test a bug that was found in ; HDF5 versions 1.8.0 through 1.8.4, and hence exists in NCL V5.1.1. ; ; This bug seems to manifest itself under all of the following conditions: ; ; - You are using NCL V5.1.1. ; ; - You are writing a NetCDF-4 classic file on a *big endian* machine. ; ; - You are writing more than 10 attributes to either a variable ; or a file. ; ; - You try to read the file back in on a *little endian* machine, either ; with another NCL script, with "ncl_filedump" or "ncl_convert2nc", or ; any other program that reads NetCDF 4 classic files (like h5dump). ; ; This script writes two NetCDF-4 classic files using both the ; efficient and inefficient methods. ; ; [You can write NetCDF-3 files if you set WRITE_NC4 to False, but ; NetCDF-3 files should be fine in V5.1.1.] ; ; Once you run this script, put the two test*nc files it creates ; on a little endian system. Try to run ncl_filedump on these files: ; ; ncl_filedump test_hdf5_bug_ineff_nc4_classic_5.1.1.nc ; ncl_filedump test_hdf5_bug_eff_nc4_classic_5.1.1.nc ; ; If you get an error that looks like this: ; ; fatal:HDF error ; fatal:Could not open (test_hdf5_bug_ineff_nc4_classic_5.1.1.nc) ; Variable: f (file variable) ; (0) File Missing Value : -1 ; ; then you've reproduced the bug. ; begin ; ; Initialize number of variables, attributes, length of arrays, ; attribute and variable names. ; if(.not.isvar("WRITE_NC4")) then WRITE_NC4 = True ; Whether to write netcdf 4 classic or not. end if nvars = 20 natts = 20 nvals = 30 ii = ispan(1,nvals,1) ff = fspan(-100,100,nvals) ff!0 = "dim0" varnames = "var_" + ispan(0,nvars-1,1) attnames = "att_" + ispan(0,natts-1,1) dimNames = "dim0" dimSizes = nvals dimUnlim = False ncl_version = get_ncl_version() ; ; Set up file writing options. ; print("====================================================") if(WRITE_NC4) then ext = "nc4_classic" setfileoption("nc","Format", "NetCDF4Classic") else ext = "nc3" end if print("NetCDF-" + ext) output_file_eff = "test_hdf5_bug_eff_" + ext + "_" + ncl_version + ".nc" output_file_ineff = "test_hdf5_bug_ineff_" + ext + "_" + ncl_version + ".nc" ; ; Remove files first, if they exist. ; if(isfilepresent(output_file_eff)) then system("/bin/rm " + output_file_eff) end if if(isfilepresent(output_file_ineff)) then system("/bin/rm " + output_file_ineff) end if fout_eff = addfile(output_file_eff,"c") ; Open the files for creating fout_ineff = addfile(output_file_ineff,"c") setfileoption(fout_eff,"DefineMode",True) ; Go into define mode ; ; Create some dummy global attributes. ; fatt = True do i=0,natts-1 fatt@$attnames(i)$ = ii fout_ineff@$attnames(i)$ = ii end do fileattdef( fout_eff, fatt ) ; copy file attributes to file delete(fatt) ; ; Predefine the coordinate variables and their dimensionality. ; filedimdef(fout_eff,dimNames,dimSizes,dimUnlim) ; ; Predefine the dimensionality of the variables to be written ; and their attributes. ; do i=0,nvars-1 fout_ineff->$varnames(i)$ = (/ff/) vatts = True filevardef(fout_eff, varnames(i), typeof(ff), getvardims(ff)) ; ; Create some dummy variable attributes. ; vattnames = varnames(i) + "_att_" + ispan(0,natts-1,1) do j=0,natts-1 fout_ineff->$varnames(i)$@$vattnames(j)$ = (/ii/) vatts@$vattnames(j)$ = (/ii/) end do filevarattdef( fout_eff, varnames(i), vatts) delete(vatts) end do ; ; Go out of define mode; we are ready to write actual values to file. ; setfileoption(fout_eff,"DefineMode",False) do i=0,nvars-1 fout_eff->$varnames(i)$ = (/ff/) end do print("") print("Created files '" + output_file_eff + "'") print(" '" + output_file_ineff + "'") print("") print("To finish testing this problem, you must transfer these") print("two files to a little endian machine and see if you can") print("run 'ncl_filedump' on them:") print("") print(" ncl_filedump " + output_file_eff) print(" ncl_filedump " + output_file_ineff) print("") print("If you get an error like this:") print("") print(" fatal:HDF error") print(" fatal:Could not open (test_hdf5_bug_ineff_nc4_classic_5.1.1.nc)") print(" Variable: f (file variable)") print(" (0) File Missing Value : -1") print("") print("then you've reproduced the bug.") print("") print("====================================================") end