Re: [netcdfgroup] Creating NetCDF dataset from 2D array by progressive writing of array columns

Hi Nicholas,

Instead of this:
>          // Write each column to file?
>          for(int i = 0; i <  NY; i++)
>              data->put( dataOut, i, NX );

try the following:

for (int i=0; i<NY; i++)  // iterate over rows
{  
  data->set_cur(i*NX);    // set data's current_pointer to start of i'th row
  data->put(dataOut,1,NX);// copy 1*NX numbers from dataOut to data; row (Y) 
major
}

I haven't digested the rest of your code, but certainly the arguments to put() 
are lengths, not indexes.

Good luck,

Sjur K :-)





> -----Original Message-----
> From: netcdfgroup-bounces@xxxxxxxxxxxxxxxx 
> [mailto:netcdfgroup-bounces@xxxxxxxxxxxxxxxx] On Behalf Of 
> Nicholas Kinar
> Sent: 13. mai 2010 21:21
> To: netcdfgroup@xxxxxxxxxxxxxxxx
> Subject: [netcdfgroup] Creating NetCDF dataset from 2D array 
> by progressive writing of array columns
> 
> Hello--
> 
> I would like to store an M-by-N array in a NetCDF file.  The 
> array would 
> be stored as a single variable.  I know the values of M and 
> N, but due 
> to physical memory limitations on my desktop computer, I 
> cannot load the 
> entire 2D array, which would consist of thousands of rows and 
> hundreds 
> of columns.  Instead of loading the entire 2D array, I would like to 
> load M-by-1 arrays (1D arrays), and then progressively add 
> each column 
> to the NetCDF file to create the M-by-N array.
> 
> Is this possible?  The following code snippet (based on the 
> C++ example 
> given in the documentation) demonstrates what I would like to 
> accomplish.  However, after running this code snippet, the 
> NetCDF file 
> produced appears to be nothing but junk data.  (I am using 
> ParaView from 
> Kitware as the NetCDF viewer.)
> 
> /// start of program
>   #include <iostream>
>   #include <netcdfcpp.h>
> 
>   using namespace std;
>   static const int NX = 100;
>   static const int NY = 100;
>   static const int NC_ERR = 2;
> 
>   int main(void)
>    {
>         int dataOut[NX];
> 
>          for(int i = 0; i < NX; i++)
>              dataOut[i] = i;
> 
>          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);
>          NcVar *data = dataFile.add_var("data", ncInt, xDim, yDim);
> 
>          // Write each column to file?
>          for(int i = 0; i <  NY; i++)
>              data->put( dataOut, i, NX );
> 
>          return 0;
> }
> 
> 
> /// end of program
> 
> Thank you for helping to shed some light on this matter.
> 
> Nicholas Kinar
> n.kinar@xxxxxxxx
> Researcher, Centre for Hydrology
> University of Saskatchewan
> Saskatoon, Saskatchewan, CANADA
> 
> 
> 
> 
> _______________________________________________
> netcdfgroup mailing list
> netcdfgroup@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe,  visit: 
> http://www.unidata.ucar.edu/mailing_lists/ 
> 


  • 2010 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: