[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 19990711: extra header space



>To: address@hidden
>From: Michael Nolta <address@hidden>
>Subject: extra header space
>Organization: Princeton
>Keywords: 199907110517.XAA12464 netCDF

Hi Mike,

> I'm having a little trouble creating extra space in the header using the
> '__' functions. The little test program I wrote isn't behaving as I
> expected. It creates a file with an integer array, fills the array, and
> then reenters define mode to add a "title" global attribute. Looking at
> the output file, it seems that adding the "title" attribute causes the
> "x" variable data to be rewritten, overwriting the extra header space in
> the process. What am I doing wrong?

It looks like you aren't doing anything wrong, and it also appears to
me as if things are working as expected, at least when I compile and
run your example with netCDF version 3.4 on a SunOS 5.7 SPARC
platform.  What evidence do you have that adding the title attribute
overwrites the extra space in the header?  When I run your program,
ncdump on the result shows the title attribute has the expected value:

    $ ncdump header_test.nc 
    netcdf header_test {
    dimensions:
            i = 768 ;
    variables:
            int x(i) ;

    // global attributes:
                    :title = "header test" ;
    data:

     x = 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, 
     ...
        752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 
        766, 767 ;
    }

--Russ

> #include <netcdf.h>
> #include <string.h>
> 
> #define N 768
> 
> int
> main( int argc, char *argv[] )
> {
>         int ncid, dimid, varid;
>         char title[] = "header test";
>         int i, x[N];
> 
>         for ( i = 0; i < N; i++ ) x[i] = i;
> 
>         nc_create( "header_test.nc", NC_CLOBBER, &ncid );
> 
>         nc_def_dim( ncid, "i", N, &dimid );
>         nc_def_var( ncid, "x", NC_INT, 1, &dimid, &varid );
> 
>         nc__enddef( ncid, 1024, 4, 0, 4 );
> 
>         nc_put_var_int( ncid, varid, x );
> 
>         nc_redef( ncid );
>         nc_put_att_text( ncid, NC_GLOBAL, "title", strlen(title), title );
>         nc_close( ncid );
> 
>         return 0;
> }