NcFileStitcher { static int[] determineSourceOffsets(int sectionSize, Variable variable) { int totalSize = 1; for (int i = 0; i < variable.getDimensions().size(); i++) { totalSize *= variable.getDimension(i).getLength(); } final int numberOfSections = totalSize / sectionSize; int[] sourceOffsets = new int[numberOfSections]; for (int i = 0; i < numberOfSections; i++) { sourceOffsets[i] = i * sectionSize; } return sourceOffsets; }    }
@Test public void testDetermineSourceOffsets() throws IOException, URISyntaxException { final File f1_BT_io_file = getSecondNcFile("F1_BT_io.nc"); final NetcdfFile f1_BT_io_netcdfFile = NetcdfFileOpener.open(f1_BT_io_file); assertNotNull(f1_BT_io_netcdfFile); final Variable f1_BT_io_variable = f1_BT_io_netcdfFile.getVariables().get(0); assertArrayEquals(new int[]{0}, NcFileStitcher.determineSourceOffsets(1800000, f1_BT_io_variable)); final File met_tx_file = getFirstNcFile("met_tx.nc"); final NetcdfFile met_tx_netcdfFile = NetcdfFileOpener.open(met_tx_file); assertNotNull(met_tx_netcdfFile); final Variable u_wind_tx_variable = met_tx_netcdfFile.getVariables().get(11); assertArrayEquals(new int[]{0, 260000, 520000, 780000, 1040000}, NcFileStitcher.determineSourceOffsets(260000, u_wind_tx_variable)); }