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] possible bug in 4.3.3.1 with unlimited dimensions in NetCDF-4 format?

Hello,

  I just upgraded from NetCDF 4.1.3 to NetCDF 4.3.3.1 and am seeing a problem 
in our regression test when writing unlimited dimensions to a NetCDF-4 format 
file.  Specifically, if the unlimited dimension is last instead of the first in 
the dimension list, or if I declare more than one unlimited dimension, the 
program errors with the NC_EEDGE error:

    Error: NetCDF: Start+count exceeds dimension bound

  This does not occur in our current NetCDF version 4.1.3.
  To isolate the issue, I built NetCDF 4.3.3.1 outside of our build 
infrastructure and wrote a standalone C program to write to a NetCDF-4 file - 
so I am bypassing MATLAB completely.

  Can you please help me determine if this is a bug in the NetCDF code, 
specifically in dvarput.c?

  Below is the standalone C program that will throw the error above when 
linking to NetCDF 4.3.3.1.  Note I built this with HDF5 1.8.12.

  Thank you!
     Ellen Johnson
     Software Engineer
     Image and Scientific File Formats
     MathWorks


#include <stdio.h>
#include <string.h>
#include <netcdf.h>

#define FILE_NAME "unlim.nc"

/* 3D matrix, 6 x 4 x 3 */

#define NDIMS 3
#define X_LEN 6
#define Y_LEN 4
#define Z_LEN 3

/* Handle errors by printing an error message */
#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); return 2;}
int
main()
{
    size_t start[NDIMS] = {0, 0, 0};
    size_t count[NDIMS] = {X_LEN, Y_LEN, Z_LEN};
    ptrdiff_t stride[NDIMS] = {1, 1, 1};
    float mydata[X_LEN * Y_LEN * Z_LEN];
    int i;
    int retval;

    int ncid, varid;
    int dimids[NDIMS];

    for (i = 0; i < (X_LEN * Y_LEN * Z_LEN); i++)
        mydata[i] = i;

    /* create the file in NetCDF-4 format */
    if ((retval = nc_create(FILE_NAME, NC_NETCDF4, &ncid)))
        ERR(retval);

    /* define dimensions */
    if ((retval = nc_def_dim(ncid, "time", X_LEN, &dimids[0])))
        ERR(retval);
    if ((retval = nc_def_dim(ncid, "lat", Y_LEN, &dimids[1])))
        ERR(retval);
    if ((retval = nc_def_dim(ncid, "lon", NC_UNLIMITED, &dimids[2])))
        ERR(retval);

   /* define the variable */
    if ((retval = nc_def_var(ncid, "data", NC_FLOAT, NDIMS, dimids, &varid)))
        ERR(retval);

    /* end define mode */
    if ((retval = nc_enddef(ncid)))
        ERR(retval);

    /* write data */
    if ((retval = nc_put_vars_float(ncid, varid, start, count, stride, mydata)))
        ERR(retval);

    /* close the file */
    if ((retval = nc_close(ncid)))
        ERR(retval);

    printf("\n\n*** SUCCESS writing example file %s!\n", FILE_NAME);
    return 0;
}
  • 2015 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: