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.

Incorrect netCDF file growth

While modifying a file structure and content to add new variables I
noted file growth out of proportion to the variables added.  It
appeared that NC_LONG, NC_SHORT, and NC_BYTE types require the same
storage space. Experiments with test programs and files produced the
results listed below. The work was done on a Sun Sparc 2, OS 4.1.1,
netCDF 2.02. The test program list follows. Variable types are
changed for each run.

Comments or suggestions appreciated. 

variable 1 - NC_DOUBLE : variable 2 - NC_LONG
file size w/ 1 record = 168  - 2 records = 180 - 3 records = 192 (diff = 12)

variable 1 - NC_DOUBLE : variable 2 - NC_SHORT
file size w/ 1 record = 168  - 2 records = 180 - 3 records = 192 (diff = 12)
                                                                should be 10
variable 1 - NC_DOUBLE : variable 2 - NC_BYTE
file size w/ 1 record = 168  - 2 records = 180 - 3 records = 192 (diff = 12)
                                                                should be 9
variable 1 - NC_LONG : variable 2 - NC_LONG
file size w/ 1 record = 164  - 2 records = 172 - 3 records = 180 (diff = 8)

variable 1 - NC_LONG : variable 2 - NC_SHORT
file size w/ 1 record = 164  - 2 records = 172 - 3 records = 180 (diff = 8)
                                                                should be 6
variable 1 - NC_LONG : variable 2 - NC_BYTE
file size w/ 1 record = 164  - 2 records = 172 - 3 records = 180 (diff = 8)
                                                                should be 5

/*----------------------------------------------------------------------*/
#include <stdio.h>
#include "netcdf.h"

int cdfid;
int v1_id, v2_id;
short v1;
byte v2;

main(argc,argv)
int argc;
char **argv;
{
        int n,i,ix[1];
        
        if(argc < 2)
                n = 1;                          /* default to one record */
        else
                n = atoi(argv[1]);      /* or request number of records */

        docdf();                                /* define and create the file */
        v1 = 1;
        v2 = 2;

        for(i = 0; i < n; i++)  /* write the requested records */
        {
                ix[0] = i;

                ncvarput1(cdfid, v1_id, ix, (void *) &v1);
                ncvarput1(cdfid, v2_id, ix, (void *) &v2);
        }
        ncclose(cdfid);
}       
/*----------------------------------------------------------------------*/
docdf()
{
        int dims[3];
        int record_dim;
                
        cdfid = nccreate("test.cdf", NC_CLOBBER);

        record_dim = ncdimdef(cdfid, "record", NC_UNLIMITED);

        dims[0] = record_dim;

        v1_id = ncvardef (cdfid, "var1", NC_DOUBLE, 1, dims);
        v2_id = ncvardef (cdfid, "var2", NC_SHORT,  1, dims);

        ncattput(cdfid,NC_GLOBAL,"title",NC_CHAR,13,(void *)"CDF TEST DATA");

        ncendef (cdfid);
}
___________________________________________________________________________
            Ken Prada                 |
Applied Ocean Physics and Engineering |Organization is critical to success.
Woods Hole Oceanographic Institution  |
       (508) 457-2000 Ext 2711        |Try eating a soup sandwich.
          kegp@xxxxxxxxxxxxx          |


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