Re: Odd behaviour -v3.4 3.3 DEC Alpha

Hi Jeff,

> I've noticed an odd behaviour with the netCDF libraries v3.3 & v3.4 
> compiled for DEC Alpha.
> 
> When creating a file from scratch the resulting netCDF file is fine.  If I 
> subsequently add an additional variable to the file, other (pre-existing) 
> variables will get scrambled.  This only occurs to some variables at some 
> 2-D slices.  Visually it looks like a 2-D slice has been subdivided into 
> several rectangular areas then randomly put back together.  I'm guessing 
> that some internal directory header is getting corrupted when the new 
> variable is getting defined.  This was not a problem pre-v3.  Current libs 
> work fine on the SGI.
> 
> Anyone else see this and have a fix?  I haven't tested the effect of file 
> size but the ones we use are typically >100mb .

I've just tried a small example (appended) that adds a variable to an
existing file, and it seems to work fine on our DEC Alpha/OSF1 4.0.
If you can construct an example that demonstrates the problem and send
it to "support@xxxxxxxxxxxxxxxx", we'll look at it.  Otherwise the
problem you are seeing may be a symptom of a problem with the way the
library was built.  Check that the extensive tests run by "make test"
work with the installed library.

If the problem only occurs with large files, it may be related to a
vaguely similar problem reported on a different platform in the
following support messages, for which a workaround was developed
that's described there:

 http://www.unidata.ucar.edu/glimpse/netcdf/3265
 http://www.unidata.ucar.edu/glimpse/netcdf/3293
 http://www.unidata.ucar.edu/glimpse/netcdf/3295

--Russ

_____________________________________________________________________

Russ Rew                                         UCAR Unidata Program
russ@xxxxxxxxxxxxxxxx                     http://www.unidata.ucar.edu

To test: store appended CDL file in "ex2.cdl".  Store appended C
program in "ex2.c".  Invoke "ncgen -b ex2.cdl" to create the netCDF
file "ex2.nc".  Compile and link "ex2.c", storing resulting executable
in "ex2".  Save what's in "ex2.nc" before invoking test program with
"ncdump ex2.nc > before".  Invoke "ex2" to add a variable to "ex2.nc".
See what's in "ex2.nc" after running "ex2" with "ncdump ex2.nc >
after".  Compare files "before" and "after" to verify that no values
of existing variables were changed.

-------------- ex2.cdl ------------------
netcdf ex2 {
dimensions:
        lat = 5 ;
        lon = 10 ;
        level = 4 ;
        time = UNLIMITED ;
variables:
        float temp(time, level, lat, lon) ;
                temp:long_name = "temperature" ;
                temp:units = "celsius" ;
        float rh(time, lat, lon) ;
                rh:long_name = "relative humidity" ;
                rh:valid_range = 0., 1. ;
        int lat(lat) ;
                lat:units = "degrees_north" ;
        int lon(lon) ;
                lon:units = "degrees_east" ;
        int level(level) ;
                level:units = "millibars" ;
        short time(time) ;
                time:units = "hours since 1990-11-25 12:00 UTC" ;

// global attributes:
                :source = "National Weather Service" ;
data:

 temp
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  40, 41, 42, 43, 44, 45, 46, 47, 48, 49 ;

 rh
  0.5, 0.2, 0.4, 0.2, 0.3, 0.2, 0.4, 0.5, 0.6, 0.7,
  0.1, 0.3, 0.1, 0.1, 0.1, 0.1, 0.5, 0.7, 0.8, 0.8,
  0.1, 0.2, 0.2, 0.2, 0.2, 0.5, 0.7, 0.8, 0.9, 0.9,
  0.1, 0.2, 0.3, 0.3, 0.3, 0.3, 0.7, 0.8, 0.9, 0.9,
  0, 0.1, 0.2, 0.4, 0.4, 0.4, 0.4, 0.7, 0.9, 0.9 ;

 lat = 20, 30, 40, 50, 60 ;

 lon = -160, -140, -118, -96, -84, -52, -45, -35, -25, -15 ;

 level = 1000, 850, 700, 500 ;

 time = 12 ;
}

-------------- ex2.c --------------------
#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() {                        /* add new variable to ex2.nc */

   int  ncid;                   /* netCDF id */

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

   /* variable ids */
   int pressure_id;

   /* rank (number of dimensions) for each variable */
#  define RANK_pressure 4

   /* variable shapes */
   int pressure_dims[RANK_pressure];

   int stat = nc_open("ex2.nc", NC_WRITE, &ncid);
   check_err(stat,__LINE__,__FILE__);

   /* get dimension ids */
   stat = nc_inq_dimid(ncid, "time", &time_dim);
   check_err(stat,__LINE__,__FILE__);
   stat = nc_inq_dimid(ncid, "level", &level_dim);
   check_err(stat,__LINE__,__FILE__);
   stat = nc_inq_dimid(ncid, "lat", &lat_dim);
   check_err(stat,__LINE__,__FILE__);
   stat = nc_inq_dimid(ncid, "lon", &lon_dim);
   check_err(stat,__LINE__,__FILE__);

   /* enter define mode */
   stat = nc_redef(ncid);
   check_err(stat,__LINE__,__FILE__);
   
   /* define a new variable */

   pressure_dims[0] = time_dim;
   pressure_dims[1] = level_dim;
   pressure_dims[2] = lat_dim;
   pressure_dims[3] = lon_dim;
   stat = nc_def_var(ncid, "pressure", NC_FLOAT, RANK_pressure, pressure_dims, 
&pressure_id);
   check_err(stat,__LINE__,__FILE__);

   /* assign attributes */
   stat = nc_put_att_text(ncid, pressure_id, "long_name", 11, "atmospheric 
pressure");
   check_err(stat,__LINE__,__FILE__);
   stat = nc_put_att_text(ncid, pressure_id, "units", 7, "hectopascals");
   check_err(stat,__LINE__,__FILE__);

   /* leave define mode */
   stat = nc_enddef (ncid);
   check_err(stat,__LINE__,__FILE__);

   {                    /* store pressure */
    static size_t pressure_start[RANK_pressure];
    static size_t pressure_count[RANK_pressure];

    /* dimension lengths of pressure data to store */
    size_t lat_len = 5;
    size_t lon_len = 10;
    size_t level_len = 4;
    size_t time_len = 1;

    static float pressure[] = {
      900,901,902,903,904,905,906,907,908,909,
      910,911,912,913,914,915,916,917,918,919,
      920,921,922,923,924,925,926,927,928,929,
      930,931,932,933,934,935,936,937,938,939,
      940,941,942,943,944,945,946,947,948,949,
      900,901,902,903,904,905,906,907,908,909,
      910,911,912,913,914,915,916,917,918,919,
      920,921,922,923,924,925,926,927,928,929,
      930,931,932,933,934,935,936,937,938,939,
      940,941,942,943,944,945,946,947,948,949,
      900,901,902,903,904,905,906,907,908,909,
      910,911,912,913,914,915,916,917,918,919,
      920,921,922,923,924,925,926,927,928,929,
      930,931,932,933,934,935,936,937,938,939,
      940,941,942,943,944,945,946,947,948,949,
      900,901,902,903,904,905,906,907,908,909,
      910,911,912,913,914,915,916,917,918,919,
      920,921,922,923,924,925,926,927,928,929,
      930,931,932,933,934,935,936,937,938,939,
      940,941,942,943,944,945,946,947,948,949};

    pressure_start[0] = 0;
    pressure_start[1] = 0;
    pressure_start[2] = 0;
    pressure_start[3] = 0;
    pressure_count[0] = time_len;
    pressure_count[1] = level_len;
    pressure_count[2] = lat_len;
    pressure_count[3] = lon_len;
    stat = nc_put_vara_float(ncid, pressure_id, 
                             pressure_start, pressure_count, pressure);
    check_err(stat,__LINE__,__FILE__);
   }

   stat = nc_close(ncid);
   check_err(stat,__LINE__,__FILE__);
   return 0;
}

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