0

I am trying to read a NetCDF file with 4 parameters (Time, Depth, Latitude, Longitude), I want to read the file at a constant Time and depth.

Right now I am reading the whole file and then getting the values in a 4D grid and then parsing the grid to get the values at constant depth and time into a 2D array

//I have read the values of time and depth in TimeArr and depthArr respectively

int depthIndex = binarySearchInArray(depthArr, d);
int timeIndex = binarySearchInArray(timeArr, d);

ArrayFloat.D4 tempArr = (ArrayFloat.D4) v.read();
float[][] grid = new float[(int) latArr.getSize()][(int) lonArr.getSize()];
for (int i = 0; i < latArr.getSize(); i++) {
    for (int j = 0; j < lonArr.getSize(); j++) {
        grid[i][j] = tempArr.get(timeIndex, depthIndex, i, j);
    }
}
return grid;

The line "ArrayFloat.D4 tempArr = (ArrayFloat.D4) v.read();" takes a lot of time to read the file if it's too large. Also, it is pointless to read all the dimensions when I need it for only one.

Is there a way to directly read a file along 2 dimensions only (with 2 dimensions, Time and Depth, kept constant)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.