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

Re: NetCDF question (fwd)



> Organization: NOAA/FSL
> Keywords: 199406151630.AA18068

Hi Barry,

> I'm trying to write a NetCDF file that will contain gridded data.
> I am currently using ncvpt (which in C is routine ncvarput).
> Essentially, what I want to do is write part of an array out
> (or as they say, hyperslab of data). I've got an array called
> x which has four dimensions, i.e., x(i,j,k,l) where i=82 j=62
> k=37, and l=5. I want to write to separate variables in a netcdf
> file x(i,j,k,1), x(i,j,k,2) x(i,j,k,3) etc. I thought that the 
> netcdf arrays start and count controlled what you wrote, that is,
> 
>              integer start(4)
>              integer count(4)
>              start(1)=1
>              start(2)=1
>              start(3)=1
>              start(4)=1
> 
>              count(1)=82
>              count(2)=62
>              count(3)=37
>              count(4)=1
> 
> this would write out only the first variable (l=1,5 are the different
> grids stored in the array x). What do I do if I want x(i,j,k,2) written
> to a separate variable in a NetCDF file? I've tried setting start(4)=2
> and count(4)=2 and this doesn't work. 

First, there is no reason to use four-dimensional variables in the netCDF
file if you just want them each to contain one three-dimensional slab.  In
that case, you would just be using the first three values of the start and
count arrays you have listed above and things should work fine.  You just
specify the values you are writing as starting from x(1,1,1,1), x(1,1,1,2),
..., x(1,1,1,5) in the five calls to ncvpt, like this:

        integer start(3)
        integer count(3)
        start(1)=1
        start(2)=1
        start(3)=1

        count(1)=82
        count(2)=62
        count(3)=37

        call ncvpt(ncid, var1id, start, count, x(1,1,1,1), rcode)
        call ncvpt(ncid, var2id, start, count, x(1,1,1,2), rcode)
        ...
        call ncvpt(ncid, var5id, start, count, x(1,1,1,5), rcode)


>                                        What is wierd is that I get
> a rcode = 0 after I try (which says everything worked, right?) yet
> when I ncdump the file, the variable's values are all missing saying
> that it didn't work.
> 
> Anyway, in the Netcdf output file, the arrays I'm writing to are dimensioned
> (i,j,k,1). The software will not write to an array that is different from
> the array x, that is, the target array in the output netcdf file has to be
> of the same size (apparently) as the array that you are writing out, or
> again,

No, there need not be any relation between the dimensions of the array you
are writing out and the dimensions of the netCDF variable to which you are
writing.  The values are written to the netCDF variable consecutively from
the array position you specify, and as many values are written as the
product of the supplied count array values (or as many of them as there are
dimensions in the netCDF variable).

--Russ