> From: "Glenn P. Davis" <davis@xxxxxxxxxxxxxxxx>
> Byte and short variable sizes are rounded up to the next even 32 bit boundary.
> This is so that 'seeks' are always done "words", not bytes within a word.
> This is true within "record" varables as well.
>
Yes, it sounds reasonable, but seems not to be true in all cases.
For example, you have one variable and 9 NC_BYTE-long vector-records
were written into the file. main() is fed by 1,2,3,4,5 etc., the
number of records:
---------------------------------------------------------------------*/
#include <stdio.h>
#include "netcdf.h"
int cdfid;
int v1_id, v2_id;
short v1;
char v2;
char* cp;
main(argc,argv)
int argc;
char **argv;
{
int n,i,ix[1];
if(argc < 2)
{
n = 1; /* default to one record */
cp="1";
}
else
{
n = atoi(argv[1]); /* or request number of records */
cp=argv[1];
}
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);
}
ncclose(cdfid);
}
/*---------------------------------------------------------------------*/
docdf()
{
int dims[3];
int record_dim;
int vector_dim;
char name[100];
strcat(name, "gabor.");
strcat(name, cp);
cdfid = nccreate( name, NC_CLOBBER);
record_dim = ncdimdef(cdfid, "record", NC_UNLIMITED);
vector_dim = ncdimdef(cdfid, "vector", 9);
dims[0] = record_dim;
dims[1] = vector_dim;
v1_id = ncvardef (cdfid, "var1", NC_BYTE, 2, dims);
ncattput(cdfid,NC_GLOBAL,"title",NC_CHAR,13,(void *)"CDF TEST DATA");
ncendef (cdfid);
}
/*----------------------------------------------------------------------*/
And see the sizes I received:
-rw-r----- 1 gabor 152 Mar 26 16:27 gabor.1 <-- 1 record
-rw-r----- 1 gabor 161 Mar 26 16:27 gabor.2 <-- 2 records
-rw-r----- 1 gabor 170 Mar 26 16:27 gabor.3 <-- 3 records
-rw-r----- 1 gabor 179 Mar 26 16:27 gabor.4 <-- 4 records
-rw-r----- 1 gabor 188 Mar 26 16:27 gabor.5 <-- 5 records
Absolute file size is not adjusted to word boundary. The increment
caused by adding one more record is always 9 bytes, it is not rounded
to word boundary.
********************************************************************************
********************************************************************************
And now the honey on the cake: I had TWO variables, Each contained
1,2,3 records. The record was 1,2,3 and 5 NC_BYTE long.
record = 1 NC_BYTE
variable 1 - NC_BYTE(1) : variable 2 - NC_BYTE(1)
file size w/ 1 record = 188 - 2 records = 196 - 3 records = 204 (diff = 8)
should be 2
record = 2 NC_BYTEs
variable 1 - NC_BYTE(2) : variable 2 - NC_BYTE(2)
file size w/ 1 record = 188 - 2 records = 196 - 3 records = 204 (diff = 8)
should be 4
record = 3 NC_BYTEs
variable 1 - NC_BYTE(3) : variable 2 - NC_BYTE(3)
file size w/ 1 record = 188 - 2 records = 196 - 3 records = 204 (diff = 8)
should be 6
record = 5 NC_BYTEs
variable 1 - NC_BYTE(5) : variable 2 - NC_BYTE(5)
file size w/ 1 record = 196 - 2 records = 212 - 3 records = 228 (diff = 16)
should be 10
NOW it was rounded!!! But when I had only ONE variable, it was not
rounded!?!? How does it come? //
********************************************************************************
********************************************************************************
Gabor Fichtinger
Scientific Visualization Group,
Center for High Performance Computing
The University of Texas System
Balcones Research Center, 1.154 CMS
10100 Burnet Road, Austin, TX, 78758-4497
Ph. : (512) 471 2409
Ph. : 1-800-262-2472/2409 (toll free)
Fax : (512) 471 2445
Email: gabor@xxxxxxxxxxxxxxx
__o
__o -\<,
-\<, __________O / O
___________O / O