<div dir="ltr"><div>Hi,</div><div><br></div><div>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.</div><div><br></div><div><div><a href="http://ncl.ucar.edu/Document/Functions/Built-in/setfileoption.shtml">http://ncl.ucar.edu/Document/Functions/Built-in/setfileoption.shtml</a></div></div><div><br></div><div>Again, I'm just speculating, but it would be easy to test!</div><div><br></div><div>Rick</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 27, 2020 at 1:39 AM 边晴云 via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<p style="font-family:Arial">
        Dear All,
</p>
<p style="font-family:Arial">
        <br>
</p>
<p style="font-family:Arial">
        I was trying to change the value of an int variable in a netcdf file using NCL. Followed are my code:
</p>
<p style="font-family:Arial">
        <br>
</p>
<p style="font-family:Arial">
        <span style="font-family:Arial">begin</span><br>
<br>
<span style="font-family:Arial">fin = addfile("<a href="http://domain_cfg.nc" target="_blank">domain_cfg.nc</a>","rw")</span><br>
<span style="font-family:Arial">data=fin->jperio</span><br>
<span style="font-family:Arial">data_v = new(dimsizes(data),typeof(data),data@_FillValue)</span><br>
<span style="font-family:Arial">data_v = 0</span><br>
<span style="font-family:Arial"><br>
</span><br>
<span style="font-family:Arial">copy_VarMeta(data,data_v)</span><br>
<span style="font-family:Arial">fin->jperio = data_v</span><br>
<br>
<span style="font-family:Arial">end</span><br>
</p>
<p style="font-family:Arial">
        <br>
</p>
<p style="font-family:Arial">
        However, I got the following error message:
</p>
<p style="font-family:Arial">
        --------
</p>
<p style="font-family:Arial">
        fatal:["NclNetCDF4.c":3073]:NclNetCDF4.c: Error in nc_def_var_chunking in file (<a href="http://domain_cfg.nc" target="_blank">domain_cfg.nc</a>) for writing, at line: 3073<br>
<br>
line 3074 of NclNetCDF4.c: NetCDF: Attempt to define var properties, like deflate, after enddef.<br>
</p>
<p style="font-family:Arial">
        <br>
</p>
<p style="font-family:Arial">
        I have no idea how to resolve it. Any suggestions?
</p>
<p style="font-family:Arial">
        Thank you!
</p>
<p style="font-family:Arial">
        <br>
</p>
<p style="font-family:Arial">
        Followed are some information about the  netcdf file.
</p>
<p style="font-family:Arial">
        ---------
</p>
<p style="font-family:Arial">
        netcdf domain_cfg {<br>
dimensions:<br>
        x = 2710 ;<br>
        y = 1542 ;<br>
        z = 75 ;<br>
        t = UNLIMITED ; // (1 currently)<br>
variables:<br>
        float nav_lon(y, x) ;<br>
                nav_lon:_Storage = "chunked" ;<br>
                nav_lon:_ChunkSizes = 135, 206 ;<br>
                nav_lon:_Endianness = "little" ;<br>
        float nav_lat(y, x) ;<br>
                nav_lat:_Storage = "chunked" ;<br>
                nav_lat:_ChunkSizes = 135, 206 ;<br>
                nav_lat:_Endianness = "little" ;<br>
        float nav_lev(z) ;<br>
                nav_lev:_Storage = "chunked" ;<br>
                nav_lev:_ChunkSizes = 1 ;<br>
                nav_lev:_Endianness = "little" ;<br>
        double time_counter(t) ;<br>
                time_counter:_Storage = "chunked" ;<br>
                time_counter:_ChunkSizes = 1 ;<br>
                time_counter:_Endianness = "little" ;<br>
        int jpiglo ;<br>
                jpiglo:_Endianness = "little" ;<br>
        int jpjglo ;<br>
                jpjglo:_Endianness = "little" ;<br>
        int jpkglo ;<br>
                jpkglo:_Endianness = "little" ;<br>
        int jperio ;<br>
                jperio:_Endianness = "little" ;<br>
        double glamt(t, y, x) ;<br>
                glamt:_Storage = "chunked" ;<br>
                glamt:_ChunkSizes = 1, 135, 206 ;<br>
                glamt:_Endianness = "little" ;<br>
        double glamu(t, y, x) ;<br>
                glamu:_Storage = "chunked" ;<br>
                glamu:_ChunkSizes = 1, 135, 206 ;<br>
                glamu:_Endianness = "little" ;<br>
<br>
// global attributes:<br>
                :file_name = "<a href="http://domain_cfg.nc" target="_blank">domain_cfg.nc</a>" ;<br>
                :TimeStamp = "24/08/2020 16:38:57 +0800" ;<br>
                :_NCProperties = "version=1|netcdflibversion=4.4.1|hdf5libversion=1.8.13" ;<br>
                :_SuperblockVersion = 0 ;<br>
                :_IsNetcdf4 = 1 ;<br>
                :_Format = "netCDF-4" ;<br>
</p>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></blockquote></div>