Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string attributes not supported? #156

Open
Chrismarsh opened this issue Oct 18, 2024 · 0 comments
Open

string attributes not supported? #156

Chrismarsh opened this issue Oct 18, 2024 · 0 comments

Comments

@Chrismarsh
Copy link

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:

	double datetime(datetime) ;
		datetime:_FillValue = NaN ;
		string datetime:standard_name = "time" ;
		string datetime:long_name = "time" ;
		string datetime:units = "seconds since 1970-01-01T00:00:00" ;
		string datetime:calendar = "proleptic_gregorian" ;

If I have a non-string attr like:

	double datetime(datetime) ;
		datetime:_FillValue = NaN ;
		datetime:standard_name = "time" ;
		datetime:long_name = "time" ;
		datetime:units = "seconds since 1970-01-01T00:00:00" ;
		datetime:calendar = "proleptic_gregorian" ;

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:

netcdf-c@4.9.2
netcdf-cxx4@4.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant