-
Notifications
You must be signed in to change notification settings - Fork 266
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
Mandatory relaxed coordinate bound checking in 4.7.4? #1951
Comments
THis will be more clear if you also provide an ncdump of the file. Basically what seems to be the confusion here is the use of nc_get_var_double() instead of, for example, nc_get_vara_double(), in which you would see more clearly what is happening. nc_get_var_double() gets the whole contents of the variable (i.e. all the data). But in the case of the NC_UNLIMITED data, what happens when you do an nc_get_var_double() before writing any data? There are zero records, so the nc_get_var_double() does nothing and returns NC_NOERR. Similarly when you do nc_get_var_int() on the other variable. There is no data, so nothing in the file to read. Since you used nc_get_var_int(), netcdf-c tries to read all the data. It sees there is no data, so it does nothing and tells you it has read what you asked for, which is nothing. ;-) The relaxation coord bound checking was a bug in the handling of parallel I/O (which may involve pnetcdf or HDF5.) When I originally wrote the code, I did not account for the fact that asking for zero items in a parallel I/O read is a perfectly valid read. This was fixed with an option in configure which turned the fix on and off for different builds, which was incorrect. In your code above, what do you expect to happen that is not happening? If you were to try using nc_get_vara_() or nc_get_var1_() would would get a more clear error, because instead of asking for "all the data" which could be no data, you are asking for a specific range of data. In this case, you will get an error because there is no data in the file. Using nc_get_var_*() functions with record data involves the trickiness of what happens when there is zero data records. |
Hi Ed, thanks for your reply! Here's the ncdump output of the file:
I tried nc_get_vara_double as you suggested:
And indeed I see the difference between the NC_NOERROR (0) when using nc_get_var_double and NC_EINVALCOORD (-40) with nc_get_vara_double.
What you said about how nc_get_var_double returns NC_NOERR when there is no data to retrieve make sense. Plus you answered my question about what I expect to see happen by suggesting I compare the return status using var* versus vara*. (I was looking more at the value of the returned data of 0.0, but I guess there's no way to distinguish between an uninitialized double variable to hold the return data, versus retrieving a true value of 0.0 that was written to the file -- unless you examine the return value of the function). But I'm puzzled as to why getting a range of data (vara) returns the error -- there still is no data to retrieve (in the range), so there's nothing to read. Wouldn't you want to return NC_NOERR and return nothing as in the case of var*? As for MATLAB, I'll update our code to handle the new mandatory relaxed coordinate bound feature, and I'll remove the CMake build flag -DENABLE_ZERO_LENGTH_COORD_BOUND=OFF since it's being ignored now during the build process. Thanks! |
I believe this issue can be closed. |
software version: netcdf-c-4.7.4
OS: linux, gcc
Hi everyone! I just upgraded to 4.7.4 and see relaxed coordinate bound checking strikes again! I first noticed this with test failures in our test suite. I see you made the relaxed coordinate bound checking mandatory for all builds( #1519, #1561, and #1010).
We got around this when we upgraded from 4.6.1 to 4.7.3 by adding the flag -DENABLE_ZERO_LENGTH_COORD_BOUND=OFF when building netcdf. Ward recommended this, and it preserved our existing behavior in MATLAB – if users try to read data from an empty variable with an unlimited dimension, we catch the NC_EINVALCOORDS (-40) error, and we return an empty variable.
With 4.7.4 we no longer get the NC_EINVALCOORDS error, and return a 0x1 empty variable instead of a 0x0 empty variable. Looks like the build flag is no longer being honored in the CMake files. This is a compatibility issue for our users, as they may have legacy functions where they’re checking for an empty variable instead of a 0x1 empty variable. This happens whether we create a classic file or a netcdf-4 classic file.
Questions:
Here's my C program. It creates a netcdf classic file with two dimensions: time (unlimited), and lon (fixed, size 10). It creates two variables: time (double) with one dimension (the unlimited time dimension), and x (int) with two dimensions (time and lon). I'm fuzzy on how to create the return variables for capturing output from reading from an empty variable with unlimited dimension, hopefully I got it right.
And the output:
status after close = 0
time variable = 0.000000
x variable element 0 = 1824139184
x variable element 1 = 1824139224
status after close = 0
End of test.
I'm also puzzled by why the value for the double variable (time) is 0.00, but the x variable (int) is garbage, unless that's a compiler thing.
Thank you!
The text was updated successfully, but these errors were encountered: