[ncl-talk] Issue writing to netcdf4

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Wed Jun 19 08:19:30 MDT 2019


Andrew,

Here are some debugging tips.  You said you get a fatal error on this line:

filevardef(fo, "peaks", typeof(names_14ers), getvardims(names_14ers))

This uses functions within a function.  This is usually okay.  However, it
is a little complicated, and gets in the way of debugging.

So break out typeof and getvardims into separate lines.  Assign each to a
unique variable.  Print each variable before calling filevardef.  Then call
filevardef using the new variables as calling arguments, not functions
within a function.

Also for debugging and conversing with the mailing list, reduce a copy of
your program down to the absolute minimum to trigger the error.  Keep only
addfile and the minimum necessary to get to that filevardef statement.
Then call exit immediately after filevardef.

If the source of the fatal error does not become obvious, then please post
a complete copy of the reduced test script, and a complete copy of the
console output from the test script.  In-line or attachments of type *.txt
work best.

--Dave


On Tue, Jun 18, 2019 at 8:56 PM Andrew Kren - NOAA Affiliate via ncl-talk <
ncl-talk at ucar.edu> wrote:

> Hi ncl-talk,
>
> I'm writing a number of variables to netcdf-4. The variables are a mix of
> intengers, strings, and floats so I thought netcdf4 is the right way to go.
>
> I followed instructions on the ncl support page, but appear to be getting
> issues with writing the data.
>
> *I have this written below. More is written after it but it fails before
> getting to the rest.*
>
> filo = "/home/arsenic1/scripts/gfs/" + utc_start + "z/
> saved_14er_variables_gfs_new.nc"
>
> ;===================================================================
>
>
>  setfileoption("nc", "Format",  "NetCDF4")
>
>  fon = filo
>
>  system("/bin/rm -f " + fon) ; remove if exists
>
>  fo = addfile(fon, "c")
>
>
> ;===================================================================
>
> ; explicitly declare file definition mode. Improve efficiency.
>
> ;===================================================================
>
>  setfileoption(fo,"DefineMode",True)
>
>
>  ; create global attributes of the file
>
>  ;===================================================================
>
>  fAtt               = True            ; assign file attributes
>
>  fAtt at title         = "GFS 14er Data File"
>
>  fAtt at source_file   = filo
>
>  fAtt at Conventions   = "None"
>
>  fAtt at creation_date = systemfunc ("date")
>
>  fileattdef(fo, fAtt)   ; copy file attributes
>
>
> ;===================================================================
>
> ; predefine the coordinate variables and their dimensionality
>
> ; Note: to get an UNLIMITED record dimension, we set the dimensionality
>
> ; to -1 (or the actual size) and set the dimension name to True.
>
> ;===================================================================
>
>  dimNames = (/"peaks","time"/)
>
>  dimSizes = (/dimsizes(names_14ers),dimsizes(fcst_hr)/)
>
>  dimUnlim = (/False,False/)
>
>  filedimdef(fo, dimNames, dimSizes, dimUnlim)
>
>
>  mtim = dimsizes(fcst_hr)
>
>  mname = dimsizes(names_14ers)
>
>  chunkSizes = (/ mtim, mname/)
>
>  filechunkdimdef(fo,dimNames,chunkSizes,dimUnlim)
>
>
>  grpnames = (/"grp1", "group2", "g3"/)
>
>  filegrpdef(fo,grpnames)
>
>
>  ; predefine the the dimensionality of the variables to be written out
>
>  ;===================================================================
>
>  ; Here we are using NCL functions to facilitate defining
>
>  ; each variable's dimension name(s) and type.
>
>  ;===================================================================
>
>  filevardef(fo, "peaks", typeof(names_14ers), getvardims(names_14ers))
>
>  filevarattdef(fo,"peaks", names_14ers)                   ; copy time
> attributes
>
>  fo->peaks   = (/names_14ers/)
>
> The program gives a fatal error at the green line, and I'm not sure why.
> My actual dims of my variables are name by time so I'm confused. When I do
> an ncl_filedump on the file, I get this message in the report:
>
> *ERROR: Invalid _NCProperties attribute*
>
>
> Any help on this is much appreciated, as I have tried a number of
> different ways to rectify this.
>
>
> Thanks!
>
> --
> Andrew Kren
> Assistant Scientist
> University of Miami CIMAS - NOAA/AOML
> Global Observing Systems Analysis (GOSA) Group
> NOAA/AOML Quantitative Observing System Assessment Program (QOSAP)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190619/2d1d9819/attachment.html>


More information about the ncl-talk mailing list