netcdf-c: NC_DISKLESS returns garbage data for certain files
using the latest netcdf-c from master, NC_DISKLESS mode can return garbage data for certain files.
With the following file: foo.zip
and the following code:
#include <iostream>
#include <netcdf.h>
#include <netcdf_mem.h>
#include <iostream>
#include <fstream>
#include <assert.h>
#import <vector>
using namespace std;
#define HRAPY 200
#define HRAPX 333
static size_t value_count[] = {HRAPY, HRAPX};
static size_t start[] = {0, 0};
int main(int argc, const char * argv[]) {
ifstream file("/tmp/foo.nc", ios::in | ios::binary | ios::ate);
streamsize size = file.tellg();
file.seekg(0, ios::beg);
std::vector<char> buffer(size);
int status;
int ncid;
if (file.read(buffer.data(), size))
{
// status = nc_open_mem(".nc", 0, size, buffer.data(), &ncid);
status = nc_open("/tmp/foo.nc", NC_DISKLESS|NC_CDF5, &ncid);
if(status != NC_NOERR) {
cout << nc_strerror(status);
assert(false);
}
int rh_id;
status = nc_inq_varid(ncid, "amountofprecip", &rh_id);
if(status != NC_NOERR) {
cout << nc_strerror(status);
assert(false);
}
int rh_vals[HRAPY][HRAPX];
status = nc_get_vara_int(ncid, rh_id, start, value_count, (int*)rh_vals);
if(status != NC_NOERR) {
cout << nc_strerror(status);
assert(false);
}
}
std::cout << "Hello, World!\n";
return 0;
}
note there’s no errors, however rows > 100 return garbage, row 100 looks like:
[ -71 76 96 37 20 8 -67 -47 -89 62 52 -52 78 86 -62
60 46 44 -68 -44 -34 28 30 -30 -2 -1 14 -64 -68 -63
-88 -86 -95 40 -70 -55 5 -56 -50 -61 88 57 45 -73 -3
-45 19 5 -73 -6 -
whereas row 101 looks like:
[ 4325376 2818048 393215 -3997697 -4063233 -1114113 -1310720 4915199
-6488064 5832703 -1114113 -2228225 -2686977 -3932160 6160384 3276799
-720896 3670015 -4063232 6225919 -5636096 1966080 3014655 -4063233
-5308416 1114112 3407871 -4653057
opening the same file with nc_open does not return corrupt data.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 33 (27 by maintainers)
Commits related to this issue
- Refactored new diskless mode in support of https://github.com/Unidata/netcdf-c/issues/401 to reflect cdf5-specific issue. — committed to Unidata/netcdf-c by WardF 7 years ago
- re: issue https://github.com/Unidata/netcdf-c/issues/401 It turns out that the chunksize used in the ncio-related code must be a multiple of eight in size. Both memio.c and mmapio.c were potentially... — committed to Unidata/netcdf-c by DennisHeimbigner 7 years ago
using
and running it, doesn’t seem to reproduce any garbage data.
Interestingly enough, when I try to run this test from a straight C program integrated into the unit tests, the issue disappears. Investigating further.
On Tue, May 2, 2017 at 2:17 PM, Alexander Mohr notifications@github.com wrote:
Thanks; replicated on my end, and using
NC_DISKLESS|NC_CDF5does not correct the issue.I will take a look; I was out of town for the past week but will start digging into this shortly.