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

Re: 950304: is 0 valid value for count[]?



>Organization: NCSA
>Keywords: 199503042325.AA13316

Hi Shiming,

> Recently I tried a user's program and realized that
> 
> 1.NCvarput/NCvario will write out a record filled with the fill-value if:
> 
>     dim[0]=NC_UNLIMITED;
>     dim[1]=10;
>     start[0]=start[1]=0;
>     count[0]=count[1]=0;
>     --------------------------------------------
>     xongmao 63> ../ncdump/ncdump badnc.nc
>     netcdf badnc {
>     dimensions:
>         dim0 = UNLIMITED ; // (1 currently)
>         dim1 = 10 ;
> 
>     variables:
>         long vname(dim0, dim1) ;
> 
>     data:
> 
>     vname =
>        -2147483647, -2147483647, -2147483647, -2147483647, -2147483647,
>        -2147483647, -2147483647, -2147483647, -2147483647, -2147483647 ;
>     }
>     ---------------------------------------------------
> 
>     My question is:
> 
>        . Is 0 a valid value for count[]?
>        . If 0 is valid, should 0 instead of 1 record be written to the file
>          every time NCvarput is called?

0 should be a valid value for count, just as it is valid to call the Unix
function `write' to write 0 bytes of data or the stdio function `fwrite' to
write 0 items.  I think you are right, that 0 instead of 1 records should be
written in this case.  Thanks for pointing out his bug.

> 2. If:
>     dim[0]=NC_UNLIMITED;
>     dim[1]=10;
>     start[0]=start[1]=0;
>     count[0]=count[1]=0;
>     stride[0]=stride[1]=2;
>     data[0]= data[1]= ...= data[9] = 33;
> 
>     calling NCvarputg(cdfid, vid, start, count, stride, NULL, (void *) data)
>     will write out a record filled with the fill-value except
>      the first element with value 33.
>    ------------------------------------------------
>    xongmao 65> ../ncdump/ncdump badncg.nc
>    netcdf badncg {
>    dimensions:
>         dim0 = UNLIMITED ; // (1 currently)
>         dim1 = 10 ;
> 
>    variables:
>         long vname(dim0, dim1) ;
> 
>    data:
> 
>    vname =
>         33, -2147483647, -2147483647, -2147483647, -2147483647,
>         -2147483647, -2147483647, -2147483647, -2147483647, -2147483647 ;
>    }
>    -------------------------------------------------------
> 
>    My question is:
> 
>    . Is 0 a valid value for count[]?

Yes, and as with write(2) and fwrite(3), nothing should happen to the file
when a count of 0 is specified.

>    . If so, should 0 element and 0 record be written?

Yes, and the current behavior of writing 1 record appears to be a bug.

> They are not really problems. I just want to make sure whether or not
> the above outputs are intended.
> 
> I modified line 91 of putgetg.c to:
> 
>     91              iocount[idim]       = (count[idim] == 0) ? 0 : 1;
> 
> With this fix, the second case stops writing out the '33'. But
> it still writes out a record of fill-value.

Thanks for providing the fix.  We'll try to fix the other problems before
the next release.

--Russ

______________________________________________________________________________

Russ Rew                                                UCAR Unidata Program
address@hidden                                          P.O. Box 3000
http://www.unidata.ucar.edu/                          Boulder, CO 80307-3000
______________________________________________________________________________