Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Re: Appending a Netcdf file in C++

>From: Alain Mazurier <mazurier@xxxxxxx>
>Keywords: 200104041159.f34BxML07668

Hi Alain,

> I am trying to append a Netcdf file ,that it is already exist ,with a new
> variable and new data:
> After appending, when i am looking to the file, it didn't
> append it but it has overwritten data ?
> I have the same size between the file before and after appending
> 
> this is my code:
> 
>   NcFile* lp_fichier;
>   lp_fichier = new NcFile( aiv_file, NcFile::Write);
>   NcDim* lp_dim[2];
>   lp_dim[0] = lp_fichier->get_dim("mbCycleNbr") ;
>   lp_dim[1] = lp_fichier->get_dim("mbBeamNbr") ;
> 
>   NcVar* lp_var = lp_fichier->add_var((NcToken )"mbAzimutBeamAngle",
> ncShort,(const NcDim*)lp_dim[0], (const NcDim*)lp_dim[1]);
>   lp_var->add_att("type", "real");
>   lp_var->add_att("long_name", "Beam azimut");
>   lp_var->add_att("name_code", "MB_AZIMUT_BEAM_ANGLE");
>   lp_var->add_att("units", "degree");
>   lp_var->add_att("unit_code", "MB_DEGREE");
>   lp_var->add_att("add_offset", 0.0);
>   lp_var->add_att("scale_factor", 0.01);
>   lp_var->add_att("valid_minimum", 0);
>   lp_var->add_att("valid_maximum", 35999);
>   lp_var->add_att("missing_value", 32767);
>   lp_var->add_att("format_C", "%.2f");
>   lp_var->add_att("orientation", "direct");
> 
>   long lv_nbData = lp_dim[0]->size()*lp_dim[1]->size();
>   short* lp_tabData = new short[lv_nbData];
>   for (long lv_i=0; lv_i< lv_nbData;lv_i++)
>     lp_tabData[lv_i]=32767;
>   lp_var->put(lp_tabData, lp_var->edges());
> 
>   lp_fichier->close();
>   // liberation des ressources
>   delete [] lp_tabData;
> 
> Have you an idea or better a solution

I can't duplicate the problem without an example input file, but I
suspect this is an example of the "redef bug" in netCDF 3.4 that
occurred under certain circumstances when adding a new variable.  In
terms of the underlying C interface, the bug occurred when

  ... nc_enddef() is called after nc_redef(), the file is growing such
  that the new beginning of a record variable is in the next "chunk",
  and the size of at least one record variable exceeds the chunk size
  (see netcdf.3 man page for a description of this tuning parameter
  and how to set it).  This bug resulted in corruption of some values
  in other variables than the one being added.

This bug is fixed in the just-released netCDF 3.5.0, so you could
verify whether this was the problem by trying your program with the
new release.  See the next message to the netcdfgroup mailing list for
an announcement of netCDF 3.5.0 and how to get it.

If this doesn't fix the problem, please let us know and provide access
to an example file that demonstrates the problem.

--Russ

_____________________________________________________________________

Russ Rew                                         UCAR Unidata Program
russ@xxxxxxxxxxxxxxxx                     http://www.unidata.ucar.edu

 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690