You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a C++ code that loads a netcdf file and accesses the units attribute like this:
netCDF::NcFile _data;
// open file [...]
auto a = _data.getVar("valid_time").getAtt("units");
SPDLOG_DEBUG(a.getType().getName()); // prints string
std::string epoch;
a.getValues(epoch); // throws exception
which results in an exception with the following error:
NetCDF: Attempt to convert between text & numbers
This netcdf has string attributes and are Copernicus CDS ERA5 netcdf files. ncdump shows:
@Chrismarsh, I recently encountered a similar issue, but with reading string variables. When working with string variables, you need to allocate a temporary char** buffer for the number of strings you want to read. Here's the process I followed:
Allocate the first dimension of the char** buffer (NetCDF manages the individual string memory).
Pass the buffer to the getVar method.
After reading, copy the buffer data into a std::vectorstd::string or similar container.
Free the buffer using NetCDF’s string memory management functions.
Deallocate the buffer memory you allocated.
For reference, here is an example of reading a string array variable in C++.
I have a C++ code that loads a netcdf file and accesses the
units
attribute like this:which results in an exception with the following error:
This netcdf has string attributes and are Copernicus CDS ERA5 netcdf files.
ncdump
shows:If I have a non-string attr like:
the above C++ code works as expected.
This problem appears to be the same issue noted in this
netcdf-fortran
issue Unidata/netcdf-fortran#181 (comment)However, as I understand it, string attributes is supposed to work with
netcdf-c
. Is this a limitation to the C++ api?Versions:
The text was updated successfully, but these errors were encountered: