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.
Hi Coy, > I recompiled my code in Visual Studio 2005 (C++) with the new NetCDF-4 > header and libraries. This works fine and produces the same NetCDF-3 > files that I was producing earlier. So far, so good. > > Now I would like to enable the NetCDF-4 functionality so that I can use > two or more unlimited dimensions. The first and only step I have taken > so far is to add the NC_NETCDF4 flag to the nc_create call. I would > assume this would allow me to write and read the exact same information > into a NetCDF-4 file. But this single change causes a run-time failure. Yes, you should be able to write any netCDF-3 information as a netCDF-4 file with the same API calls, except for the addition of a netCDF-4 flag to the nc_create() call. > I include the NetCDF-4 libraries > > #include "../../libs/netcdf-4/netcdf.h" > > I added the flag to make this a NetCDF-4 file. This is the only change I > made. > > iReturn = nc_create(m_Write_strFileName.c_str(), > NC_NETCDF4|NC_CLOBBER, &m_iNcFileID); > > Here I define my dimensions. Notice that I have only one unlimited > dimensions. > > iReturn = nc_def_dim (m_iNcFileID, "Heights", 60, &m_iDim_Height); > > iReturn = nc_def_dim (m_iNcFileID, "Time", NC_UNLIMITED, &m_iDim_URI); > > Here I define a dimension: > > int aURIHeight[] = {m_iDim_URI, m_iDim_Height}; > > Here I define the variable: > > iReturn = nc_def_var (m_iNcFileID, "MeanDopplerVelocity", NC_FLOAT, 2, > aURIHeight, &m_iMeanDopplerVelocity); Did you check the value of iReturn after all the above calls? They look OK, but without the actual program source and the declarations you used, it's hard to tell if everything in the calls is correct. > The above calls all complete with out issue. But now this call fails > with an error code -49. > > size_t iIndex[] = {m_Write_iURICount,0}; > > size_t iCount[] = {1,60}; > > iReturn = nc_put_vara_float (m_iNcFileID, m_iMeanDopplerVelocity, > iIndex, iCount, &pLapxmData->pData[(0*lNumReceivers*lNumHeights)]); The error code -49 corresponds to the error message "Variable not found" which is the string returned by a call to the function nc_strerror(-49). That means the variable ID you supplied to the nc_put_vara_float call as the second argument was not recognized as a valid variable ID for this file. Did you call nc_enddef(m_iNcFileID) before calling nc_put_vara_float, and did it return NC_NOERR (0) to indicate success? > I check the values and found: > > iNcFileID = 65536 > > iMeanDopplerVelocity = 52 If you mean m_iMeanDopplerVelocity, and if this was the variable ID of the first variable declared, it should have had the value 0 rather than 52. That's why I have to wonder whether the nc_def_var call and subsequent nc_enddef call returned an NC_NOERR value. > iIndex = {0,0} > > iCount = {0, 60) That's strange, because the nc_put_vara_float call should not have changed the iCount values, but iCount[0] is now 0 instead of 1. If you can supply source for a small program that we can use to reproduce the problem, we can provide a better diagnosis. Anyway, I hope this helps. --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: MZI-587321 Department: Support netCDF Priority: Normal Status: Closed