This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>To: address@hidden >From: CHEUNG WENDY WAI WAN <address@hidden> >Subject: C++/netcdf-3.4 >Organization: . >Keywords: 199803230217.TAA20025 Hi Wendy, > I'm a engineering grad student at CU and I have a potentially simple > problem. > > My model requires variables to be double precision. I have been playing > with the 'example.cc' program in the /netcdf-3.4/src/cxx directory. In the > code, I make 2 simple substitutions: float(NcFloat) with double (NcDouble) > > 1(line 25) NcVar* P = nc.add_var("P", ncDouble, frtimed, latd, lond); > > 2(line 73) static double P_data[] = { > > and I get the following error: > > ncvarput: ncid 3: Not a netCDF data type or _FillValue type mismatch Just also change line 30 from P->add_att("_FillValue", -9999.0f); to P->add_att("_FillValue", -9999.0); to make the _FillValue attribute of the same type as the variable, and things should work fine. It's not necessary to define a _FillValue attribute for variables, but when you do, its type must agree with the type of the variable. The C++ interface doesn't have an explicit type parameter for defining attributes, but instead just uses the type corresponding to the value to create an attribute of the appropriate type, and in this case the float type of the constant "-9999.f" cause it to create an attribute of type NcFloat which disagreed with the NcDouble type of the variable. --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu