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

[netCDF #YMC-304801]: An Array inside of and array



Stephen,

> An additional question:
> 
> How would and array be placed inside an array for netCDF
> 
> Example
> 3d array of data where each 3d element id a 2d array

The netCDF-3 "classic data model" doesn't support nested arrays such as
you describe, so data providers have gotten around this by either using
higher dimensionality arrays (such as a 5D array in the case you describe, 
with the most rapidly varying 2 dimensions used for the inner 2D array).

Another approach is to use multiple variables for the elements of the 2D
array.  For example, if you want a 3D array of wind vectors, with each
wind vector having an eastward component and a northward component, the
conventional way to do this is to define two variables with standard name 
attributes that define the relation between them.  That's why the CF 
standard name table

has the names "geostrophic_eastward_wind" and "geostrophic_northward_wind" 
that identify the related non-vector quantities.

If you decide to use the netCDF-4 enhanced data model, it supports nested
types and array members of user-defined types, so there is a straightforward
way to do what you want.  Just define a type that contains a 2D member and
then define a variable that is a 3D array of values of that type.  Here's
the CDL that the ncgen utility would understand:

  netcdf ymc {
  types:
    compound twod_t {
      float inner(2, 2) ;
    }; // twod_t
  dimensions:
          k = 2 ;
          m = 3 ;
          n = 4 ;
  variables:
          twod_t my_var(k, m, n) ;
  data:

   my_var =
    {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}},
    {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}},
    {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}},
    {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}},
    {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}},
    {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}} ;
  }

--Russ



  

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



Ticket Details
===================
Ticket ID: YMC-304801
Department: Support netCDF
Priority: Normal
Status: Closed