NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

[netcdfgroup] Netcdf error in nc_close when a string array is defined

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

  • 2018 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: