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

[netCDF #FIB-693038]: Adding a Altitude Dimension



Hi Stephen,

> Questions:
> 
> 1) a) What are the differences between the netCDF format 1.0 and 3.0 ?

"1.0" and "3.0" refer to software release versions rather than format
versions.  There is no netCDF format 3.0, but netCDF-3 software reads
netCDF "classic" and "64-bit offset" formats.  The netCDF-4 software
reads those and also netCDF-4 format (which is uses HDF5 as a storage
layer).  The situation with formats and software releases is explained
in this FAQ answer:

  http://www.unidata.ucar.edu/software/netcdf/docs/faq.html#formats-and-versions

> b) Can something that reads 1.0 read 3.0 ?

New versions of netCDF software support all previous versions of the
format and data model, so the latest version of the software will be
able to read netCDF data produced by any version of the software, even
files written in 1989 by the first release.  The software detects
which format variant is used for the data, so you don't have to know
or care how the netCDF data was written.  New versions of netCDF
software can also modify and write all format variants.  The only time
you have to know about formats is when you create a new netCDF file
and want to write it in a non-default format variant.  Currently the
default is netCDF classic model, which is understood by all versions
of the software.

There is one exception currently, which will be fixed soon, involving
the experimental CXX4 API for supporting netCDF-4 with a modern C++
interface.  The version in the current snapshot is limited to only
reading or writing the netCDF-4 HDF5-based format.

> 2) I have defined dimensions and a variable to create data in 3D,
> how would I write a single point of data
> Example:
> 
> Data => Press[k][j][i]

To write a single value, data, to the [k][j][i] element of the
pressure variable:

  // assume presVar is address of pressure variable returned from get_var()
  if(!presVar->set_cur(k, j, i)) // set "corner" for writing block of values
    // error
  if(!presVar->put(data, 1, 1, 1) // block of 1x1x1 values (a single value, 
data)
    // error

> Single => CenterOfPres@ k,j,I

I'm not sure what you're asking here.  Does "CenterOfPres" mean center
point of the pressure variable?  In that case, assuming the variable
is dimensioned for K by J by I, maybe what you want is

  if(!presVar->set_cur((K - 1)/2, (J - 1)/2, (I - 1)/2))
    // error
  if(!presVar->put(data, 1, 1, 1) // block of 1x1x1 values (a single value, 
data)
    // error

> Single => MaxPres @ k,j,I = maximumLevel

If what you're asking for here is to overwrite the maximum pressure
value currently in the pressure variable, the netCDF API can't
determine the indices of that maximum value for you.  You have to read
through all the values of the variable and note the indices of the
maximum value.  Then you can overwrite that value as in the first case
above.

> 3) I need to have a dynamic array for the 3D data, how do I pass that to 
> netCDF ?
> 
> Example has
> double pres [NLVL][NLAT][NLON]
> presVar->put_rec(&pres[0][0][0], rec)

Note that put_rec() is only useful if the first dimension of the
variable is a "record dimension", that is a dimension with a size that
may increase as you add more data.  In a classic netCDF file, only one
such dimension is permitted.  So the above assumes the dimension
corresponding to NLVL has been created using the add_dim(NcToken
dimname) method (no length specified).

> And I need
> double ***pres = new double **[zCount]
> double **innerArray_1 = new double*[zCount * yCount]
> double *innerArray_2 = new double[zCount * yCount * xCount]
> for ( k = 0 to zCount)
> {
> pres[k] = innerArray_1 + ( k*yCount)
> 
> for ( j = 0 to yCount)
> {
> pres[k][j] = innerArray_2 + ((k*yCount) + j ) * xCount
> }
> }
> 
> presVar->put_rec(&conc[0][0][0], rec);
> 
> Would this be correct ?

I don't think so.  I don't see the declaration for the "conc" array,
but the put_rec method and all the put methods assume the address of a
contiguous block of in-memory data is provided to the method for
converting to portable form and writing to disk.  So you need one put
call for each contiguous data block.  Multiple non-contiguous arrays
allocated with distinct new calls require multiple corresponding put
calls. 

The NetCDF C++ Interface Guide isn't clear on this.  That guide was
written assuming

  ... familiarity with the netCDF User's Guide, where the concepts of
  netCDF dimensions, variables, and attributes are discussed.

It also seems to assume familiarity with the way the C and Fortran
interfaces work, writing values stored in contiguous areas of memory
to the disk.

--Russ

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



Ticket Details
===================
Ticket ID: FIB-693038
Department: Support netCDF
Priority: Normal
Status: Closed