/** * Find the set of Enhancements that matches the String. For backwards compatibility, 'true' = All. * * @param enhanceMode : 'None', 'All', 'ScaleMissing', 'ScaleMissingDefer', 'CoordSystems', All', case insensitive * @return EnumSet<EnhanceMode> */ static public Set<Enhance> parseEnhanceMode(String enhanceMode) { if (enhanceMode == null) return null; Set<Enhance> mode = null; if (enhanceMode.equalsIgnoreCase("true") || enhanceMode.equalsIgnoreCase("All")) { mode = getEnhanceAll(); } else if (enhanceMode.equalsIgnoreCase("AllDefer")) { mode = EnumSet.of(Enhance.ScaleMissingDefer, Enhance.CoordSystems, Enhance.ConvertEnums); } else if (enhanceMode.equalsIgnoreCase("ScaleMissing")) { mode = EnumSet.of(Enhance.ScaleMissing); } else if (enhanceMode.equalsIgnoreCase("ScaleMissingDefer")) { mode = EnumSet.of(Enhance.ScaleMissingDefer); } else if (enhanceMode.equalsIgnoreCase("CoordSystems")) { mode = EnumSet.of(Enhance.CoordSystems); } else if (enhanceMode.equalsIgnoreCase("ConvertEnums")) { mode = EnumSet.of(Enhance.ConvertEnums); } return mode; }
/** * Find the set of Enhancements that matches the String. For backwards compatibility, 'true' = All. * * @param enhanceMode : 'None', 'All', 'ScaleMissing', 'ScaleMissingDefer', 'CoordSystems', All', case insensitive * @return EnumSet<EnhanceMode> */ static public Set<Enhance> parseEnhanceMode(String enhanceMode) { if (enhanceMode == null) return null; Set<Enhance> mode = null; if (enhanceMode.equalsIgnoreCase("true") || enhanceMode.equalsIgnoreCase("All")) { mode = getEnhanceAll(); } else if (enhanceMode.equalsIgnoreCase("AllDefer")) { mode = EnumSet.of(Enhance.ScaleMissingDefer, Enhance.CoordSystems, Enhance.ConvertEnums); } else if (enhanceMode.equalsIgnoreCase("ScaleMissing")) { mode = EnumSet.of(Enhance.ScaleMissing); } else if (enhanceMode.equalsIgnoreCase("ScaleMissingDefer")) { mode = EnumSet.of(Enhance.ScaleMissingDefer); } else if (enhanceMode.equalsIgnoreCase("CoordSystems")) { mode = EnumSet.of(Enhance.CoordSystems); } else if (enhanceMode.equalsIgnoreCase("ConvertEnums")) { mode = EnumSet.of(Enhance.ConvertEnums); } return mode; }
case "all": return getEnhanceAll(); case "none": return getEnhanceNone(); case "convertenums": return EnumSet.of(Enhance.ConvertEnums); Enhance.IncompleteCoordSystems); case "true": return getEnhanceAll(); case "scalemissingdefer": return getEnhanceNone(); case "alldefer": return EnumSet.of(Enhance.ConvertEnums, Enhance.CoordSystems);
System.out.printf("---fd compare ok %s%n%s%n", ok,out); NetcdfDataset nc3 = NetcdfDataset.wrap(nc1, NetcdfDataset.getEnhanceAll()); System.out.printf("---NetcdfDataset.wrap(nc1, enhance) object == %d%n", nc3.hashCode()); FeatureDataset fd3 = ucar.nc2.ft.FeatureDatasetFactoryManager.wrap(ucar.nc2.constants.FeatureType.STATION, nc3, null, new Formatter(System.out));
for (int i=0; i<2; i++) { NetcdfDataset ncd = NetcdfDataset.acquireDataset(durl, true, null); NetcdfDataset ncd2 = NetcdfDataset.wrap(ncd, NetcdfDataset.getEnhanceAll()); Formatter out = new Formatter(); ok &= CompareNetcdf2.compareFiles(ncd, ncd2, out, false, false, false);
@Test public void testVarWithUnsignedType() throws IOException { String ncml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2' location='"+TestDir.cdmLocalTestDataDir +"testWrite.nc'>\n" + " <variable name='bvar' shape='lat' type='ubyte'/>" + "</netcdf>"; try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), null); NetcdfFile ncd = NetcdfDataset.wrap(ncfile, NetcdfDataset.getEnhanceAll())) { Variable v = ncd.findVariable("bvar"); Assert.assertNotNull(v); Assert.assertEquals(DataType.USHORT, v.getDataType()); boolean hasSigned = false; Array data = v.read(); while (data.hasNext()) { float b = data.nextFloat(); if (b < 0) hasSigned = true; } Assert.assertTrue(!hasSigned); } }
@Test public void testVarWithUnsignedAttribute() throws IOException { String ncml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2' location='"+TestDir.cdmLocalTestDataDir +"testWrite.nc'>\n" + " <variable name='bvar' shape='lat' type='byte'>\n" + " <attribute name='_Unsigned' value='true' />\n" + " </variable>\n" + "</netcdf>"; try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), null); NetcdfFile ncd = NetcdfDataset.wrap(ncfile, NetcdfDataset.getEnhanceAll())) { Variable v = ncd.findVariable("bvar"); Assert.assertNotNull(v); Assert.assertEquals(DataType.USHORT, v.getDataType()); boolean hasSigned = false; Array data = v.read(); while (data.hasNext()) { float b = data.nextFloat(); if (b < 0) hasSigned = true; } Assert.assertTrue(!hasSigned); } }
@Test public void testUnsignedWrap() throws IOException { String ncml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2' location='"+TestDir.cdmLocalTestDataDir +"testWrite.nc'>\n" + " <variable name='bvar' shape='lat' type='byte'>\n" + " <attribute name='_Unsigned' value='true' />\n" + " <attribute name='scale_factor' type='float' value='2.0' />\n" + " </variable>\n" + "</netcdf>"; try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), null); NetcdfFile ncd = NetcdfDataset.wrap(ncfile, NetcdfDataset.getEnhanceAll())) { Variable v = ncd.findVariable("bvar"); Assert.assertNotNull(v); Assert.assertEquals(DataType.FLOAT, v.getDataType()); boolean hasSigned = false; Array data = v.read(); while (data.hasNext()) { float b = data.nextFloat(); if (b < 0) hasSigned = true; } Assert.assertTrue(!hasSigned); } }
@Test public void testAttWithUnsignedAtt() throws IOException { String ncml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2' location='"+TestDir.cdmLocalTestDataDir +"testWrite.nc'>\n" + " <attribute name='gatt' type='byte' isUnsigned='true'>1 0 -1</attribute>" + "</netcdf>"; try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), null); NetcdfFile ncd = NetcdfDataset.wrap(ncfile, NetcdfDataset.getEnhanceAll())) { Attribute att = ncd.findGlobalAttribute("gatt"); Assert.assertNotNull(att); Assert.assertEquals(DataType.UBYTE, att.getDataType()); Assert.assertEquals(3, att.getLength()); Array gattValues = att.getValues(); boolean hasSigned = false; while (gattValues.hasNext()) { short b = gattValues.nextShort(); if (b < 0) hasSigned = true; } Assert.assertTrue(!hasSigned); } }
@Test public void testAttWithUnsignedType() throws IOException { String ncml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2' location='"+TestDir.cdmLocalTestDataDir +"testWrite.nc'>\n" + " <attribute name='gatt' type='ubyte'>1 0 -1</attribute>" + "</netcdf>"; try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), null); NetcdfFile ncd = NetcdfDataset.wrap(ncfile, NetcdfDataset.getEnhanceAll())) { Attribute att = ncd.findGlobalAttribute("gatt"); Assert.assertNotNull(att); Assert.assertEquals(DataType.UBYTE, att.getDataType()); Assert.assertEquals(3, att.getLength()); Array gattValues = att.getValues(); boolean hasSigned = false; while (gattValues.hasNext()) { short b = gattValues.nextShort(); if (b < 0) hasSigned = true; } Assert.assertTrue(!hasSigned); } }
@Test public void testAttWithUnsignedType2() throws IOException { String ncml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2' location='"+TestDir.cdmLocalTestDataDir +"testWrite.nc'>\n" + " <attribute name='gatt' type='ubyte' value='1 0 -1' />" + "</netcdf>"; try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), null); NetcdfFile ncd = NetcdfDataset.wrap(ncfile, NetcdfDataset.getEnhanceAll())) { Attribute att = ncd.findGlobalAttribute("gatt"); Assert.assertNotNull(att); Assert.assertEquals(DataType.UBYTE, att.getDataType()); Assert.assertEquals(3, att.getLength()); Array gattValues = att.getValues(); boolean hasSigned = false; while (gattValues.hasNext()) { short b = gattValues.nextShort(); if (b < 0) hasSigned = true; } Assert.assertTrue(!hasSigned); } } }