2007 Unidata NetCDF Workshop for Developers and Data Providers > NetCDF Example Programs
6.12 Reading Generic Data of Unknown Dimensonality
The odometer code in the netCDF library can read data in a general
way, without knowing the dimensionality.
/* Perform I/O. Exit when done. */
for (;;)
{
int lretval = pg_vara(pg, nc, ncid, varid, mystart, iocount, xtype,
is_long, data);
if (lretval != NC_NOERR
&& (retval == NC_NOERR || lretval != NC_ERANGE))
retval = lretval;
/*
* The following code permutes through the variable s
* external start-index space and it s internal address
* space. At the UPC, this algorithm is commonly
* called "odometer code".
*/
idim = maxidim;
carry:
data = (char *)data + (mymap[idim] * mem_type_size);
mystart[idim] += mystride[idim];
if (mystart[idim] == stop[idim])
{
mystart[idim] = start[idim];
data = (char *)data - (length[idim] * mem_type_size);
if (--idim < 0)
break; /* normal return */
goto carry;
}
} /* I/O loop */
2007 Unidata NetCDF Workshop for Developers and Data Providers > NetCDF Example Programs