<div dir="ltr">Rick,<div><br></div><div>I discovered that my current complaint is all due to the underlying Netcdf library, currently version 4.4.1.  I would not have sent an NCL bug report if I had realized this earlier.  I do intend to report this back to Netcdf.</div><div><br></div><div>In Netcdf-4 file format, there is apparently a restriction that _FillValue may not be changed after data is written.  This is a notable difference from Netcdf-3 format.  Functions in the nc_put_att family list this possible error, which I think applies to Netcdf-4 file access only:<br><br>    NC_ELATEFILL -- Fill values must be written while the file is still in initial define mode.<br><br>This is probably due to the underlying HDF5 layer:<br><br>    &quot;the fill value for a dataset cannot be modified once the dataset has been created&quot;<br>    <a href="https://support.hdfgroup.org/HDF5/hdf5-quest.html#pfillvalue">https://support.hdfgroup.org/HDF5/hdf5-quest.html#pfillvalue</a><br><br>This is why I think the correct response for both NCL and C programs should be to fail with NC_ELATEFILL or equivalent, rather than &quot;just work&quot;.  To &quot;just work&quot; might involve a large performance penalty along the lines of scanning or re-writing the entire file variable.  Either way, previous data should not be erased, i.e. set to _FillValue.</div><div class="gmail_extra"><br></div><div class="gmail_extra">--Dave</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Mar 28, 2017 at 4:44 PM, Rick Brownrigg <span dir="ltr">&lt;<a href="mailto:brownrig@ucar.edu" target="_blank">brownrig@ucar.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div>Hi Dave,<br><br></div>I will look into this and likely file a bug report. At one point, there was an issue whereby if _FillValue (or any attribute) was added to a variable, it caused all the other attributes to be dropped (but the data was preserved). This was traced to a bug in the underlying NetCDF library, which was fixed in version 4.4.1 around summer 2016.  The NetCDF library was going to a lot of effort to make it possible to rewrite a preexisting variable, so I would think the correct response is for it to &quot;just work&quot;, rather than error out and do nothing?<br><br></div>Rick<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 28, 2017 at 2:59 PM, Dave Allured - NOAA Affiliate <span dir="ltr">&lt;<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">NCL team,<div><br></div><div>Under some conditions, adding a _FillValue attribute to an existing Netcdf-4 file erases previous data.  I find this behavior with both NCL 6.3.0 and 6.4.0 on Mac OS 10.11 (El Capitan).  I get the same behavior with both netcdf4-classic and full netcdf4 formats.</div><div><br></div><div><div>mac56:~/ncl/bugs/fillvalue1 2&gt; ncdump -s <a href="http://test3.nc" target="_blank">test3.nc</a> </div><div>netcdf test3 {</div><div>dimensions:</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>dim = 10 ;</div><div>variables:</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>int var(dim) ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>var:_Storage = &quot;contiguous&quot; ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>var:_Endianness = &quot;little&quot; ;</div><div><br></div><div>// global attributes:</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>:_NCProperties = &quot;version=1|netcdflibversion=4.<wbr>4.1|hdf5libversion=1.8.17&quot; ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>:_SuperblockVersion = 0 ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>:_IsNetcdf4 = 1 ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>:_Format = &quot;netCDF-4 classic model&quot; ;</div><div>data:</div><div><br></div><div> var = 11, 22, 33, 44, 55, _, _, _, _, _ ;</div><div>}</div><div><br></div><div>mac56:~/ncl/bugs/fillvalue1 3&gt; ncl</div><div> Copyright (C) 1995-2017 - All Rights Reserved</div><div> University Corporation for Atmospheric Research</div><div> NCAR Command Language Version 6.4.0</div><div> The use of this software is governed by a License Agreement.</div><div> See <a href="http://www.ncl.ucar.edu/" target="_blank">http://www.ncl.ucar.edu/</a> for more details.</div><div>ncl 0&gt; f=addfile(&quot;<a href="http://test3.nc" target="_blank">test3.nc</a>&quot;,&quot;w&quot;)</div><div>ncl 1&gt; f-&gt;var@_FillValue = 99</div><div>ncl 2&gt; exit</div><div><br></div><div>mac56:~/ncl/bugs/fillvalue1 4&gt; ncdump -s <a href="http://test3.nc" target="_blank">test3.nc</a></div><div>netcdf test3 {</div><div>dimensions:</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>dim = 10 ;</div><div>variables:</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>int var(dim) ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>var:_FillValue = 99 ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>var:_Storage = &quot;contiguous&quot; ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>var:_Endianness = &quot;little&quot; ;</div><div><br></div><div>// global attributes:</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>:_NCProperties = &quot;version=1|netcdflibversion=4.<wbr>4.1|hdf5libversion=1.8.17&quot; ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>:_SuperblockVersion = 0 ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>:_IsNetcdf4 = 1 ;</div><div><span class="gmail-m_-8821085031259303329m_7077803766920794331m_7973063563983683359m_6761569823105552128gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>:_Format = &quot;netCDF-4 classic model&quot; ;</div><div>data:</div><div><br></div><div> var = _, _, _, _, _, _, _, _, _, _ ;</div><div>}</div></div><div><br></div><div>In my opinion, the correct response for netcdf-4 formats should be an error, something like &quot;Can not change _FillValue after data is written in netcdf-4&quot;, and the file is unchanged.  In any case, previous data should not be silently erased.  If you agree, please fix this for the next release.  Thanks. </div></div></blockquote></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">--Dave</div></blockquote></div></div></blockquote></div></div></div>