[ncl-talk] Error in nc_def_var_chunking in file (domain_cfg.nc) for writing

边晴云 bianqy at tea.ac.cn
Wed Oct 28 01:54:12 MDT 2020



Hi Dave and Rick,


Thank you very much for your reply! It works!
Cheers,


边晴云


-----Original Messages-----
From:"Dave Allured - NOAA Affiliate" <dave.allured at noaa.gov>
Sent Time:2020-10-28 03:22:38 (Wednesday)
To: "边晴云" <bianqy at tea.ac.cn>
Cc: bianqy818 at 163.com, ncl-talk at ucar.edu
Subject: Re: [ncl-talk] Error in nc_def_var_chunking in file (domain_cfg.nc) for writing


边晴云, you want to change the value of an existing variable in a netcdf file.


(1)  As Rick indicated, change the addfile open mode from "rw" which is invalid, to just "w".  See documentation for addfile.

(2)  Remove this line, it is not needed:


    copy_VarMeta(data,data_v)

(3)  Change this line:


    From:  fin->jperio = data_v
    To:    fin->jperio = (/ data_v /)

This is called "value-only assignment" in the NCL users manual.  This change will overwrite only the actual data values, and not try to change any metadata.  I think this will avoid the define error that you are getting.




On Tue, Oct 27, 2020 at 8:28 AM Rick Brownrigg via ncl-talk <ncl-talk at mailman.ucar.edu> wrote:

Hi,


I don't know the issue for certain. However, "rw" is not a valid open mode -- its either "r" (read) or "w" (read-write), and I am speculating that the code is looking at only the first character and proceeding from there, in which case the file would be in read mode. "enddef" refers to ending "define mode", which is an esoteric property of NetCDF files whereby one must define structural properties (vars, shapes, dims, etc.) before writing the actual data. If you read the description of "DefineMode" at the link below, it indicates the file would only be in define mode if opened for writing.


http://ncl.ucar.edu/Document/Functions/Built-in/setfileoption.shtml


Again, I'm just speculating, but it would be easy to test!


Rick




On Tue, Oct 27, 2020 at 1:39 AM 边晴云 via ncl-talk <ncl-talk at mailman.ucar.edu> wrote:




Dear All,




I was trying to change the value of an int variable in a netcdf file using NCL. Followed are my code:




begin

fin = addfile("domain_cfg.nc","rw")
data=fin->jperio
data_v = new(dimsizes(data),typeof(data),data at _FillValue)
data_v = 0

copy_VarMeta(data,data_v)
fin->jperio = data_v

end




However, I got the following error message:

--------

fatal:["NclNetCDF4.c":3073]:NclNetCDF4.c: Error in nc_def_var_chunking in file (domain_cfg.nc) for writing, at line: 3073

line 3074 of NclNetCDF4.c: NetCDF: Attempt to define var properties, like deflate, after enddef.




I have no idea how to resolve it. Any suggestions?

Thank you!




Followed are some information about the  netcdf file.

---------

netcdf domain_cfg {
dimensions:
        x = 2710 ;
        y = 1542 ;
        z = 75 ;
        t = UNLIMITED ; // (1 currently)
variables:
        float nav_lon(y, x) ;
                nav_lon:_Storage = "chunked" ;
                nav_lon:_ChunkSizes = 135, 206 ;
                nav_lon:_Endianness = "little" ;
        float nav_lat(y, x) ;
                nav_lat:_Storage = "chunked" ;
                nav_lat:_ChunkSizes = 135, 206 ;
                nav_lat:_Endianness = "little" ;
        float nav_lev(z) ;
                nav_lev:_Storage = "chunked" ;
                nav_lev:_ChunkSizes = 1 ;
                nav_lev:_Endianness = "little" ;
        double time_counter(t) ;
                time_counter:_Storage = "chunked" ;
                time_counter:_ChunkSizes = 1 ;
                time_counter:_Endianness = "little" ;
        int jpiglo ;
                jpiglo:_Endianness = "little" ;
        int jpjglo ;
                jpjglo:_Endianness = "little" ;
        int jpkglo ;
                jpkglo:_Endianness = "little" ;
        int jperio ;
                jperio:_Endianness = "little" ;
        double glamt(t, y, x) ;
                glamt:_Storage = "chunked" ;
                glamt:_ChunkSizes = 1, 135, 206 ;
                glamt:_Endianness = "little" ;
        double glamu(t, y, x) ;
                glamu:_Storage = "chunked" ;
                glamu:_ChunkSizes = 1, 135, 206 ;
                glamu:_Endianness = "little" ;

// global attributes:
                :file_name = "domain_cfg.nc" ;
                :TimeStamp = "24/08/2020 16:38:57 +0800" ;
                :_NCProperties = "version=1|netcdflibversion=4.4.1|hdf5libversion=1.8.13" ;
                :_SuperblockVersion = 0 ;
                :_IsNetcdf4 = 1 ;
                :_Format = "netCDF-4" ;









边晴云 中国科学院大气物理研究所

TEL:18710037107

★☆活着,其实就是活一种精神状态~~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201028/1e2148f5/attachment.html>


More information about the ncl-talk mailing list