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

Re: 960524: reading a netcdf file with unknown names



>From: Xin Zhu <address@hidden>
>Keywords: 199605241627.AA20936

Hi Xin,

> I am reading a netcdf file. I used NCINQ and got
> NDIMS:  4
> NVARS:  5
> NGATTS: 1
> RECDIM: -1
> RCODE:  0
> Now I don't have any IDs or variabl names to continue. Would somebody  
> help me to read data from the netcdf file?

The way to do this is described in the section "Reading a netCDF File with
Unknown Names", in the NetCDF User's Guide.  For example, if you have a WWW
browser, you can read it at

    http://www.unidata.ucar.edu/packages/netcdf/guide_6.html#SEC35

The key to getting the names is:

    Dimension IDs are assigned by using consecutive integers (beginning at
    0 in C, 1 in FORTRAN). Also dimensions, once created, cannot be
    deleted. Therefore, knowing the number of dimension IDs in a netCDF
    file means knowing all the dimension IDs: they are the integers 0, 1,
    2, ..., (or 1, 2, 3, ... in FORTRAN). For each dimension ID, a call to
    the inquire function ncdiminq (or NCDINQ) returns the dimension name
    and size.

    Variable IDs are also assigned from consecutive integers 0, 1, 2, ...,
    (or 1, 2, 3, ... in FORTRAN). These can be used in ncvarinq (or NCVINQ)
    calls to find out the names, types, shapes, and the number of
    attributes assigned to each variable.

    Once the number of attributes for a variable is known, successive calls
    to ncattname (or NCANAM) return the name for each attribute given the
    netCDF ID, variable ID, and attribute number. Armed with the attribute
    name, a call to ncattinq (or NCAINQ) returns its type and length. Given
    the type and length, you can allocate enough space to hold the
    attribute values. Then a call to ncattget (or NCAGT or NCAGTC) returns
    the attribute values.

    ...

______________________________________________________________________________

Russ Rew                                           UCAR Unidata Program
address@hidden                              http://www.unidata.ucar.edu