Subset of timesteps from large 4D netcdf files

Oct 1, 2013 at 11:00 AM

I am using the sds library to read large 4-dimensional netcdf files in C#. The dimensions are [Time, Depth, Lat, Long]. The following works perfectly well for smaller files (with fewer time-steps):

var ds = DataSet.Open("");
float[, , ,] v = ds.GetData<float[, , ,]>(ds.Variables[0].Name);

But I run out of memory when using the above when considering many time-steps (say a year).
Ideally, I would like to either read in 1 time-step at a time, or maybe 30 time-steps at a time. I see there are methods to do this (DataSet.ReduceDim() and DataSet.Range(). I have tested these to extract 1D data from 2D data, but can't get them to work for my 4D data. For example I have tried:

float[, , ,] v = ds.GetData<float[, ,]>(ds.Variables[0].Name, DataSet.ReduceDim(0), DataSet.Range(0,30));

in an attempt to extract time-steps 0-30, but I am clearly missing something.

Some example code on how to do this simple task would be very appreciated.

Thanks in advance!
Oct 3, 2013 at 3:41 PM
No need to reply to this. If anyone else is interested, this reads the i'th time-step from data into memory:

float[, ,] v = ds.GetData<float[, ,]>("v", DataSet.ReduceDim(i), DataSet.Range(0, No_Depths - 1), DataSet.Range(0, No_Y - 1), DataSet.Range(0, No_X - 1));