Re: beta1 bug

Ed Hartnett wrote:
Jeff Whitaker <jswhit@xxxxxxxxxxx> writes:

Ed:  The attached C program creates a netcdf4_classic file that is
unreadable (ncdump'ing it gives an 'HDF Error').

[ ..SNIP..]
Thanks Jeff!

This is not an ncdump bug; nc_open fails on this file!

I have added it to the netCDF-4 tests and will let you know when I get
it solved...

Thanks,

Ed

Ed: Here's a C program that triggers the H5Oalloc error I mentioned in my previous message.

-Jeff

--
Jeffrey S. Whitaker         Phone  : (303)497-6313
Meteorologist               FAX    : (303)497-6449
NOAA/OAR/PSD  R/PSD1        Email  : Jeffrey.S.Whitaker@xxxxxxxx
325 Broadway                Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg

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

void
check_err(const int stat, const int line, const char *file) {
    if (stat != NC_NOERR) {
           (void) fprintf(stderr, "line %d of %s: %s\n", line, file, 
nc_strerror(stat));
        exit(1);
    }
}

int
main() {                        /* create testfile.nc */

   int  stat;                   /* return status */
   int  ncid;                   /* netCDF id */

   /* dimension ids */
   int lat_dim;
   int time_dim;
   int lon_dim;

   /* dimension lengths */
   size_t lat_len = 73;
   size_t time_len = 10;
   size_t lon_len = 145;

   /* variable ids */
   int wind_id;

   /* rank (number of dimensions) for each variable */
#  define RANK_wind 1

   /* variable shapes */
   int wind_dims[RANK_wind];

   /* attribute vectors */
   int wind_slobber[1];
   int cdf_goober[1];

   stat = nc_set_default_format(NC_FORMAT_NETCDF4, NULL);
   check_err(stat,__LINE__,__FILE__);

   /* define dataset */
   stat = nc_create("testfile.nc", NC_CLOBBER, &ncid);
   check_err(stat,__LINE__,__FILE__);

   /* define dimensions */
   stat = nc_def_dim(ncid, "lon", lon_len, &lon_dim);
   check_err(stat,__LINE__,__FILE__);
   stat = nc_def_dim(ncid, "lat", lat_len, &lat_dim);
   check_err(stat,__LINE__,__FILE__);
   stat = nc_def_dim(ncid, "time", time_len, &time_dim);
   check_err(stat,__LINE__,__FILE__);

   stat = nc_put_att_text(ncid, NC_GLOBAL, "foo", 3, "bar");
   check_err(stat,__LINE__,__FILE__);
   cdf_goober[0] = 2;
   stat = nc_put_att_int(ncid, NC_GLOBAL, "goober", NC_INT, 1, cdf_goober);
   check_err(stat,__LINE__,__FILE__);

   /* define variables */
   wind_dims[0] = lon_dim;
   stat = nc_def_var(ncid, "temp", NC_FLOAT, RANK_wind, wind_dims, &wind_id);
   check_err(stat,__LINE__,__FILE__);

   stat = nc_put_att_text(ncid, wind_id, "bar", 3, "foo");
   check_err(stat,__LINE__,__FILE__);
   wind_slobber[0] = 3;
   stat = nc_put_att_int(ncid, wind_id, "slobber", NC_INT, 1, wind_slobber);
   check_err(stat,__LINE__,__FILE__);

   stat = nc_close(ncid);
   check_err(stat,__LINE__,__FILE__);

   /* re-open dataset*/
   stat = nc_open("testfile.nc", NC_WRITE, &ncid);
   check_err(stat,__LINE__,__FILE__);
   stat = nc_inq_dimid(ncid, "lon", &lon_dim);
   check_err(stat,__LINE__,__FILE__);
   /* rename dimension */
   stat = nc_rename_dim(ncid, lon_dim, "longitude");
   check_err(stat,__LINE__,__FILE__);
   stat = nc_inq_varid(ncid, "temp", &wind_id);
   check_err(stat,__LINE__,__FILE__);
   /* rename variable */
   stat = nc_rename_var(ncid, wind_id, "wind");
   check_err(stat,__LINE__,__FILE__);
   stat = nc_close(ncid);
   check_err(stat,__LINE__,__FILE__);

   return 0;
}