-
Notifications
You must be signed in to change notification settings - Fork 264
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
HDF error when unlimited dimension and a variable share the same name #975
Comments
Confirmed. I don't yet understand why it doesn't happen with an equivalent C or C++ program. |
at the risk of stating the obvious, it's a bad idea to have a variable with the same name as a dimension that is not a coordinate variable (that describes the dimension's values). Although it's not a good practice, I don't think it should cause the library to crash. |
Here's a c program that triggers the error for me. Let me know if this reproduces your error and I'll create a netcdf-c issue #include <netcdf.h>
#include <stdio.h>
int main() {
int dataset_id, timesubset_id, time_id, timevar_id, dummyvar_id, ierr;
size_t start[1] = {0};
size_t count[1] = {1};
double data[1] = {2};
nc_create("test.nc", NC_CLOBBER | NC_NETCDF4, &dataset_id);
nc_def_dim(dataset_id, "time", NC_UNLIMITED, &time_id);
nc_def_dim(dataset_id, "time_subset", 50, ×ubset_id);
// this works
//nc_def_var(dataset_id, "time", NC_DOUBLE, 1, &time_id, &timevar_id);
//nc_def_var(dataset_id, "dummy", NC_DOUBLE, 1, ×ubset_id, &dummyvar_id);
// this produces ierr=-101 (HDF5 error) on close
// note: variable is called 'time', same as unlimited dimension, but
// is defined with a different (fixed) dimension.
nc_def_var(dataset_id, "time", NC_DOUBLE, 1, ×ubset_id, &timevar_id);
nc_def_var(dataset_id, "dummy", NC_DOUBLE, 1, &time_id, &dummyvar_id);
ierr=nc_put_vara(dataset_id, timevar_id, start, count, data);
printf ( "ierr from nc_put_vara=%d\n", ierr);
ierr=nc_put_vara(dataset_id, dummyvar_id, start, count, data);
printf ( "ierr from nc_put_vara=%d\n", ierr);
ierr=nc_close(dataset_id);
printf ( "ierr from nc_close=%d\n", ierr);
} |
I confirm failure at the end of the program, when nc_close is called: gcc -lnetcdf -o test_netcdf_jswhit test_netcdf_jswhit.c
./test_netcdf_jswhit
ierr from nc_put_vara=0
ierr from nc_put_vara=0
ierr from nc_close=-101 |
I have just submitted a PR with a fix to netcdf-c. See Unidata/netcdf-c#1528 @oceandatalab I have long admired your sentinel data viewers on the web. Beautiful! ;-) Keep in netCDFing! |
Thanks a lot @edhartnett ! We will try to apply your fix as soon as possible on our dev machines. EDIT: tested the fix with C and C++ snippets, then with the Python code that triggered the error in the first place, everything works as expected, thanks again! |
Closing the issue since it was not caused by a bug in netcdf4-python and because the problem will be solved once the next version of netcdf-c is out. Thanks again for your help @jswhit and @edhartnett ! |
It seems there is an issue when a variable shares the same name as an unlimited dimension
Here a a simple test script which creates:
Calling the script with any name other than "time" works fine:
But if you create a variable named "time", you get an HDF error:
Creating another unlimited dimension and assigning it to the time variable generates no error:
So it seems impossible to have an unlimited dimension and a variable with the same name if the variable does not have an unlimited dimension too.
I also tried to replicate the issue with the C++ bindings but it managed to create the NetCDF file just fine.
Tested on Archlinux with the following package/library versions:
The text was updated successfully, but these errors were encountered: