Re: [netcdfgroup] netCDF file close error on Windows Visual Studio 2015

I was about to write a small test program to demonstrate this problem, when I 
realized I had already written one to demonstrate another problem back in 2011. 
 It is attached.  It writes 4100 1M arrays, and prints any error message when 
closing the file.

This is the end of the output when running the program on Linux (Centos 7 
64-bit).  It works fine.
writing record 4098/4100
writing record 4099/4100
writing record 4100/4100
Closing file test.nc

This on Windows with the VS 2010 compiler.  It also works fine.
writing record 4098/4100
writing record 4099/4100
writing record 4100/4100
Closing file test.nc

This is on Windows with the VS 2015 compiler.  It returns an "Unknown error" 
when closing the file.
writing record 4098/4100
writing record 4099/4100
writing record 4100/4100
Closing file test.nc
error=Unknown error

Thanks,
Mark


From: netcdf group-bounces@xxxxxxxxxxxxxxxx 
<netcdfgroup-bounces@xxxxxxxxxxxxxxxx> On Behalf Of Mark Rivers
Sent: Tuesday, November 6, 2018 8:42 PM
To: 'netcdfgroup@xxxxxxxxxxxxxxxx' <netcdfgroup@xxxxxxxxxxxxxxxx>
Subject: [netcdfgroup] netCDF file close error on Windows Visual Studio 2015

Folks,

I am running a C application built with netCDF 4.1.3.  I am using 64-bit offset 
files, not HDF5.  I am creating files larger than 2 GB, typically 4GB or 8 GB.

It is working fine on Linux, and on Windows when building with Visual Studio 
2010.

When building with Visual Studio 2015 it works fine with files less than 2GB.  
However, when the file size exceeds 2GB I get an error closing the file.  The 
file is actually written fine, and I can process the data for an 8GB file.  
However, because the file is not closed properly I cannot delete the file 
without closing the application.

Is this a known problem, and if so is it fixed in a later release?

Thanks,
Mark


/* test_big_classic.c
 * Test program to write large (>4GB files in netCDF classic format
 */
 
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <netcdf.h>

#define MAX_DIMS 3
#define XSIZE 1024
#define YSIZE 1024
#define NUM_RECORDS 4100

/* Handle errors by printing an error message and exiting with a
 * non-zero status. */
#define ERR(e) {printf("error=%s\n", \
                nc_strerror(e)); \
                return(-1);}

int main(int argc, char **argv)
{
    /* When we create netCDF variables and dimensions, we get back an
     * ID for each one. */
    int dimIds[MAX_DIMS];
    size_t start[MAX_DIMS] = {0, 0, 0};
    size_t count[MAX_DIMS] = {1, YSIZE, XSIZE};
    int ncId;
    int dataId;
    int retval;
    int i;
    char *fileName = argv[1];
    char *pData = calloc(XSIZE, YSIZE);

    if (argc != 2) {
        printf("Usage: test_big_classic filename\n");
        return(-1);
    }
    
    /* Create the file. The NC_CLOBBER parameter tells netCDF to
     * overwrite this file, if it already exists.  No other flags, so it is 
classic format. */
    printf("Creating file %s\n", fileName);
    if ((retval = nc_create(fileName, NC_CLOBBER, &ncId)))
        ERR(retval);

    /* Define the dimensions */
    if ((retval = nc_def_dim(ncId, "numArrays", NC_UNLIMITED, &dimIds[0])))
        ERR(retval);

    if ((retval = nc_def_dim(ncId, "YSize", YSIZE, &dimIds[1])))
        ERR(retval);

    if ((retval = nc_def_dim(ncId, "XSize", XSIZE, &dimIds[2])))
        ERR(retval);

    /* Define the array data variable. */
    if ((retval = nc_def_var(ncId, "array_data", NC_BYTE, 3,
                 dimIds, &dataId)))
        ERR(retval);

    /* End define mode. This tells netCDF we are done defining
     * metadata. */
    if ((retval = nc_enddef(ncId)))
        ERR(retval);
        
    /* Write data to file */
    for (i=0; i<NUM_RECORDS; i++) {
      printf("writing record %d/%d\n", i+1, NUM_RECORDS);
        start[0] = i;
        if ((retval = nc_put_vara_schar(ncId, dataId, start, count, (signed 
char*)pData)))
            ERR(retval);
    }
    printf("Closing file %s\n", fileName);
   if ((retval = nc_close(ncId)))
        ERR(retval);

   return(0);
}

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