[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 20020714: support-netcdf Coding Assistance C++
- Subject: Re: 20020714: support-netcdf Coding Assistance C++
- Date: Mon, 15 Jul 2002 15:29:05 -0600
>To: address@hidden
>From: Steve Nguyen <address@hidden>
>Subject: Coding Assistance C++
>Organization: UCAR/Unidata
>Keywords: 200207142318.g6ENIva29161
Hi Eggy,
> I am given unknown sized limit"s" to apply to a
> multi-dimensional array.
>
> Example :
> int row; int col;
>
> int **weather = new int*[row];
> int *weatherblock = new int[row * col];
>
> Is this correct?
> I am a smidge worried I might screw this up.
In the C++ interface, the put method requires the location of the
beginning of a contiguous block of values, as in the example program
in "src/cxx/example.cpp" from the netCDF source distribution:
static float P_data[2][4][3] = {
{{950, 951, 952}, {953, 954, 955}, {956, 957, 958}, {959, 960, 961}},
{{962, 963, 964}, {965, 966, 967}, {968, 969, 970}, {971, 972, 973}}
};
P->put(&P_data[0][0][0], P->edges());
So using "weatherblock" as you have defined it above would be OK for
writing a two-dimensional array of values with one put call, since
they are all in contiguous locations. But your definition for
weather:
int **weather = new int*[row];
has not actually allocated any array storage (just an array of
pointers to rows) and even if you allocate the actual storage for the
rows in a loop, the resulting storage will only be contiguous for each
row, not for the whole array. So that would work with the netCDF C++
interface only if you intend to write out one row at a time, rather
than the whole array in one call.
I hope I've interpreted your question as you intended. Let us know if
this is still not clear ...
--Russ
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu