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

Re: 950308: netCDF to Vis5D



Mechthild,

> In STEP2, I use ncvarget in order to read a hyperslab of 
> values produced by the file my_file.cc. I don't know if I 
> use this function in a correct way.

It looks right to me.

> My goal is to read a 144*72*16 grid, write it to g and 
> convert it to vis5d-format. But g doesn't get the right 
> values!

g gets the same values you wrote as the variable "m", in the same order.
Perhaps there is a misunderstanding about the order in which v5dWrite()
expects the values.  The order in which you have read the values
(extracted from the output of "ncdump -f c netCDFdaten.nc") is:

 m =
    16838 ,  // m(0,0,0)
     5758 ,  // m(0,0,1)
    10113 ,  // m(0,0,2)
     ...
    17543 ,  // m(0,0,15)
    25089 ,  // m(0,1,0)
     ...
    28505 ,  // m(0,1,15)
    28394 ,  // m(0,2,0)
     ...
    8911 ,  // m(143,71,14)
    27040 ;  // m(143,71,15)

with the z ("Hoehe") dimension varying fastest, and the x ("Laenge")
dimension varying most slowly.  Judging by the definition of the macro G in
the source:

> #define G(ROW, COLUMN, LEVEL)   g[ (ROW) + ((COLUMN) + (LEVEL) * Nc) * Nr ];

it appears that v5dWrite might be expecting the x to vary fastest and the z
to vary most slowly.  Thus you may have to either reorder the data, read it
in in the order expected, or change the order in which you are writing it.
Or perhaps Vis5D has some other way of handling data in a different orders.

> I hope that you understand now, I send you a new version of
> my program.

There is another problem in your program that writes the data:

>     NcVar* z = nc.add_var("z", ncLong, zd);
>     z->add_att("long_name", "Hoehe");
>     z->add_att("units", "Km");

You define this as type ncLong, but later

>     float *zs = new float[zd->size()];
>     for(i = 0; i < zd->size(); i++)
>       zs[i] = 10. + 0.5*i;
>     z->put(zs, zd->size());

you try to write float values into it.  The C++ interface is type-safe, so
it actually doesn't permit this.  The z->put() call above returns FALSE.  If
you want to catch errors like this, you will need to check the return values
of the netCDF C++ member functions that return boolean, for example:

     if(!z->put(zs, zd->size()) {
        cerr << "error writing " << zd->name() << "\n";
     }

______________________________________________________________________________

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