Re: [netcdfgroup] nasty netcdf-4.1 bug

Jeff Whitaker wrote:

Ed et al: Here's a simple C program that produces an incorrect netcdf file with netcdf-4.1

Can anyone confirm or deny that this is a real bug? I noticed that netcdf-4.1 was pulled from the ftp site, so I guess that means someone is working on it ....

-Jeff

#include <stdio.h>
#include <string.h>
#include <netcdf.h>
#define FILE_NAME "test.nc"
#define NDIMS 2
#define NLAT 10
#define NLON 20 #define LAT_NAME "lat"
#define LON_NAME "lon"
#define START_LAT 25.0
#define START_LON -125.0
int
main()
{
  int ncid, lon_dimid, lat_dimid;
  int lat_varid, lon_varid;
  int dimids[NDIMS];
  float lats[NLAT], lons[NLON];
  int lat, lon;
  int retval;
  for (lat = 0; lat < NLAT; lat++)
     lats[lat] = START_LAT + 5.*lat;
  for (lon = 0; lon < NLON; lon++)
     lons[lon] = START_LON + 5.*lon;
  retval = nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid);
  retval = nc_def_dim(ncid, LAT_NAME, NLAT, &lat_dimid);
  retval = nc_def_dim(ncid, LON_NAME, NLON, &lon_dimid);
retval = nc_def_var(ncid, LON_NAME, NC_FLOAT, 1, &lon_dimid, &lon_varid);
  retval = nc_put_var_float(ncid, lon_varid, &lons[0]);
retval = nc_def_var(ncid, LAT_NAME, NC_FLOAT, 1, &lat_dimid, &lat_varid);
  retval = nc_put_var_float(ncid, lat_varid, &lats[0]);
  retval = nc_close(ncid);
  return 0;
}

An ncdump of the resulting file looks like this:

ncdump test.nc
netcdf test {
dimensions:
       lat = 10 ;
       lat = 10 ;
variables:
       float lon(lat) ;
       float lat(lat) ;
data:

lon = -125, -120, -115, -110, -105, -100, -95, -90, -85, -80 ;

lat = 25, 30, 35, 40, 45, 50, 55, 60, 65, 70 ;
}

which is more than a little weird. Linking the program with either netcdf-4.0.1 or netcdf-4.1-rc1 produces the correct netcdf file

ncdump test.nc
netcdf test {
dimensions:
       lat = 10 ;
       lon = 20 ;
variables:
       float lon(lon) ;
       float lat(lat) ;
data:

lon = -125, -120, -115, -110, -105, -100, -95, -90, -85, -80 ;

lat = 25, 30, 35, 40, 45, 50, 55, 60, 65, 70 ;
}

-Jeff

_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/



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