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

[netCDF #SFB-153535]: fundimental question about ncgen



Hi Ben,

You're right that the ncgen program in netCDF-3 can only read values for a 
variable at a time, and CDL has no syntax for representing simple structures 
such as (x,y) pairs in a single variable, other than a 2-dimensional array.  
NetCDF-4 will support structures and arrays of structures, but for now, I think 
the best you can do is to define a two-dimensional array using CDL such as

  dimensions:
     two = 2;
     n = 1500;
  variables:
     float xy(n,two);
  data:
     xy = 1.0, 1.1,
          2.0, 2.1,
       ...
          1500.0, 1500.1;

to represent the 1500 pairs (1.0, 1.1), (2.0, 2.1), ... (1500.0, 1500.1).

If instead you want to have two variables, x and y, in a structure such as

  dimensions:
    n = 1500;
  variables:
    float x(n);
    float y(n);
  data:
    x = 1.0, 2.0, ..., 1500.0;
    y = 1.1, 2.1, ..., 1500.1;

you will have to transpose the value pairs you have now from an n by 2 array to 
a 2 by n array to make a CDL file.  This is not hard with scripting languages 
such as perl, python, or ruby, and may even be easy using tools like Excel.  
Alternatively, a program that reads in the values as pairs and writes them into 
the netCDF file as they are read in is relatively short, using a C, C++, f77, 
f90, or Java interface.  In the next beta release of netCDF 3.6.2, we will have 
a tutorial with examples for writing and reading simple datasets in C, C++, 
f77, and f90, and these examples will also soon be on the Web.

Sorry that CDL is currently too simple for your needs.  Please let us know if 
you have more questions about this.

--Russ

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



Ticket Details
===================
Ticket ID: SFB-153535
Department: Support netCDF
Priority: Normal
Status: Closed