[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netCDF #QQU-296951]: NcVar put method
- Subject: [netCDF #QQU-296951]: NcVar put method
- Date: Wed, 10 Nov 2010 15:52:05 -0700
Hi Salah,
Sorry to have taken so long to respond to your question ...
It looks like you got the help you needed from the netcdfgroup
mailing list.
--Russ
> I am trying to use this method signature -NcBool put(const ....* vals,
> const long* counts)-; but I have a problem , can some one please tell
> me what is my mistake .
>
> Why - data->put(&dataOut[0],*dim);- is not working. Please see the code.
>
>
> #include <iostream>
> #include <netcdfcpp.h>
>
> using namespace std;
>
> // We are writing 2D data, a 6 x 12 grid.
> static const int NDIMS = 2;
> static const int NX = 6;
> static const int NY = 12;
>
> // Return this in event of a problem.
> static const int NC_ERR = 2;
>
> int main(void)
> {
> // Different ways to write arrays
>
> int dataOut[NX * NY];
> int dataOut2[NX] [NY];
>
> // Create some pretend data. Note that dataOut and dataOut2 are
> identical...!!!
> for(int i = 0; i < NX; i++)
> for(int j = 0; j < NY; j++){
> dataOut[i * NY +j] = (i+1) * (j+1);
> dataOut2[i][j] = (i+1) * (j+1);
> }
>
>
> // Create the file.
> NcFile dataFile("simple_xy.nc", NcFile::Replace);
>
> if (!dataFile.is_valid())
> {
> cout << "Couldn't open file!\n";
> return NC_ERR;
> }
>
> NcDim* xDim = dataFile.add_dim("x", NX);
> NcDim* yDim = dataFile.add_dim("y", NY);
>
>
> const NcDim* all[2] ;
> all[0] = xDim;
> all[1] = yDim;
>
> int *dim;
> dim = new int[2];
> dim[0] = 6;
> dim[1] = 12;
>
> NcVar *data = dataFile.add_var("data", ncInt, 2, all);
> NcVar *data2 = dataFile.add_var("data2", ncInt, 2, all);
>
> // This works fine and data and data2 are identical
> // data->put(&dataOut[0],NX, NY);
> data2->put(&dataOut2[0][0], NX, NY);
>
> // try to use another signature
>
> data->put(&dataOut[0],*dim); //nothing is written
>
> cout << "*** SUCCESS writing example file simple_xy.nc!" << endl;
>
> return 0;
> }
>
>
>
>
>
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
Ticket Details
===================
Ticket ID: QQU-296951
Department: Support netCDF
Priority: Normal
Status: Closed