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

Fix netcdf type for Index #565

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/nc_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,22 @@ void nca_get_data_long(const int ncid, const String& name, long* data) {
nca_error(retval, "nc_get_var(" + name + ")");
}

//! Read variable of type long long from NetCDF file.
/**
\param[in] ncid NetCDF file descriptor
\param[in] name Variable name in NetCDF file
\param[out] data Data read from file

\author Oliver Lemke
*/
void nca_get_data_longlong(const int ncid, const String& name, long long* data) {
int retval, varid;
if ((retval = nc_inq_varid(ncid, name.c_str(), &varid)))
nca_error(retval, "nc_inq_varid(" + name + ")");
if ((retval = nc_get_var_longlong(ncid, varid, data)))
nca_error(retval, "nc_get_var(" + name + ")");
}

//! Read variable of type double from NetCDF file.
/**
\param[in] ncid NetCDF file descriptor
Expand Down Expand Up @@ -418,7 +434,7 @@ void nca_get_data_ArrayOfIndex(const int ncid,
aoi.resize(nelem);
if (nelem) {
Index* ind_arr = new Index[nelem];
nca_get_data_long(ncid, name, ind_arr);
nca_get_data_longlong(ncid, name, ind_arr);
Index i = 0;
for (ArrayOfIndex::iterator it = aoi.begin(); it != aoi.end(); it++, i++)
*it = ind_arr[i];
Expand Down Expand Up @@ -545,7 +561,7 @@ bool nca_put_var_ArrayOfIndex(const int ncid,
for (Index i = 0; i < a.nelem(); i++) ind_arr[i] = a[i];

int retval;
if ((retval = nc_put_var_long(ncid, varid, ind_arr)))
if ((retval = nc_put_var_longlong(ncid, varid, ind_arr)))
nca_error(retval, "nc_put_var");

delete[] ind_arr;
Expand Down
3 changes: 3 additions & 0 deletions src/nc_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ void nca_get_data_int(const int ncid, const String& name, int* data);

void nca_get_data_long(const int ncid, const String& name, long* data);

void nca_get_data_longlong(const int ncid, const String& name, long long* data);


void nca_get_data_double(const int ncid, const String& name, Numeric* data);

void nca_get_dataa_double(const int ncid,
Expand Down