@Test public void testReadSubsection() throws IOException, InvalidRangeException { String location = TestDir.cdmUnitTestDir + "formats/netcdf4/ncom_relo_fukushima_1km_tmp_2011040800_t000.nc4"; try (NetcdfFile ncfile = NetcdfFile.open(location); NetcdfFile jni = openJni(location)) { jni.setLocation(location + " (jni)"); // float salinity(time=1, depth=40, lat=667, lon=622); Array data1 = read(ncfile, "salinity", "0,11:12,22,:"); //NCdumpW.printArray(data1); System.out.printf("Read from jni%n"); Array data2 = read(jni, "salinity", "0,11:12,22,:"); assert MAMath.nearlyEquals(data1, data2); System.out.printf("data is equal%n"); } }
public boolean isStationary() { // only check once if (!isStationaryChecked) { Variable lat = ds.findVariable("latitude"); if (lat != null) { if (lat.isScalar()) isStationary = lat.getSize() == 1; else { // if array, check to see if all of the values are // approximately the same Array gar = null; try { gar = lat.read(); Object firstVal = gar.getObject(0); Array gar2 = gar.copy(); for (int i = 1; i < gar.getSize(); i++) { gar2.setObject(i, firstVal); } isStationary = nearlyEquals(gar, gar2); } catch (IOException e) { log.error("Error reading latitude variable {}. Cannot determine if " + "platform is stationary. Setting to default (false).", lat.getFullName()); } } } isStationaryChecked = true; } return isStationary; }
@Test public void testReadSubsection() throws IOException, InvalidRangeException { String location = canonjoin(tdsContentRootPath,"thredds/public/testdata/nc_test_cdf5.nc"); try (RandomAccessFile raf = RandomAccessFile.acquire(location)) { // Verify that this is a netcdf-5 file int format = NCheader.checkFileType(raf); Assert.assertTrue("Fail: file format is not CDF-5",format == NCheader.NC_FORMAT_64BIT_DATA); } try (NetcdfFile jni = openJni(location)) { jni.setLocation(location + " (jni)"); Array data = read(jni, "f4", "0:2"); if(prop_visual) { String dump = NCdumpW.toString(data); logger.debug(dump); String testresult = dump.replace('r', ' ').replace('\n', ' ').trim(); visual("CDF Read", testresult); } Assert.assertTrue(String.format("***Fail: data mismatch"), MAMath.nearlyEquals(data, BASELINE)); System.err.println("***Pass"); } }
Array coordData = coord.read(); Array newData = Array.makeArray(coord.getDataType(), values); if (MAMath.nearlyEquals(coordData, newData)) { if (debugBreakup) parseInfo.format(" use existing coord %s%n", dim); return dim;
public static boolean equals(StructureData sdata1, StructureData sdata2) { if (sdata1 == sdata2) { return true; } else if (sdata1 == null || sdata2 == null) { return false; } if (!equals(sdata1.getStructureMembers(), sdata2.getStructureMembers())) { return false; } for (String memberName : sdata1.getStructureMembers().getMemberNames()) { Array memberArray1 = sdata1.getArray(memberName); Array memberArray2 = sdata2.getArray(memberName); if (!MAMath.nearlyEquals(memberArray1, memberArray2)) { return false; } } return true; }
-1.1f, -1.0f, -0.7f, -0.8f, -0.5f, -0.2f, 0.0f, 0.3f, 0.5f, 1.3000001f, 1.6f, 1.7f, 2.2f, 2.8f }); Assert.assertTrue(MAMath.nearlyEquals(expectedUcomponentValues, actualUcomponentValues));