Hi all,
I encountered something that looks like a bug in netcdf, but as a new user of
the lib I may be wrong somewhere. I have a simple code that creates a netcdf
file, defines a dimension and a string variable, closes the file, then try to
reopen it and close it again.
#include <netcdf.h>
#include <iostream>
static void checkNetcdf(int status){
if (status != NC_NOERR){
printf("NETCDF error: %s\n", nc_strerror(status));
std::exit(-1);
}
}
int main() {
int rootGrp;
checkNetcdf(nc_create("test.nc", NC_NETCDF4, &rootGrp));
int fieldDimId;
checkNetcdf(nc_def_dim(rootGrp, "field", 5, &fieldDimId));
int fieldVarId, fieldVarDims[1];
fieldVarDims[0] = fieldDimId;
checkNetcdf(nc_def_var(rootGrp, "field", NC_STRING, 1, fieldVarDims,
&fieldVarId));
checkNetcdf(nc_close(rootGrp));
checkNetcdf(nc_open("test.nc", NC_WRITE, &rootGrp));
checkNetcdf(nc_close(rootGrp));
}
However, it crashes at runtime.
I installed the NetCDF-4 64-bit pre-built library on Windows. When I debug in
visual studio, x64 I get:
testNetcdfString.exe has triggered a breakpoint.
The program is stopped at the second (last) nc_close.
In normal execution, I have the classical Windows popup: testNetcdfString.exe
has stopped working
Is there anything wrong in this code or is it a bug? This only happens when
using NC_STRING type, not with other types.
Kind regards,
Sebastien Blaise
Senior Engineer
T +32 (0)2 77 60 624
s.blaise@xxxxxxxxx | www.fugro.be
Fugro
Av. de Broqueville 12, 1150 Brussels, Belgium
VAT nr BE0418609636