List<GeoPointCarbon> occurrencesToList(Document document, Region region) { String DATASETNAME_LAT = "RetrievalGeometry/retrieval_latitude"; String DATASETNAME_LONG = "RetrievalGeometry/retrieval_longitude"; String DATASETNAME_XCO2 = "RetrievalResults/xco2"; String DATASETNAME_XCO2_INTERF = "RetrievalResults/xco2_uncert_interf"; String DATASETNAME_XCO2_NOISE = "RetrievalResults/xco2_uncert_noise"; String DATASETNAME_DATE = "Metadata/OrbitStartDate"; H5File file = null; Dataset latitude = null; Dataset longitude = null; Dataset xco2 = null; Dataset xco2_interf = null; Dataset xco2_noise = null; H5ScalarDS orbitStartDate = null; int latitude_dataspace_id = -1; int longitude_dataspace_id = -1; int xco2_dataspace_id = -1; int xco2_interf_dataspace_id = -1; int xco2_noise_dataspace_id = -1; int latitude_dataset_id = -1; int longitude_dataset_id = -1; int xco2_dataset_id = -1; int xco2_interf_dataset_id = -1; int xco2_noise_dataset_id = -1; long[] latitude_dims = {1}; long[] longitude_dims = {1}; long[] xco2_dims = {1}; long[] xco2_interf_dims = {1}; long[] xco2_noise_dims = {1}; float[] latitude_data; float[] longitude_data; float[] xco2_data; float[] xco2_interf_data; float[] xco2_noise_data; String[] date_data = {""}; List<GeoPointCarbon> listOfPoints = new ArrayList<>(); try { // Open an existing file in the folder it is located. file = new H5File(document.getFileName(), FileFormat.READ); file.open(); // Open latitude dataset. latitude = (Dataset) file.get(DATASETNAME_LAT); latitude_dataset_id = latitude.open(); // Open longitude dataset. longitude = (Dataset) file.get(DATASETNAME_LONG); longitude_dataset_id = longitude.open(); // Open xco2 dataset. xco2 = (Dataset) file.get(DATASETNAME_XCO2); xco2_dataset_id = xco2.open(); // Get orbitStartDate dataset. orbitStartDate = (H5ScalarDS) file.get(DATASETNAME_DATE); // Get latitude dataspace and allocate memory for the read buffer. if (latitude_dataset_id >= 0) latitude_dataspace_id = H5.H5Dget_space(latitude_dataset_id); if (latitude_dataspace_id >= 0) H5.H5Sget_simple_extent_dims(latitude_dataspace_id, latitude_dims, null); // Get longitude dataspace and allocate memory for the read buffer. if (longitude_dataset_id >= 0) longitude_dataspace_id = H5.H5Dget_space(longitude_dataset_id); if (longitude_dataset_id >= 0) H5.H5Sget_simple_extent_dims(longitude_dataspace_id, longitude_dims, null); // Get xco2 dataspace and allocate memory for the read buffer. if (xco2_dataset_id >= 0) xco2_dataspace_id = H5.H5Dget_space(xco2_dataset_id); if (xco2_dataset_id >= 0) H5.H5Sget_simple_extent_dims(xco2_dataspace_id, xco2_dims, null); // Allocate array of pointers to rows. latitude_data = new float[(int) latitude_dims[0]]; longitude_data = new float[(int) longitude_dims[0]]; xco2_data = new float[(int) xco2_dims[0]]; // Read the data using the default properties. latitude.init(); latitude_data = (float[]) latitude.getData(); longitude.init(); longitude_data = (float[]) longitude.getData(); xco2.init(); xco2_data = (float[]) xco2.getData(); date_data = (String[]) orbitStartDate.read(); // Process data for (int i = 0; i < latitude_data.length; i++) { if (region.inRegion(latitude_data[i], longitude_data[i])) { listOfPoints.add( new GeoPointCarbon( latitude_data[i], longitude_data[i], date_data[0], (float) (xco2_data[i] * Math.pow(10, 6)))); } } // End access to the latitude dataset and release resources used by it. if (latitude_dataset_id >= 0) latitude.close(latitude_dataset_id); if (latitude_dataspace_id >= 0) H5.H5Sclose(latitude_dataspace_id); // End access to the longitude dataset and release resources used by it. if (longitude_dataset_id >= 0) longitude.close(longitude_dataset_id); if (longitude_dataspace_id >= 0) H5.H5Sclose(longitude_dataspace_id); // End access to the xco2 dataset and release resources used by it. if (xco2_dataset_id >= 0) xco2.close(xco2_dataset_id); if (xco2_dataspace_id >= 0) H5.H5Sclose(xco2_dataspace_id); // Close the file. file.close(); } catch (Exception e) { e.printStackTrace(); } return listOfPoints; }