+
# netCDF-Java/CDM
The netCDF Java library provides an interface for scientific data access.
diff --git a/cdm-test-utils/src/main/java/ucar/unidata/util/test/UnitTestCommon.java b/cdm-test-utils/src/main/java/ucar/unidata/util/test/UnitTestCommon.java
index 8809a4a0b7..04607014ac 100644
--- a/cdm-test-utils/src/main/java/ucar/unidata/util/test/UnitTestCommon.java
+++ b/cdm-test-utils/src/main/java/ucar/unidata/util/test/UnitTestCommon.java
@@ -209,16 +209,6 @@ public String modify(String text) {
//////////////////////////////////////////////////
// Instance variables
- // System properties
- protected boolean prop_ascii = true;
- protected boolean prop_diff = true;
- protected boolean prop_baseline = false;
- protected boolean prop_visual = false;
- protected boolean prop_debug = DEBUG;
- protected boolean prop_generate = true;
- protected String prop_controls = null;
- protected boolean prop_display = false;
-
protected String title = "Testing";
protected String name = "testcommon";
@@ -231,32 +221,6 @@ public UnitTestCommon() {
public UnitTestCommon(String name) {
this.title = name;
- setSystemProperties();
- }
-
- /**
- * Try to get the system properties
- */
- protected void setSystemProperties() {
- if (System.getProperty("nodiff") != null)
- prop_diff = false;
- if (System.getProperty("baseline") != null)
- prop_baseline = true;
- if (System.getProperty("nogenerate") != null)
- prop_generate = false;
- if (System.getProperty("debug") != null)
- prop_debug = true;
- if (System.getProperty("visual") != null)
- prop_visual = true;
- if (System.getProperty("ascii") != null)
- prop_ascii = true;
- if (System.getProperty("utf8") != null)
- prop_ascii = false;
- if (System.getProperty("hasdisplay") != null)
- prop_display = true;
- if (prop_baseline && prop_diff)
- prop_diff = false;
- prop_controls = System.getProperty("controls", "");
}
//////////////////////////////////////////////////
@@ -379,12 +343,10 @@ protected void unbindstd() {
// Copy result into the a specified dir
public static void writefile(String path, String content) throws IOException {
- File f = new File(path);
- if (f.exists())
- f.delete();
- FileWriter out = new FileWriter(f);
- out.write(content);
- out.close();
+ // We need to set the Charset to UTF-8, but that is not possible
+ // until JDK level 11, so fake it.
+ byte utf8[] = content.getBytes("UTF-8");
+ writefile(path, utf8);
}
// Copy result into the a specified dir
@@ -616,75 +578,4 @@ protected static boolean check(int code, int[] ok) {
return false;
}
- /*
- * // Replacement for stderr & stdout
- * static public class STDIO
- * {
- * public STDIO(String name)
- * {
- * }
- *
- * public void
- * printf(String format, Object... args)
- * {
- * System.err.println(String.format(format, args));
- * }
- *
- * public void
- * println(String msg)
- * {
- * printf("%s%n", msg);
- * }
- *
- * public void
- * print(String msg)
- * {
- * printf("%s", msg);
- * }
- *
- * public void
- * flush()
- * {
- * }
- * }
- *
- * static public STDIO stderr = new STDIO("test");
- * static public STDIO stdout = new STDIO("test");
- *
- * static TemporaryFolder temporaryfolder = null;
- *
- * static public File
- * makeTemporaryDir(String name)
- * throws IOException
- * {
- * if(temporaryfolder == null)
- * temporaryfolder = new TemporaryFolder();
- * return temporaryfolder.newFolder(name);
- * }
- *
- * static public File
- * makeTemporaryFile(String name)
- * throws IOException
- * {
- * if(temporaryfolder == null)
- * temporaryfolder = new TemporaryFolder();
- * return temporaryfolder.newFile(name);
- * }
- * static public void
- * logify(String s)
- * {
- * StringReader rs = new StringReader(s);
- * BufferedReader r = new BufferedReader(rs);
- * String line = null;
- * for(; ; ) {
- * try {
- * line = r.readLine();
- * } catch (IOException ioe) {
- * break;
- * }
- * if(line == null) break;
- * System.err.println(line);
- * }
- * }
- */
}
diff --git a/cdm/core/src/main/java/ucar/ma2/Index.java b/cdm/core/src/main/java/ucar/ma2/Index.java
index 11f6ebb0a6..7d3fea3420 100644
--- a/cdm/core/src/main/java/ucar/ma2/Index.java
+++ b/cdm/core/src/main/java/ucar/ma2/Index.java
@@ -570,7 +570,7 @@ public Index set(int[] index) {
throw new ArrayIndexOutOfBoundsException();
if (rank == 0)
return this;
- int prefixrank = (hasvlen ? rank : rank - 1);
+ int prefixrank = (!hasvlen ? rank : rank - 1);
System.arraycopy(index, 0, current, 0, prefixrank);
if (hasvlen)
current[prefixrank] = -1;
diff --git a/cdm/core/src/main/java/ucar/nc2/Attribute.java b/cdm/core/src/main/java/ucar/nc2/Attribute.java
index b8ab59955d..fc20509233 100644
--- a/cdm/core/src/main/java/ucar/nc2/Attribute.java
+++ b/cdm/core/src/main/java/ucar/nc2/Attribute.java
@@ -32,15 +32,6 @@
* @author caron
*/
public class Attribute extends CDMNode {
- /** @deprecated move to jni.Nc4Iosp */
- @Deprecated
- private static final String SPECIALPREFIX = "_";
-
- /** @deprecated move to jni.Nc4Iosp */
- @Deprecated
- static public final String[] SPECIALS =
- {CDM.NCPROPERTIES, CDM.ISNETCDF4, CDM.SUPERBLOCKVERSION, CDM.DAP4_LITTLE_ENDIAN, CDM.EDU_UCAR_PREFIX};
-
/**
* Turn a list into a map
*
@@ -59,20 +50,6 @@ public static Map makeMap(List atts) {
return result;
}
- /** @deprecated move to jni.Nc4Iosp */
- @Deprecated
- public static boolean isspecial(Attribute a) {
- String nm = a.getShortName();
- if (nm.startsWith(SPECIALPREFIX)) {
- /* Check for selected special attributes */
- for (String s : SPECIALS) {
- if (nm.startsWith(s))
- return true; /* is special */
- }
- }
- return false; /* is not special */
- }
-
///////////////////////////////////////////////////////////////////////////////////
/**
diff --git a/cdm/core/src/main/java/ucar/nc2/Dimension.java b/cdm/core/src/main/java/ucar/nc2/Dimension.java
index a5bfc510b1..051c237ee6 100644
--- a/cdm/core/src/main/java/ucar/nc2/Dimension.java
+++ b/cdm/core/src/main/java/ucar/nc2/Dimension.java
@@ -457,9 +457,6 @@ public void setLength(int n) {
} else if (isUnlimited) {
if (n < 0)
throw new IllegalArgumentException("Unlimited Dimension length =" + n + " must >= 0");
- } else {
- if (n < 1)
- throw new IllegalArgumentException("Dimension length =" + n + " must be > 0");
}
this.length = n;
}
diff --git a/cdm/core/src/main/java/ucar/nc2/Group.java b/cdm/core/src/main/java/ucar/nc2/Group.java
index 8ebb113285..4399c2c9bd 100755
--- a/cdm/core/src/main/java/ucar/nc2/Group.java
+++ b/cdm/core/src/main/java/ucar/nc2/Group.java
@@ -20,6 +20,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ucar.ma2.DataType;
+import ucar.nc2.constants.CDM;
import ucar.nc2.util.EscapeStrings;
import ucar.nc2.util.Indent;
import java.util.ArrayList;
@@ -297,7 +298,7 @@ public Dimension findDimensionLocal(String shortName) {
/** The attributes contained by this Group. */
public AttributeContainer attributes() {
- return AttributeContainer.filter(attributes, Attribute.SPECIALS);
+ return AttributeContainer.filter(attributes, CDM.SPECIALS);
}
/** Find the attribute by name, return null if not exist */
@@ -318,7 +319,7 @@ public String findAttributeString(String attName, String defaultValue) {
/** @deprecated Use attributes() */
@Deprecated
public java.util.List getAttributes() {
- return AttributeContainer.filter(attributes, Attribute.SPECIALS).getAttributes();
+ return attributes().getAttributes();
}
/** @deprecated Use attributes() */
@@ -526,7 +527,7 @@ void writeCDL(Formatter out, Indent indent, boolean strict) {
for (Attribute att : attributes) {
// String name = strict ? NetcdfFile.escapeNameCDL(getShortName()) : getShortName();
- if (!Attribute.isspecial(att)) {
+ if (!CDM.isspecial(att)) {
out.format("%s", indent);
att.writeCDL(out, strict, null);
out.format(";");
diff --git a/cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java b/cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java
index 9aa9c3dba2..3806ee7b02 100644
--- a/cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java
+++ b/cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java
@@ -70,7 +70,7 @@ public class NetcdfFiles {
registerIOProvider("ucar.nc2.internal.iosp.hdf5.H5iospNew");
} catch (Throwable e) {
if (loadWarnings)
- log.info("Cant load class H5iosp", e);
+ log.info("Cant load class H5iospNew", e);
}
try {
registerIOProvider("ucar.nc2.stream.NcStreamIosp");
diff --git a/cdm/core/src/main/java/ucar/nc2/Structure.java b/cdm/core/src/main/java/ucar/nc2/Structure.java
index 65ab45900b..cc9d4872e6 100644
--- a/cdm/core/src/main/java/ucar/nc2/Structure.java
+++ b/cdm/core/src/main/java/ucar/nc2/Structure.java
@@ -23,6 +23,7 @@
import ucar.ma2.StructureData;
import ucar.ma2.StructureDataIterator;
import ucar.ma2.StructureMembers;
+import ucar.nc2.constants.CDM;
import ucar.nc2.util.Indent;
/**
@@ -635,7 +636,7 @@ protected void writeCDL(Formatter buf, Indent indent, boolean useFullName, boole
buf.format(";%s%n", extraInfo());
for (Attribute att : attributes()) {
- if (Attribute.isspecial(att))
+ if (CDM.isspecial(att))
continue;
buf.format("%s", indent);
att.writeCDL(buf, strict, getShortName());
diff --git a/cdm/core/src/main/java/ucar/nc2/Variable.java b/cdm/core/src/main/java/ucar/nc2/Variable.java
index a94219af21..8410a46274 100644
--- a/cdm/core/src/main/java/ucar/nc2/Variable.java
+++ b/cdm/core/src/main/java/ucar/nc2/Variable.java
@@ -1025,7 +1025,7 @@ else if (dataType.isEnum()) {
indent.incr();
for (Attribute att : attributes()) {
- if (Attribute.isspecial(att))
+ if (CDM.isspecial(att))
continue;
buf.format("%s", indent);
att.writeCDL(buf, strict, getShortName());
diff --git a/cdm/core/src/main/java/ucar/nc2/constants/CDM.java b/cdm/core/src/main/java/ucar/nc2/constants/CDM.java
index 21f06b01c9..c6eeb46725 100644
--- a/cdm/core/src/main/java/ucar/nc2/constants/CDM.java
+++ b/cdm/core/src/main/java/ucar/nc2/constants/CDM.java
@@ -5,6 +5,8 @@
package ucar.nc2.constants;
+import ucar.nc2.Attribute;
+
/**
* CDM constants.
*
@@ -55,12 +57,31 @@ public class CDM {
public static final String TIME_OFFSET_HOUR = "hoursFrom0z";
public static final String RUNTIME_COORDINATE = "runtimeCoordinate";
- // Special Attribute Names used in jni.Nc4Iosp
+ // Special attributes
+
+ private static final String SPECIALPREFIX = "_";
+
+ // Define Special attributes that should be suppressed
public static final String NCPROPERTIES = "_NCProperties";
public static final String ISNETCDF4 = "_IsNetcdf4";
public static final String SUPERBLOCKVERSION = "_SuperblockVersion";
- public static final String DAP4_LITTLE_ENDIAN = "_DAP4_Little_Endian";
- public static final String EDU_UCAR_PREFIX = "_edu.ucar";
+
+ static public final String[] SPECIALS = {NCPROPERTIES, ISNETCDF4, SUPERBLOCKVERSION};
+
+ // public static final String DAP4_LITTLE_ENDIAN = "_DAP4_Little_Endian";
+ // public static final String EDU_UCAR_PREFIX = "_edu.ucar";
+
+ public static boolean isspecial(Attribute a) {
+ String nm = a.getShortName();
+ if (nm.startsWith(SPECIALPREFIX)) {
+ /* Check for selected special attributes */
+ for (String s : SPECIALS) {
+ if (nm.startsWith(s))
+ return true; /* is special */
+ }
+ }
+ return false; /* is not special */
+ }
// class not interface, per Bloch edition 2 item 19
private CDM() {} // disable instantiation
diff --git a/cdm/core/src/main/java/ucar/nc2/dataset/DatasetUrl.java b/cdm/core/src/main/java/ucar/nc2/dataset/DatasetUrl.java
index a333a49a74..2bdab61062 100644
--- a/cdm/core/src/main/java/ucar/nc2/dataset/DatasetUrl.java
+++ b/cdm/core/src/main/java/ucar/nc2/dataset/DatasetUrl.java
@@ -287,7 +287,7 @@ private static ServiceType decodePathExtension(String path) {
if (path.endsWith(".dds") || path.endsWith(".das") || path.endsWith(".dods"))
return ServiceType.OPENDAP;
- if (path.endsWith(".dmr") || path.endsWith(".dap") || path.endsWith(".dsr"))
+ if (path.matches("^.*[.](dmr|dap|dsr)([.](xml|html))?$"))
return ServiceType.DAP4;
if (path.endsWith(".xml") || path.endsWith(".ncml"))
@@ -365,7 +365,7 @@ private static ServiceType disambiguateHttp(String location) throws IOException
checkDap2 = true;
}
- if (location.contains("dap4")) {
+ if (location.contains("dap4") || location.contains("d4ts")) {
ServiceType result = checkIfDap4(location);
if (result != null)
return result;
@@ -445,27 +445,27 @@ private static ServiceType checkIfDods(String location) throws IOException {
// check for dmr
private static ServiceType checkIfDap4(String location) throws IOException {
- // Strip off any trailing DAP4 prefix
- if (location.endsWith(".dap"))
- location = location.substring(0, location.length() - ".dap".length());
- else if (location.endsWith(".dmr"))
- location = location.substring(0, location.length() - ".dmr".length());
- else if (location.endsWith(".dmr.xml"))
- location = location.substring(0, location.length() - ".dmr.xml".length());
- else if (location.endsWith(".dsr"))
- location = location.substring(0, location.length() - ".dsr".length());
- try (HTTPMethod method = HTTPFactory.Get(location + ".dmr.xml")) {
+ if (!location.matches("^.*[.](dmr|dap|dsr)([.](xml|html))?$"))
+ return null;
+ // Strip off any trailing DAP4 suffix
+ if (location.endsWith(".xml"))
+ location = location.substring(0, location.length() - ".xml".length());
+ else if (location.endsWith(".html"))
+ location = location.substring(0, location.length() - ".html".length());
+ // location must end with dap, dmr, or dsr
+ location = location.substring(0, location.length() - ".dxx".length());
+
+ try (HTTPMethod method = HTTPFactory.Get(location + ".dsr.xml")) {
int status = method.execute();
if (status == HTTP_OK) {
Optional value = method.getResponseHeaderValue("Content-Type");
if (value.isPresent()) {
- if (value.get().startsWith("application/vnd.opendap.org"))
+ if (value.get().contains("application/vnd.opendap.dap4"))
return ServiceType.DAP4;
}
}
if (status == HTTP_UNAUTHORIZED || status == HTTP_FORBIDDEN)
throw new IOException("Unauthorized to open dataset " + location);
-
// not dods
return null;
}
diff --git a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerWriter.java b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerWriter.java
index 2cb14b793e..74d60d5f9b 100644
--- a/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerWriter.java
+++ b/cdm/core/src/main/java/ucar/nc2/internal/iosp/netcdf3/N3headerWriter.java
@@ -19,6 +19,7 @@
import ucar.nc2.Dimension;
import ucar.nc2.NetcdfFile;
import ucar.nc2.Variable;
+import ucar.nc2.constants.CDM;
import ucar.unidata.io.RandomAccessFile;
/** Class to write a netcdf3 header. */
@@ -217,8 +218,8 @@ int sizeHeader(boolean largeFile) {
private void writeAtts(Iterable atts, Formatter fout) throws IOException {
- final List attributesToWrite = StreamSupport.stream(atts.spliterator(), false)
- .filter(att -> !Attribute.isspecial(att)).collect(Collectors.toList());
+ final List attributesToWrite =
+ StreamSupport.stream(atts.spliterator(), false).filter(att -> !CDM.isspecial(att)).collect(Collectors.toList());
int n = Iterables.size(attributesToWrite);
if (n == 0) {
diff --git a/cdm/core/src/main/java/ucar/nc2/iosp/hdf5/H5header.java b/cdm/core/src/main/java/ucar/nc2/iosp/hdf5/H5header.java
index 429b9d1b41..5d6f73d268 100644
--- a/cdm/core/src/main/java/ucar/nc2/iosp/hdf5/H5header.java
+++ b/cdm/core/src/main/java/ucar/nc2/iosp/hdf5/H5header.java
@@ -1745,7 +1745,7 @@ private boolean makeVariableShapeAndType(Variable v, MessageDatatype mdt, Messag
ncGroup.getEnumTypedefs().stream().filter((e) -> e.equalsMapOnly(local)).findFirst().orElse(local);
if (enumTypedef != null) {
// if found, make sure it is added to the group
- ncGroup.addEnumeration(enumTypedef);
+ assert (ncGroup.getEnumTypedefs().contains(enumTypedef));
} else { // if shared object, wont have a name, shared version gets added later
enumTypedef = new EnumTypedef(mdt.enumTypeName, mdt.map);
ncGroup.addEnumeration(enumTypedef);
diff --git a/cdm/core/src/main/java/ucar/nc2/write/CDLWriter.java b/cdm/core/src/main/java/ucar/nc2/write/CDLWriter.java
index 7eaaa2800c..96db9dfc23 100644
--- a/cdm/core/src/main/java/ucar/nc2/write/CDLWriter.java
+++ b/cdm/core/src/main/java/ucar/nc2/write/CDLWriter.java
@@ -24,6 +24,8 @@
import ucar.nc2.NetcdfFiles;
import ucar.nc2.Structure;
import ucar.nc2.Variable;
+import ucar.nc2.constants.CDM;
+import ucar.nc2.iosp.netcdf4.Nc4;
import ucar.nc2.util.Indent;
import ucar.unidata.util.StringUtil2;
@@ -157,7 +159,7 @@ private void writeCDL(Group group, Indent indent) {
for (Attribute att : group.attributes()) {
// String name = strict ? NetcdfFile.escapeNameCDL(getShortName()) : getShortName();
- if (!Attribute.isspecial(att)) {
+ if (!CDM.isspecial(att)) {
out.format("%s", indent);
writeCDL(att, null);
out.format(";");
@@ -292,8 +294,12 @@ else if (dataType.isEnum()) {
out.format("enum UNKNOWN");
else
out.format("enum %s", NetcdfFile.makeValidCDLName(v.getEnumTypedef().getShortName()));
- } else
- out.format("%s", dataType.toString());
+ } else {
+ String printname = dataType.toString();
+ if (strict)
+ printname = printname.toLowerCase();
+ out.format("%s", printname);
+ }
// if (isVariableLength) out.append("(*)"); // LOOK
out.format(" ");
@@ -303,7 +309,7 @@ else if (dataType.isEnum()) {
indent.incr();
for (Attribute att : v.attributes()) {
- if (Attribute.isspecial(att))
+ if (CDM.isspecial(att))
continue;
out.format("%s", indent);
writeCDL(att, v.getShortName());
@@ -347,7 +353,7 @@ private void writeCDL(Structure s, Indent indent, boolean useFullName) {
out.format(";%n");
for (Attribute att : s.attributes()) {
- if (Attribute.isspecial(att))
+ if (CDM.isspecial(att))
continue;
out.format("%s", indent);
writeCDL(att, s.getShortName());
diff --git a/cdm/core/src/main/java/ucar/nc2/write/Ncdump.java b/cdm/core/src/main/java/ucar/nc2/write/Ncdump.java
index 0e8b32ad06..e8268b4ed3 100644
--- a/cdm/core/src/main/java/ucar/nc2/write/Ncdump.java
+++ b/cdm/core/src/main/java/ucar/nc2/write/Ncdump.java
@@ -562,7 +562,8 @@ private static void printStringArray(Formatter out, Array ma, Indent indent, Can
out.format("%n%s{", indent);
indent.incr();
for (int ii = 0; ii < last; ii++) {
- ArrayObject slice = (ArrayObject) ma.slice(0, ii);
+ Array slice = (Array) ma.slice(0, ii); // replaces ArrayObject slice = (ArrayObject)o; because ArrayObject is
+ // over-casting since printStringArray takes Array
if (ii > 0)
out.format(",");
printStringArray(out, slice, indent, ct);
diff --git a/cdm/core/src/test/java/ucar/nc2/TestSpecialAttributes.java b/cdm/core/src/test/java/ucar/nc2/TestSpecialAttributes.java
index bc94e28e8f..c54effe7fb 100644
--- a/cdm/core/src/test/java/ucar/nc2/TestSpecialAttributes.java
+++ b/cdm/core/src/test/java/ucar/nc2/TestSpecialAttributes.java
@@ -10,6 +10,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ucar.nc2.constants.CDM;
+import ucar.nc2.iosp.netcdf4.Nc4;
import ucar.unidata.util.test.TestDir;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
@@ -23,7 +24,7 @@ public void testReadAll() throws IOException {
NetcdfFile ncfile = TestDir.openFileLocal("testSpecialAttributes.nc4");
// Iterate over all top-level visible attributes and see if it is special
for (Attribute a : ncfile.getRootGroup().getAttributes()) {
- Assert.assertFalse("Attribute iteration found special attribute: " + a.getShortName(), Attribute.isspecial(a));
+ Assert.assertFalse("Attribute iteration found special attribute: " + a.getShortName(), CDM.isspecial(a));
}
ncfile.close();
}
@@ -34,7 +35,7 @@ public void testReadByName() throws IOException {
// Attempt to read special attributes by name
for (String name : new String[] {CDM.NCPROPERTIES}) {
Attribute special = ncfile.getRootGroup().findAttribute(name);
- Assert.assertTrue("Could not access special attribute: " + name, special != null && Attribute.isspecial(special));
+ Assert.assertTrue("Could not access special attribute: " + name, special != null && CDM.isspecial(special));
}
ncfile.close();
}
diff --git a/dap4/build.gradle b/dap4/build.gradle
index dbdef58cfb..7df0a6635b 100644
--- a/dap4/build.gradle
+++ b/dap4/build.gradle
@@ -1,22 +1,40 @@
ext.title = 'Data Access Protocol (DAP) version 4.0' // Will be inherited by subprojects.
-// dap4 has no source code nor any artifacts to publish
-
-// NON-TRANSITIVE Dependency graph:
-// module depends on
-// ----------------------------------------
-// common:
-// d4core nothing
-// d4lib d4core httpservices
-// d4cdm d4lib cdm
-// server:
-// d4servletshared d4cdmshared netcdf4
-// d4ts d4servletshared
-// d4tswar d4ts
-// tests:
-// d4tests d4servletshared d4ts
-
-subprojects {
- // TODO: Give the subprojects real titles.
- ext.title = "DAP4: $name"
+apply from: "$rootDir/gradle/any/dependencies.gradle"
+apply from: "$rootDir/gradle/any/java-library.gradle"
+apply from: "$rootDir/gradle/any/gretty.gradle"
+
+dependencies {
+ api enforcedPlatform(project(':netcdf-java-platform'))
+
+ implementation project(':httpservices')
+ implementation project(':cdm:cdm-core')
+ implementation project(':netcdf4')
+ testImplementation project(':cdm-test-utils')
+
+ implementation 'org.apache.httpcomponents:httpclient'
+ compileOnly 'org.apache.httpcomponents:httpcore'
+ compileOnly 'net.java.dev.jna:jna'
+ compileOnly 'com.beust:jcommander'
+ compileOnly 'org.slf4j:slf4j-api'
+
+ compileOnly enforcedPlatform(project(':netcdf-java-platform'))
+ testImplementation enforcedPlatform(project(':netcdf-java-testing-platform'))
+ testImplementation 'junit:junit'
+ testImplementation 'org.slf4j:slf4j-api'
+ testRuntimeOnly 'ch.qos.logback:logback-classic'
+}
+
+test {
+ systemProperties['testargs'] = System.getProperty('testargs', '')
+
+ include 'dap4/test/TestParserDMR.class'
+ include 'dap4/test/TestParserCE.class'
+ include 'dap4/test/TestRaw.class'
+ include 'dap4/test/TestRemote.class'
+ include 'dap4/test/TestConstraints.class'
+ include 'dap4/test/TestHyrax.class'
+
+ dependsOn('farmBeforeIntegrationTest')
+ finalizedBy('farmAfterIntegrationTest')
}
diff --git a/dap4/d4cdm/build.gradle b/dap4/d4cdm/build.gradle
deleted file mode 100644
index 1337719928..0000000000
--- a/dap4/d4cdm/build.gradle
+++ /dev/null
@@ -1,11 +0,0 @@
-apply from: "$rootDir/gradle/any/dependencies.gradle"
-apply from: "$rootDir/gradle/any/java-library.gradle"
-
-dependencies {
- api enforcedPlatform(project(':netcdf-java-platform'))
-
- compile project(':dap4:d4core')
- compile project(':dap4:d4lib')
- compile project(':cdm:cdm-core')
- compile project(':netcdf4')
-}
diff --git a/dap4/d4cdm/src/main/java/dap4/cdm/arch.txt b/dap4/d4cdm/src/main/java/dap4/cdm/arch.txt
deleted file mode 100644
index 9b05ad15a3..0000000000
--- a/dap4/d4cdm/src/main/java/dap4/cdm/arch.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-CDM :: Dap4 Interactions occur in two ways.
-
-1. Server side.
-The goal is to wrap a NetcdfDataset object as a DSP
-so it can be written using the DAP4 protocol.
-The relevant classes are:
- thredds.server.dap4.ThreddsDSP.java (in /tds/src/main/java/thredds/server/dap4 for access reasons)
- dap4.cdm.dsp.CDMDSP.java
- dap4.cdm.dsp.CDMDataCompoundArray.java
- dap4.cdm.dsp.CDMDataDataset.java
- dap4.cdm.dsp.CDMDataRecord.java
- dap4.cdm.dsp.CDMDataset.java
- dap4.cdm.dsp.CDMDataStructure.java
- dap4.cdm.dsp.CDMDataVariable.java
- dap4.cdm.dsp.CDMDataAtomic.java
-
-2. Client Side
-The goal is to wrap a D4DSP to make it look like a CDM NetcdfDataset.
-The D4DSP itself wraps the serialized data of the DAP4 protocol.
-The relevant classes are as follows:
- dap4.cdm.nc2.DapNetcdfDataset.java
- dap4.cdm.nc2.DMRToCDM.java
- dap4.cdm.nc2.DataToCDM.java
- dap4.cdm.nc2.CDMCompiler.java
- dap4.cdm.nc2.CDMArray.java
- dap4.cdm.nc2.CDMArrayAtomic.java
- dap4.cdm.nc2.CDMArrayDelegate.java
- dap4.cdm.nc2.CDMArraySequence.java
- dap4.cdm.nc2.CDMArrayStructure.java
-
-The following are shared Utilities:
- CDMUtil.java
- NodeMap.java
-
-What about?
- CDMDataFactory.java
diff --git a/dap4/d4cdm/src/main/java/dap4/cdm/dsp/CDMCursor.java b/dap4/d4cdm/src/main/java/dap4/cdm/dsp/CDMCursor.java
deleted file mode 100644
index 16afc87c86..0000000000
--- a/dap4/d4cdm/src/main/java/dap4/cdm/dsp/CDMCursor.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.cdm.dsp;
-
-import dap4.cdm.CDMTypeFcns;
-import dap4.cdm.CDMUtil;
-import dap4.core.dmr.*;
-import dap4.core.util.*;
-import dap4.core.util.Index;
-import dap4.dap4lib.AbstractCursor;
-import ucar.ma2.*;
-import java.util.List;
-
-public class CDMCursor extends AbstractCursor {
- //////////////////////////////////////////////////
- // Instance variables
-
- protected ucar.ma2.Array array = null;
- protected ucar.ma2.StructureData structdata = null; // scheme == STRUCTURE
- ucar.ma2.StructureMembers.Member member = null; // for field cursors
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public CDMCursor(Scheme scheme, CDMDSP dsp, DapNode template, CDMCursor container) throws DapException {
- super(scheme, dsp, template, container);
- }
-
- public CDMCursor(CDMCursor c) {
- super(c);
- assert false;
- this.array = c.array;
- this.structdata = c.structdata;
- this.member = c.member;
-
- }
-
- //////////////////////////////////////////////////
- // AbstractCursor Abstract Methods
-
- @Override
- public Object read(List slices) throws DapException {
- switch (this.scheme) {
- case ATOMIC:
- return readAtomic(slices);
- case STRUCTURE:
- if (((DapVariable) this.getTemplate()).getRank() > 0 || DapUtil.isScalarSlices(slices))
- throw new DapException("Cannot slice a scalar variable");
- CDMCursor[] instances = new CDMCursor[1];
- instances[0] = this;
- return instances;
- case SEQUENCE:
- if (((DapVariable) this.getTemplate()).getRank() > 0 || DapUtil.isScalarSlices(slices))
- throw new DapException("Cannot slice a scalar variable");
- instances = new CDMCursor[1];
- instances[0] = this;
- return instances;
- case STRUCTARRAY:
- Odometer odom = Odometer.factory(slices);
- instances = new CDMCursor[(int) odom.totalSize()];
- for (int i = 0; odom.hasNext(); i++) {
- instances[i] = readStructure(odom.next());
- }
- return instances;
- case SEQARRAY:
- instances = readSequence(slices);
- return instances;
- default:
- throw new DapException("Attempt to slice a scalar object");
- }
- }
-
- @Override
- public Object read(Index index) throws DapException {
- return read(DapUtil.indexToSlices(index));
- }
-
- @Override
- public CDMCursor readField(int findex) throws DapException {
- if (this.scheme != scheme.RECORD && this.scheme != scheme.STRUCTURE)
- throw new DapException("Illegal cursor scheme for readfield()");
- DapVariable var = (DapVariable) getTemplate();
- DapStructure basetype = (DapStructure) var.getBaseType();
- if (findex < 0 || findex >= basetype.getFields().size())
- throw new DapException("Field index out of range: " + findex);
- CDMCursor fieldcursor = null;
- if (this.scheme == Scheme.RECORD) {
- DapSequence seq = (DapSequence) basetype;
- DapVariable field = seq.getField(0);
- DapType fieldtype = field.getBaseType();
- switch (fieldtype.getTypeSort()) {
- default: // atomic
- DataType cdmfieldtype = CDMTypeFcns.daptype2cdmtype(fieldtype);
- if (cdmfieldtype == null)
- throw new dap4.core.util.DapException("Unknown field type: " + fieldtype);
- int ri = (int) this.recordindex;
- Object o = array.getObject(ri);
- Array fielddata = CDMTypeFcns.arrayify(cdmfieldtype, o); // not very efficient; should do conversion
- fieldcursor = new CDMCursor(Scheme.ATOMIC, (CDMDSP) this.dsp, field, this);
- fieldcursor.setArray(fielddata);
- break;
- case Sequence:
- case Structure:
- break;
- }
- } else { // scheme == STRUCTURE
- assert this.structdata != null;
- fieldcursor = getFieldCursor(this, findex);
- }
- return fieldcursor;
- }
-
- protected CDMCursor getFieldCursor(CDMCursor container, int findex) throws DapException {
- // Now, create a cursors for a field f this instance
- DapVariable var = (DapVariable) getTemplate();
- DapStructure type = (DapStructure) var.getBaseType();
- DapVariable field = (DapVariable) type.getFields().get(findex);
- DapType ftype = field.getBaseType();
- Scheme scheme = schemeFor(field);
- CDMCursor fc = new CDMCursor(scheme, (CDMDSP) this.dsp, field, this);
- StructureMembers.Member member = this.structdata.getStructureMembers().getMember(findex);
- fc.setMember(member);
- fc.setArray(this.structdata.getArray(fc.member));
- return fc;
- }
-
- @Override
- public CDMCursor readRecord(long i) throws DapException {
- if (this.scheme != scheme.SEQUENCE)
- throw new DapException("Attempt to read record from non-sequence cursor");
- if (i < 0 || i >= this.recordcount)
- throw new DapException("Record index out of bounds");
- DapVariable var = (DapVariable) getTemplate();
- CDMCursor c = new CDMCursor(Scheme.RECORD, (CDMDSP) this.dsp, var, this);
- c.setArray(this.array);
- c.setRecordIndex(i);
- return c;
- }
-
- //////////////////////////////////////////////////
- // Support Methods
-
- protected Object readAtomic(List slices) throws DapException {
- if (slices == null)
- throw new DapException("DataCursor.read: null set of slices");
- assert (this.scheme == scheme.ATOMIC);
- DapVariable atomvar = (DapVariable) getTemplate();
- assert slices != null && ((atomvar.getRank() == 0 && slices.size() == 1) || (slices.size() == atomvar.getRank()));
- return sliceAtomic(slices, this.array, atomvar);
- }
-
- protected Object sliceAtomic(List slices, Array array, DapVariable var) throws DapException {
- List dimset = var.getDimensions();
- DapType basetype = var.getBaseType();
- // If content.getDataType returns object, then we
- // really do not know its true datatype. So, as a rule,
- // we will rely on this.basetype.
- DataType datatype = CDMTypeFcns.daptype2cdmtype(basetype);
- if (datatype == null)
- throw new dap4.core.util.DapException("Unknown basetype: " + basetype);
- Object content = array.get1DJavaArray(datatype); // not very efficient; should do conversion
- Odometer odom = Odometer.factory(slices, dimset);
- Object data = CDMTypeFcns.createVector(datatype, odom.totalSize());
- for (int dstoffset = 0; odom.hasNext(); dstoffset++) {
- Index index = odom.next();
- long srcoffset = index.index();
- CDMTypeFcns.vectorcopy(basetype, content, data, srcoffset, dstoffset);
- }
- return data;
- }
-
-
- protected CDMCursor readStructure(Index index) throws DapException {
- assert (index != null);
- DapVariable var = (DapVariable) getTemplate();
- DapStructure type = (DapStructure) var.getBaseType();
- long pos = index.index();
- if (pos < 0 || pos > var.getCount())
- throw new IndexOutOfBoundsException("read: " + index);
- ArrayStructure sarray = (ArrayStructure) this.array;
- CDMCursor instance;
- assert (this.scheme == scheme.STRUCTARRAY);
- ucar.ma2.StructureData sd = sarray.getStructureData((int) pos);
- assert sd != null;
- instance = new CDMCursor(Scheme.STRUCTURE, (CDMDSP) this.dsp, var, null).setStructureData(sd);
- instance.setIndex(index);
- return instance;
- }
-
- protected CDMCursor[] readSequence(List slices) throws DapException {
- assert (this.scheme == scheme.SEQARRAY);
- DapVariable var = (DapVariable) getTemplate();
- DapSequence type = (DapSequence) var.getBaseType();
- // new CDMCursor(Scheme.SEQUENCE, (CDMDSP) this.dsp, var, this);
- CDMCursor[] instances = new CDMCursor[(int) DapUtil.sliceProduct(slices)];
- Array seqarray = this.array;
- if (var.getRank() == 0) {// scalar
- if (!DapUtil.isScalarSlices(slices))
- throw new DapException("Non-scalar slice set applied to scalar variable");
- instances[0] = new CDMCursor(Scheme.SEQUENCE, (CDMDSP) this.dsp, var, this);
- instances[0].setArray(seqarray);
- instances[0].setRecordCount(seqarray.getSize());
- } else {
- List rlist = CDMUtil.createCDMRanges(slices);
- Array instancearray;
- try {
- instancearray = seqarray.section(rlist);
- } catch (InvalidRangeException e) {
- throw new DapException("Illegal slice set", e);
- }
- // extracted via List. IN theory, this should be an array of arrays,
- // but if the sequence field basetype is atomic, thenit is an array
- // of atomic values.
- int slicecount = (int) DapUtil.sliceProduct(slices);
- for (int i = 0; i < slicecount; i++) {
- Array ao = (Array) instancearray.getObject(i);
- CDMCursor c = new CDMCursor(Scheme.SEQUENCE, (CDMDSP) this.dsp, var, this);
- c.setArray(ao);
- long rcount = ao.getSize();
- c.setRecordCount(rcount);
- instances[i] = c;
- }
- }
- return instances;
- }
-
- //////////////////////////////////////////////////
- // CDMCursor Extensions
-
- public CDMCursor setArray(ucar.ma2.Array a) {
- this.array = a;
- return this;
- }
-
- public ucar.ma2.Array getArray() {
- return this.array;
- }
-
- public CDMCursor setStructureData(ucar.ma2.StructureData sd) {
- this.structdata = sd;
- return this;
- }
-
- public CDMCursor setMember(ucar.ma2.StructureMembers.Member m) {
- this.member = m;
- return this;
- }
-
-
-}
diff --git a/dap4/d4cdm/src/main/java/dap4/cdm/dsp/CDMDMR.java b/dap4/d4cdm/src/main/java/dap4/cdm/dsp/CDMDMR.java
deleted file mode 100644
index 296d7cdeda..0000000000
--- a/dap4/d4cdm/src/main/java/dap4/cdm/dsp/CDMDMR.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.cdm.dsp;
-
-import dap4.core.dmr.*;
-
-public class CDMDMR {
- //////////////////////////////////////////////////
-
- public static class CDMAttribute extends DapAttribute {
- public CDMAttribute(String name, DapType basetype) {
- super(name, basetype);
- }
- }
-
- public static class CDMAttributeSet extends DapAttributeSet {
- public CDMAttributeSet(String name) {
- super(name);
- }
- }
-
- public static class CDMDimension extends DapDimension {
- public CDMDimension(String name, long size) {
- super(name, size);
- }
- }
-
- public static class CDMMap extends DapMap {
- public CDMMap(DapVariable target) {
- super(target);
- }
- }
-
- public abstract static class CDMVariable extends DapVariable {
- public CDMVariable(String name, DapType t) {
- super(name, t);
- }
- }
-
- public static class CDMGroup extends DapGroup {
- public CDMGroup(String name) {
- super(name);
- }
- }
-
- public static class CDMDataset extends DapDataset {
- public CDMDataset(String name) {
- super(name);
- }
- }
-
- public static class CDMEnumeration extends DapEnumeration {
- public CDMEnumeration(String name, DapType basetype) {
- super(name, basetype);
- }
- }
-
- public static class CDMEnumConst extends DapEnumConst {
- public CDMEnumConst(String name, long value) {
- super(name, value);
- }
- }
-
- public static class CDMStructure extends DapStructure {
- public CDMStructure(String name) {
- super(name);
- }
- }
-
- public static class CDMSequence extends DapSequence {
- public CDMSequence(String name) {
- super(name);
- }
- }
-
- public static class CDMOtherXML extends DapOtherXML {
- public CDMOtherXML(String name) {
- super(name);
- }
- }
-}
diff --git a/dap4/d4cdm/src/main/java/dap4/cdm/dsp/CDMDSP.java b/dap4/d4cdm/src/main/java/dap4/cdm/dsp/CDMDSP.java
deleted file mode 100644
index 95b271e745..0000000000
--- a/dap4/d4cdm/src/main/java/dap4/cdm/dsp/CDMDSP.java
+++ /dev/null
@@ -1,1056 +0,0 @@
-/*
- * Copyright (c) 2012-2018 University Corporation for Atmospheric Research/Unidata
- * See LICENSE for license information.
- */
-
-package dap4.cdm.dsp;
-
-import dap4.cdm.CDMTypeFcns;
-import dap4.cdm.CDMUtil;
-import dap4.cdm.NodeMap;
-import dap4.core.data.DataCursor;
-import dap4.core.dmr.*;
-import dap4.core.util.Convert;
-import dap4.core.util.DapContext;
-import dap4.core.util.DapException;
-import dap4.core.util.DapUtil;
-import dap4.dap4lib.AbstractDSP;
-import ucar.ma2.Array;
-import ucar.ma2.DataType;
-import ucar.ma2.IndexIterator;
-import ucar.nc2.*;
-import ucar.nc2.constants.CDM;
-import ucar.nc2.dataset.*;
-import ucar.nc2.util.CancelTask;
-import java.io.IOException;
-import java.util.*;
-import ucar.nc2.write.CDLWriter;
-
-/**
- * Wrap CDM source (NetcdfDataset) to be a DSP
- * This basically means wrapping various (CDM)Array
- * object to look like DataVariable objects.
- * Currently only used on server side
- */
-
-public class CDMDSP extends AbstractDSP {
-
- //////////////////////////////////////////////////
- // Constants
-
- protected static final boolean DEBUG = false;
- protected static final boolean DUMPCDL = false;
-
- // NetcdfDataset enhancement to use: need only coord systems
- protected static Set ENHANCEMENT = EnumSet.of(NetcdfDataset.Enhance.CoordSystems);
-
- protected static final String FILLVALUE = "_FillValue";
-
- //////////////////////////////////////////////////
- // Class variables
-
- protected static boolean nc4loaded = false;
-
- //////////////////////////////////////////////////
- // Class methods
-
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected NetcdfDataset ncdfile = null;
- protected boolean closed = false;
- protected DMRFactory dmrfactory = null;
-
- // Keep various context-dependent maps between
- // CDMNode instances and DapNode instances
- // package access
-
- // Variable map
- protected NodeMap varmap = new NodeMap<>();
-
- // Variable <-> DapStructure (basetype) map; compound types only
- protected NodeMap compoundmap = new NodeMap<>();
-
- // Map Variable <-> DapSequence vlen type
- protected NodeMap vlenmap = new NodeMap<>();
-
- // Map All other kinds of CDMNode <-> DapNode
- protected NodeMap nodemap = new NodeMap<>();
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public CDMDSP() {}
-
- public CDMDSP(String path) throws DapException {
- super();
- setLocation(path);
- }
-
- //////////////////////////////////////////////////
- // DSP Interface
-
- // This is intended to be the last DSP checked
- @Override
- public boolean dspMatch(String path, DapContext context) {
- return true;
- }
-
- /**
- * @param filepath - absolute path to a file
- * @return CDMDSP instance
- * @throws DapException
- */
- @Override
- public CDMDSP open(String filepath) throws DapException {
- try {
- NetcdfFile ncfile = createNetcdfFile(filepath, null);
- NetcdfDataset ncd = new NetcdfDataset(ncfile, ENHANCEMENT);
- return open(ncd);
- } catch (IOException ioe) {
- throw new DapException("CDMDSP: cannot process: " + filepath, ioe);
- }
- }
-
- /**
- * Provide an extra API for use in testing
- *
- * @param ncd netcdf dataset
- * @return the cdmdsp
- * @throws DapException
- */
- public CDMDSP open(NetcdfDataset ncd) throws DapException {
- assert this.context != null;
- this.dmrfactory = new DMRFactory();
- this.ncdfile = ncd;
- setLocation(this.ncdfile.getLocation());
- buildDMR();
- return this;
- }
-
- @Override
- public void close() throws IOException {
- if (this.ncdfile != null)
- this.ncdfile.close();
- }
-
-
- @Override
- public DataCursor getVariableData(DapVariable var) throws DapException {
- Variable cdmvar = this.varmap.get(var);
- if (cdmvar == null)
- throw new DapException("Unknown variable: " + var);
- CDMCursor vardata = (CDMCursor) super.getVariableData(var);
- if (vardata == null) {
- DataCursor.Scheme scheme = CDMCursor.schemeFor(var);
- try {
- vardata = new CDMCursor(scheme, this, var, null);
- vardata.setArray(cdmvar.read());
- } catch (IOException e) {
- throw new DapException(e);
- }
- super.addVariableData(var, vardata);
- }
- return vardata;
- }
-
- //////////////////////////////////////////////////
- // Abstract DSP Abstract methods
-
- //////////////////////////////////////////////////
- // CDMDSP Specific Accessors
-
- public NetcdfDataset getNetcdfDataset() {
- return this.ncdfile;
- }
-
- //////////////////////////////////////////////////
- // Nodemap Management
-
- /*
- * Make sure that we use the proper
- * object in order to avoid identity
- * problems.
- */
-
- /**
- * Track generic CDMNode <-> DapNode
- */
- protected void recordNode(CDMNode cdm, DapNode dap) {
- assert this.nodemap.get(cdm) == null && this.nodemap.get(dap) == null;
- this.nodemap.put(cdm, dap);
- }
-
- /**
- * Track Variable <-> DapVariable
- */
- protected void recordVar(Variable cdm, DapVariable dap) {
- cdm = CDMUtil.unwrap(cdm);
- assert varmap.get(cdm) == null && varmap.get(dap) == null;
- varmap.put(cdm, dap);
- }
-
- /**
- * Track Variable <-> DapStructure
- */
- protected void recordStruct(Variable cdm, DapStructure dap) {
- cdm = CDMUtil.unwrap(cdm);
- assert this.nodemap.get(cdm) == null && this.nodemap.get(dap) == null;
- compoundmap.put(cdm, dap);
- }
-
- /**
- * Track Variable <-> DapSequence
- */
- protected void recordSeq(Variable cdm, DapSequence dap) {
- cdm = CDMUtil.unwrap(cdm);
- assert this.vlenmap.get(cdm) == null && this.vlenmap.get(dap) == null;
- vlenmap.put(cdm, dap);
- }
-
- /**
- * Lookup a cdmnode in the cdmnodemap.
- * Make sure that we use the proper
- * object in order to avoid identity
- * problems.
- *
- * @param cdmnode The CMDNode (variable, dimension, etc) to record
- * @return The DapNode to which the cdmnode is to be mapped or null.
- */
- /*
- * protected DapNode
- * lookupNode(CDMNode cdmnode)
- * {
- * CDMSort sort = cdmnode.getSort();
- * if(sort == CDMSort.VARIABLE || sort == CDMSort.STRUCTURE) {
- * Variable basev = CDMUtil.unwrap((Variable) cdmnode);
- * assert (basev != null) : "Unwrap() failed";
- * cdmnode = (CDMNode) basev;
- * }
- * return this.nodemap.get(cdmnode);
- * }
- */
-
- //////////////////////////////////////////////////
-
- /**
- * Extract the metadata from the NetcdfDataset
- * and build the DMR.
- */
-
- public void buildDMR() throws DapException {
- if (getDMR() != null)
- return;
- try {
- if (DUMPCDL) {
- System.out.println("writecdl:");
- CDLWriter.writeCDL(this.ncdfile, System.out, false);
- System.out.flush();
- }
- // Use the file path to define the dataset name
- String name = this.ncdfile.getLocation();
- // Normalize the name
- name = DapUtil.canonicalpath(name);
- // Remove any path prefix
- int index = name.lastIndexOf('/');
- if (index >= 0)
- name = name.substring(index + 1, name.length());
- // Initialize the root dataset node
- setDMR((DapDataset) dmrfactory.newDataset(name).annotate(NetcdfDataset.class, this.ncdfile));
- // Map the CDM root group to this group
- recordNode(this.ncdfile.getRootGroup(), getDMR());
- getDMR().setBase(DapUtil.canonicalpath(this.ncdfile.getLocation()));
-
- // Now recursively build the tree. Start by
- // Filling the dataset with the contents of the ncfile
- // root group.
- fillgroup(getDMR(), this.ncdfile.getRootGroup());
-
- // Add an order index to the tree
- getDMR().sort();
-
- // Now locate the coordinate variables for maps
-
- /* Walk looking for VariableDS instances */
- processmappedvariables(this.ncdfile.getRootGroup());
-
- // Now set the view
- getDMR().finish();
-
- } catch (DapException e) {
- setDMR(null);
- throw new DapException(e);
- }
- }
-
- //////////////////////////////////////////////////
- // Actions
-
- protected void fillgroup(DapGroup dapgroup, Group cdmgroup) throws DapException {
- // Create decls in dap group for Dimensions
- for (Dimension cdmdim : cdmgroup.getDimensions()) {
- DapDimension dapdim = builddim(cdmdim);
- }
- // Create decls in dap group for Enumerations
- for (EnumTypedef cdmenum : cdmgroup.getEnumTypedefs()) {
- String name = cdmenum.getShortName();
- DapEnumeration dapenum = buildenum(cdmenum);
- dapenum.setShortName(name);
- dapgroup.addDecl(dapenum);
- }
- // Create decls in dap group for vlen induced Sequences
- // Do this before building compound types
- for (Variable cdmvar0 : cdmgroup.getVariables()) {
- Variable cdmvar = CDMUtil.unwrap(cdmvar0);
- buildseqtypes(cdmvar);
- }
- // Create decls in dap group for Compound Types
- for (Variable cdmvar0 : cdmgroup.getVariables()) {
- Variable cdmvar = CDMUtil.unwrap(cdmvar0);
- if (cdmvar.getDataType() != DataType.STRUCTURE && cdmvar.getDataType() != DataType.SEQUENCE)
- continue;
- DapStructure struct = buildcompoundtype(cdmvar, dapgroup);
- }
-
- // Create decls in dap group for Variables
- for (Variable cdmvar0 : cdmgroup.getVariables()) {
- Variable cdmvar = CDMUtil.unwrap(cdmvar0);
- DapNode newvar = buildvariable(cdmvar, dapgroup, cdmvar.getDimensions());
- }
- // Create decls in dap group for subgroups
- for (Group subgroup : cdmgroup.getGroups()) {
- DapGroup newgroup = buildgroup(subgroup);
- dapgroup.addDecl(newgroup);
- }
- // Create decls in dap group for group-level attributes
- buildattributes(dapgroup, cdmgroup.attributes());
- }
-
- //////////////////////////////////////////////////
- // Declaration Builders
-
- protected DapDimension builddim(Dimension cdmdim) throws DapException {
- if (cdmdim.isVariableLength())
- throw new DapException("* dimensions not supported");
- DapDimension dapdim = null;
- long cdmsize = dapsize(cdmdim);
- String name = cdmdim.getShortName();
- if (name != null && name.length() == 0)
- name = null;
- boolean shared = cdmdim.isShared();
- if (!shared) {
- // Unlike the parser, since we are working
- // from a NetcdfDataset instance, there might
- // be multiple anonymous dimension objects
- // the same size. So, just go ahead and create
- // multiple instances.
- dapdim = (DapDimension) dmrfactory.newDimension(null, cdmsize);
- getDMR().addDecl(dapdim);
- } else { // Non anonymous; create in current group
- dapdim = (DapDimension) dmrfactory.newDimension(name, cdmsize);
- dapdim.setShared(true);
- if (cdmdim.isUnlimited()) {
- dapdim.setUnlimited(true);
- }
- Group cdmparent = cdmdim.getGroup();
- DapGroup dapparent = (DapGroup) this.nodemap.get(cdmparent);
- assert dapparent != null;
- assert (dapparent != null);
- dapparent.addDecl(dapdim);
- }
- recordNode(cdmdim, dapdim);
- return dapdim;
- }
-
- protected DapEnumeration buildenum(EnumTypedef cdmenum) throws DapException {
- // Set the enum's basetype
- DapType base = null;
- switch (cdmenum.getBaseType()) {
- case ENUM1:
- base = DapType.INT8;
- break;
- case ENUM2:
- base = DapType.INT16;
- break;
- case ENUM4:
- default:
- base = DapType.INT32;
- break;
- }
- DapEnumeration dapenum = (DapEnumeration) dmrfactory.newEnumeration(cdmenum.getShortName(), base);
- recordNode(cdmenum, dapenum);
- // Create the enum constants
- Map ecvalues = cdmenum.getMap();
- for (Map.Entry entry : ecvalues.entrySet()) {
- String name = entry.getValue();
- assert (name != null);
- int value = (int) entry.getKey();
- dapenum.addEnumConst(dmrfactory.newEnumConst(name, new Long(value)));
- }
- return dapenum;
- }
-
- protected DapStructure buildcompoundtype(Variable cdmvar, DapNode parent) throws DapException {
- cdmvar = CDMUtil.unwrap(cdmvar);
- DapStructure struct;
- if (cdmvar.getDataType() == DataType.STRUCTURE)
- struct = (DapStructure) dmrfactory.newStructure(cdmvar.getShortName());
- else if (cdmvar.getDataType() == DataType.SEQUENCE)
- struct = (DapStructure) dmrfactory.newSequence(cdmvar.getShortName());
- else
- throw new DapException("Internal error");
- struct.setParent(parent);
- recordStruct(cdmvar, struct);
- Structure cdmstruct = (Structure) cdmvar;
- List fields = cdmstruct.getVariables();
- // recurse to create compound types of any fields c
- for (CDMNode node : fields) {
- Variable cdmfield = (Variable) node;
- List dimset = cdmfield.getDimensions();
- // Recurse on any nested compound types
- if (cdmfield.getDataType() == DataType.STRUCTURE || cdmfield.getDataType() == DataType.SEQUENCE) {
- DapStructure fieldstruct = buildcompoundtype(cdmfield, struct);
- }
- }
- // Add the fields to this compound type
- for (CDMNode node : fields) {
- Variable cdmfield = (Variable) node;
- DapType basetype = null;
- switch (cdmfield.getDataType()) {
- default:
- basetype = CDMTypeFcns.cdmtype2daptype(cdmfield.getDataType());
- break;
- case STRUCTURE:
- case SEQUENCE:
- basetype = compoundmap.get(cdmfield);// since no forward references
- break;
- }
- // build the field variable
- List fielddims = cdmfield.getDimensions();
- DapVariable dapfield;
- if (CDMUtil.hasVLEN(cdmfield)) {
- // Get the fake sequence associated with this vlen
- DapSequence seq = vlenmap.get(cdmfield);
- List coredims = getCoreDimset(fielddims);
- // We need to build a variable whose basetype is the
- // fake sequence rather than the cdmfield type
- // First, build a variable using the existing cdmfield
- dapfield = buildvariable(cdmfield, struct, coredims);
- // Now modify it to use the fake sequence
- dapfield.setBaseType(seq);
- } else {
- dapfield = buildvariable(cdmfield, struct, fielddims);
- }
- struct.addField(dapfield);
- }
- return struct;
- }
-
- protected DapVariable buildvariable(Variable cdmbasevar, DapNode parent, List cdmdims)
- throws DapException {
- DapVariable dapvar = null;
- CDMSort sort = cdmbasevar.getSort();
- switch (sort) {
- case VARIABLE:
- switch (cdmbasevar.getDataType()) {
- default:
- dapvar = buildatomicvar(cdmbasevar, parent);
- break;
- case ENUM1:
- case ENUM2:
- case ENUM4:
- dapvar = buildenumvar(cdmbasevar);
- break;
- case OPAQUE:
- dapvar = buildopaquevar(cdmbasevar);
- break;
- case STRING:
- dapvar = buildstringvar(cdmbasevar);
- break;
- case STRUCTURE:
- case SEQUENCE:
- assert false : "Internal error"; // How could this ever happen?
- break;
-
- }
- builddimrefs(dapvar, cdmdims);
- break;
- case STRUCTURE:
- dapvar = buildstructvar(cdmbasevar);
- builddimrefs(dapvar, cdmdims);
- break;
- case SEQUENCE:
- default:
- assert false : "Internal Error";
- }
- if (parent != null)
- addToParent(parent, dapvar);
- return dapvar;
- }
-
- protected DapVariable buildatomicvar(Variable cdmvar, DapNode parent) throws DapException {
- // Atomic => not opaque and not enum
- DapType basetype = CDMTypeFcns.cdmtype2daptype(cdmvar.getDataType());
- if (basetype == null)
- throw new DapException("DapFile: illegal CDM variable base type: " + cdmvar.getDataType());
- DapVariable dapvar = (DapVariable) dmrfactory.newVariable(cdmvar.getShortName(), basetype);
- recordVar(cdmvar, dapvar);
- buildattributes(dapvar, cdmvar.attributes());
- if (CDMUtil.hasVLEN(cdmvar)) {
- // Get the fake sequence associated with this vlen
- DapSequence seq = vlenmap.get(cdmvar);
- List coredims = getCoreDimset(cdmvar.getDimensions());
- // We need to build a variable whose basetype is the
- // fake sequence rather than the cdmfield type
- // First, build a variable using the existing cdmfield
- // Now modify it to use the fake sequence
- dapvar.setBaseType(seq);
- }
- return dapvar;
- }
-
- protected DapVariable buildopaquevar(Variable cdmvar) throws DapException {
- assert (cdmvar.getDataType() == DataType.OPAQUE) : "Internal error";
- DapVariable dapvar = (DapVariable) dmrfactory.newVariable(cdmvar.getShortName(), DapType.OPAQUE);
- recordVar(cdmvar, dapvar);
- buildattributes(dapvar, cdmvar.attributes());
- Object osize = cdmvar.annotation(UCARTAGOPAQUE);
- if (osize != null) {
- dapvar.addXMLAttribute(UCARTAGOPAQUE, osize.toString());
- }
- return dapvar;
- }
-
- protected DapVariable buildstringvar(Variable cdmvar) throws DapException {
- assert (cdmvar.getDataType() == DataType.STRING) : "Internal error";
- DapVariable dapvar = (DapVariable) dmrfactory.newVariable(cdmvar.getShortName(), DapType.STRING);
- recordVar(cdmvar, dapvar);
- buildattributes(dapvar, cdmvar.attributes());
- return dapvar;
- }
-
- protected DapVariable buildenumvar(Variable cdmvar) throws DapException {
- assert (cdmvar.getDataType() == DataType.ENUM1 || cdmvar.getDataType() == DataType.ENUM2
- || cdmvar.getDataType() == DataType.ENUM4) : "Internal error";
-
- // Now, we need to locate the actual enumeration decl
- EnumTypedef enumdef = cdmvar.getEnumTypedef();
- EnumTypedef trueenumdef = findMatchingEnum(enumdef);
- // Modify the cdmvar
- cdmvar.setEnumTypedef(trueenumdef);
- // Now, map to a DapEnumeration
- DapEnumeration dapenum = (DapEnumeration) this.nodemap.get(trueenumdef);
- assert (dapenum != null);
- DapVariable dapvar = (DapVariable) dmrfactory.newVariable(cdmvar.getShortName(), dapenum);
- recordVar(cdmvar, dapvar);
- buildattributes(dapvar, cdmvar.attributes());
- return dapvar;
- }
-
- protected DapVariable buildstructvar(Variable cdmvar) throws DapException {
- assert (cdmvar.getDataType() == DataType.STRUCTURE) : "Internal error";
- // Find the DapStructure that is the basetype for this var
- DapStructure struct = compoundmap.get(cdmvar);
- assert struct != null : "Internal Error";
- DapVariable dapvar = (DapVariable) dmrfactory.newVariable(cdmvar.getShortName(), struct);
- recordVar(cdmvar, dapvar);
- buildattributes(dapvar, cdmvar.attributes());
- return dapvar;
- }
-
- /*
- * Create a sequence from a variable with a
- * variable length last dimension.
- * Suppose we have cdm equivalent to this:
- * T var[d1]...[dn]][*]
- * We convert to the following
- *
- *
- *
- * ...
- *
- *
- */
-
- protected DapSequence buildseqtype(Variable cdmvar) throws DapException {
- cdmvar = CDMUtil.unwrap(cdmvar);
- assert (CDMUtil.hasVLEN(cdmvar));
- DataType dt = cdmvar.getDataType();
- DapType daptype = CDMTypeFcns.cdmtype2daptype(dt);
- DapSequence seq = (DapSequence) dmrfactory.newSequence(cdmvar.getShortName());
- // fill DapSequence with a single field; note that the dimensions
- // are elided because they will attach to the sequence variable,
- // not the field
- DapVariable field = dmrfactory.newVariable(cdmvar.getShortName(), daptype);
- seq.addField(field);
- field.setParent(seq);
- recordSeq(cdmvar, seq);
- return seq;
- }
-
- /**
- * Walk this variable, including fields, to construct sequence types
- * for any contained vlen dimensions
- *
- * @param cdmvar variable to walk
- */
-
- protected void buildseqtypes(Variable cdmvar) throws DapException {
- if (CDMUtil.hasVLEN(cdmvar)) {
- buildseqtype(cdmvar);
- }
- if (cdmvar.getDataType() == DataType.STRUCTURE || cdmvar.getDataType() == DataType.SEQUENCE) {
- Structure struct = (Structure) cdmvar;
- List fields = struct.getVariables();
- for (int i = 0; i < fields.size(); i++) {
- Variable field = fields.get(i);
- buildseqtypes(field); // recurse for inner vlen dims
- }
- }
- }
-
- protected void buildattributes(DapNode node, AttributeContainer attributes) throws DapException {
- for (Attribute attr : attributes) {
- if (!suppress(attr.getShortName())) {
- DapAttribute dapattr = buildattribute(attr);
- node.addAttribute(dapattr);
- }
- }
- }
-
- protected DapAttribute buildattribute(Attribute cdmattr) throws DapException {
- DapType attrtype = CDMTypeFcns.cdmtype2daptype(cdmattr.getDataType());
- EnumTypedef cdmenum = cdmattr.getEnumType();
- boolean enumfillvalue = (cdmattr.getShortName().equals(FILLVALUE) && cdmenum != null);
- DapEnumeration dapenum = null;
-
- // We need to handle _FillValue specially if the
- // the variable is enum typed.
- if (enumfillvalue) {
- cdmenum = findMatchingEnum(cdmenum);
- // Make sure the cdm attribute has type enumx
- if (!cdmenum.getBaseType().isEnum())
- throw new DapException("CDM _FillValue attribute type is not enumX");
- // Modify the attr
- cdmattr.setEnumType(cdmenum);
- // Now, map to a DapEnumeration
- dapenum = (DapEnumeration) this.nodemap.get(cdmenum);
- if (dapenum == null)
- throw new DapException("Illegal CDM variable attribute type: " + cdmenum);
- attrtype = dapenum;
- }
- if (attrtype == null)
- throw new DapException("DapFile: illegal CDM variable attribute type: " + cdmattr.getDataType());
- DapAttribute dapattr = (DapAttribute) dmrfactory.newAttribute(cdmattr.getShortName(), attrtype);
- recordNode(cdmattr, dapattr);
- // Transfer the values
- Array values = cdmattr.getValues();
- if (!validatecdmtype(cdmattr.getDataType(), values.getElementType()))
- throw new DapException("Attr type versus attribute data mismatch: " + values.getElementType());
- IndexIterator iter = values.getIndexIterator();
- String[] valuelist = null;
- Object vec = CDMTypeFcns.createVector(cdmattr.getDataType(), values.getSize());
- for (int i = 0; iter.hasNext(); i++) {
- java.lang.reflect.Array.set(vec, i, iter.next());
- }
- valuelist = (String[]) Convert.convert(DapType.STRING, attrtype, vec);
- dapattr.setValues(valuelist);
- return dapattr;
- }
-
- /**
- * Assign dimensions to a variable
- *
- * @param dapvar The variable to which we wish to assign dimensions
- * @param cdmdims The cdm dimensions from which we will find the dimension info
- */
- protected void builddimrefs(DapVariable dapvar, List cdmdims) throws DapException {
- if (cdmdims == null || cdmdims.size() == 0)
- return;
- // It is unfortunately the case that the dimensions
- // associated with the variable are not
- // necessarily the same object as those dimensions
- // as declared, so we need to use a non-trivial
- // matching algorithm.
- for (Dimension cdmdim : cdmdims) {
- DapDimension dapdim = null;
- if (cdmdim.isShared()) {
- Dimension declareddim = finddimdecl(cdmdim);
- if (declareddim == null)
- throw new DapException("Unprocessed cdm dimension: " + cdmdim);
- dapdim = (DapDimension) this.nodemap.get(declareddim);
- assert dapdim != null;
- } else if (cdmdim.isVariableLength()) {// ignore
- continue;
- } else {// anonymous
- dapdim = builddim(cdmdim);
- }
- assert (dapdim != null) : "Internal error";
- dapvar.addDimension(dapdim);
- }
- }
-
- protected void processmappedvariables(Group g) throws DapException {
- for (Variable v0 : g.getVariables()) {
- Variable cdmvar = CDMUtil.unwrap(v0);
- if (cdmvar == null)
- throw new DapException("NetcdfDataset synthetic variable: " + v0);
- DapNode dapvar = this.varmap.get(cdmvar);
- if (dapvar == null)
- throw new DapException("Unknown variable: " + cdmvar);
- if (!(dapvar instanceof DapVariable))
- throw new DapException("CDMVariable not mapping to dap variable: " + cdmvar);
- buildmaps((DapVariable) dapvar, v0);
- }
- }
-
-
- /**
- * @param dapvar The variable to which we wish to assign maps
- * @param var The NetcdfDataset variable from which to extract coord system
- */
- protected void buildmaps(DapVariable dapvar, Variable var) throws DapException {
- // See if this cdm variable has one (or more) coordinate system
- List css = null;
- if (var.getSort() == CDMSort.VARIABLE) {
- VariableDS vds = (VariableDS) var;
- css = vds.getCoordinateSystems();
- } else {
- StructureDS sds = (StructureDS) var;
- css = sds.getCoordinateSystems();
- }
- if (css != null && css.size() > 0) {
- // Not sure what to do with multiple coordinate systems
- // For now, only use the first
- CoordinateSystem coordsystems = css.get(0);
- for (CoordinateAxis axis : coordsystems.getCoordinateAxes()) {
- // First step is to find the dap variable
- // corresponding to the map
- VariableDS vds = (VariableDS) axis.getOriginalVariable();
- if (vds != null) {
- Variable v = CDMUtil.unwrap(vds);
- if (v != null) {
- DapVariable mapvar = varmap.get(v);
- if (mapvar == null)
- throw new DapException("Illegal map variable:" + v.toString());
- if (!mapvar.isAtomic())
- throw new DapException("Non-atomic map variable:" + v.toString());
- // Ignore maps where the map variable is inside this scope
- /*
- * if(!mapvar.isTopLevel()) {
- * DapNode parent = mapvar.getContainer();
- * switch (parent.getSort()) {
- * case SEQUENCE:
- * case STRUCTURE:
- * if(dapvar.getBaseType() == parent) // Do we need to do transitive closure?
- * throw new DapException("Map var cannot be in same structure as map");
- * break;
- * default:
- * assert false : "Unexpected container type";
- * }
- */
- DapMap map = (DapMap) dmrfactory.newMap(mapvar);
- dapvar.addMap(map);
- }
- }
- }
- }
- }
-
- protected DapGroup buildgroup(Group cdmgroup) throws DapException {
- DapGroup dapgroup = (DapGroup) dmrfactory.newGroup(cdmgroup.getShortName());
- recordNode(cdmgroup, dapgroup);
- dapgroup.setShortName(cdmgroup.getShortName());
- fillgroup(dapgroup, cdmgroup);
- return dapgroup;
- }
-
- //////////////////////////////////////////////////
- // Utilities
-
- /**
- * Unfortunately, the CDM Iosp does not
- * actually use the declared enums. Rather,
- * for every enum type'd variable, a new
- * enum decl is defined. So, we need
- * to find the original enum decl that matches
- * the variable's enum.
- */
-
- protected EnumTypedef findMatchingEnum(EnumTypedef varenum) throws DapException {
- List candidates = new ArrayList<>();
- for (Map.Entry entry : this.nodemap.getCDMMap().entrySet()) {
- CDMNode cdmnode = entry.getValue();
- if (cdmnode.getSort() != CDMSort.ENUMERATION)
- continue;
- // Compare the enumeration (note names will differ)
- EnumTypedef target = (EnumTypedef) cdmnode;
- /*
- * Ideally, we should test the types of the enums,
- * but, unfortunately, the var enum is always enum4.
- * if(target.getBaseType() != varenum.getBaseType())
- * continue;
- */
- Map targetmap = target.getMap();
- Map varmap = varenum.getMap();
- if (targetmap.size() != varmap.size())
- continue;
- boolean match = true; // until otherwise shown
- for (Map.Entry tpair : targetmap.entrySet()) {
- String tname = tpair.getValue();
- int value = (int) tpair.getKey();
- boolean found = false;
- for (Map.Entry vpair : varmap.entrySet()) {
- if (tname.equals(vpair.getValue()) && value == (int) vpair.getKey()) {
- found = true;
- break;
- }
- }
- if (!found) {
- match = false;
- break;
- }
- }
- if (!match)
- continue;
-
- // Save it unless it is shadowed by a closer enum
- boolean shadowed = false;
- for (EnumTypedef etd : candidates) {
- if (shadows(etd.getGroup(), target.getGroup())) {
- shadowed = true;
- break;
- }
- }
- if (!shadowed)
- candidates.add(target);
- }
-
- switch (candidates.size()) {
- case 0:
- throw new DapException("CDMDSP: No matching enum type decl: " + varenum.getShortName());
- case 1:
- break;
- default:
- throw new DapException("CDMDSP: Multiple matching enum type decls: " + varenum.getShortName());
- }
- return candidates.get(0);
- }
-
- protected boolean shadows(Group parent, Group child) {
- if (child == parent)
- return true;
- Group candidate = child;
- do {
- candidate = candidate.getGroup();
- } while (candidate != null && candidate != parent);
- return (candidate == parent);
- }
-
- // Convert cdm size to DapDimension size
- protected long dapsize(Dimension cdmdim) {
- assert (!cdmdim.isVariableLength());
- return (long) cdmdim.getLength();
- }
-
- protected boolean validatecdmtype(DataType datatype, Class typeclass) {
- switch (datatype) {
- case CHAR:
- return typeclass == char.class;
- case BYTE:
- case UBYTE:
- return typeclass == byte.class;
- case SHORT:
- case USHORT:
- return typeclass == short.class;
- case INT:
- case UINT:
- return typeclass == int.class;
- case LONG:
- case ULONG:
- return typeclass == long.class;
- case FLOAT:
- return typeclass == float.class;
- case DOUBLE:
- return typeclass == double.class;
- case STRING:
- return typeclass == String.class;
- case OPAQUE:
- return typeclass == Byte[].class;
- // For these, return the integer basetype
- case ENUM1:
- return typeclass == byte.class;
- case ENUM2:
- return typeclass == short.class;
- case ENUM4:
- return typeclass == int.class;
-
- // Undefined
- case SEQUENCE:
- case STRUCTURE:
- default:
- break;
- }
- return false;
- }
-
-
- protected Dimension finddimdecl(Dimension dimref) {
- // Search on the full name, but be careful,
- // the rule is that the declared dimension's fqn
- // must be a prefix of the dimension reference.
- for (Map.Entry entry : this.nodemap.getCDMMap().entrySet()) {
- if (entry.getValue().getSort() != CDMSort.DIMENSION)
- continue;
- Dimension d = (Dimension) entry.getValue();
- if (isDimDeclFor(d, dimref))
- return d;
- }
- return null;
- }
-
- protected boolean isDimDeclFor(Dimension decl, Dimension ref) {
- if (!decl.isShared())
- return false; // Has no name
- // First check shortname and size
- if (!decl.getShortName().equals(ref.getShortName()))
- return false;
- if (decl.getLength() != ref.getLength())
- return false;
- // Make sure they are in the same group
- String dprefix = decl.getGroup().getFullName();
- String rprefix = ref.getGroup().getFullName();
- return (dprefix.equals(rprefix));
- }
-
- /*
- * protected String
- * fixvalue(Object o, DapType datatype)
- * {
- * TypeSort atype = datatype.getTypeSort();
- * if(o instanceof Character) {
- * long l = (long) ((Character) o).charValue();
- * if(atype.isUnsigned())
- * l = l & 0xffL;
- * o = Long.valueOf(l);
- * } else if(o instanceof Float || o instanceof Double) {
- * if(atype == TypeSort.Float32)
- * o = Float.valueOf(((Number) o).floatValue());
- * else if(atype == TypeSort.Float64)
- * o = Double.valueOf(((Number) o).doubleValue());
- * else
- * assert false : "Internal error";
- * } else if(o instanceof Number) {
- * long l = ((Number) o).longValue();
- * switch (atype) {
- * case Char:
- * case UInt8:
- * l = l & 0xffL;
- * break;
- * case UInt16:
- * l = l & 0xffffL;
- * break;
- * case UInt32:
- * l = l & 0xffffffffL;
- * break;
- * default:
- * break;
- * }
- * o = Long.valueOf(l);
- * } else if(o instanceof String) {
- * o = o.toString();
- * } else if(o instanceof ByteBuffer) {
- * // leave it unchanged
- * } else if(o instanceof byte[]) {
- * o = ByteBuffer.wrap((byte[]) o);
- * } else if(o instanceof Byte[]) {
- * Byte[] ob = (Byte[]) o;
- * byte[] bb = new byte[ob.length];
- * for(int i = 0; i < bb.length; i++) {
- * bb[i] = (byte) ob[i];
- * }
- * o = ByteBuffer.wrap(bb);
- * } //else { // leave it unchanged
- * return o;
- * }
- */
-
- //////////////////////////////////////////////////
-
- protected NetcdfFile createNetcdfFile(String location, CancelTask canceltask) throws DapException {
- try {
- NetcdfFile ncfile = NetcdfFile.open(location, -1, canceltask, getContext());
- return ncfile;
- } catch (DapException de) {
- if (DEBUG)
- de.printStackTrace();
- throw de;
- } catch (Exception e) {
- if (DEBUG)
- e.printStackTrace();
- throw new DapException(e);
- }
- }
-
- //////////////////////////////////////////////////
- // Utilities
-
- /**
- * Strip vlen dimensions from a set of dimensions
- *
- * @param dimset
- * @return subset of dimset with (trailing) vlen removed
- * @throws DapException
- */
- static List getCoreDimset(List dimset) throws DapException {
- if (dimset == null)
- return null;
- List core = new ArrayList<>();
- int pos = -1;
- int count = 0;
- for (int i = 0; i < dimset.size(); i++) {
- if (dimset.get(i).isVariableLength()) {
- pos = i;
- count++;
- } else
- core.add(dimset.get(i));
- }
- if ((pos != dimset.size() - 1) || count > 1)
- throw new DapException("Unsupported use of (*) Dimension");
- return core;
- }
-
- /**
- * Some attributes that are added by the NetcdfDataset
- * need to be kept out of the DMR. This function
- * defines that set.
- *
- * @param attrname A non-escaped attribute name to be tested for suppression
- * @return true if the attribute should be suppressed, false otherwise.
- */
- protected boolean suppress(String attrname) {
- if (attrname.startsWith("_Coord"))
- return true;
- if (attrname.equals(CDM.UNSIGNED))
- return true;
- return false;
- }
-
- protected void addToParent(DapNode parent, DapVariable dapvar) throws DapException {
- assert (parent != null);
- switch (parent.getSort()) {
- case GROUP:
- case DATASET:
- ((DapGroup) parent).addDecl(dapvar);
- break;
- case SEQUENCE:
- case STRUCTURE:
- dapvar.setParent(parent);
- break;
- default:
- assert (false) : "Internal error";
- }
- }
-
-}
diff --git a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArray.java b/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArray.java
deleted file mode 100644
index 8fd48da4a2..0000000000
--- a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArray.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.cdm.nc2;
-
-import dap4.core.dmr.*;
-import dap4.core.data.DSP;
-
-/**
- * It is convenient to be able to create
- * a common "parent" interface for all
- * the CDM array classes
- */
-
-/* package */ interface CDMArray {
- public DSP getDSP();
-
- public DapVariable getTemplate();
-
- public long getSizeBytes(); // In bytes
-
- public DapType getBaseType();
-
-
-}
diff --git a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayAtomic.java b/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayAtomic.java
deleted file mode 100644
index b82b3fe2c9..0000000000
--- a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayAtomic.java
+++ /dev/null
@@ -1,549 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.cdm.nc2;
-
-import dap4.cdm.CDMTypeFcns;
-import dap4.cdm.CDMUtil;
-import dap4.core.data.DSP;
-import dap4.core.data.DataCursor;
-import dap4.core.dmr.DapType;
-import dap4.core.dmr.DapVariable;
-import dap4.core.util.Convert;
-import dap4.core.util.DapException;
-import dap4.core.util.DapUtil;
-import dap4.core.util.Slice;
-import ucar.ma2.Array;
-import ucar.ma2.DataType;
-import ucar.ma2.Index;
-import ucar.ma2.IndexIterator;
-import ucar.nc2.Group;
-import java.io.IOException;
-import java.util.List;
-import static dap4.core.data.DataCursor.Scheme;
-
-/**
- * CDMArrayAtomic wraps a DataCursor object to present
- * the ucar.ma2.Array interface.
- * CDMArrayAtomic manages a single CDM atomic variable:
- * either top-level or for a member.
- */
-
-/* package */ class CDMArrayAtomic extends Array implements CDMArray {
- /////////////////////////////////////////////////////
- // Constants
-
- /////////////////////////////////////////////////////
- // Instance variables
-
- protected DSP dsp = null;
- protected DapVariable template = null;
- protected DapType basetype = null;
-
- // CDMArray variables
- protected DataCursor data = null;
- protected Group cdmroot = null;
- protected int elementsize = 0; // of one element
- protected long dimsize = 0; // # of elements in array; scalar uses value 1
- protected long totalsize = 0; // elementsize*dimsize except when isbytestring
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- /**
- * Constructor
- *
- * @param data DataCursor object providing the actual data
- */
- CDMArrayAtomic(DataCursor data) throws DapException {
- super(CDMTypeFcns.daptype2cdmtype(((DapVariable) data.getTemplate()).getBaseType()),
- CDMUtil.computeEffectiveShape(((DapVariable) data.getTemplate()).getDimensions()));
- this.dsp = data.getDSP();
- this.data = data;
- this.template = (DapVariable) this.data.getTemplate();
- this.basetype = this.template.getBaseType();
-
- this.dimsize = DapUtil.dimProduct(this.template.getDimensions());
- this.elementsize = this.basetype.getSize();
- }
-
- /////////////////////////////////////////////////
- // CDMArray Interface
-
- @Override
- public DapType getBaseType() {
- return this.basetype;
- }
-
- @Override
- public DSP getDSP() {
- return this.dsp;
- }
-
- @Override
- public DapVariable getTemplate() {
- return this.template;
- }
-
- //////////////////////////////////////////////////
- // Accessors
-
- //////////////////////////////////////////////////
- // Array Interface
-
- public String toString() {
- StringBuilder buf = new StringBuilder();
- DapType basetype = getBaseType();
- String sbt = (basetype == null ? "?" : basetype.toString());
- String st = (template == null ? "?" : template.getShortName());
- buf.append(String.format("%s %s[%d]", sbt, st, dimsize));
- return buf.toString();
- }
-
- //////////////////////////////////////////////////
- // Array API
- // TODO: add index range checks
-
- public Class getElementType() {
- DataType dt = CDMTypeFcns.daptype2cdmtype(this.basetype);
- if (dt == null)
- throw new IllegalArgumentException("Unknown datatype: " + this.basetype);
- return CDMTypeFcns.cdmElementClass(dt);
- }
-
- public double getDouble(ucar.ma2.Index cdmidx) {
- return getDouble(CDMUtil.cdmIndexToIndex(cdmidx));
- }
-
- public float getFloat(ucar.ma2.Index cdmidx) {
- return getFloat(CDMUtil.cdmIndexToIndex(cdmidx));
- }
-
- public long getLong(ucar.ma2.Index cdmidx) {
- return getLong(CDMUtil.cdmIndexToIndex(cdmidx));
- }
-
- public int getInt(ucar.ma2.Index cdmidx) {
- return getInt(CDMUtil.cdmIndexToIndex(cdmidx));
- }
-
- public short getShort(ucar.ma2.Index cdmidx) {
- return getShort(CDMUtil.cdmIndexToIndex(cdmidx));
- }
-
- public byte getByte(ucar.ma2.Index cdmidx) {
- return getByte(CDMUtil.cdmIndexToIndex(cdmidx));
- }
-
- public char getChar(ucar.ma2.Index cdmidx) {
- return getChar(CDMUtil.cdmIndexToIndex(cdmidx));
- }
-
- public boolean getBoolean(ucar.ma2.Index cdmidx) {
- return getBoolean(CDMUtil.cdmIndexToIndex(cdmidx));
- }
-
- public Object getObject(ucar.ma2.Index cdmidx) {
- return getObject(CDMUtil.cdmIndexToIndex(cdmidx));
- }
-
- // Convert int base to Index based
-
- public double getDouble(int offset) {
- DapVariable d4var = (DapVariable) getTemplate();
- long[] dimsizes = DapUtil.getDimSizes(d4var.getDimensions());
- return getDouble(DapUtil.offsetToIndex(offset, dimsizes));
- }
-
- public float getFloat(int offset) {
- DapVariable d4var = (DapVariable) getTemplate();
- long[] dimsizes = DapUtil.getDimSizes(d4var.getDimensions());
- return getFloat(DapUtil.offsetToIndex(offset, dimsizes));
- }
-
- public long getLong(int offset) {
- DapVariable d4var = (DapVariable) getTemplate();
- long[] dimsizes = DapUtil.getDimSizes(d4var.getDimensions());
- return getLong(DapUtil.offsetToIndex(offset, dimsizes));
- }
-
- public int getInt(int offset) {
- DapVariable d4var = (DapVariable) getTemplate();
- long[] dimsizes = DapUtil.getDimSizes(d4var.getDimensions());
- return getInt(DapUtil.offsetToIndex(offset, dimsizes));
- }
-
- public short getShort(int offset) {
- DapVariable d4var = (DapVariable) getTemplate();
- long[] dimsizes = DapUtil.getDimSizes(d4var.getDimensions());
- return getShort(DapUtil.offsetToIndex(offset, dimsizes));
- }
-
- public byte getByte(int offset) {
- DapVariable d4var = (DapVariable) getTemplate();
- long[] dimsizes = DapUtil.getDimSizes(d4var.getDimensions());
- return getByte(DapUtil.offsetToIndex(offset, dimsizes));
- }
-
- public char getChar(int offset) {
- DapVariable d4var = (DapVariable) getTemplate();
- long[] dimsizes = DapUtil.getDimSizes(d4var.getDimensions());
- return getChar(DapUtil.offsetToIndex(offset, dimsizes));
- }
-
- public boolean getBoolean(int offset) {
- DapVariable d4var = (DapVariable) getTemplate();
- long[] dimsizes = DapUtil.getDimSizes(d4var.getDimensions());
- return getBoolean(DapUtil.offsetToIndex(offset, dimsizes));
- }
-
- public Object getObject(int offset) {
- DapVariable d4var = (DapVariable) getTemplate();
- long[] dimsizes = DapUtil.getDimSizes(d4var.getDimensions());
- return getObject(DapUtil.offsetToIndex(offset, dimsizes));
- }
-
- public Object getStorage() {
- try {
- List slices = DapUtil.dimsetToSlices(this.template.getDimensions());
- Object result = this.data.read(slices);
- return result;
- } catch (DapException e) {
- throw new IllegalArgumentException();
- }
- }
-
-
- // Unsupported Methods
-
- public void setDouble(Index ima, double value) {
- throw new UnsupportedOperationException();
- }
-
- public void setFloat(Index ima, float value) {
- throw new UnsupportedOperationException();
- }
-
- public void setLong(Index ima, long value) {
- throw new UnsupportedOperationException();
- }
-
- public void setInt(Index ima, int value) {
- throw new UnsupportedOperationException();
- }
-
- public void setShort(Index ima, short value) {
- throw new UnsupportedOperationException();
- }
-
- public void setByte(Index ima, byte value) {
- throw new UnsupportedOperationException();
- }
-
- public void setChar(Index ima, char value) {
- throw new UnsupportedOperationException();
- }
-
- public void setBoolean(Index ima, boolean value) {
- throw new UnsupportedOperationException();
- }
-
- public void setObject(Index ima, Object value) {
- throw new UnsupportedOperationException();
- }
-
- public void setDouble(int elem, double value) {
- throw new UnsupportedOperationException();
- }
-
- public void setFloat(int elem, float value) {
- throw new UnsupportedOperationException();
- }
-
- public void setLong(int elem, long value) {
- throw new UnsupportedOperationException();
- }
-
- public void setInt(int elem, int value) {
- throw new UnsupportedOperationException();
- }
-
- public void setShort(int elem, short value) {
- throw new UnsupportedOperationException();
- }
-
- public void setByte(int elem, byte value) {
- throw new UnsupportedOperationException();
- }
-
- public void setChar(int elem, char value) {
- throw new UnsupportedOperationException();
- }
-
- public void setBoolean(int elem, boolean value) {
- throw new UnsupportedOperationException();
- }
-
- public void setObject(int elem, Object value) {
- throw new UnsupportedOperationException();
- }
-
- protected void copyTo1DJavaArray(IndexIterator indexIterator, Object o) {
- throw new UnsupportedOperationException();
- }
-
- protected void copyFrom1DJavaArray(IndexIterator iter, Object javaArray) {
- throw new UnsupportedOperationException();
- }
-
- protected Array createView(Index index) {
- return this;
- }
-
- //////////////////////////////////////////////////
- // Internal common extractors
-
- /**
- * Get the array element at a specific dap4 index as a double
- *
- * @param idx of element to get
- * @return value at index cast to double if necessary.
- */
- protected double getDouble(dap4.core.util.Index idx) {
- assert data.getScheme() == Scheme.ATOMIC;
- try {
- Object value = data.read(idx);
- value = Convert.convert(DapType.FLOAT64, this.basetype, value);
- return (Double) java.lang.reflect.Array.get(value, 0);
- } catch (IOException ioe) {
- throw new IndexOutOfBoundsException(ioe.getMessage());
- }
- }
-
- /**
- * Get the array element at a specific dap4 index as a float
- * converting as needed.
- *
- * @param idx of element to get
- * @return value at index cast to float if necessary.
- */
- protected float getFloat(dap4.core.util.Index idx) {
- assert data.getScheme() == Scheme.ATOMIC;
- try {
- Object value = data.read(idx);
- value = Convert.convert(DapType.FLOAT32, this.basetype, value);
- return (Float) java.lang.reflect.Array.get(value, 0);
- } catch (IOException ioe) {
- throw new IndexOutOfBoundsException(ioe.getMessage());
- }
- }
-
- /**
- * Get the array element at a specific dap4 index as a long
- *
- * @param idx of element to get
- * @return value at index cast to long if necessary.
- */
- protected long getLong(dap4.core.util.Index idx) {
- assert data.getScheme() == Scheme.ATOMIC;
- try {
- Object value = data.read(idx);
- value = Convert.convert(DapType.INT64, this.basetype, value);
- return (Long) java.lang.reflect.Array.get(value, 0);
- } catch (IOException ioe) {
- throw new IndexOutOfBoundsException(ioe.getMessage());
- }
- }
-
- /**
- * Get the array element at a specific dap4 index as a integer
- *
- * @param idx of element to get
- * @return value at index cast to integer if necessary.
- */
- protected int getInt(dap4.core.util.Index idx) {
- assert data.getScheme() == Scheme.ATOMIC;
- try {
- Object value = data.read(idx);
- value = Convert.convert(DapType.INT32, this.basetype, value);
- return (Integer) java.lang.reflect.Array.get(value, 0);
- } catch (IOException ioe) {
- throw new IndexOutOfBoundsException(ioe.getMessage());
- }
- }
-
- /**
- * Get the array element at a specific dap4 index as a short
- *
- * @param idx of element to get
- * @return value at index cast to short if necessary.
- */
- protected short getShort(dap4.core.util.Index idx) {
- assert data.getScheme() == Scheme.ATOMIC;
- try {
- Object value = data.read(idx);
- value = Convert.convert(DapType.INT16, this.basetype, value);
- return (Short) java.lang.reflect.Array.get(value, 0);
- } catch (IOException ioe) {
- throw new IndexOutOfBoundsException(ioe.getMessage());
- }
- }
-
- /**
- * Get the array element at a specific dap4 index as a byte
- *
- * @param idx of element to get
- * @return value at index cast to byte if necessary.
- */
- protected byte getByte(dap4.core.util.Index idx) {
- assert data.getScheme() == Scheme.ATOMIC;
- try {
- Object value = data.read(idx);
- value = Convert.convert(DapType.INT8, this.basetype, value);
- return (Byte) java.lang.reflect.Array.get(value, 0);
- } catch (IOException ioe) {
- throw new IndexOutOfBoundsException(ioe.getMessage());
- }
- }
-
- /**
- * Get the array element at a specific dap4 index as a char
- *
- * @param idx of element to get
- * @return value at index cast to char if necessary.
- */
- protected char getChar(dap4.core.util.Index idx) {
- assert data.getScheme() == Scheme.ATOMIC;
- try {
- Object value = data.read(idx);
- value = Convert.convert(DapType.CHAR, this.basetype, value);
- return (Character) java.lang.reflect.Array.get(value, 0);
- } catch (IOException ioe) {
- throw new IndexOutOfBoundsException(ioe.getMessage());
- }
- }
-
- /**
- * Get the array element at a specific dap4 index as a boolean
- *
- * @param idx of element to get
- * @return value at index cast to char if necessary.
- */
- protected boolean getBoolean(dap4.core.util.Index idx) {
- assert data.getScheme() == Scheme.ATOMIC;
- try {
- Object value = data.read(idx);
- value = Convert.convert(DapType.INT64, this.basetype, value);
- return ((Long) java.lang.reflect.Array.get(value, 0)) != 0;
- } catch (IOException ioe) {
- throw new IndexOutOfBoundsException(ioe.getMessage());
- }
- }
-
- /**
- * Get the array element at a specific dap4 index as an Object
- *
- * @param idx of element to get
- * @return value at index cast to Object if necessary.
- */
- protected Object getObject(dap4.core.util.Index idx) {
- assert data.getScheme() == Scheme.ATOMIC;
- try {
- Object value = data.read(idx);
- value = java.lang.reflect.Array.get(value, 0);
- return value;
- } catch (IOException ioe) {
- throw new IndexOutOfBoundsException(ioe.getMessage());
- }
- }
-
-
- //////////////////////////////////////////////////
- // DataAtomic Interface
-
- public DapVariable getVariable() {
- return this.template;
- }
-
- public DapType getType() {
- return this.basetype;
- }
-
- /*
- * protected Object
- * read(long index, DapType datatype, DataAtomic content)
- * throws DapException
- * {
- * Object result;
- * int i = (int) index;
- * long tmp = 0;
- * switch (datatype.getTypeSort()) {
- * case Int8:
- * result = (Byte) content.getByte(i);
- * break;
- * case Char:
- * result = (Character) content.getChar(i);
- * break;
- * case SHORT:
- * result = (Short) content.getShort(i);
- * break;
- * case INT:
- * result = (Integer) content.getInt(i);
- * break;
- * case LONG:
- * result = (Long) content.getLong(i);
- * break;
- * case FLOAT:
- * result = (Float) content.getFloat(i);
- * break;
- * case DOUBLE:
- * result = (Double) content.getDouble(i);
- * break;
- * case STRING:
- * result = content.getObject(i).toString();
- * break;
- * case OBJECT:
- * result = content.getObject(i);
- * break;
- * case UBYTE:
- * tmp = content.getByte(i) & 0xFF;
- * result = (Byte) (byte) tmp;
- * break;
- * case USHORT:
- * tmp = content.getShort(i) & 0xFFFF;
- * result = (Short) (short) tmp;
- * break;
- * case UINT:
- * tmp = content.getInt(i) & 0xFFFFFFFF;
- * result = (Integer) (int) tmp;
- * break;
- * case ULONG:
- * result = (Long) content.getLong(i);
- * break;
- * case ENUM1:
- * result = read(index, DataType.BYTE, content);
- * break;
- * case ENUM2:
- * result = read(index, DataType.SHORT, content);
- * break;
- * case ENUM4:
- * result = read(index, DataType.INT, content);
- * break;
- * case OPAQUE:
- * result = content.getObject(i);
- * break;
- * case STRUCTURE:
- * case SEQUENCE:
- * default:
- * throw new DapException("Attempt to read non-atomic value of type: " + datatype);
- * }
- * return result;
- * }
- */
-
- //////////////////////////////////////////////////
- // Utilities
-}
-
diff --git a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayDelegate.java b/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayDelegate.java
deleted file mode 100644
index ec75886200..0000000000
--- a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayDelegate.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.cdm.nc2;
-
-import dap4.core.dmr.*;
-import dap4.core.data.DSP;
-
-/**
- * Since we can't use AbstractCDMArray,
- * we define a delegator for CDMArray.
- * This class actually is never used, it is just
- * a placeholder to store the API that should be
- * included in every class implementing CMDArray.
- * If this class fails to compile then any fix
- * must be propagated to the CDMArray implementing classes.
- */
-
-/* package */ class CDMArrayDelegate implements CDMArray {
- protected DSP dsp = null;
- protected DapVariable template = null;
- protected long bytesize = 0;
- protected DapType basetype = null;
- protected TypeSort primitivetype = null;
-
- /*
- * The implementing class will need to
- * initialize the fields.
- * this.template = template;
- * this.bytesize = 0;
- * this.root = root;
- * this.dsp = dsp;
- * this.bytesize = size;
- * this.basetype = this.template.getBaseType();
- * this.primitivetype = this.basetype.getPrimitiveType();
- */
-
- @Override
- public DSP getDSP() {
- return this.dsp;
- }
-
- @Override
- public DapVariable getTemplate() {
- return this.template;
- }
-
- @Override
- public long getSizeBytes() {
- return this.bytesize;
- }
-
- @Override
- public DapType getBaseType() {
- return this.basetype;
- }
-
-}
diff --git a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArraySequence.java b/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArraySequence.java
deleted file mode 100644
index b60a033e8f..0000000000
--- a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArraySequence.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.cdm.nc2;
-
-import dap4.cdm.CDMTypeFcns;
-import dap4.core.data.DSP;
-import dap4.core.data.DataCursor;
-import dap4.core.dmr.DapSequence;
-import dap4.core.dmr.DapStructure;
-import dap4.core.dmr.DapType;
-import dap4.core.dmr.DapVariable;
-import dap4.core.util.*;
-import ucar.ma2.*;
-import ucar.nc2.Group;
-import java.io.IOException;
-import java.util.List;
-
-/**
- * CDM now has an ArraySequence type intended to
- * support VLEN (aka CDM (*) dimension).
- * So, sequence is simulated as a rank n+1 structure where
- * the last dimension is "*" (i.e. variable length).
- * That is, given the following DAP4:
- * Sequence S {f1,f2,...fm} [d1][d2]...[dn]
- * Represent it in CDM as this:
- * Structure S {f1,f2,...fm} [d1][d2]...[dn][*]
- * We cannot subclass CDMArrayStructure because we need to subclass
- * ArraySequence, so we are forced to duplicate a lot of the CDMArrayStructure
- * code.
- * The important point to note is that for CDM, we do not need to support
- * Dimensioned sequences; the dimensions are supported by the enclosing
- * ArrayStructure covering the non-vlen dimensions
- */
-
-/* package */ class CDMArraySequence extends ArraySequence implements CDMArray {
-
- //////////////////////////////////////////////////
- // Type decls
-
- // Define an open wrapper around a field array in order
- // to make the code somewhat more clear
-
- protected static class FieldSet {
- public Array[] fields;
-
- FieldSet(int nfields) {
- fields = new Array[nfields];
- }
- }
-
- public static class SDI implements StructureDataIterator {
- protected StructureData[] list;
- protected int position;
-
- public SDI() {
- this.list = null;
- this.position = 0;
- }
-
- public SDI setList(StructureData[] list) {
- this.list = list;
- return this;
- }
-
- public boolean hasNext() throws IOException {
- return position < list.length;
- }
-
- public StructureData next() throws IOException {
- if (position >= list.length)
- throw new IOException("No next element");
- return list[position++];
- }
-
- public StructureDataIterator reset() {
- position = 0;
- return this;
- }
-
- public int getCurrentRecno() {
- return position;
- }
-
- }
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected Group cdmroot = null;
- protected DSP dsp;
- protected DapVariable template;
- protected DapType basetype;
- protected long bytesize = 0;
- protected long recordcount = 0;
- protected int nmembers = 0;
-
- protected DataCursor seqdata = null;
-
- /**
- * Since in CDM a sequence is the last dimension of
- * array, we do not need to keep dimensionality info, only
- * the variable length stuff, which we do using
- * StructureDataA instances: 1 per record.
- */
-
- // Track the records of this sequence as an array
- // Note: term records here means the elements of the array,
- // not record as in Sequence
-
- protected FieldSet[] records = null; // list of records
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- /**
- * Constructor
- *
- * @param data
- */
- CDMArraySequence(Group group, DataCursor data) throws DapException {
- super(CDMArrayStructure.computemembers((DapVariable) data.getTemplate()), new SDI(), 0);
- this.template = (DapVariable) data.getTemplate();
- this.basetype = this.template.getBaseType();
- // Currently do not allow non-scalar sequences
- if (this.template.getRank() != 0)
- throw new DapException("Non-scalar sequences unsupported through CDM interface");
- assert data.getScheme() == DataCursor.Scheme.SEQARRAY;
- this.cdmroot = group;
- this.dsp = dsp;
- // Since this is a scalar, pull out the single instance
- this.seqdata = ((DataCursor[]) data.read(dap4.core.util.Index.SCALAR))[0];
- this.recordcount = this.seqdata.getRecordCount();
- this.nmembers = ((DapStructure) this.basetype).getFields().size();
-
- // Fill in the structdata (in parent) and record vectors
- super.sdata = new StructureDataA[(int) this.recordcount];
- records = new FieldSet[(int) this.recordcount];
- for (int i = 0; i < this.recordcount; i++) {
- super.sdata[i] = new StructureDataA(this, i);
- records[i] = new FieldSet(this.nmembers);
- }
-
- ((SDI) super.iter).setList(super.sdata);
- }
-
- //////////////////////////////////////////////////
- // Compiler API
-
- /* package */
- void add(long recno, int fieldno, Array field) {
- // Make sure all the space is allocated
- if (records.length <= recno) {
- FieldSet[] newrecs = new FieldSet[(int) recno + 1];
- System.arraycopy(records, 0, newrecs, 0, records.length);
- records = newrecs;
- }
- FieldSet fs = records[(int) recno];
- if (fs == null) {
- records[(int) recno] = (fs = new FieldSet(this.nmembers));
- }
- fs.fields[fieldno] = field;
- }
-
- //////////////////////////////////////////////////
- // CDMArray Interface
-
- @Override
- public DapType getBaseType() {
- return this.basetype;
- }
-
- @Override
- public DSP getDSP() {
- return this.dsp;
- }
-
- @Override
- public DapVariable getTemplate() {
- return template;
- }
-
- //////////////////////////////////////////////////
-
- public String toString() {
- StringBuilder buf = new StringBuilder();
- DapVariable var = this.template;
- DapSequence seq = (DapSequence) this.basetype;
- long dimsize = DapUtil.dimProduct(var.getDimensions());
- for (int i = 0; i < dimsize; i++) {
- List fields = seq.getFields();
- if (i < (dimsize - 1))
- buf.append("\n");
- buf.append("Sequence {\n");
- buf.append(String.format("} [%d/%d]", i, dimsize));
- }
- return buf.toString();
- }
-
-
- //////////////////////////////////////////////////
- // ArraySequence/ArrayStructure overrides
-
- @Override
- public int getStructureDataCount() {
- return this.records.length;
- }
-
- @Override
- protected StructureData makeStructureData(ArrayStructure as, int index) {
- throw new UnsupportedOperationException("Cannot subset a Sequence");
- }
-
- /**
- * Get the index'th StructureData(StructureDataA) object
- * We need instances of StructureData to give to the user.
- * We use StructureDataA so we can centralize everything
- * in this class. The total number of StructureData objects
- * is dimsize.
- *
- * @param index
- * @return
- */
- @Override
- public StructureData getStructureData(int index) {
- assert (super.sdata != null);
- if (index < 0 || index >= this.records.length)
- throw new IllegalArgumentException(index + " >= " + super.sdata.length);
- assert (super.sdata[index] != null);
- return super.sdata[index];
- }
-
- public ArraySequence getArraySequence(StructureMembers.Member m) {
- return this;
- }
-
- /////////////////////////
- // Define API required by StructureDataA
- @Override
- public Array copy() {
- return this; // temporary
- }
-
- /**
- * Get member data of any type for a specific record as an Array.
- * This may avoid the overhead of creating the StructureData object,
- * but is equivalent to getStructure(recno).getArray( Member m).
- *
- * @param recno get data from the recnum-th StructureData of the ArrayStructure.
- * Must be less than getSize();
- * @param m get data from this StructureMembers.Member.
- * @return Array values.
- */
- public Array getArray(int recno, StructureMembers.Member m) {
- return (ucar.ma2.Array) memberArray(recno, CDMArrayStructure.memberIndex(m));
- }
-
- /////////////////////////
-
- protected CDMArrayAtomic getAtomicArray(int index, StructureMembers.Member m) {
- Array dd = memberArray(index, CDMArrayStructure.memberIndex(m));
- if (dd.getDataType() != DataType.STRUCTURE && dd.getDataType() != DataType.SEQUENCE)
- return (CDMArrayAtomic) dd;
- throw new ForbiddenConversionException("Cannot convert structure to AtomicArray");
- }
-
- protected Array memberArray(int recno, int memberindex) {
-
- Object[] values = new Object[(int) this.recordcount];
- for (int i = 0; i < this.recordcount; i++) {
- FieldSet fs = records[i];
- values[i] = fs.fields[memberindex];
- }
- DapVariable field = ((DapStructure) this.basetype).getField(memberindex);
- DapType base = field.getBaseType();
- if (base == null)
- throw new IllegalStateException("Unknown field type: " + field);
- DataType dt = CDMTypeFcns.daptype2cdmtype(base);
- Class elemtype = CDMTypeFcns.cdmElementClass(dt);
- int shape[] = new int[] {(int) this.recordcount};
- return new ArrayObject(dt, elemtype, false, shape, values);
- }
-}
-
diff --git a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayStructure.java b/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayStructure.java
deleted file mode 100644
index 57421103f9..0000000000
--- a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayStructure.java
+++ /dev/null
@@ -1,487 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.cdm.nc2;
-
-import dap4.cdm.CDMTypeFcns;
-import dap4.cdm.CDMUtil;
-import dap4.core.data.DSP;
-import dap4.core.data.DataCursor;
-import dap4.core.dmr.DapStructure;
-import dap4.core.dmr.DapType;
-import dap4.core.dmr.DapVariable;
-import dap4.core.util.DapException;
-import dap4.core.util.DapUtil;
-import dap4.core.util.Slice;
-import dap4.dap4lib.LibTypeFcns;
-import ucar.ma2.*;
-import ucar.nc2.Group;
-import java.nio.ByteBuffer;
-import java.util.List;
-import static dap4.core.data.DataCursor.Scheme;
-
-/**
- * Implementation of ArrayStructure that wraps
- * DAP4 databuffer
- * (Note: Needs serious optimization applied).
- *
- * Given
- * Structure S {f1,f2,...fm} [d1][d2]...[dn],
- * internally, this is stored as a 2-D array
- * CDMArray[][] instances;
- * The first dimension's length is d1*d2*...dn.
- * The second dimension has size |members| i.e. the number
- * of fields in the sequence.
- */
-
-/* package */ class CDMArrayStructure extends ArrayStructure implements CDMArray {
- //////////////////////////////////////////////////
- // Type decls
-
- /**
- * We need to keep a map of index X fieldno -> Array
- * representing the Array behind each field for each
- * struct instance in a matrix of struct instances.
- * To promote some clarity a eschew Array[|dimset|][|fields|]
- * in favor of FieldArrays[|dimset|].
- */
- protected static class FieldArrays {
- public Array[] fields; // Make externally accessible
-
- FieldArrays(int nfields) {
- fields = new Array[nfields];
- }
-
- }
-
- //////////////////////////////////////////////////
- // Instance variables
-
- // CDMArry variables
- protected Group cdmroot = null;
- protected DSP dsp = null;
- protected DapVariable template = null;
- protected DapType basetype = null;
- protected long dimsize = 0;
- protected int nmembers = 0;
-
- protected DataCursor data = null;
-
- /**
- * Since we are using StructureDataA,
- * we store a list Field sets
- * So we have a map: index -> Field object.
- * Total number of objects is dimsize.
- * Accessed by calls from StructureDataA.
- * Note: We use the super.sdata field to store
- * the StructureData instances.
- */
-
- // Note: term records here means the elements of the array,
- // not record as in Sequence
-
- protected FieldArrays[] records = null; // list of Structure elements
-
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- /**
- * Constructor
- *
- * @param cdmroot the parent CDMDataset
- * @param data the structure data
- */
- CDMArrayStructure(Group cdmroot, DataCursor data) {
- super(computemembers((DapVariable) data.getTemplate()),
- CDMUtil.computeEffectiveShape(((DapVariable) data.getTemplate()).getDimensions()));
- this.template = (DapVariable) data.getTemplate();
- assert data.getScheme() == Scheme.STRUCTARRAY;
- this.dsp = data.getDSP();
- this.cdmroot = cdmroot;
- this.basetype = this.template.getBaseType();
- this.dimsize = DapUtil.dimProduct(template.getDimensions());
- this.nmembers = ((DapStructure) template.getBaseType()).getFields().size();
-
- this.data = data;
-
- // Fill in the structdata (in parent) and instance vectors
- super.sdata = new StructureDataA[(int) this.dimsize];
- records = new FieldArrays[(int) this.dimsize];
- for (int i = 0; i < dimsize; i++) {
- super.sdata[i] = new StructureDataA(this, i);
- records[i] = new FieldArrays(this.nmembers);
- }
- }
-
- /**
- *
- * @param recno struct instance
- * @param fieldno field of that struct
- * @param field Array backing this field in this struct instance
- */
- /* package */
- void add(long recno, int fieldno, Array field) {
- FieldArrays fs = records[(int) recno];
- if (fs == null)
- records[(int) recno] = (fs = new FieldArrays(this.nmembers));
- fs.fields[fieldno] = field;
- }
- //////////////////////////////////////////////////
- // CDMArray Interface
-
- @Override
- public DSP getDSP() {
- return this.dsp;
- }
-
- @Override
- public DapVariable getTemplate() {
- return this.template;
- }
-
- @Override
- public DapType getBaseType() {
- return this.basetype;
- }
-
- //////////////////////////////////////////////////
- // Accessors
-
- @Override
- public long getSize() {
- return this.dimsize;
- }
-
- //////////////////////////////////////////////////
-
- public String toString() {
- StringBuilder buf = new StringBuilder();
- DapVariable var = (DapVariable) this.template;
- DapStructure struct = (DapStructure) var.getBaseType();
- for (int i = 0; i < this.dimsize; i++) {
- List fields = struct.getFields();
- if (i < (this.dimsize - 1))
- buf.append("\n");
- buf.append("Structure {\n");
- if (fields != null) {
- for (int j = 0; j < this.nmembers; j++) {
- Array field = records[i].fields[j];
- String sfield = (field == null ? "null" : fields.toString());
- buf.append(sfield + "\n");
- }
- }
- buf.append(String.format("} [%d/%d]", i, dimsize));
- }
- return buf.toString();
- }
-
- //////////////////////////////////////////////////
- // ArrayStructure interface
-
- /**
- * Get the index'th StructureData(StructureDataA) object
- * We need instances of StructureData to give to the user.
- * We use StructureDataA so we can centralize everything
- * in this class. The total number of StructureData objects
- * is dimsize.
- *
- * @param index
- * @return
- */
- @Override
- public StructureData getStructureData(int index) {
- assert (super.sdata != null);
- if (index < 0 || index >= this.dimsize)
- throw new IllegalArgumentException(index + " >= " + super.sdata.length);
- assert (super.sdata[index] != null);
- return super.sdata[index];
- }
-
- public double getScalarDouble(int index, StructureMembers.Member m) {
- CDMArrayAtomic data = getAtomicArray(index, m);
- return data.getDouble(0);
- }
-
- public float getScalarFloat(int index, StructureMembers.Member m) {
- CDMArrayAtomic data = getAtomicArray(index, m);
- return data.getFloat(0);
- }
-
- public byte getScalarByte(int index, StructureMembers.Member m) {
- CDMArrayAtomic data = getAtomicArray(index, m);
- return data.getByte(0);
- }
-
- public short getScalarShort(int index, StructureMembers.Member m) {
- CDMArrayAtomic data = getAtomicArray(index, m);
- return data.getShort(0);
- }
-
- public int getScalarInt(int index, StructureMembers.Member m) {
- CDMArrayAtomic data = getAtomicArray(index, m);
- return data.getInt(0);
- }
-
- public long getScalarLong(int index, StructureMembers.Member m) {
- CDMArrayAtomic data = getAtomicArray(index, m);
- return data.getLong(0);
- }
-
- public char getScalarChar(int index, StructureMembers.Member m) {
- CDMArrayAtomic data = getAtomicArray(index, m);
- return data.getChar(0);
- }
-
- /**
- * Get member databuffer of type String or char.
- *
- * @param recnum get databuffer from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();
- * @param m get databuffer from this StructureMembers.Member. Must be of type String or char.
- * @return scalar String value
- */
- public String getScalarString(int recnum, StructureMembers.Member m) {
- Array data = m.getDataArray();
- return (String) data.getObject(recnum).toString();
- }
-
- public double[] getJavaArrayDouble(int recnum, StructureMembers.Member m) {
- CDMArrayAtomic array = getAtomicArray(recnum, m);
- if (!array.getBaseType().isNumericType())
- throw new IllegalArgumentException("Cannot convert non-numeric type");
- DapType atomtype = array.getBaseType();
- try {
- List slices = CDMUtil.shapeToSlices(m.getShape());
- Object vector = data.read(slices);
- return (double[]) LibTypeFcns.convertVector(DapType.FLOAT64, atomtype, vector);
- } catch (DapException de) {
- throw new UnsupportedOperationException(de);
- }
- }
-
- public float[] getJavaArrayFloat(int index, StructureMembers.Member m) {
- CDMArrayAtomic array = getAtomicArray(index, m);
- if (!array.getBaseType().isNumericType())
- throw new IllegalArgumentException("Cannot convert non-numeric type");
- DapType atomtype = array.getBaseType();
- try {
- List slices = CDMUtil.shapeToSlices(m.getShape());
- Object vector = data.read(slices);
- return (float[]) LibTypeFcns.convertVector(DapType.FLOAT32, atomtype, vector);
- } catch (DapException de) {
- throw new UnsupportedOperationException(de);
- }
- }
-
- public byte[] getJavaArrayByte(int index, StructureMembers.Member m) {
- CDMArrayAtomic array = getAtomicArray(index, m);
- if (!array.getBaseType().isNumericType())
- throw new IllegalArgumentException("Cannot convert non-numeric type");
- DapType atomtype = array.getBaseType();
- try {
- List slices = CDMUtil.shapeToSlices(m.getShape());
- Object vector = data.read(slices);
- return (byte[]) LibTypeFcns.convertVector(DapType.INT8, atomtype, vector);
- } catch (DapException de) {
- throw new UnsupportedOperationException(de);
- }
- }
-
- public short[] getJavaArrayShort(int index, StructureMembers.Member m) {
- CDMArrayAtomic array = getAtomicArray(index, m);
- if (!array.getBaseType().isNumericType())
- throw new IllegalArgumentException("Cannot convert non-numeric type");
- DapType atomtype = array.getBaseType();
- try {
- List slices = CDMUtil.shapeToSlices(m.getShape());
- Object vector = data.read(slices);
- return (short[]) LibTypeFcns.convertVector(DapType.INT16, atomtype, vector);
- } catch (DapException de) {
- throw new UnsupportedOperationException(de);
- }
- }
-
- public int[] getJavaArrayInt(int index, StructureMembers.Member m) {
- CDMArrayAtomic array = getAtomicArray(index, m);
- if (!array.getBaseType().isNumericType())
- throw new IllegalArgumentException("Cannot convert non-numeric type");
- DapType atomtype = array.getBaseType();
- try {
- List slices = CDMUtil.shapeToSlices(m.getShape());
- Object vector = data.read(slices);
- return (int[]) LibTypeFcns.convertVector(DapType.INT32, atomtype, vector);
- } catch (DapException de) {
- throw new UnsupportedOperationException(de);
- }
- }
-
- public long[] getJavaArrayLong(int index, StructureMembers.Member m) {
- CDMArrayAtomic array = getAtomicArray(index, m);
- if (!array.getBaseType().isNumericType())
- throw new IllegalArgumentException("Cannot convert non-numeric type");
- DapType atomtype = array.getBaseType();
- try {
- List slices = CDMUtil.shapeToSlices(m.getShape());
- Object vector = data.read(slices);
- return (long[]) LibTypeFcns.convertVector(DapType.INT64, atomtype, vector);
- } catch (DapException de) {
- throw new UnsupportedOperationException(de);
- }
- }
-
- public char[] getJavaArrayChar(int index, StructureMembers.Member m) {
- CDMArrayAtomic array = getAtomicArray(index, m);
- if (!array.getBaseType().isNumericType())
- throw new IllegalArgumentException("Cannot convert non-numeric type");
- DapType atomtype = array.getBaseType();
- try {
- List slices = CDMUtil.shapeToSlices(m.getShape());
- Object vector = data.read(slices);
- return (char[]) LibTypeFcns.convertVector(DapType.CHAR, atomtype, vector);
- } catch (DapException de) {
- throw new UnsupportedOperationException(de);
- }
- }
-
- public String[] getJavaArrayString(int index, StructureMembers.Member m) {
- CDMArrayAtomic array = getAtomicArray(index, m);
- DapType atomtype = array.getBaseType();
- try {
- List slices = CDMUtil.shapeToSlices(m.getShape());
- Object vector = data.read(slices);
- return (String[]) LibTypeFcns.convertVector(DapType.STRING, atomtype, vector);
- } catch (DapException de) {
- throw new UnsupportedOperationException(de);
- }
- }
-
- public ByteBuffer[] getJavaArrayOpaque(int index, StructureMembers.Member m) {
- CDMArrayAtomic array = getAtomicArray(index, m);
- DapType atomtype = array.getBaseType();
- try {
- List slices = CDMUtil.shapeToSlices(m.getShape());
- Object vector = data.read(slices);
- return (ByteBuffer[]) LibTypeFcns.convertVector(DapType.OPAQUE, atomtype, vector);
- } catch (DapException de) {
- throw new UnsupportedOperationException(de);
- }
- }
-
- // Non-atomic cases
-
- public StructureData getScalarStructure(int index, StructureMembers.Member m) {
- if (m.getDataType() != DataType.STRUCTURE)
- throw new ForbiddenConversionException("Atomic field cannot be converted to Structure");
- Array ca = memberArray(index, memberIndex(m));
- if (ca.getDataType() != DataType.STRUCTURE && ca.getDataType() != DataType.SEQUENCE)
- throw new ForbiddenConversionException("Attempt to access non-structure member");
- CDMArrayStructure as = (CDMArrayStructure) ca;
- return as.getStructureData(0);
- }
-
- public ArrayStructure getArrayStructure(int index, StructureMembers.Member m) {
- if (m.getDataType() != DataType.STRUCTURE)
- throw new ForbiddenConversionException("Atomic field cannot be converted to Structure");
- Array dd = memberArray(index, memberIndex(m));
- if (dd.getDataType() != DataType.STRUCTURE && dd.getDataType() != DataType.SEQUENCE)
- throw new ForbiddenConversionException("Attempt to access non-structure member");
- return (CDMArrayStructure) dd;
- }
-
- public ArraySequence getArraySequence(StructureMembers.Member m) {
- throw new UnsupportedOperationException("CDMArraySequence");
- }
-
- @Override
- public Array copy() {
- return this; // temporary
- }
-
- /////////////////////////
- // Define API required by StructureDataA
-
- /**
- * Key interface method coming in from StructureDataA.
- *
- * @param recno The instance # of the array of Structure instances
- * @param m The member of interest in the Structure instance
- * @return The ucar.ma2.Array instance corresponding to the instance.
- *
- * Hidden: friend of StructureDataA
- */
- @Override
- public ucar.ma2.Array getArray(int recno, StructureMembers.Member m) {
- return (ucar.ma2.Array) memberArray(recno, memberIndex(m));
- }
-
- //////////////////////////////////////////////////
- // Utilities
-
- @Override
- protected StructureData makeStructureData(ArrayStructure as, int index) {
- if (super.sdata[index] == null)
- super.sdata[index] = new StructureDataA(as, index);
- return super.sdata[index];
- }
-
- /**
- * Compute the StructureMembers object
- * from a DapStructure. May need to recurse
- * if a field is itself a Structure
- *
- * @param var The DapVariable to use to construct
- * a StructureMembers object.
- * @return The StructureMembers object for the given DapStructure
- */
- static StructureMembers computemembers(DapVariable var) {
- DapStructure ds = (DapStructure) var.getBaseType();
- StructureMembers sm = new StructureMembers(ds.getShortName());
- List fields = ds.getFields();
- for (int i = 0; i < fields.size(); i++) {
- DapVariable field = fields.get(i);
- DapType dt = field.getBaseType();
- DataType cdmtype = CDMTypeFcns.daptype2cdmtype(dt);
- StructureMembers.Member m =
- sm.addMember(field.getShortName(), "", null, cdmtype, CDMUtil.computeEffectiveShape(field.getDimensions()));
- m.setDataParam(i); // So we can index into various lists
- // recurse if this field is itself a structure
- if (dt.getTypeSort().isStructType()) {
- StructureMembers subsm = computemembers(field);
- m.setStructureMembers(subsm);
- }
- }
- return sm;
- }
-
- /**
- * @param recno The instance # of the array of Structure instances
- * @param memberindex The member of interest in the Structure instance
- * @return The ucar.ma2.Array instance corresponding to the instance.
- */
- protected Array memberArray(int recno, int memberindex) {
- DapVariable var = (DapVariable) this.getTemplate();
- DapStructure struct = (DapStructure) var.getBaseType();
- DapVariable field = struct.getField(memberindex);
- DapType base = field.getBaseType();
- if (base == null)
- throw new IllegalStateException("Unknown field type: " + field);
- Object[] values = new Object[(int) field.getCount()];
- FieldArrays fs = records[recno];
- Array fa = fs.fields[memberindex];
- return fa;
- }
-
- protected static int memberIndex(StructureMembers.Member m) {
- return m.getDataParam();
- }
-
- protected CDMArrayAtomic getAtomicArray(int index, StructureMembers.Member m) {
- Array dd = memberArray(index, memberIndex(m));
- if (dd.getDataType() != DataType.STRUCTURE && dd.getDataType() != DataType.SEQUENCE)
- return (CDMArrayAtomic) dd;
- throw new ForbiddenConversionException("Cannot convert structure to AtomicArray");
- }
-
-}
diff --git a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/DataToCDM.java b/dap4/d4cdm/src/main/java/dap4/cdm/nc2/DataToCDM.java
deleted file mode 100644
index 96b85a765d..0000000000
--- a/dap4/d4cdm/src/main/java/dap4/cdm/nc2/DataToCDM.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-
-package dap4.cdm.nc2;
-
-import dap4.cdm.NodeMap;
-import dap4.core.data.DSP;
-import dap4.core.data.DataCursor;
-import dap4.core.dmr.*;
-import dap4.core.util.DapException;
-import dap4.core.util.DapUtil;
-import dap4.core.util.Index;
-import dap4.core.util.Odometer;
-import ucar.ma2.Array;
-import ucar.nc2.Attribute;
-import ucar.nc2.Group;
-import ucar.nc2.Variable;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Create a set of CDM ucar.ma2.array objects that wrap a DSP.
- */
-
-public class DataToCDM {
- public static boolean DEBUG = false;
-
- //////////////////////////////////////////////////
- // Constants
-
- protected static final int COUNTSIZE = 8; // databuffer as specified by the DAP4 spec
-
- protected static final String LBRACE = "{";
- protected static final String RBRACE = "}";
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected DapNetcdfFile ncfile = null;
- protected DSP dsp = null;
- protected DapDataset dmr = null;
- protected Group cdmroot = null;
- protected Map arraymap = null;
- protected NodeMap nodemap = null;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- /**
- * Constructor
- *
- * @param ncfile the target NetcdfDataset
- * @param dsp the compiled D4 databuffer
- */
-
- public DataToCDM(DapNetcdfFile ncfile, DSP dsp, NodeMap nodemap) throws DapException {
- this.ncfile = ncfile;
- this.dsp = dsp;
- this.dmr = dsp.getDMR();
- this.nodemap = nodemap;
- this.cdmroot = ncfile.getRootGroup();
- arraymap = new HashMap();
- // Add endianness attribute to the group
- /*
- * ByteOrder remoteorder = ncfile.getDSP().getOrder();
- * String endianness = null;
- * if(remoteorder != null) {
- * if(remoteorder == ByteOrder.BIG_ENDIAN)
- * endianness = "big";
- * else if(remoteorder == ByteOrder.BIG_ENDIAN)
- * endianness = "little";
- * }
- * if(endianness != null) {
- * Attribute aendian = new Attribute(DapUtil.ENDIANATTRNAME, endianness);
- * this.cdmroot.addAttribute(aendian);
- * }
- */
- }
-
- //////////////////////////////////////////////////
- // Compile DataCursor objects to ucar.ma2.Array objects
-
- /* package access */
- Map create() throws DapException {
- // iterate over the variables represented in the DSP
- List topvars = this.dmr.getTopVariables();
- Map map = null;
- for (DapVariable var : topvars) {
- DataCursor cursor = this.dsp.getVariableData(var);
- Array array = createVar(cursor);
- Variable cdmvar = (Variable) nodemap.get(var);
- arraymap.put(cdmvar, array);
- }
- return this.arraymap;
- }
-
- protected Array createVar(DataCursor data) throws DapException {
- Array array = null;
- DapVariable d4var = (DapVariable) data.getTemplate();
- switch (d4var.getBaseType().getTypeSort()) {
- default: // atomic var
- array = createAtomicVar(data);
- break;
- case Sequence:
- array = createSequence(data);
- break;
- case Structure:
- array = createStructure(data);
- break;
- }
- if (d4var.isTopLevel() && this.dsp.getChecksumMode().enabled(dsp.getChecksumMode())) {
- // transfer the checksum attribute
- int csum = d4var.getChecksum();
- String scsum = String.format("0x%08x", csum);
- Variable cdmvar = (Variable) nodemap.get(d4var);
- Attribute acsum = new Attribute(DapUtil.CHECKSUMATTRNAME, scsum);
- cdmvar.addAttribute(acsum);
- }
- return array;
- }
-
- /**
- * Create an Atomic Valued variable.
- *
- * @return An Array object wrapping d4var.
- * @throws DapException
- */
- protected CDMArrayAtomic createAtomicVar(DataCursor data) throws DapException {
- CDMArrayAtomic array = new CDMArrayAtomic(data);
- return array;
- }
-
- /**
- * Create an array of structures. WARNING: the underlying CDM code
- * (esp. NetcdfDataset) apparently does not support nested
- * structure arrays; so this code may throw an exception.
- *
- * @return A CDMArrayStructure for the databuffer for this struct.
- * @throws DapException
- */
- protected CDMArrayStructure createStructure(DataCursor data) throws DapException {
- CDMArrayStructure arraystruct = new CDMArrayStructure(this.cdmroot, data);
- DapVariable var = (DapVariable) data.getTemplate();
- DapStructure struct = (DapStructure) var.getBaseType();
- int nmembers = struct.getFields().size();
- List dimset = var.getDimensions();
- Odometer odom = Odometer.factory(DapUtil.dimsetToSlices(dimset));
- while (odom.hasNext()) {
- Index index = odom.next();
- long offset = index.index();
- DataCursor[] cursors = (DataCursor[]) data.read(index);
- DataCursor ithelement = cursors[0];
- for (int f = 0; f < nmembers; f++) {
- DataCursor dc = (DataCursor) ithelement.readField(f);
- Array afield = createVar(dc);
- arraystruct.add(offset, f, afield);
- }
- }
- return arraystruct;
- }
-
- /**
- * Create a sequence. WARNING: the underlying CDM code
- * (esp. NetcdfDataset) apparently does not support nested
- * sequence arrays.
- *
- * @param data the data underlying this sequence instance
- * @return A CDMArraySequence for this instance
- * @throws DapException
- */
-
- protected CDMArraySequence createSequence(DataCursor data) throws DapException {
- CDMArraySequence arrayseq = new CDMArraySequence(this.cdmroot, data);
- DapVariable var = (DapVariable) data.getTemplate();
- DapSequence template = (DapSequence) var.getBaseType();
- List dimset = var.getDimensions();
- long dimsize = DapUtil.dimProduct(dimset);
- int nfields = template.getFields().size();
- Odometer odom = Odometer.factory(DapUtil.dimsetToSlices(dimset));
- while (odom.hasNext()) {
- odom.next();
- DataCursor seq = ((DataCursor[]) data.read(odom.indices()))[0];
- long nrecords = seq.getRecordCount();
- for (int r = 0; r < nrecords; r++) {
- DataCursor rec = seq.readRecord(r);
- for (int f = 0; f < nfields; f++) {
- DataCursor dc = rec.readField(f);
- Array afield = createVar(dc);
- arrayseq.add(r, f, afield);
- }
- }
- }
- return arrayseq;
- }
-}
diff --git a/dap4/d4cdm/src/main/resources/META-INF/services/ucar.nc2.dataset.spi.NetcdfFileProvider b/dap4/d4cdm/src/main/resources/META-INF/services/ucar.nc2.dataset.spi.NetcdfFileProvider
deleted file mode 100644
index 8acc1012f6..0000000000
--- a/dap4/d4cdm/src/main/resources/META-INF/services/ucar.nc2.dataset.spi.NetcdfFileProvider
+++ /dev/null
@@ -1 +0,0 @@
-dap4.cdm.nc2.DapNetcdfFileProvider
\ No newline at end of file
diff --git a/dap4/d4core/build.gradle b/dap4/d4core/build.gradle
deleted file mode 100644
index 9e4a50d5b4..0000000000
--- a/dap4/d4core/build.gradle
+++ /dev/null
@@ -1,5 +0,0 @@
-// d4core has no dependencies
-apply from: "$rootDir/gradle/any/java-library.gradle"
-
-dependencies {
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/data/ChecksumMode.java b/dap4/d4core/src/main/java/dap4/core/data/ChecksumMode.java
deleted file mode 100644
index 5554e36c42..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/data/ChecksumMode.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.data;
-
-/**
- * Define possible checksum modes:
- *
- */
-public enum ChecksumMode {
- NONE, // => serialized data has no checksums
- IGNORE, // => skip, but ignore any checksumming (client side)
- DMR, // => compute checksums for DMR requests only
- DAP, // => compute checksums for Data requests only
- ALL; // => compute checksums for both kinds of requestsNONE, DMR, DAP, ALL;
-
- /**
- * Return true if the ckm mode is allowed with this, false otherwise
- *
- * @param ckm
- * @return true, if enabled
- */
- public boolean enabled(ChecksumMode ckm) {
- if (ckm == null || this == NONE)
- return false;
- if (this == ckm)
- return true;
- if (this == ALL)
- return true;
- return false;
- }
-
- public static ChecksumMode modeFor(String s) {
- if (s == null || s.length() == 0)
- return DAP;
- for (ChecksumMode mode : values()) {
- if (mode.name().equalsIgnoreCase(s))
- return mode;
- }
- return null;
- }
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/data/Constraint.java b/dap4/d4core/src/main/java/dap4/core/data/Constraint.java
deleted file mode 100644
index 271e341d78..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/data/Constraint.java
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.data;
-
-/**
- * This interface is intended to serve
- * as a standin for some kind of constraint.
- */
-
-public interface Constraint {
- // Deliberately empty
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/data/DSP.java b/dap4/d4core/src/main/java/dap4/core/data/DSP.java
deleted file mode 100644
index 7715ee5a35..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/data/DSP.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.data;
-
-import dap4.core.dmr.DapDataset;
-import dap4.core.dmr.DapVariable;
-import dap4.core.util.DapContext;
-import dap4.core.util.DapException;
-import java.io.IOException;
-import java.nio.ByteOrder;
-
-public interface DSP {
- /*
- * All implementing classes must implement:
- * 1. a static dspMatch() function
- * 2. A parameterless constructor
- */
-
- /**
- * Determine if a path refers to an object processable by this DSP
- *
- * @param path
- * @param context
- * @return true if this path can be processed by an instance of this DSP
- */
- public boolean dspMatch(String path, DapContext context);
-
- /**
- * @param path It is assumed that the path
- * is appropriate to the dsp
- * E.g. an absolute path or a url
- * @return DSP wrapping the path source
- * @throws dap4.core.util.DapException
- */
- public DSP open(String path) throws DapException;
-
- public void close() throws IOException;
-
- public String getLocation();
-
- public DSP setLocation(String location);
-
- public Object getContext();
-
- public void setContext(DapContext cxt);
-
- public DapDataset getDMR() throws dap4.core.util.DapException;
-
- public DataCursor getVariableData(DapVariable var) throws DapException;
-
- public ByteOrder getOrder();
-
- public ChecksumMode getChecksumMode();
-
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/data/DataCursor.java b/dap4/d4core/src/main/java/dap4/core/data/DataCursor.java
deleted file mode 100644
index 2da280d972..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/data/DataCursor.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.data;
-
-import dap4.core.dmr.DapNode;
-import dap4.core.util.DapException;
-import dap4.core.util.Index;
-import dap4.core.util.Slice;
-import java.util.List;
-
-/**
- * For data access, we adopt a cursor model.
- * This comes from database technology where a
- * cursor object is used to walk over the
- * results of a database query. Here the cursor
- * walks the underlying data and stores enough
- * state to extract data depending on its
- * sort. The cursor may (or may not) contain
- * internal subclasses to track various kinds of
- * state.
- */
-
-public interface DataCursor {
- //////////////////////////////////////////////////
- // Kinds of Cursor
-
- public static enum Scheme {
- ATOMIC, STRUCTARRAY, STRUCTURE, SEQARRAY, SEQUENCE, RECORD;
-
- public boolean isCompoundArray() {
- return this == STRUCTARRAY || this == SEQARRAY;
- }
- }
-
- //////////////////////////////////////////////////
- // API
-
- public Scheme getScheme();
-
- public DSP getDSP();
-
- public DapNode getTemplate();
-
- public Index getIndex() throws DapException;
-
- public boolean isScalar();
-
- public boolean isField();
-
- // Return null if top-level, else return the struct/seq from which this is derived
- public DataCursor getContainer();
-
- //////////////////////////////////////////////////
- // Atomic Data Management
-
- // As a rule, only one will be fully implemented and the other written
- // to use the fully implemented one.
- // Returns:
- // atomic - array of data values
- // structure/sequence - DataCursor[]
- // Even if the result is a scalar,
- // a 1-element array will be returned.
-
- public Object read(List slices) throws DapException;
-
- public Object read(Index index) throws DapException;
-
- //////////////////////////////////////////////////
- // Sequence record management
- // assert scheme == SEQUENCE
-
- public long getRecordCount() throws DapException;
-
- public DataCursor readRecord(long i) throws DapException;
-
- public long getRecordIndex() throws DapException; // assert scheme == RECORD
-
- //////////////////////////////////////////////////
- // field management
- // assert scheme == STRUCTURE | scheme == RECORD
-
- public int fieldIndex(String name) throws DapException; // Convert a name to an index
-
- public DataCursor readField(int fieldindex) throws DapException;
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/AnnotatedNode.java b/dap4/d4core/src/main/java/dap4/core/dmr/AnnotatedNode.java
deleted file mode 100644
index d1fc804b04..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/AnnotatedNode.java
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr;
-
-public interface AnnotatedNode {
- public void annotate(Object key, Object value);
-
- public Object annotation(Object key);
-
- public void clearAnnotations();
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/DapXML.java b/dap4/d4core/src/main/java/dap4/core/dmr/DapXML.java
deleted file mode 100644
index 74256c63b5..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/DapXML.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr;
-
-import dap4.core.util.DapException;
-import org.w3c.dom.Node;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * This class is not intended to be a full org.w3c.DOM
- * implementation. Rather it stores more-or-less
- * equivalent information in a more AST like form.
- */
-
-public class DapXML {
- //////////////////////////////////////////////////
- // Types
-
- public static class XMLList extends ArrayList {
- }
-
- // This corresponds to a subset of the org.w3c.dom.Node
- // nodetype codes.
-
- public static enum NodeType {
- ELEMENT(Node.ELEMENT_NODE), ATTRIBUTE(Node.ATTRIBUTE_NODE), TEXT(Node.TEXT_NODE), CDATA(
- Node.CDATA_SECTION_NODE), COMMENT(
- Node.COMMENT_NODE), DOCUMENT(Node.DOCUMENT_NODE), DOCTYPE(Node.DOCUMENT_TYPE_NODE);
-
- private short w3c_nodetype;
-
- private NodeType(short nodetype) {
- this.w3c_nodetype = nodetype;
- }
-
- public short getW3CNodeType() {
- return w3c_nodetype;
- }
- }
-
- //////////////////////////////////////////////////
- // Instance Variables
-
- protected String name = null;
- protected DapXML parent = null;
-
- // Applies to all (or almost all) node types
- protected NodeType nodetype = null;
- protected String prefix = null; // namespace prefix or null
-
- // case NodeType.ELEMENT
- protected List elements = new ArrayList();
- protected Map xmlattributes = new HashMap();
-
- // case NodeType.ATTRIBUTE
- protected String value = null; // for attribute nodes
-
- // case NodeType.TEXT
- // case NodeType.CDATA
- // case NodeType.COMMENT
- protected String text = null; // for text or cdata nodes
-
- // case NodeType.DOCUMENT
- // case NodeType.DOCTYPE
- // unused
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public DapXML() {
- super();
- }
-
- public DapXML(NodeType nodetype, String fullname) {
- setNodeType(nodetype);
- // Decompose name into prefix plus short name
- int i = fullname.indexOf(':');
- if (i >= 0) {
- this.prefix = fullname.substring(i);
- fullname = fullname.substring(i + 1, fullname.length());
- if (this.prefix.length() == 0)
- this.prefix = null;
- }
- setName(fullname);
- }
-
- //////////////////////////////////////////////////
- // Get/Set
-
- public String getName() {
- return this.name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public NodeType getNodeType() {
- return nodetype;
- }
-
- public void setNodeType(NodeType nodetype) {
- this.nodetype = nodetype;
- this.prefix = null;
- String fullname = null;
- switch (nodetype) {
- case COMMENT:
- fullname = "#comment";
- break;
- case TEXT:
- fullname = "#text";
- break;
- case DOCUMENT:
- fullname = "#document";
- break;
- case CDATA:
- fullname = "#cdata-section";
- break;
- default:
- break;
- }
- setName(fullname);
- }
-
- public String getLocalName() {
- return getName();
- }
-
- public void setLocalName(String localname) {
- setName(localname);
- }
-
- public String getPrefix() {
- return prefix;
- }
-
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-
- public DapXML getParent() {
- return this.parent;
- }
-
- public void setParent(DapXML parent) {
- this.parent = parent;
- }
-
- public List getElements() {
- return this.elements;
- }
-
- public void addElement(DapXML child) {
- if (elements == null)
- this.elements = new ArrayList();
- elements.add(child);
- child.setParent(this);
- }
-
- public Map getXMLAttributes() {
- return xmlattributes;
- }
-
- public void addXMLAttribute(DapXML attr) throws DapException {
- if (xmlattributes == null)
- this.xmlattributes = new HashMap();
- if (xmlattributes.containsKey(attr.getName()))
- throw new DapException("DapXML: attempt to add duplicate xml attribute: " + attr.getName());
- xmlattributes.put(attr.getName(), attr);
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public String getText() {
- return text;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
- public String toString() {
- StringBuilder buf = new StringBuilder();
- stringify(0, buf);
- return buf.toString();
- }
-
- protected void stringify(int depth, StringBuilder buf) {
- switch (this.nodetype) {
- case ELEMENT:
- indent(depth, buf);
- buf.append(this.name);
- for (Map.Entry entry : xmlattributes.entrySet()) {
- buf.append(' ');
- entry.getValue().stringify(depth + 1, buf);
- }
- buf.append(">\n");
- for (DapXML sub : elements) {
- sub.stringify(depth + 1, buf);
- }
- buf.append("");
- buf.append(this.name);
- buf.append(">\n");
- break;
- case ATTRIBUTE:
- buf.append(this.name);
- buf.append('=');
- buf.append('"');
- buf.append(this.value);
- buf.append('"');
- break;
- case TEXT:
- indent(depth, buf);
- buf.append(this.text);
- buf.append("\n");
- break;
- case CDATA:
- indent(depth, buf);
- buf.append("\n");
- break;
- case COMMENT:
- indent(depth, buf);
- buf.append("\n");
- break;
- case DOCUMENT:
- case DOCTYPE:
- break;
- }
- }
-
- protected void indent(int n, StringBuilder buf) {
- for (int i = 0; i < n; i++) {
- buf.append(' ');
- }
- }
-
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Bison.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Bison.java
deleted file mode 100644
index 245bfffc17..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Bison.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-/**
- * Define Bison specific decls.
- */
-
-package dap4.core.dmr.parser.bison;
-
-import org.xml.sax.Locator;
-
-public abstract class Bison {
- public static class Position {
- public Locator location;
-
- public Position(Locator loc) {
- this.location = loc;
- }
-
- public String toString() {
- return location.getLineNumber() + ":" + location.getColumnNumber();
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof Position))
- return false;
- Position po = (Position) o;
- return po.location.getLineNumber() == po.location.getLineNumber()
- && po.location.getColumnNumber() == po.location.getColumnNumber();
- }
-
- @Override
- public int hashCode() {
- return location.getLineNumber() << 20 | location.getColumnNumber();
- }
- }
-
- /**
- * A class defining a pair of positions. Positions, defined by the
- * Bison.Position class, denote a point in the input.
- * Locations represent a part of the input through the beginning
- * and ending positions.
- */
- public static class Location {
- /**
- * The first, inclusive, position in the range.
- */
- public Bison.Position begin;
-
- /**
- * The first position beyond the range.
- */
- public Bison.Position end;
-
- /**
- * Create a Location denoting an empty range located at
- * a given point.
- *
- * @param loc The position at which the range is anchored.
- */
- public Location(Bison.Position loc) {
- this.begin = this.end = loc;
- }
-
- /**
- * Create a Location from the endpoints of the range.
- *
- * @param begin The first position included in the range.
- * @param end The first position beyond the range.
- */
- public Location(Bison.Position begin, Bison.Position end) {
- this.begin = begin;
- this.end = end;
- }
-
- /**
- * Print a representation of the location. For this to be correct,
- * Bison.Position should override the equals
- * method.
- */
- public String toString() {
- if (begin.equals(end))
- return begin.toString();
- else
- return begin.toString() + "-" + end.toString();
- }
- }
-
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4Actions.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4Actions.java
deleted file mode 100644
index 6843d415a9..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4Actions.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr.parser.bison;
-
-import dap4.core.dmr.DapXML;
-import dap4.core.dmr.parser.ParseException;
-import dap4.core.util.DapException;
-import dap4.core.util.DapSort;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * The role of this class is as follows:
- * 1. Define the abstract action procedures
- * 2. Define useful common constants
- * 3. Define useful common utility procedures
- */
-
-public abstract class Dap4Actions extends Dap4EventHandler {
-
- //////////////////////////////////////////////////
- // Constants
-
- static final float DAPVERSION = 4.0f;
- static final float DMRVERSION = 1.0f;
-
- static final int RULENULL = 0;
- static final int RULEDIMREF = 1;
- static final int RULEMAPREF = 2;
- static final int RULEVAR = 3;
- static final int RULEMETADATA = 4;
-
- static final String[] RESERVEDTAGS = new String[] {"_edu.ucar"};
-
- static final BigInteger BIG_INT64_MAX = BigInteger.valueOf(Long.MAX_VALUE);
-
- static final DapSort[] METADATASCOPES = new DapSort[] {DapSort.DATASET, DapSort.GROUP, DapSort.DIMENSION, DapSort.MAP,
- DapSort.VARIABLE, DapSort.STRUCTURE, DapSort.SEQUENCE, DapSort.ATTRIBUTESET};
-
- //////////////////////////////////////////////////
- // Type Decls
-
- // Predefined map types
- static class XMLAttributeMap extends HashMap {
- }
-
- static class NamespaceList extends ArrayList {
- }
-
-
- //////////////////////////////////////////////////
- // Instance variables
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public Dap4Actions() {}
-
- ///////////////////////////////////////////////////
- // Non-abstract parser actions
-
- XMLAttributeMap xml_attribute_map() throws DapException {
- return new XMLAttributeMap();
- }
-
- XMLAttributeMap xml_attribute_map(XMLAttributeMap map, SaxEvent token) throws DapException {
- assert (map != null && token != null);
- if (map.containsKey(token.name))
- throw new DapException("XML attribute: duplicate xml attribute: " + token.name);
- map.put(token.name.toLowerCase(), token);
- return map;
- }
-
- NamespaceList namespace_list() throws DapException {
- return new NamespaceList();
- }
-
- NamespaceList namespace_list(NamespaceList list, SaxEvent token) throws DapException {
- assert (list != null);
- if (token != null && !list.contains(token.name))
- list.add(token.name);
- return list;
- }
-
- DapXML createxmltext(String text) throws DapException {
- DapXML node = new DapXML(DapXML.NodeType.TEXT, null);
- node.setText(text);
- return node;
- }
-
- DapXML createxmlelement(SaxEvent open, XMLAttributeMap map) throws DapException {
- DapXML node = new DapXML(DapXML.NodeType.ELEMENT, open.name);
- for (Map.Entry entry : map.entrySet()) {
- SaxEvent att = entry.getValue();
- DapXML a = new DapXML(DapXML.NodeType.ATTRIBUTE, att.name);
- a.addXMLAttribute(a);
- }
- return node;
- }
-
- //////////////////////////////////////////////////
- // Abstract (subclass defined) parser actions
-
- abstract void enterdataset(XMLAttributeMap attrs) throws ParseException;
-
- abstract void leavedataset() throws ParseException;
-
- abstract void entergroup(XMLAttributeMap attrs) throws ParseException;
-
- abstract void leavegroup() throws ParseException;
-
- abstract void enterenumdef(XMLAttributeMap attrs) throws ParseException;
-
- abstract void leaveenumdef() throws ParseException;
-
- abstract void enumconst(SaxEvent name, SaxEvent value) throws ParseException;
-
- abstract void enterdimdef(XMLAttributeMap attrs) throws ParseException;
-
- abstract void leavedimdef() throws ParseException;
-
- abstract void dimref(SaxEvent nameorsize) throws ParseException;
-
- abstract void enteratomicvariable(SaxEvent open, XMLAttributeMap attrs) throws ParseException;
-
- abstract void leaveatomicvariable(SaxEvent close) throws ParseException;
-
- abstract void enterenumvariable(XMLAttributeMap attrs) throws ParseException;
-
- abstract void leaveenumvariable(SaxEvent close) throws ParseException;
-
- abstract void entermap(SaxEvent name) throws ParseException;
-
- abstract void leavemap() throws ParseException;
-
- abstract void enterstructurevariable(XMLAttributeMap attrs) throws ParseException;
-
- abstract void leavestructurevariable(SaxEvent close) throws ParseException;
-
- abstract void entersequencevariable(XMLAttributeMap attrs) throws ParseException;
-
- abstract void leavesequencevariable(SaxEvent close) throws ParseException;
-
- abstract void enteratomicattribute(XMLAttributeMap attrs, NamespaceList nslist) throws ParseException;
-
- abstract void leaveatomicattribute() throws ParseException;
-
- abstract void entercontainerattribute(XMLAttributeMap attrs, NamespaceList nslist) throws ParseException;
-
- abstract void leavecontainerattribute() throws ParseException;
-
- abstract void value(SaxEvent value) throws ParseException;
-
- abstract void value(String value) throws ParseException;
-
- abstract void entererror(XMLAttributeMap attrs) throws ParseException;
-
- abstract void leaveerror() throws ParseException;
-
- abstract void errormessage(String value) throws ParseException;
-
- abstract void errorcontext(String value) throws ParseException;
-
- abstract void errorotherinfo(String value) throws ParseException;
-
- abstract void otherxml(XMLAttributeMap attrs, DapXML root) throws ParseException;
-
- abstract DapXML.XMLList xml_body(DapXML.XMLList body, DapXML elemortext) throws ParseException;
-
- abstract DapXML element_or_text(SaxEvent open, XMLAttributeMap xmlattrlist, DapXML.XMLList body, SaxEvent close)
- throws ParseException;
-
- abstract DapXML xmltext(SaxEvent text) throws ParseException;
-
- abstract String textstring(String prefix, SaxEvent text) throws ParseException;
-
-}// class Dap4Actions
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4BisonParser.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4BisonParser.java
deleted file mode 100644
index c35758d2dd..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4BisonParser.java
+++ /dev/null
@@ -1,1954 +0,0 @@
-/* A Bison parser, made by GNU Bison 3.0.4. */
-
-/*
- * Skeleton implementation for Bison LALR(1) parsers in Java
- *
- * Copyright (C) 2007-2015 Free Software Foundation, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-/*
- * As a special exception, you may create a larger work that contains
- * part or all of the Bison parser skeleton and distribute that work
- * under terms of your choice, so long as that work isn't itself a
- * parser generator using the skeleton or a modified version thereof
- * as a parser skeleton. Alternatively, if you modify or redistribute
- * the parser skeleton itself, you may (at your option) remove this
- * special exception, which will cause the skeleton and the resulting
- * Bison output files to be licensed under the GNU General Public
- * License without this special exception.
- *
- * This special exception was added by the Free Software Foundation in
- * version 2.2 of Bison.
- */
-
-package dap4.core.dmr.parser.bison;
-/* First part of user declarations. */
-
-/* "Dap4BisonParser.java":37 */ /* lalr1.java:91 */
-
-/* "Dap4BisonParser.java":39 */ /* lalr1.java:92 */
-/* "%code imports" blocks. */
-/* "dap4.y":17 */ /* lalr1.java:93 */
-
-import dap4.core.util.DapException;
-import dap4.core.dmr.DapXML;
-
-/* "Dap4BisonParser.java":46 */ /* lalr1.java:93 */
-
-/**
- * A Bison parser, automatically generated from dap4.y.
- *
- * @author LALR (1) parser skeleton written by Paolo Bonzini.
- */
-abstract class Dap4BisonParser extends Dap4Actions {
- /** Version number for the Bison executable that generated this parser. */
- public static final String bisonVersion = "3.0.4";
-
- /** Name of the skeleton that generated this parser. */
- public static final String bisonSkeleton = "lalr1.java";
-
-
- /**
- * True if verbose error messages are enabled.
- */
- private boolean yyErrorVerbose = true;
-
- /**
- * Return whether verbose error messages are enabled.
- */
- public final boolean getErrorVerbose() {
- return yyErrorVerbose;
- }
-
- /**
- * Set the verbosity of error messages.
- *
- * @param verbose True to request verbose error messages.
- */
- public final void setErrorVerbose(boolean verbose) {
- yyErrorVerbose = verbose;
- }
-
-
-
- /**
- * Communication interface between the scanner and the Bison-generated
- * parser Dap4BisonParser.
- */
- public interface Lexer {
- /** Token returned by the scanner to signal the end of its input. */
- public static final int EOF = 0;
-
- /* Tokens. */
- /** Token number,to be returned by the scanner. */
- static final int DATASET_ = 258;
- /** Token number,to be returned by the scanner. */
- static final int _DATASET = 259;
- /** Token number,to be returned by the scanner. */
- static final int GROUP_ = 260;
- /** Token number,to be returned by the scanner. */
- static final int _GROUP = 261;
- /** Token number,to be returned by the scanner. */
- static final int ENUMERATION_ = 262;
- /** Token number,to be returned by the scanner. */
- static final int _ENUMERATION = 263;
- /** Token number,to be returned by the scanner. */
- static final int ENUMCONST_ = 264;
- /** Token number,to be returned by the scanner. */
- static final int _ENUMCONST = 265;
- /** Token number,to be returned by the scanner. */
- static final int NAMESPACE_ = 266;
- /** Token number,to be returned by the scanner. */
- static final int _NAMESPACE = 267;
- /** Token number,to be returned by the scanner. */
- static final int DIMENSION_ = 268;
- /** Token number,to be returned by the scanner. */
- static final int _DIMENSION = 269;
- /** Token number,to be returned by the scanner. */
- static final int DIM_ = 270;
- /** Token number,to be returned by the scanner. */
- static final int _DIM = 271;
- /** Token number,to be returned by the scanner. */
- static final int ENUM_ = 272;
- /** Token number,to be returned by the scanner. */
- static final int _ENUM = 273;
- /** Token number,to be returned by the scanner. */
- static final int MAP_ = 274;
- /** Token number,to be returned by the scanner. */
- static final int _MAP = 275;
- /** Token number,to be returned by the scanner. */
- static final int STRUCTURE_ = 276;
- /** Token number,to be returned by the scanner. */
- static final int _STRUCTURE = 277;
- /** Token number,to be returned by the scanner. */
- static final int SEQUENCE_ = 278;
- /** Token number,to be returned by the scanner. */
- static final int _SEQUENCE = 279;
- /** Token number,to be returned by the scanner. */
- static final int VALUE_ = 280;
- /** Token number,to be returned by the scanner. */
- static final int _VALUE = 281;
- /** Token number,to be returned by the scanner. */
- static final int ATTRIBUTE_ = 282;
- /** Token number,to be returned by the scanner. */
- static final int _ATTRIBUTE = 283;
- /** Token number,to be returned by the scanner. */
- static final int OTHERXML_ = 284;
- /** Token number,to be returned by the scanner. */
- static final int _OTHERXML = 285;
- /** Token number,to be returned by the scanner. */
- static final int ERROR_ = 286;
- /** Token number,to be returned by the scanner. */
- static final int _ERROR = 287;
- /** Token number,to be returned by the scanner. */
- static final int MESSAGE_ = 288;
- /** Token number,to be returned by the scanner. */
- static final int _MESSAGE = 289;
- /** Token number,to be returned by the scanner. */
- static final int CONTEXT_ = 290;
- /** Token number,to be returned by the scanner. */
- static final int _CONTEXT = 291;
- /** Token number,to be returned by the scanner. */
- static final int OTHERINFO_ = 292;
- /** Token number,to be returned by the scanner. */
- static final int _OTHERINFO = 293;
- /** Token number,to be returned by the scanner. */
- static final int CHAR_ = 294;
- /** Token number,to be returned by the scanner. */
- static final int _CHAR = 295;
- /** Token number,to be returned by the scanner. */
- static final int BYTE_ = 296;
- /** Token number,to be returned by the scanner. */
- static final int _BYTE = 297;
- /** Token number,to be returned by the scanner. */
- static final int INT8_ = 298;
- /** Token number,to be returned by the scanner. */
- static final int _INT8 = 299;
- /** Token number,to be returned by the scanner. */
- static final int UINT8_ = 300;
- /** Token number,to be returned by the scanner. */
- static final int _UINT8 = 301;
- /** Token number,to be returned by the scanner. */
- static final int INT16_ = 302;
- /** Token number,to be returned by the scanner. */
- static final int _INT16 = 303;
- /** Token number,to be returned by the scanner. */
- static final int UINT16_ = 304;
- /** Token number,to be returned by the scanner. */
- static final int _UINT16 = 305;
- /** Token number,to be returned by the scanner. */
- static final int INT32_ = 306;
- /** Token number,to be returned by the scanner. */
- static final int _INT32 = 307;
- /** Token number,to be returned by the scanner. */
- static final int UINT32_ = 308;
- /** Token number,to be returned by the scanner. */
- static final int _UINT32 = 309;
- /** Token number,to be returned by the scanner. */
- static final int INT64_ = 310;
- /** Token number,to be returned by the scanner. */
- static final int _INT64 = 311;
- /** Token number,to be returned by the scanner. */
- static final int UINT64_ = 312;
- /** Token number,to be returned by the scanner. */
- static final int _UINT64 = 313;
- /** Token number,to be returned by the scanner. */
- static final int FLOAT32_ = 314;
- /** Token number,to be returned by the scanner. */
- static final int _FLOAT32 = 315;
- /** Token number,to be returned by the scanner. */
- static final int FLOAT64_ = 316;
- /** Token number,to be returned by the scanner. */
- static final int _FLOAT64 = 317;
- /** Token number,to be returned by the scanner. */
- static final int STRING_ = 318;
- /** Token number,to be returned by the scanner. */
- static final int _STRING = 319;
- /** Token number,to be returned by the scanner. */
- static final int URL_ = 320;
- /** Token number,to be returned by the scanner. */
- static final int _URL = 321;
- /** Token number,to be returned by the scanner. */
- static final int OPAQUE_ = 322;
- /** Token number,to be returned by the scanner. */
- static final int _OPAQUE = 323;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_BASE = 324;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_BASETYPE = 325;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_DAPVERSION = 326;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_DMRVERSION = 327;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_ENUM = 328;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_HREF = 329;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_NAME = 330;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_NAMESPACE = 331;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_NS = 332;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_SIZE = 333;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_TYPE = 334;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_VALUE = 335;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_HTTPCODE = 336;
- /** Token number,to be returned by the scanner. */
- static final int ATTR_SPECIAL = 337;
- /** Token number,to be returned by the scanner. */
- static final int TEXT = 338;
- /** Token number,to be returned by the scanner. */
- static final int UNKNOWN_ATTR = 339;
- /** Token number,to be returned by the scanner. */
- static final int UNKNOWN_ELEMENT_ = 340;
- /** Token number,to be returned by the scanner. */
- static final int _UNKNOWN_ELEMENT = 341;
-
-
-
- /**
- * Method to retrieve the semantic value of the last scanned token.
- *
- * @return the semantic value of the last scanned token.
- */
- Object getLVal();
-
- /**
- * Entry point for the scanner. Returns the token identifier corresponding
- * to the next token and prepares to return the semantic value
- * of the token.
- *
- * @return the token identifier corresponding to the next token.
- */
- int yylex() throws DapException;
-
- /**
- * Entry point for error reporting. Emits an error
- * in a user-defined way.
- *
- *
- * @param msg The string for the error message.
- */
- void yyerror(String msg);
- }
-
- private class YYLexer implements Lexer {
- /* "%code lexer" blocks. */
- /* "dap4.y":22 */ /* lalr1.java:236 */
-
- public Object getLVal() {
- return null;
- }
-
- public int yylex() {
- return 0;
- }
-
- public Bison.Position getStartPos() {
- return null;
- }
-
- public Bison.Position getEndPos() {
- return null;
- }
-
- public void yyerror(String s) {
- System.err.println(s);
- System.err.printf("near %s%n", getLocator());
- }
-
-
- /* "Dap4BisonParser.java":304 */ /* lalr1.java:236 */
-
- }
-
- /**
- * The object doing lexical analysis for us.
- */
- private Lexer yylexer;
-
-
-
- /**
- * Instantiates the Bison-generated parser.
- */
- public Dap4BisonParser() {
-
- this.yylexer = new YYLexer();
-
- }
-
-
- /**
- * Instantiates the Bison-generated parser.
- *
- * @param yylexer The scanner that will supply tokens to the parser.
- */
- protected Dap4BisonParser(Lexer yylexer) {
-
- this.yylexer = yylexer;
-
- }
-
- private java.io.PrintStream yyDebugStream = System.err;
-
- /**
- * Return the PrintStream on which the debugging output is
- * printed.
- */
- public final java.io.PrintStream getDebugStream() {
- return yyDebugStream;
- }
-
- /**
- * Set the PrintStream on which the debug output is printed.
- *
- * @param s The stream that is used for debugging output.
- */
- public final void setDebugStream(java.io.PrintStream s) {
- yyDebugStream = s;
- }
-
- private int yydebug = 0;
-
- /**
- * Answer the verbosity of the debugging output; 0 means that all kinds of
- * output from the parser are suppressed.
- */
- public final int getDebugLevel() {
- return yydebug;
- }
-
- /**
- * Set the verbosity of the debugging output; 0 means that all kinds of
- * output from the parser are suppressed.
- *
- * @param level The verbosity level for debugging output.
- */
- public final void setDebugLevel(int level) {
- yydebug = level;
- }
-
- /**
- * Print an error message via the lexer.
- *
- * @param msg The error message.
- */
- public final void yyerror(String msg) {
- yylexer.yyerror(msg);
- }
-
-
- protected final void yycdebug(String s) {
- if (yydebug > 0)
- yyDebugStream.println(s);
- }
-
- private final class YYStack {
- private int[] stateStack = new int[16];
-
- private Object[] valueStack = new Object[16];
-
- public int size = 16;
- public int height = -1;
-
- public final void push(int state, Object value) {
- height++;
- if (size == height) {
- int[] newStateStack = new int[size * 2];
- System.arraycopy(stateStack, 0, newStateStack, 0, height);
- stateStack = newStateStack;
-
-
- Object[] newValueStack = new Object[size * 2];
- System.arraycopy(valueStack, 0, newValueStack, 0, height);
- valueStack = newValueStack;
-
- size *= 2;
- }
-
- stateStack[height] = state;
-
- valueStack[height] = value;
- }
-
- public final void pop() {
- pop(1);
- }
-
- public final void pop(int num) {
- // Avoid memory leaks... garbage collection is a white lie!
- if (num > 0) {
- java.util.Arrays.fill(valueStack, height - num + 1, height + 1, null);
-
- }
- height -= num;
- }
-
- public final int stateAt(int i) {
- return stateStack[height - i];
- }
-
- public final Object valueAt(int i) {
- return valueStack[height - i];
- }
-
- // Print the state stack on the debug stream.
- public void print(java.io.PrintStream out) {
- out.print("Stack now");
-
- for (int i = 0; i <= height; i++) {
- out.print(' ');
- out.print(stateStack[i]);
- }
- out.println();
- }
- }
-
- /**
- * Returned by a Bison action in order to stop the parsing process and
- * return success (true).
- */
- public static final int YYACCEPT = 0;
-
- /**
- * Returned by a Bison action in order to stop the parsing process and
- * return failure (false).
- */
- public static final int YYABORT = 1;
-
-
- /**
- * Returned by a Bison action in order to request a new token.
- */
- public static final int YYPUSH_MORE = 4;
-
- /**
- * Returned by a Bison action in order to start error recovery without
- * printing an error message.
- */
- public static final int YYERROR = 2;
-
- /**
- * Internal return codes that are not supported for user semantic
- * actions.
- */
- private static final int YYERRLAB = 3;
- private static final int YYNEWSTATE = 4;
- private static final int YYDEFAULT = 5;
- private static final int YYREDUCE = 6;
- private static final int YYERRLAB1 = 7;
- private static final int YYRETURN = 8;
- private static final int YYGETTOKEN = 9; /* Signify that a new token is expected when doing push-parsing. */
-
- private int yyerrstatus_ = 0;
-
-
- /* Lookahead and lookahead in internal form. */
- int yychar = yyempty_;
- int yytoken = 0;
-
- /* State. */
- int yyn = 0;
- int yylen = 0;
- int yystate = 0;
- YYStack yystack = new YYStack();
- int label = YYNEWSTATE;
-
- /* Error handling. */
- int yynerrs_ = 0;
-
-
- /* Semantic value of the lookahead. */
- Object yylval = null;
-
- /**
- * Return whether error recovery is being done. In this state, the parser
- * reads token until it reaches a known state, and then restarts normal
- * operation.
- */
- public final boolean recovering() {
- return yyerrstatus_ == 0;
- }
-
- /**
- * Compute post-reduction state.
- *
- * @param yystate the current state
- * @param yysym the nonterminal to push on the stack
- */
- private int yy_lr_goto_state_(int yystate, int yysym) {
- int yyr = yypgoto_[yysym - yyntokens_] + yystate;
- if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
- return yytable_[yyr];
- else
- return yydefgoto_[yysym - yyntokens_];
- }
-
- private int yyaction(int yyn, YYStack yystack, int yylen) throws DapException {
- Object yyval;
-
-
- /*
- * If YYLEN is nonzero, implement the default value of the action:
- * '$$ = $1'. Otherwise, use the top of the stack.
- *
- * Otherwise, the following line sets YYVAL to garbage.
- * This behavior is undocumented and Bison
- * users should not rely upon it.
- */
- if (yylen > 0)
- yyval = yystack.valueAt(yylen - 1);
- else
- yyval = yystack.valueAt(0);
-
- yy_reduce_print(yyn, yystack);
-
- switch (yyn) {
- case 4:
- if (yyn == 4)
- /* "dap4.y":106 */ /* lalr1.java:489 */
- {
- leavedataset();
- } ;
- break;
-
-
- case 5:
- if (yyn == 5)
- /* "dap4.y":112 */ /* lalr1.java:489 */
- {
- enterdataset(((XMLAttributeMap) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 6:
- if (yyn == 6)
- /* "dap4.y":119 */ /* lalr1.java:489 */
- {
- leavegroup();
- } ;
- break;
-
-
- case 7:
- if (yyn == 7)
- /* "dap4.y":125 */ /* lalr1.java:489 */
- {
- entergroup(((XMLAttributeMap) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 14:
- if (yyn == 14)
- /* "dap4.y":147 */ /* lalr1.java:489 */
- {
- leaveenumdef();
- } ;
- break;
-
-
- case 15:
- if (yyn == 15)
- /* "dap4.y":153 */ /* lalr1.java:489 */
- {
- enterenumdef(((XMLAttributeMap) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 18:
- if (yyn == 18)
- /* "dap4.y":163 */ /* lalr1.java:489 */
- {
- enumconst(((SaxEvent) (yystack.valueAt(4 - (2)))), ((SaxEvent) (yystack.valueAt(4 - (3)))));
- } ;
- break;
-
-
- case 19:
- if (yyn == 19)
- /* "dap4.y":165 */ /* lalr1.java:489 */
- {
- enumconst(((SaxEvent) (yystack.valueAt(4 - (3)))), ((SaxEvent) (yystack.valueAt(4 - (2)))));
- } ;
- break;
-
-
- case 20:
- if (yyn == 20)
- /* "dap4.y":172 */ /* lalr1.java:489 */
- {
- leavedimdef();
- } ;
- break;
-
-
- case 21:
- if (yyn == 21)
- /* "dap4.y":178 */ /* lalr1.java:489 */
- {
- enterdimdef(((XMLAttributeMap) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 22:
- if (yyn == 22)
- /* "dap4.y":183 */ /* lalr1.java:489 */
- {
- dimref(((SaxEvent) (yystack.valueAt(3 - (2)))));
- } ;
- break;
-
-
- case 23:
- if (yyn == 23)
- /* "dap4.y":185 */ /* lalr1.java:489 */
- {
- dimref(((SaxEvent) (yystack.valueAt(3 - (2)))));
- } ;
- break;
-
-
- case 28:
- if (yyn == 28)
- /* "dap4.y":200 */ /* lalr1.java:489 */
- {
- leaveatomicvariable(((SaxEvent) (yystack.valueAt(3 - (3)))));
- } ;
- break;
-
-
- case 29:
- if (yyn == 29)
- /* "dap4.y":207 */ /* lalr1.java:489 */
- {
- enteratomicvariable(((SaxEvent) (yystack.valueAt(2 - (1)))), ((XMLAttributeMap) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 30:
- if (yyn == 30)
- /* "dap4.y":214 */ /* lalr1.java:489 */
- {
- leaveenumvariable(((SaxEvent) (yystack.valueAt(3 - (3)))));
- } ;
- break;
-
-
- case 31:
- if (yyn == 31)
- /* "dap4.y":221 */ /* lalr1.java:489 */
- {
- enterenumvariable(((XMLAttributeMap) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 32:
- if (yyn == 32)
- /* "dap4.y":226 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 33:
- if (yyn == 33)
- /* "dap4.y":227 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 34:
- if (yyn == 34)
- /* "dap4.y":228 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 35:
- if (yyn == 35)
- /* "dap4.y":229 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 36:
- if (yyn == 36)
- /* "dap4.y":230 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 37:
- if (yyn == 37)
- /* "dap4.y":231 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 38:
- if (yyn == 38)
- /* "dap4.y":232 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 39:
- if (yyn == 39)
- /* "dap4.y":233 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 40:
- if (yyn == 40)
- /* "dap4.y":234 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 41:
- if (yyn == 41)
- /* "dap4.y":235 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 42:
- if (yyn == 42)
- /* "dap4.y":236 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 43:
- if (yyn == 43)
- /* "dap4.y":237 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 44:
- if (yyn == 44)
- /* "dap4.y":238 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 45:
- if (yyn == 45)
- /* "dap4.y":239 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 46:
- if (yyn == 46)
- /* "dap4.y":240 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 47:
- if (yyn == 47)
- /* "dap4.y":244 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 48:
- if (yyn == 48)
- /* "dap4.y":245 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 49:
- if (yyn == 49)
- /* "dap4.y":246 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 50:
- if (yyn == 50)
- /* "dap4.y":247 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 51:
- if (yyn == 51)
- /* "dap4.y":248 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 52:
- if (yyn == 52)
- /* "dap4.y":249 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 53:
- if (yyn == 53)
- /* "dap4.y":250 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 54:
- if (yyn == 54)
- /* "dap4.y":251 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 55:
- if (yyn == 55)
- /* "dap4.y":252 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 56:
- if (yyn == 56)
- /* "dap4.y":253 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 57:
- if (yyn == 57)
- /* "dap4.y":254 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 58:
- if (yyn == 58)
- /* "dap4.y":255 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 59:
- if (yyn == 59)
- /* "dap4.y":256 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 60:
- if (yyn == 60)
- /* "dap4.y":257 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 61:
- if (yyn == 61)
- /* "dap4.y":258 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 62:
- if (yyn == 62)
- /* "dap4.y":259 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 67:
- if (yyn == 67)
- /* "dap4.y":273 */ /* lalr1.java:489 */
- {
- leavemap();
- } ;
- break;
-
-
- case 68:
- if (yyn == 68)
- /* "dap4.y":279 */ /* lalr1.java:489 */
- {
- entermap(((SaxEvent) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 69:
- if (yyn == 69)
- /* "dap4.y":286 */ /* lalr1.java:489 */
- {
- leavestructurevariable(((SaxEvent) (yystack.valueAt(3 - (3)))));
- } ;
- break;
-
-
- case 70:
- if (yyn == 70)
- /* "dap4.y":292 */ /* lalr1.java:489 */
- {
- enterstructurevariable(((XMLAttributeMap) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 76:
- if (yyn == 76)
- /* "dap4.y":307 */ /* lalr1.java:489 */
- {
- leavesequencevariable(((SaxEvent) (yystack.valueAt(3 - (3)))));
- } ;
- break;
-
-
- case 77:
- if (yyn == 77)
- /* "dap4.y":313 */ /* lalr1.java:489 */
- {
- entersequencevariable(((XMLAttributeMap) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 89:
- if (yyn == 89)
- /* "dap4.y":345 */ /* lalr1.java:489 */
- {
- leaveatomicattribute();
- } ;
- break;
-
-
- case 90:
- if (yyn == 90)
- /* "dap4.y":349 */ /* lalr1.java:489 */
- {
- leaveatomicattribute();
- } ;
- break;
-
-
- case 91:
- if (yyn == 91)
- /* "dap4.y":356 */ /* lalr1.java:489 */
- {
- enteratomicattribute(((XMLAttributeMap) (yystack.valueAt(3 - (2)))),
- ((NamespaceList) (yystack.valueAt(3 - (3)))));
- } ;
- break;
-
-
- case 92:
- if (yyn == 92)
- /* "dap4.y":361 */ /* lalr1.java:489 */
- {
- yyval = namespace_list();
- } ;
- break;
-
-
- case 93:
- if (yyn == 93)
- /* "dap4.y":363 */ /* lalr1.java:489 */
- {
- yyval = namespace_list(((NamespaceList) (yystack.valueAt(2 - (1)))), ((SaxEvent) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 94:
- if (yyn == 94)
- /* "dap4.y":370 */ /* lalr1.java:489 */
- {
- yyval = (((SaxEvent) (yystack.valueAt(3 - (2)))));
- } ;
- break;
-
-
- case 95:
- if (yyn == 95)
- /* "dap4.y":377 */ /* lalr1.java:489 */
- {
- leavecontainerattribute();
- } ;
- break;
-
-
- case 96:
- if (yyn == 96)
- /* "dap4.y":384 */ /* lalr1.java:489 */
- {
- entercontainerattribute(((XMLAttributeMap) (yystack.valueAt(3 - (2)))),
- ((NamespaceList) (yystack.valueAt(3 - (3)))));
- } ;
- break;
-
-
- case 101:
- if (yyn == 101)
- /* "dap4.y":401 */ /* lalr1.java:489 */
- {
- value(((String) (yystack.valueAt(3 - (2)))));
- } ;
- break;
-
-
- case 102:
- if (yyn == 102)
- /* "dap4.y":403 */ /* lalr1.java:489 */
- {
- value(((SaxEvent) (yystack.valueAt(3 - (2)))));
- } ;
- break;
-
-
- case 103:
- if (yyn == 103)
- /* "dap4.y":411 */ /* lalr1.java:489 */
- {
- otherxml(((XMLAttributeMap) (yystack.valueAt(4 - (2)))), ((DapXML) (yystack.valueAt(4 - (3)))));
- } ;
- break;
-
-
- case 104:
- if (yyn == 104)
- /* "dap4.y":415 */ /* lalr1.java:489 */
- {
- yyval = xml_body(null, ((DapXML) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 105:
- if (yyn == 105)
- /* "dap4.y":416 */ /* lalr1.java:489 */
- {
- yyval = xml_body(((DapXML.XMLList) (yystack.valueAt(2 - (1)))), ((DapXML) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 106:
- if (yyn == 106)
- /* "dap4.y":424 */ /* lalr1.java:489 */
- {
- yyval =
- element_or_text(((SaxEvent) (yystack.valueAt(4 - (1)))), ((XMLAttributeMap) (yystack.valueAt(4 - (2)))),
- ((DapXML.XMLList) (yystack.valueAt(4 - (3)))), ((SaxEvent) (yystack.valueAt(4 - (4)))));
- } ;
- break;
-
-
- case 107:
- if (yyn == 107)
- /* "dap4.y":426 */ /* lalr1.java:489 */
- {
- yyval = xmltext(((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 108:
- if (yyn == 108)
- /* "dap4.y":434 */ /* lalr1.java:489 */
- {
- yyval = xml_attribute_map();
- } ;
- break;
-
-
- case 109:
- if (yyn == 109)
- /* "dap4.y":436 */ /* lalr1.java:489 */
- {
- yyval = xml_attribute_map(((XMLAttributeMap) (yystack.valueAt(2 - (1)))),
- ((SaxEvent) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 184:
- if (yyn == 184)
- /* "dap4.y":530 */ /* lalr1.java:489 */
- {
- leaveerror();
- } ;
- break;
-
-
- case 185:
- if (yyn == 185)
- /* "dap4.y":537 */ /* lalr1.java:489 */
- {
- entererror(((XMLAttributeMap) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
- case 188:
- if (yyn == 188)
- /* "dap4.y":547 */ /* lalr1.java:489 */
- {
- errormessage(((String) (yystack.valueAt(3 - (2)))));
- } ;
- break;
-
-
- case 189:
- if (yyn == 189)
- /* "dap4.y":549 */ /* lalr1.java:489 */
- {
- errorcontext(((String) (yystack.valueAt(3 - (2)))));
- } ;
- break;
-
-
- case 190:
- if (yyn == 190)
- /* "dap4.y":551 */ /* lalr1.java:489 */
- {
- errorotherinfo(((String) (yystack.valueAt(3 - (2)))));
- } ;
- break;
-
-
- case 191:
- if (yyn == 191)
- /* "dap4.y":556 */ /* lalr1.java:489 */
- {
- yyval = textstring(null, ((SaxEvent) (yystack.valueAt(1 - (1)))));
- } ;
- break;
-
-
- case 192:
- if (yyn == 192)
- /* "dap4.y":558 */ /* lalr1.java:489 */
- {
- yyval = textstring(((String) (yystack.valueAt(2 - (1)))), ((SaxEvent) (yystack.valueAt(2 - (2)))));
- } ;
- break;
-
-
-
- /* "Dap4BisonParser.java":1087 */ /* lalr1.java:489 */
- default:
- break;
- }
-
- yy_symbol_print("-> $$ =", yyr1_[yyn], yyval);
-
- yystack.pop(yylen);
- yylen = 0;
-
- /* Shift the result of the reduction. */
- int yystate = yy_lr_goto_state_(yystack.stateAt(0), yyr1_[yyn]);
- yystack.push(yystate, yyval);
- return YYNEWSTATE;
- }
-
-
- /*
- * Return YYSTR after stripping away unnecessary quotes and
- * backslashes, so that it's suitable for yyerror. The heuristic is
- * that double-quoting is unnecessary unless the string contains an
- * apostrophe, a comma, or backslash (other than backslash-backslash).
- * YYSTR is taken from yytname.
- */
- private final String yytnamerr_(String yystr) {
- if (yystr.charAt(0) == '"') {
- StringBuffer yyr = new StringBuffer();
- strip_quotes: for (int i = 1; i < yystr.length(); i++)
- switch (yystr.charAt(i)) {
- case '\'':
- case ',':
- break strip_quotes;
-
- case '\\':
- if (yystr.charAt(++i) != '\\')
- break strip_quotes;
- /* Fall through. */
- default:
- yyr.append(yystr.charAt(i));
- break;
-
- case '"':
- return yyr.toString();
- }
- } else if (yystr.equals("$end"))
- return "end of input";
-
- return yystr;
- }
-
-
- /*--------------------------------.
- | Print this symbol on YYOUTPUT. |
- `--------------------------------*/
-
- private void yy_symbol_print(String s, int yytype, Object yyvaluep) {
- if (yydebug > 0)
- yycdebug(s + (yytype < yyntokens_ ? " token " : " nterm ") + yytname_[yytype] + " ("
- + (yyvaluep == null ? "(null)" : yyvaluep.toString()) + ")");
- }
-
-
-
- /**
- * Push Parse input from external lexer
- *
- * @param yylextoken current token
- * @param yylexval current lval
- *
- *
- * @return YYACCEPT, YYABORT, YYPUSH_MORE
- */
- public int push_parse(int yylextoken, Object yylexval) throws DapException, DapException {
-
-
-
- if (!this.push_parse_initialized) {
- push_parse_initialize();
-
- yycdebug("Starting parse\n");
- yyerrstatus_ = 0;
- } else
- label = YYGETTOKEN;
-
- boolean push_token_consumed = true;
-
- for (;;)
- switch (label) {
- /*
- * New state. Unlike in the C/C++ skeletons, the state is already
- * pushed when we come here.
- */
- case YYNEWSTATE:
- yycdebug("Entering state " + yystate + "\n");
- if (yydebug > 0)
- yystack.print(yyDebugStream);
-
- /* Accept? */
- if (yystate == yyfinal_) {
- label = YYACCEPT;
- break;
- }
-
- /* Take a decision. First try without lookahead. */
- yyn = yypact_[yystate];
- if (yy_pact_value_is_default_(yyn)) {
- label = YYDEFAULT;
- break;
- }
- /* Fall Through */
-
- case YYGETTOKEN:
- /* Read a lookahead token. */
- if (yychar == yyempty_) {
-
- if (!push_token_consumed)
- return YYPUSH_MORE;
- yycdebug("Reading a token: ");
- yychar = yylextoken;
- yylval = yylexval;
- push_token_consumed = false;
-
- }
-
- /* Convert token to internal form. */
- if (yychar <= Lexer.EOF) {
- yychar = yytoken = Lexer.EOF;
- yycdebug("Now at end of input.\n");
- } else {
- yytoken = yytranslate_(yychar);
- yy_symbol_print("Next token is", yytoken, yylval);
- }
-
- /*
- * If the proper action on seeing token YYTOKEN is to reduce or to
- * detect an error, take that action.
- */
- yyn += yytoken;
- if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
- label = YYDEFAULT;
-
- /* <= 0 means reduce or error. */
- else if ((yyn = yytable_[yyn]) <= 0) {
- if (yy_table_value_is_error_(yyn))
- label = YYERRLAB;
- else {
- yyn = -yyn;
- label = YYREDUCE;
- }
- }
-
- else {
- /* Shift the lookahead token. */
- yy_symbol_print("Shifting", yytoken, yylval);
-
- /* Discard the token being shifted. */
- yychar = yyempty_;
-
- /*
- * Count tokens shifted since error; after three, turn off error
- * status.
- */
- if (yyerrstatus_ > 0)
- --yyerrstatus_;
-
- yystate = yyn;
- yystack.push(yystate, yylval);
- label = YYNEWSTATE;
- }
- break;
-
- /*-----------------------------------------------------------.
- | yydefault -- do the default action for the current state. |
- `-----------------------------------------------------------*/
- case YYDEFAULT:
- yyn = yydefact_[yystate];
- if (yyn == 0)
- label = YYERRLAB;
- else
- label = YYREDUCE;
- break;
-
- /*-----------------------------.
- | yyreduce -- Do a reduction. |
- `-----------------------------*/
- case YYREDUCE:
- yylen = yyr2_[yyn];
- label = yyaction(yyn, yystack, yylen);
- yystate = yystack.stateAt(0);
- break;
-
- /*------------------------------------.
- | yyerrlab -- here on detecting error |
- `------------------------------------*/
- case YYERRLAB:
- /* If not already recovering from an error, report this error. */
- if (yyerrstatus_ == 0) {
- ++yynerrs_;
- if (yychar == yyempty_)
- yytoken = yyempty_;
- yyerror(yysyntax_error(yystate, yytoken));
- }
-
-
- if (yyerrstatus_ == 3) {
- /*
- * If just tried and failed to reuse lookahead token after an
- * error, discard it.
- */
-
- if (yychar <= Lexer.EOF) {
- /* Return failure if at end of input. */
- if (yychar == Lexer.EOF) {
- label = YYABORT;
- break;
- }
- } else
- yychar = yyempty_;
- }
-
- /*
- * Else will try to reuse lookahead token after shifting the error
- * token.
- */
- label = YYERRLAB1;
- break;
-
- /*-------------------------------------------------.
- | errorlab -- error raised explicitly by YYERROR. |
- `-------------------------------------------------*/
- case YYERROR:
-
-
- /*
- * Do not reclaim the symbols of the rule which action triggered
- * this YYERROR.
- */
- yystack.pop(yylen);
- yylen = 0;
- yystate = yystack.stateAt(0);
- label = YYERRLAB1;
- break;
-
- /*-------------------------------------------------------------.
- | yyerrlab1 -- common code for both syntax error and YYERROR. |
- `-------------------------------------------------------------*/
- case YYERRLAB1:
- yyerrstatus_ = 3; /* Each real token shifted decrements this. */
-
- for (;;) {
- yyn = yypact_[yystate];
- if (!yy_pact_value_is_default_(yyn)) {
- yyn += yyterror_;
- if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) {
- yyn = yytable_[yyn];
- if (0 < yyn)
- break;
- }
- }
-
- /*
- * Pop the current state because it cannot handle the
- * error token.
- */
- if (yystack.height == 0) {
- label = YYABORT;
- break;
- }
-
-
- yystack.pop();
- yystate = yystack.stateAt(0);
- if (yydebug > 0)
- yystack.print(yyDebugStream);
- }
-
- if (label == YYABORT)
- /* Leave the switch. */
- break;
-
-
-
- /* Shift the error token. */
- yy_symbol_print("Shifting", yystos_[yyn], yylval);
-
- yystate = yyn;
- yystack.push(yyn, yylval);
- label = YYNEWSTATE;
- break;
-
- /* Accept. */
- case YYACCEPT:
- this.push_parse_initialized = false;
- return YYACCEPT;
-
- /* Abort. */
- case YYABORT:
- this.push_parse_initialized = false;
- return YYABORT;
- }
- }
-
- boolean push_parse_initialized = false;
-
- /**
- * (Re-)Initialize the state of the push parser.
- */
- public void push_parse_initialize() {
- /* Lookahead and lookahead in internal form. */
- this.yychar = yyempty_;
- this.yytoken = 0;
-
- /* State. */
- this.yyn = 0;
- this.yylen = 0;
- this.yystate = 0;
- this.yystack = new YYStack();
- this.label = YYNEWSTATE;
-
- /* Error handling. */
- this.yynerrs_ = 0;
-
-
- /* Semantic value of the lookahead. */
- this.yylval = null;
-
- yystack.push(this.yystate, this.yylval);
-
- this.push_parse_initialized = true;
-
- }
-
-
-
- // Generate an error message.
- private String yysyntax_error(int yystate, int tok) {
- if (yyErrorVerbose) {
- /*
- * There are many possibilities here to consider:
- * - If this state is a consistent state with a default action,
- * then the only way this function was invoked is if the
- * default action is an error action. In that case, don't
- * check for expected tokens because there are none.
- * - The only way there can be no lookahead present (in tok) is
- * if this state is a consistent state with a default action.
- * Thus, detecting the absence of a lookahead is sufficient to
- * determine that there is no unexpected or expected token to
- * report. In that case, just report a simple "syntax error".
- * - Don't assume there isn't a lookahead just because this
- * state is a consistent state with a default action. There
- * might have been a previous inconsistent state, consistent
- * state with a non-default action, or user semantic action
- * that manipulated yychar. (However, yychar is currently out
- * of scope during semantic actions.)
- * - Of course, the expected token list depends on states to
- * have correct lookahead information, and it depends on the
- * parser not to perform extra reductions after fetching a
- * lookahead from the scanner and before detecting a syntax
- * error. Thus, state merging (from LALR or IELR) and default
- * reductions corrupt the expected token list. However, the
- * list is correct for canonical LR with one exception: it
- * will still contain any token that will not be accepted due
- * to an error action in a later state.
- */
- if (tok != yyempty_) {
- /*
- * FIXME: This method of building the message is not compatible
- * with internationalization.
- */
- StringBuffer res = new StringBuffer("syntax error, unexpected ");
- res.append(yytnamerr_(yytname_[tok]));
- int yyn = yypact_[yystate];
- if (!yy_pact_value_is_default_(yyn)) {
- /*
- * Start YYX at -YYN if negative to avoid negative
- * indexes in YYCHECK. In other words, skip the first
- * -YYN actions for this state because they are default
- * actions.
- */
- int yyxbegin = yyn < 0 ? -yyn : 0;
- /* Stay within bounds of both yycheck and yytname. */
- int yychecklim = yylast_ - yyn + 1;
- int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
- int count = 0;
- for (int x = yyxbegin; x < yyxend; ++x)
- if (yycheck_[x + yyn] == x && x != yyterror_ && !yy_table_value_is_error_(yytable_[x + yyn]))
- ++count;
- if (count < 5) {
- count = 0;
- for (int x = yyxbegin; x < yyxend; ++x)
- if (yycheck_[x + yyn] == x && x != yyterror_ && !yy_table_value_is_error_(yytable_[x + yyn])) {
- res.append(count++ == 0 ? ", expecting " : " or ");
- res.append(yytnamerr_(yytname_[x]));
- }
- }
- }
- return res.toString();
- }
- }
-
- return "syntax error";
- }
-
- /**
- * Whether the given yypact_ value indicates a defaulted state.
- *
- * @param yyvalue the value to check
- */
- private static boolean yy_pact_value_is_default_(int yyvalue) {
- return yyvalue == yypact_ninf_;
- }
-
- /**
- * Whether the given yytable_
- * value indicates a syntax error.
- *
- * @param yyvalue the value to check
- */
- private static boolean yy_table_value_is_error_(int yyvalue) {
- return yyvalue == yytable_ninf_;
- }
-
- private static final short yypact_ninf_ = -186;
- private static final short yytable_ninf_ = -97;
-
- /*
- * YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
- * STATE-NUM.
- */
- private static final short yypact_[] = yypact_init();
-
- private static final short[] yypact_init() {
- return new short[] {5, -186, -186, 12, -186, -186, -186, -186, 315, 315, -186, 36, 41, -186, -186, -186, -186, -186,
- -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186,
- -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186,
- -186, 29, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, 14, -186,
- -10, -186, -186, -38, -38, -38, -186, 315, 315, 315, 315, 315, 315, 315, 43, 204, -62, 129, -186, -5, 255, 217,
- 315, 271, 316, -36, -186, 104, -186, -186, 107, -186, -14, -32, -12, 197, -186, -186, -186, -186, -186, -186,
- -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186,
- -186, -186, -186, -186, -186, -186, -186, 25, -186, -186, 0, 30, -186, -186, -186, -186, 55, -186, 32, -186,
- -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186,
- -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, 83, -16, -186, -186, -186, -186, -186,
- -186, -186, -186, 50, -186, -186, 43, 121, 164, 159, 190, -186, -4, -186, -186, 195, 137, -186, -186, -186,
- -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186,
- -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186, -186};
- }
-
- /*
- * YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
- * Performed when YYTABLE does not specify something else to do. Zero
- * means the default is an error.
- */
- private static final short yydefact_[] = yydefact_init();
-
- private static final short[] yydefact_init() {
- return new short[] {0, 108, 108, 0, 2, 8, 3, 186, 5, 185, 1, 0, 0, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
- 120, 121, 122, 123, 109, 4, 108, 108, 108, 108, 108, 108, 108, 108, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
- 43, 44, 45, 46, 13, 8, 10, 0, 9, 83, 11, 24, 63, 25, 63, 108, 26, 71, 27, 78, 12, 85, 86, 0, 87, 0, 88, 184, 0,
- 0, 0, 187, 7, 15, 21, 31, 70, 77, 92, 0, 0, 0, 0, 16, 0, 0, 0, 29, 0, 0, 0, 90, 0, 99, 97, 0, 191, 0, 0, 0, 91,
- 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
- 146, 147, 148, 149, 150, 151, 152, 107, 153, 0, 108, 6, 0, 0, 14, 17, 20, 84, 0, 62, 0, 47, 48, 49, 50, 51, 52,
- 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 28, 65, 83, 66, 30, 69, 72, 73, 74, 75, 76, 79, 80, 81, 82, 0, 0, 89,
- 100, 95, 98, 188, 192, 189, 190, 0, 93, 103, 0, 0, 0, 0, 0, 68, 0, 102, 101, 0, 0, 104, 18, 19, 22, 23, 67, 94,
- 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 180, 181, 182, 183, 105, 106};
- }
-
- /* YYPGOTO[NTERM-NUM]. */
- private static final short yypgoto_[] = yypgoto_init();
-
- private static final short[] yypgoto_init() {
- return new short[] {-186, -186, -186, -186, -186, -186, 160, -186, -186, -186, 122, -186, -186, 72, 74, -186, -186,
- -186, -186, -186, -186, 152, 76, -186, -186, -186, -186, -186, -186, -186, 45, -91, -66, -186, -186, -186, -186,
- -186, -186, -186, -186, 116, -186, -186, -185, -2, -186, -186, -186, -186, -186, -186, -186, -63};
- }
-
- /* YYDEFGOTO[NTERM-NUM]. */
- private static final short yydefgoto_[] = yydefgoto_init();
-
- private static final short[] yydefgoto_init() {
- return new short[] {-1, 3, 4, 5, 52, 53, 11, 54, 55, 90, 91, 56, 57, 167, 58, 59, 60, 61, 62, 63, 168, 93, 169, 170,
- 64, 65, 96, 66, 67, 97, 92, 68, 69, 70, 71, 108, 194, 72, 73, 103, 100, 101, 74, 206, 140, 8, 27, 141, 245, 6,
- 7, 12, 79, 105};
- }
-
- /*
- * YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
- * positive, shift that token. If negative, reduce the rule whose
- * number is the opposite. If YYTABLE_NINF, syntax error.
- */
- private static final short yytable_[] = yytable_init();
-
- private static final short[] yytable_init() {
- return new short[] {9, 148, 171, 171, 191, 177, 182, 102, 1, 147, 204, 207, 10, 143, 106, 107, 212, 35, 144, 36,
- 189, 244, 35, 35, 36, 36, 192, 80, 81, 82, 83, 84, 85, 86, 87, 184, 2, 188, 89, 98, 28, 29, 99, 30, 183, 104,
- 109, 104, 110, 31, 111, 190, 112, 32, 113, 195, 114, 33, 115, 34, 116, 95, 117, 35, 118, 36, 119, 190, 120, 190,
- 121, 190, 122, 75, 76, 37, 77, 38, 78, 39, 197, 40, 123, 41, 124, 42, 125, 43, 126, 44, 127, 45, 128, 46, 129,
- 47, 130, 48, 131, 49, 132, 50, 133, 51, 134, 198, 135, 201, 136, 203, 137, 148, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 205, 25, 138, 26, 139, 98, 199, 208, 185, 200, 35, 187, 36, 145, 89, 196, 109, 214, 110, 215,
- 111, 216, 112, 217, 113, 218, 114, 219, 115, 220, 116, 221, 117, 222, 118, 223, 119, 224, 120, 225, 121, 226,
- 122, 227, 174, 179, 175, 180, 176, 181, 209, 210, 123, 228, 124, 229, 125, 230, 126, 231, 127, 232, 128, 233,
- 129, 234, 130, 235, 131, 236, 132, 237, 133, 238, 134, 239, 135, 240, 136, 241, 137, 242, 211, 213, 193, 29,
- 142, 30, 146, 88, 94, 202, 186, 31, 0, 0, 138, 32, 139, 243, -96, 33, -96, 34, 0, 0, 0, 35, 149, 36, 0, 172,
- 151, 0, 0, 0, 0, 0, 0, 37, 35, 38, 36, 39, 0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47, 0, 48, 0, 49,
- 0, 50, 149, 51, 0, 150, 151, 0, 0, 0, 0, 0, 0, 0, 35, 0, 36, 0, 149, 0, 32, 0, 151, 0, 33, 173, 34, 152, 0, 153,
- 35, 154, 36, 155, 0, 156, 0, 157, 0, 158, 0, 159, 37, 160, 38, 161, 39, 162, 40, 163, 41, 164, 42, 165, 43, 166,
- 44, 0, 45, 0, 46, 0, 47, 149, 48, 32, 49, 151, 50, 33, 51, 34, 178, 0, 0, 35, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 37, 0, 38, 0, 39, 0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47, 0, 48, 0, 49, 0, 50, 0, 51, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 25, 0, 26};
- }
-
- private static final short yycheck_[] = yycheck_init();
-
- private static final short[] yycheck_init() {
- return new short[] {2, 92, 93, 94, 36, 96, 97, 73, 3, 14, 26, 196, 0, 75, 77, 78, 20, 27, 80, 29, 34, 206, 27, 27,
- 29, 29, 38, 29, 30, 31, 32, 33, 34, 35, 36, 98, 31, 103, 9, 25, 4, 5, 28, 7, 80, 83, 3, 83, 5, 13, 7, 83, 9, 17,
- 11, 30, 13, 21, 15, 23, 17, 63, 19, 27, 21, 29, 23, 83, 25, 83, 27, 83, 29, 32, 33, 39, 35, 41, 37, 43, 80, 45,
- 39, 47, 41, 49, 43, 51, 45, 53, 47, 55, 49, 57, 51, 59, 53, 61, 55, 63, 57, 65, 59, 67, 61, 75, 63, 75, 65, 26,
- 67, 202, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 74, 82, 83, 84, 85, 25, 75, 10, 28, 78, 27, 28, 29, 8,
- 9, 141, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
- 96, 97, 96, 97, 96, 97, 10, 16, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
- 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 16, 12, 11, 5, 6, 7, 90, 53, 62, 170, 100, 13, -1, -1, 83, 17, 85, 86,
- 27, 21, 29, 23, -1, -1, -1, 27, 15, 29, -1, 18, 19, -1, -1, -1, -1, -1, -1, 39, 27, 41, 29, 43, -1, 45, -1, 47,
- -1, 49, -1, 51, -1, 53, -1, 55, -1, 57, -1, 59, -1, 61, -1, 63, -1, 65, 15, 67, -1, 18, 19, -1, -1, -1, -1, -1,
- -1, -1, 27, -1, 29, -1, 15, -1, 17, -1, 19, -1, 21, 22, 23, 40, -1, 42, 27, 44, 29, 46, -1, 48, -1, 50, -1, 52,
- -1, 54, 39, 56, 41, 58, 43, 60, 45, 62, 47, 64, 49, 66, 51, 68, 53, -1, 55, -1, 57, -1, 59, 15, 61, 17, 63, 19,
- 65, 21, 67, 23, 24, -1, -1, 27, -1, 29, -1, -1, -1, -1, -1, -1, -1, -1, -1, 39, -1, 41, -1, 43, -1, 45, -1, 47,
- -1, 49, -1, 51, -1, 53, -1, 55, -1, 57, -1, 59, -1, 61, -1, 63, -1, 65, -1, 67, 69, 70, 71, 72, 73, 74, 75, 76,
- 77, 78, 79, 80, -1, 82, -1, 84};
- }
-
- /*
- * YYSTOS[STATE-NUM] -- The (internal number of the) accessing
- * symbol of state STATE-NUM.
- */
- private static final short yystos_[] = yystos_init();
-
- private static final short[] yystos_init() {
- return new short[] {0, 3, 31, 88, 89, 90, 136, 137, 132, 132, 0, 93, 138, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
- 79, 80, 82, 84, 133, 4, 5, 7, 13, 17, 21, 23, 27, 29, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65,
- 67, 91, 92, 94, 95, 98, 99, 101, 102, 103, 104, 105, 106, 111, 112, 114, 115, 118, 119, 120, 121, 124, 125, 129,
- 32, 33, 35, 37, 139, 132, 132, 132, 132, 132, 132, 132, 132, 93, 9, 96, 97, 117, 108, 108, 132, 113, 116, 25,
- 28, 127, 128, 119, 126, 83, 140, 140, 140, 122, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 39, 41, 43,
- 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 83, 85, 131, 134, 6, 75, 80, 8, 97, 14, 118, 15, 18, 19, 40, 42,
- 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 100, 107, 109, 110, 118, 18, 22, 100, 101, 109, 118, 24,
- 100, 101, 109, 118, 80, 140, 28, 128, 28, 119, 34, 83, 36, 38, 11, 123, 30, 132, 80, 75, 75, 78, 75, 117, 26,
- 26, 74, 130, 131, 10, 10, 16, 16, 20, 12, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 40, 42, 44, 46,
- 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 86, 131, 135};
- }
-
- /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
- private static final short yyr1_[] = yyr1_init();
-
- private static final short[] yyr1_init() {
- return new short[] {0, 87, 88, 88, 89, 90, 91, 92, 93, 93, 93, 93, 93, 93, 94, 95, 96, 96, 97, 97, 98, 99, 100, 100,
- 101, 101, 101, 101, 102, 103, 104, 105, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
- 106, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 108, 108, 108, 108, 109,
- 110, 111, 112, 113, 113, 113, 113, 113, 114, 115, 116, 116, 116, 116, 116, 117, 117, 118, 119, 119, 119, 120,
- 120, 121, 122, 122, 123, 124, 125, 126, 126, 127, 127, 128, 128, 129, 130, 130, 131, 131, 132, 132, 133, 133,
- 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
- 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 135, 135,
- 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
- 135, 135, 135, 135, 135, 135, 136, 137, 138, 138, 139, 139, 139, 140, 140};
- }
-
- /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
- private static final byte yyr2_[] = yyr2_init();
-
- private static final byte[] yyr2_init() {
- return new byte[] {0, 2, 1, 1, 3, 2, 3, 2, 0, 2, 2, 2, 2, 2, 3, 2, 1, 2, 4, 4, 3, 2, 3, 3, 1, 1, 1, 1, 3, 2, 3, 2,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 3, 2,
- 3, 2, 0, 2, 2, 2, 2, 3, 2, 0, 2, 2, 2, 2, 0, 2, 1, 1, 1, 1, 3, 2, 3, 0, 2, 3, 3, 3, 1, 2, 1, 2, 3, 3, 4, 1, 2,
- 4, 1, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 3, 2, 0, 2, 3, 3, 3, 1, 2};
- }
-
- /*
- * YYTOKEN_NUMBER[YYLEX-NUM] -- Internal symbol number corresponding
- * to YYLEX-NUM.
- */
- private static final short yytoken_number_[] = yytoken_number_init();
-
- private static final short[] yytoken_number_init() {
- return new short[] {0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273,
- 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295,
- 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317,
- 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339,
- 340, 341};
- }
-
- /*
- * YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- * First, the terminals, then, starting at \a yyntokens_, nonterminals.
- */
- private static final String yytname_[] = yytname_init();
-
- private static final String[] yytname_init() {
- return new String[] {"$end", "error", "$undefined", "DATASET_", "_DATASET", "GROUP_", "_GROUP", "ENUMERATION_",
- "_ENUMERATION", "ENUMCONST_", "_ENUMCONST", "NAMESPACE_", "_NAMESPACE", "DIMENSION_", "_DIMENSION", "DIM_",
- "_DIM", "ENUM_", "_ENUM", "MAP_", "_MAP", "STRUCTURE_", "_STRUCTURE", "SEQUENCE_", "_SEQUENCE", "VALUE_",
- "_VALUE", "ATTRIBUTE_", "_ATTRIBUTE", "OTHERXML_", "_OTHERXML", "ERROR_", "_ERROR", "MESSAGE_", "_MESSAGE",
- "CONTEXT_", "_CONTEXT", "OTHERINFO_", "_OTHERINFO", "CHAR_", "_CHAR", "BYTE_", "_BYTE", "INT8_", "_INT8",
- "UINT8_", "_UINT8", "INT16_", "_INT16", "UINT16_", "_UINT16", "INT32_", "_INT32", "UINT32_", "_UINT32",
- "INT64_", "_INT64", "UINT64_", "_UINT64", "FLOAT32_", "_FLOAT32", "FLOAT64_", "_FLOAT64", "STRING_", "_STRING",
- "URL_", "_URL", "OPAQUE_", "_OPAQUE", "ATTR_BASE", "ATTR_BASETYPE", "ATTR_DAPVERSION", "ATTR_DMRVERSION",
- "ATTR_ENUM", "ATTR_HREF", "ATTR_NAME", "ATTR_NAMESPACE", "ATTR_NS", "ATTR_SIZE", "ATTR_TYPE", "ATTR_VALUE",
- "ATTR_HTTPCODE", "ATTR_SPECIAL", "TEXT", "UNKNOWN_ATTR", "UNKNOWN_ELEMENT_", "_UNKNOWN_ELEMENT", "$accept",
- "response", "dataset", "datasetprefix", "group", "groupprefix", "groupbody", "enumdef", "enumdefprefix",
- "enumconst_list", "enumconst", "dimdef", "dimdefprefix", "dimref", "variable", "atomicvariable",
- "atomicvariableprefix", "enumvariable", "enumvariableprefix", "atomictype_", "_atomictype", "varbody", "mapref",
- "maprefprefix", "structurevariable", "structurevariableprefix", "structbody", "sequencevariable",
- "sequencevariableprefix", "sequencebody", "metadatalist", "metadata", "attribute", "atomicattribute",
- "atomicattributeprefix", "namespace_list", "namespace", "containerattribute", "containerattributeprefix",
- "attributelist", "valuelist", "value", "otherxml", "xml_body", "element_or_text", "xml_attribute_map",
- "xml_attribute", "xml_open", "xml_close", "error_response", "error_responseprefix", "error_body",
- "error_element", "textstring", null};
- }
-
- /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
- private static final short yyrline_[] = yyrline_init();
-
- private static final short[] yyrline_init() {
- return new short[] {0, 98, 98, 99, 103, 110, 116, 123, 134, 136, 137, 138, 139, 140, 144, 151, 157, 158, 162, 164,
- 169, 176, 182, 184, 189, 190, 191, 192, 197, 205, 211, 219, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
- 236, 237, 238, 239, 240, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 262,
- 264, 265, 266, 270, 277, 283, 290, 295, 297, 298, 299, 300, 304, 311, 316, 318, 319, 320, 321, 324, 326, 330,
- 334, 335, 336, 342, 347, 353, 361, 362, 367, 374, 381, 389, 390, 395, 396, 400, 402, 407, 415, 416, 420, 425,
- 434, 435, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 461, 462, 463, 464, 465, 466,
- 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488,
- 489, 490, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513,
- 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 527, 534, 540, 542, 546, 548, 550, 555, 557};
- }
-
-
- // Report on the debug stream that the rule yyrule is going to be reduced.
- private void yy_reduce_print(int yyrule, YYStack yystack) {
- if (yydebug == 0)
- return;
-
- int yylno = yyrline_[yyrule];
- int yynrhs = yyr2_[yyrule];
- /* Print the symbols being reduced, and their result. */
- yycdebug("Reducing stack by rule " + (yyrule - 1) + " (line " + yylno + "), ");
-
- /* The symbols being reduced. */
- for (int yyi = 0; yyi < yynrhs; yyi++)
- yy_symbol_print(" $" + (yyi + 1) + " =", yystos_[yystack.stateAt(yynrhs - (yyi + 1))],
- ((yystack.valueAt(yynrhs - (yyi + 1)))));
- }
-
- /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
- private static final byte yytranslate_table_[] = yytranslate_table_init();
-
- private static final byte[] yytranslate_table_init() {
- return new byte[] {0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
- 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
- 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
- 86};
- }
-
- private static final byte yytranslate_(int t) {
- if (t >= 0 && t <= yyuser_token_number_max_)
- return yytranslate_table_[t];
- else
- return yyundef_token_;
- }
-
- private static final int yylast_ = 399;
- private static final int yynnts_ = 54;
- private static final int yyempty_ = -2;
- private static final int yyfinal_ = 10;
- private static final int yyterror_ = 1;
- private static final int yyerrcode_ = 256;
- private static final int yyntokens_ = 87;
-
- private static final int yyuser_token_number_max_ = 341;
- private static final int yyundef_token_ = 2;
-
- /* User implementation code. */
-
-}
-
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4EventHandler.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4EventHandler.java
deleted file mode 100644
index cc1416b024..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4EventHandler.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr.parser.bison;
-
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import java.util.HashMap;
-import java.util.Map;
-import static dap4.core.dmr.parser.bison.Dap4BisonParser.Lexer.*;
-import static dap4.core.dmr.parser.bison.Dap4BisonParser.YYABORT;
-import static dap4.core.dmr.parser.bison.Dap4BisonParser.YYACCEPT;
-
-public class Dap4EventHandler extends SaxEventHandler {
- //////////////////////////////////////////////////
- // Constants
-
- public static String SPECIALATTRPREFIX = "_";
-
- //////////////////////////////////////////////////
- // static types
-
- //////////////////////////////////////////////////
- // static fields
-
- static Map elementmap;
- static Map attributemap;
-
- static {
- elementmap = new HashMap();
- attributemap = new HashMap();
-
- elementmap.put("Dataset",
- new Lexeme("Dataset", DATASET_, _DATASET, new String[] {"name", "dapVersion", "dmrVersion"})); // legal
- // attributes
- // (lower case)
- elementmap.put("Group", new Lexeme("Group", GROUP_, _GROUP, new String[] {"name"}));
- elementmap.put("Enumeration",
- new Lexeme("Enumeration", ENUMERATION_, _ENUMERATION, new String[] {"name", "basetype"}));
- elementmap.put("EnumConst", new Lexeme("EnumConst", ENUMCONST_, _ENUMCONST, new String[] {"name", "value"}));
- elementmap.put("Namespace", new Lexeme("Namespace", NAMESPACE_, _NAMESPACE, new String[] {"href"}));
- elementmap.put("Dimension", new Lexeme("Dimension", DIMENSION_, _DIMENSION, new String[] {"name", "size"}));
- elementmap.put("Dim", new Lexeme("Dim", DIM_, _DIM, new String[] {"name", "size"}));
- elementmap.put("Enum", new Lexeme("Enum", ENUM_, _ENUM, new String[] {"enum", "name"}));
- elementmap.put("Map", new Lexeme("Map", MAP_, _MAP, new String[] {"name"}));
- elementmap.put("Structure", new Lexeme("Structure", STRUCTURE_, _STRUCTURE, new String[] {"name"}));
- elementmap.put("Sequence", new Lexeme("Sequence", SEQUENCE_, _SEQUENCE, new String[] {"name"}));
- elementmap.put("Value", new Lexeme("Value", VALUE_, _VALUE, new String[] {"value"}));
- elementmap.put("Attribute", new Lexeme("Attribute", ATTRIBUTE_, _ATTRIBUTE, new String[] {"name", "type"}));
-
- elementmap.put("Char", new Lexeme("Char", CHAR_, _CHAR, new String[] {"name"}));
- elementmap.put("Byte", new Lexeme("Byte", BYTE_, _BYTE, new String[] {"name"}));
- elementmap.put("Int8", new Lexeme("Int8", INT8_, _INT8, new String[] {"name"}));
- elementmap.put("UInt8", new Lexeme("UInt8", UINT8_, _UINT8, new String[] {"name"}));
- elementmap.put("Int16", new Lexeme("Int16", INT16_, _INT16, new String[] {"name"}));
- elementmap.put("UInt16", new Lexeme("UInt16", UINT16_, _UINT16, new String[] {"name"}));
- elementmap.put("Int32", new Lexeme("Int32", INT32_, _INT32, new String[] {"name"}));
- elementmap.put("UInt32", new Lexeme("UInt32", UINT32_, _UINT32, new String[] {"name"}));
- elementmap.put("Int64", new Lexeme("Int64", INT64_, _INT64, new String[] {"name"}));
- elementmap.put("UInt64", new Lexeme("UInt64", UINT64_, _UINT64, new String[] {"name"}));
- elementmap.put("Float32", new Lexeme("Float32", FLOAT32_, _FLOAT32, new String[] {"name"}));
- elementmap.put("Float64", new Lexeme("Float64", FLOAT64_, _FLOAT64, new String[] {"name"}));
- elementmap.put("String", new Lexeme("String", STRING_, _STRING, new String[] {"name"}));
- elementmap.put("URL", new Lexeme("URL", URL_, _URL, new String[] {"name"}));
- elementmap.put("Opaque", new Lexeme("Opaque", OPAQUE_, _OPAQUE, new String[] {"name"}));
-
- // related elements
- elementmap.put("Error", new Lexeme("Error", ERROR_, _ERROR, new String[] {"httpcode"}));
- elementmap.put("Message", new Lexeme("Message", MESSAGE_, _MESSAGE, null));
- elementmap.put("Context", new Lexeme("Context", CONTEXT_, _CONTEXT, null));
- elementmap.put("OtherInfo", new Lexeme("OtherInfo", OTHERINFO_, _OTHERINFO, null));
-
- // Always insert the lowercase name
- attributemap.put("base", new Lexeme("base", ATTR_BASE));
- attributemap.put("basetype", new Lexeme("basetype", ATTR_BASETYPE));
- attributemap.put("dapversion", new Lexeme("dapversion", ATTR_DAPVERSION));
- attributemap.put("dmrversion", new Lexeme("dmrversion", ATTR_DMRVERSION));
- attributemap.put("enum", new Lexeme("enum", ATTR_ENUM));
- attributemap.put("href", new Lexeme("href", ATTR_HREF));
- attributemap.put("name", new Lexeme("name", ATTR_NAME));
- attributemap.put("namespace", new Lexeme("namespace", ATTR_NAMESPACE));
- attributemap.put("size", new Lexeme("size", ATTR_SIZE));
- attributemap.put("type", new Lexeme("type", ATTR_TYPE));
- attributemap.put("value", new Lexeme("value", ATTR_VALUE));
- attributemap.put("ns", new Lexeme("ns", ATTR_NS));
- // related xml attributes
- attributemap.put("httpcode", new Lexeme("httpcode", ATTR_HTTPCODE));
- }
-
- ;
-
- //////////////////////////////////////////////////
- // Instance variables
-
- boolean textok = false;
- boolean accepted = false;
- boolean otherxml = false;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public Dap4EventHandler() {}
-
- //////////////////////////////////////////////////
- // Abstract method overrides
-
- // Push the token to the parser
- // @throws SAXException if parser return YYABORT
-
- public void yyevent(SaxEvent saxtoken) throws SAXException {
- if (accepted) {
- throw new SAXException("yyevent called after parser has accepted");
- }
-
- SaxEventType event = saxtoken.eventtype;
- String name = saxtoken.name;
- int yytoken = 0;
- Lexeme element = null;
- Lexeme attr = null;
-
- element = elementmap.get(name);
-
- switch (event) {
-
- case STARTELEMENT:
- if (element == null) {// undefined
- yytoken = UNKNOWN_ELEMENT_;
- break;
- }
- yytoken = element.open;
- if (yytoken == OTHERXML_) {
- otherxml = true;
- textok = true;
- } else if (!otherxml && yytoken == VALUE_)
- textok = true;
- break;
-
- case ATTRIBUTE:
- String lcname = name.toLowerCase();
- attr = attributemap.get(lcname);
- if (attr == null) {
- if (lcname.startsWith(SPECIALATTRPREFIX))
- yytoken = ATTR_SPECIAL;
- else
- yytoken = UNKNOWN_ATTR;
- } else
- yytoken = attr.atoken;
- break;
-
- case ENDELEMENT:
- if (element == null) {// undefined
- yytoken = _UNKNOWN_ELEMENT;
- break;
- }
- yytoken = element.close;
- if (yytoken == _OTHERXML) {
- otherxml = false;
- textok = false;
- } else if (!otherxml && yytoken == _VALUE)
- textok = false;
- break;
-
- case CHARACTERS:
- if (!textok)
- return; // ignore
- yytoken = TEXT;
- break;
-
- case ENDDOCUMENT:
- yytoken = EOF;
- break;
-
- default:
- return; // ignore
-
- } // switch
-
- int status = 0;
- try {
- Locator loc = getLocator();
- Dap4BisonParser parser = (Dap4BisonParser) this;
- // Bison.Position pos = new Bison.Position(loc);
- // Dap4BisonParser.Location yyloc = parser.new Location(pos);
- status = parser.push_parse(yytoken, saxtoken);
- } catch (Exception e) {
- throw new SAXException(e);
- }
- if (status == YYABORT)
- throw new SAXException("YYABORT");
- else if (status == YYACCEPT)
- accepted = true;
- }
-
-} // class Dap4EventHandler
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4ParserImpl.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4ParserImpl.java
deleted file mode 100644
index eb5fa09979..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4ParserImpl.java
+++ /dev/null
@@ -1,1056 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr.parser.bison;
-
-import dap4.core.dmr.*;
-import dap4.core.dmr.parser.Dap4Parser;
-import dap4.core.dmr.parser.ParseException;
-import dap4.core.dmr.parser.ParseUtil;
-import dap4.core.util.DapException;
-import dap4.core.util.DapSort;
-import dap4.core.util.DapUtil;
-import dap4.core.util.Escape;
-import org.xml.sax.SAXException;
-import java.math.BigInteger;
-import java.util.*;
-
-/**
- * Implement the Dap4 Parse Actions
- */
-
-public class Dap4ParserImpl extends Dap4BisonParser implements Dap4Parser {
-
- //////////////////////////////////////////////////
- // Constants
-
- //////////////////////////////////////////////////
- // static variables
-
- protected static int globaldebuglevel = 0;
-
- //////////////////////////////////////////////////
- // Static methods
-
- public static void setGlobalDebugLevel(int level) {
- globaldebuglevel = level;
- }
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected DMRFactory factory = null;
-
- protected ErrorResponse errorresponse = null;
-
- protected Deque scopestack = new ArrayDeque();
-
- protected DapDataset root = null; // of the parse
-
- protected boolean debug = false;
-
- //////////////////////////////////////////////////
- // Constructors
-
- public Dap4ParserImpl(DMRFactory factory) {
- super();
- this.factory = (factory == null ? new DMRFactory() : factory); // see Dap4Actions
- if (globaldebuglevel > 0)
- setDebugLevel(globaldebuglevel);
- }
-
- //////////////////////////////////////////////////
- // Accessors
-
- public ErrorResponse getErrorResponse() {
- return errorresponse;
- }
-
- public DapDataset getDMR() {
- return this.root;
- }
-
- //////////////////////////////////////////////////
- // Parser API
-
- public boolean parse(String input) throws SAXException {
- return super.parse(input);
- }
-
- //////////////////////////////////////////////////
- // Parser specific methods
-
- DapGroup getGroupScope() throws DapException {
- DapGroup gscope = (DapGroup) searchScope(DapSort.GROUP, DapSort.DATASET);
- if (gscope == null)
- throw new DapException("Undefined Group Scope");
- return gscope;
- }
-
- DapNode getMetadataScope() throws DapException {
- // Search up the stack for first match.
- DapNode match = searchScope(METADATASCOPES);
- if (match == null)
- throw new ParseException("No enclosing metadata capable scope");
- return match;
- }
-
- DapNode getParentScope() throws DapException {
- DapNode parent = searchScope(DapSort.VARIABLE, DapSort.GROUP, DapSort.DATASET);
- if (parent == null)
- throw new DapException("Undefined parent scope");
- return parent;
- }
-
- DapVariable getVariableScope() throws DapException {
- DapNode match = searchScope(DapSort.VARIABLE);
- if (match == null)
- throw new ParseException("No enclosing variable scope");
- return (DapVariable) match;
- }
-
- DapNode getScope(DapSort... sort) throws DapException {
- DapNode node = searchScope(sort);
- if (node == null) // return exception if not found
- throw new ParseException("No enclosing scope of specified type");
- return node;
- }
-
- DapNode searchScope(DapSort... sort) {
- Iterator it = scopestack.iterator();
- while (it.hasNext()) {
- DapNode node = (DapNode) it.next();
- for (int j = 0; j < sort.length; j++) {
- if (node.getSort() == sort[j])
- return node;
- }
- }
- return null;
- }
-
- DapVariable findVariable(DapNode parent, String name) {
- DapVariable var = null;
- switch (parent.getSort()) {
- case DATASET:
- case GROUP:
- var = ((DapGroup) parent).findVariable(name);
- break;
- case VARIABLE:
- DapVariable v = (DapVariable) parent;
- DapType t = v.getBaseType();
- switch (t.getTypeSort()) {
- case Structure:
- var = (DapVariable) ((DapStructure) t).findByName(name);
- break;
- case Sequence:
- var = (DapVariable) ((DapSequence) t).findByName(name);
- break;
- default:
- assert false : "Container cannot be atomic variable";
- }
- default:
- break;
- }
- return var;
- }
-
- // Attribute map utilities
- SaxEvent pull(XMLAttributeMap map, String name) {
- SaxEvent event = map.remove(name.toLowerCase());
- return event;
- }
-
- /**
- * add any reserved xml attributes to a node unchanged
- */
- void passReserved(XMLAttributeMap map, DapNode node) throws ParseException {
- try {
- DapAttribute attr = null;
- for (Map.Entry entry : map.entrySet()) {
- SaxEvent event = entry.getValue();
- String key = entry.getKey();
- String value = event.value;
- if (isReserved(key))
- node.addXMLAttribute(key, value);
- }
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- // Attribute map utilities
- SaxEvent peek(XMLAttributeMap map, String name) {
- SaxEvent event = map.get(name.toLowerCase());
- return event;
- }
-
- //////////////////////////////////////////////////
- // Attribute construction
-
- DapAttribute makeAttribute(DapSort sort, String name, DapType basetype, List nslist, DapNode parent)
- throws DapException {
- DapAttribute attr = new DapAttribute(name, basetype);
- if (sort == DapSort.ATTRIBUTE) {
- attr.setBaseType(basetype);
- }
- parent.addAttribute(attr);
- attr.setNamespaceList(nslist);
- return attr;
- }
-
- boolean isempty(SaxEvent token) {
- return token == null || isempty(token.value);
- }
-
- boolean isempty(String text) {
- return (text == null || text.length() == 0);
- }
-
- List convertNamespaceList(NamespaceList nslist) {
- return nslist;
- }
-
- boolean islegalenumtype(DapType kind) {
- return kind.isIntegerType();
- }
-
- boolean islegalattributetype(DapType kind) {
- return kind.isLegalAttrType();
- }
-
- DapAttribute lookupAttribute(DapNode parent, XMLAttributeMap attrs) throws DapException {
- SaxEvent name = pull(attrs, "name");
- if (isempty(name))
- throw new ParseException("Attribute: Empty attribute name");
- String attrname = name.value;
- return parent.findAttribute(attrname);
- }
-
- void changeAttribute(DapAttribute attr, XMLAttributeMap description) throws DapException {
- SaxEvent name = pull(description, "name");
- if (isempty(name))
- throw new ParseException("Attribute: Empty attribute name");
- String attrname = name.value;
- if (!attr.getShortName().equals(attrname))
- throw new ParseException("Attribute: DATA DMR: Attribute name mismatch:" + name.name);
- switch (attr.getSort()) {
- case ATTRIBUTE:
- SaxEvent atype = pull(description, "type");
- String typename = (atype == null ? "Int32" : atype.value);
- if ("Byte".equalsIgnoreCase(typename))
- typename = "UInt8";
- DapType basetype = (DapType) root.lookup(typename, DapSort.ENUMERATION, DapSort.ATOMICTYPE);
- if (basetype != attr.getBaseType())
- throw new ParseException("Attribute: DATA DMR: Attempt to change attribute type: " + typename);
- attr.clearValues();
- SaxEvent value = pull(description, "value");
- if (value != null)
- attr.setValues(new String[] {value.value});
- break;
- case ATTRIBUTESET:
- // clear the contained attributes
- attr.setAttributes(new HashMap());
- break;
- case OTHERXML:
- throw new ParseException("Attribute: DATA DMR: OtherXML attributes not supported");
- }
- }
-
- DapAttribute createatomicattribute(XMLAttributeMap attrs, NamespaceList nslist, DapNode parent) throws DapException {
- SaxEvent name = pull(attrs, "name");
- if (isempty(name))
- throw new ParseException("Attribute: Empty attribute name");
- String attrname = name.value;
- SaxEvent atype = pull(attrs, "type");
- String typename = (atype == null ? "Int32" : atype.value);
- if ("Byte".equalsIgnoreCase(typename))
- typename = "UInt8";
- DapType basetype = (DapType) root.lookup(typename, DapSort.ENUMERATION, DapSort.ATOMICTYPE);
- if (basetype == null || !islegalattributetype(basetype))
- throw new ParseException("Attribute: Invalid attribute type: " + typename);
- List hreflist = convertNamespaceList(nslist);
- DapAttribute attr = makeAttribute(DapSort.ATTRIBUTE, name.value, basetype, hreflist, parent);
- return attr;
- }
-
- DapAttribute createcontainerattribute(XMLAttributeMap attrs, NamespaceList nslist, DapNode parent)
- throws DapException {
- SaxEvent name = pull(attrs, "name");
- if (isempty(name))
- throw new ParseException("ContainerAttribute: Empty attribute name");
- List hreflist = convertNamespaceList(nslist);
- DapAttribute attr = makeAttribute(DapSort.ATTRIBUTESET, name.value, null, hreflist, parent);
- return attr;
- }
-
- void createvalue(String value, DapAttribute parent) throws DapException {
- // Since this came from ...
- // Clean it up
- value = cleanup(value);
- if (parent != null)
- parent.setValues(new String[] {value});
- }
-
- protected String cleanup(String value) {
- value = value.trim();
- int first = -1;
- for (int i = 0; i < value.length(); i++) {
- if (first < 0 && value.charAt(i) > ' ') {
- first = i;
- break;
- }
- }
- int last = -1;
- for (int i = value.length() - 1; i >= 0; i--) {
- if (last < 0 && value.charAt(i) > ' ') {
- last = i;
- break;
- }
- }
- if (last < 0)
- last = value.length() - 1;
- if (first < 0)
- first = 0;
- value = value.substring(first, last + 1);
- return value;
- }
-
- void createvalue(SaxEvent value, DapAttribute parent) throws DapException {
- List textlist = null;
- if (value.eventtype == SaxEventType.CHARACTERS) {
- textlist = ParseUtil.collectValues(value.text);
- } else if (value.eventtype == SaxEventType.ATTRIBUTE) {
- textlist = new ArrayList();
- textlist.add(value.value);
- }
- if (textlist != null)
- parent.setValues(textlist.toArray(new String[textlist.size()]));
- }
-
- DapOtherXML createotherxml(XMLAttributeMap attrs, DapNode parent) throws DapException {
- SaxEvent name = pull(attrs, "name");
- SaxEvent href = pull(attrs, "href");
- if (isempty(name))
- throw new ParseException("OtherXML: Empty name");
- List nslist = new ArrayList();
- if (!isempty(href))
- nslist.add(href.value);
- DapOtherXML other = (DapOtherXML) makeAttribute(DapSort.OTHERXML, name.value, null, nslist, parent);
- parent.setAttribute(other);
- return other;
- }
-
- //////////////////////////////////////////////////
- // Abstract action definitions
- @Override
- void enterdataset(XMLAttributeMap attrs) throws ParseException {
- this.debug = getDebugLevel() > 0; // make sure we have the latest value
- if (debug)
- report("enterdataset");
- SaxEvent name = pull(attrs, "name");
- SaxEvent dapversion = pull(attrs, "dapversion");
- SaxEvent dmrversion = pull(attrs, "dmrversion");
- if (isempty(name))
- throw new ParseException("Empty dataset name attribute");
- // convert and test version numbers
- float ndapversion = DAPVERSION;
- if (dapversion != null)
- try {
- ndapversion = Float.parseFloat(dapversion.value);
- } catch (NumberFormatException nfe) {
- ndapversion = DAPVERSION;
- }
- if (ndapversion != DAPVERSION)
- throw new ParseException("Dataset dapVersion mismatch: " + dapversion.value);
- float ndmrversion = DMRVERSION;
- if (dmrversion != null)
- try {
- ndmrversion = Float.parseFloat(dmrversion.value);
- } catch (NumberFormatException nfe) {
- ndmrversion = DMRVERSION;
- }
- if (ndmrversion != DMRVERSION)
- throw new ParseException("Dataset dmrVersion mismatch: " + dmrversion.value);
- this.root = new DapDataset(name.value);
- this.root.setDapVersion(Float.toString(ndapversion));
- this.root.setDMRVersion(Float.toString(ndmrversion));
- this.root.setDataset(this.root);
- passReserved(attrs, this.root);
- scopestack.push(this.root);
- }
-
- @Override
- void leavedataset() throws ParseException {
- if (debug)
- report("leavedataset");
- assert (scopestack.peek() != null && scopestack.peek().getSort() == DapSort.DATASET);
- this.root.sort();
- scopestack.pop();
- if (!scopestack.isEmpty())
- throw new ParseException("Dataset: nested dataset");
- this.root.finish();
- }
-
- @Override
- void entergroup(XMLAttributeMap attrs) throws ParseException {
- if (debug)
- report("entergroup");
- SaxEvent name = pull(attrs, "name");
- if (isempty(name))
- throw new ParseException("Empty group name");
- try {
- DapGroup parent = getGroupScope();
- DapGroup group;
- group = new DapGroup(name.value);
- passReserved(attrs, group);
- parent.addDecl(group);
- scopestack.push(group);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- @Override
- void leavegroup() throws ParseException {
- if (debug)
- report("leavegroup");
- scopestack.pop();
- }
-
- @Override
- void enterenumdef(XMLAttributeMap attrs) throws ParseException {
- if (debug)
- report("enterenumdef");
- try {
- SaxEvent name = pull(attrs, "name");
- if (isempty(name))
- throw new ParseException("Enumdef: Empty Enum Declaration name");
-
- SaxEvent basetype = pull(attrs, "basetype");
- DapType basedaptype = null;
- if (basetype == null) {
- basedaptype = DapEnumeration.DEFAULTBASETYPE;
- } else {
- String typename = basetype.value;
- if ("Byte".equalsIgnoreCase(typename))
- typename = "UInt8";
- basedaptype = (DapType) this.root.lookup(typename, DapSort.ATOMICTYPE);
- if (basedaptype == null || !islegalenumtype(basedaptype))
- throw new ParseException("Enumdef: Invalid Enum Declaration Type name: " + basetype.value);
- }
- DapEnumeration dapenum = null;
- dapenum = new DapEnumeration(name.value, basedaptype);
- passReserved(attrs, dapenum);
- DapGroup parent = getGroupScope();
- parent.addDecl(dapenum);
- scopestack.push(dapenum);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
-
- @Override
- void leaveenumdef() throws ParseException {
- if (debug)
- report("leaveenumdef");
- DapEnumeration eparent = (DapEnumeration) scopestack.pop();
- List econsts = eparent.getNames();
- if (econsts.size() == 0)
- throw new ParseException("Enumdef: no enum constants specified");
- }
-
- @Override
- void enumconst(SaxEvent name, SaxEvent value) throws ParseException {
- if (debug)
- report("enumconst");
- if (isempty(name))
- throw new ParseException("Enumconst: Empty enum constant name");
- if (isempty(value))
- throw new ParseException("Enumdef: Invalid enum constant value: " + value.value);
- long lvalue = 0;
- try {
- BigInteger bivalue = new BigInteger(value.value);
- bivalue = DapUtil.BIG_UMASK64.and(bivalue);
- lvalue = bivalue.longValue();
- } catch (NumberFormatException nfe) {
- throw new ParseException("Enumconst: illegal value: " + value.value);
- }
- try {
- DapEnumeration parent = (DapEnumeration) getScope(DapSort.ENUMERATION);
- // Verify that the name is a legal enum constant name, which is restricted
- // vis-a-vis other names
- if (!ParseUtil.isLegalEnumConstName(name.value))
- throw new ParseException("Enumconst: illegal enumeration constant name: " + name.value);
- parent.addEnumConst(new DapEnumConst(name.value, lvalue));
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- @Override
- void enterdimdef(XMLAttributeMap attrs) throws ParseException {
- if (debug)
- report("enterdimdef");
- SaxEvent name = pull(attrs, "name");
- SaxEvent size = pull(attrs, "size");
- long lvalue = 0;
- if (isempty(name))
- throw new ParseException("Dimdef: Empty dimension declaration name");
- if (isempty(size))
- throw new ParseException("Dimdef: Empty dimension declaration size");
- try {
- lvalue = Long.parseLong(size.value);
- if (lvalue <= 0)
- throw new ParseException("Dimdef: value <= 0: " + lvalue);
- } catch (NumberFormatException nfe) {
- throw new ParseException("Dimdef: non-integer value: " + size.value);
- }
- DapDimension dim = null;
- try {
- dim = new DapDimension(name.value, lvalue);
- passReserved(attrs, dim);
- dim.setShared(true);
- DapGroup parent = getGroupScope();
- parent.addDecl(dim);
- scopestack.push(dim);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- @Override
- void leavedimdef() throws ParseException {
- if (debug)
- report("leavedimdef");
- scopestack.pop();
- }
-
- @Override
- void dimref(SaxEvent nameorsize) throws ParseException {
- if (debug)
- report("dimref");
- try {
- DapDimension dim = null;
- DapVariable var = getVariableScope();
- assert var != null : "Internal error";
-
- boolean isname = nameorsize.name.equals("name");
- if (isname && isempty(nameorsize))
- throw new ParseException("Dimref: Empty dimension reference name");
- else if (isempty(nameorsize))
- throw new ParseException("Dimref: Empty dimension size");
- if (isname) {
- DapGroup dg = var.getGroup();
- if (dg == null)
- throw new ParseException("Internal error: variable has no containing group");
- DapGroup grp = var.getGroup();
- if (grp == null)
- throw new ParseException("Variable has no group");
- dim = (DapDimension) grp.findByFQN(nameorsize.value, DapSort.DIMENSION);
- } else {// Size only is given; presume a number; create unique anonymous dimension
- String ssize = nameorsize.value.trim();
- {
- // Note that we create it in the root group
- assert (root != null);
- long anonsize;
- try {
- anonsize = Long.parseLong(nameorsize.value.trim());
- } catch (NumberFormatException nfe) {
- throw new ParseException("Dimref: Illegal dimension size");
- }
- dim = root.createAnonymous(anonsize);
- }
- }
- if (dim == null)
- throw new ParseException("Unknown dimension: " + nameorsize.value);
- var.addDimension(dim);
- } catch (DapException de) {
- throw new ParseException(de.getMessage(), de.getCause());
- }
- }
-
- @Override
- void enteratomicvariable(SaxEvent open, XMLAttributeMap attrs) throws ParseException {
- if (debug)
- report("enteratomicvariable");
- try {
- SaxEvent name = pull(attrs, "name");
- if (isempty(name))
- throw new ParseException("Atomicvariable: Empty dimension reference name");
- String typename = open.name;
- if ("Byte".equals(typename))
- typename = "UInt8"; // special case
- DapType basetype = (DapType) this.root.lookup(typename, DapSort.ENUMERATION, DapSort.ATOMICTYPE);
- if (basetype == null)
- throw new ParseException("AtomicVariable: Illegal type: " + open.name);
- DapVariable var = null;
- // Do type substitutions
- var = new DapVariable(name.value, basetype);
- passReserved(attrs, var);
- // Look at the parent scope
- DapNode parent = scopestack.peek();
- if (parent == null)
- throw new ParseException("Variable has no parent");
- switch (parent.getSort()) {
- case DATASET:
- case GROUP:
- ((DapGroup) parent).addDecl(var);
- break;
- case VARIABLE:
- addField((DapVariable) parent, var);
- break;
- default:
- assert false : "Atomic variable in illegal scope";
- }
- scopestack.push(var);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- void openclosematch(SaxEvent close, DapSort sort) throws ParseException {
- String typename = close.name;
- if ("Byte".equals(typename))
- typename = "UInt8"; // special case
- switch (sort) {
- case VARIABLE:
- TypeSort atype = TypeSort.getTypeSort(typename);
- DapVariable var = (DapVariable) searchScope(sort);
- assert var != null;
- TypeSort vartype = var.getBaseType().getTypeSort();
- if (atype == null)
- throw new ParseException("Variable: Illegal type: " + typename);
- if (atype != vartype)
- throw new ParseException(String.format("variable: open/close type mismatch: <%s> %s>", vartype, atype));
- break;
- default:
- throw new ParseException("Variable: Illegal type: " + typename);
- }
- }
-
- void leavevariable() throws ParseException {
- scopestack.pop();
- }
-
- void leaveatomicvariable(SaxEvent close) throws ParseException {
- openclosematch(close, DapSort.VARIABLE);
- leavevariable();
- }
-
- @Override
- void enterenumvariable(XMLAttributeMap attrs) throws ParseException {
- if (debug)
- report("enterenumvariable");
- try {
- SaxEvent name = pull(attrs, "name");
- SaxEvent enumtype = pull(attrs, "enum");
- if (isempty(name))
- throw new ParseException("Enumvariable: Empty variable name");
- if (isempty(enumtype))
- throw new ParseException("Enumvariable: Empty enum type name");
- DapEnumeration target = (DapEnumeration) root.findByFQN(enumtype.value, DapSort.ENUMERATION);
- if (target == null)
- throw new ParseException("EnumVariable: no such enum: " + name.value);
- DapVariable var = null;
- var = new DapVariable(name.value, target);
- passReserved(attrs, var);
- // Look at the parent scope
- DapNode parent = scopestack.peek();
- if (parent == null)
- throw new ParseException("Variable has no parent");
- switch (parent.getSort()) {
- case DATASET:
- case GROUP:
- ((DapGroup) parent).addDecl(var);
- break;
- case VARIABLE:
- addField((DapVariable) parent, var);
- break;
- default:
- assert false : "Atomic variable in illegal scope";
- }
- scopestack.push(var);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- @Override
- void leaveenumvariable(SaxEvent close) throws ParseException {
- if (debug)
- report("leaveenumvariable");
- openclosematch(close, DapSort.VARIABLE);
- leavevariable();
- }
-
- @Override
- void entermap(SaxEvent name) throws ParseException {
- if (debug)
- report("entermap");
- if (isempty(name))
- throw new ParseException("Mapref: Empty map name");
- DapVariable var;
- try {
- var = (DapVariable) root.findByFQN(name.value, DapSort.VARIABLE);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- if (var == null)
- throw new ParseException("Mapref: undefined variable: " + name.name);
- // Verify that this is a legal map =>
- // 1. it is outside the scope of its parent if the parent
- // is a structure.
- DapNode container = var.getContainer();
- DapNode scope;
- try {
- scope = getParentScope();
- } catch (DapException de) {
- throw new ParseException(de);
- }
- if ((container.getSort() == DapSort.STRUCTURE || container.getSort() == DapSort.SEQUENCE) && container == scope)
- throw new ParseException("Mapref: map variable not in outer scope: " + name.name);
- DapMap map = new DapMap(var);
- try {
- // Pull the top variable scope
- DapVariable parent = (DapVariable) searchScope(DapSort.VARIABLE);
- if (parent == null)
- throw new ParseException("Variable has no parent: " + var);
- parent.addMap(map);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- scopestack.push(map);
- }
-
- @Override
- void leavemap() throws ParseException {
- if (debug)
- report("leavemap");
- scopestack.pop();
- }
-
- @Override
- void enterstructurevariable(XMLAttributeMap attrs) throws ParseException {
- if (debug)
- report("enterstructurevariable");
- SaxEvent name = pull(attrs, "name");
- if (isempty(name))
- throw new ParseException("Structure: Empty structure name");
- try {
- DapStructure type = null;
- DapVariable var = null;
- type = new DapStructure(name.value);
- passReserved(attrs, type);
- var = new DapVariable(name.value, type);
- // Look at the parent scope
- DapNode parent = scopestack.peek();
- if (parent == null)
- throw new ParseException("Variable has no parent");
- switch (parent.getSort()) {
- case DATASET:
- case GROUP:
- ((DapGroup) parent).addDecl(var);
- var.getGroup().addDecl(type);
- break;
- case VARIABLE:
- addField((DapVariable) parent, var);
- var.getGroup().addDecl(type);
- break;
- default:
- assert false : "Structure variable in illegal scope";
- }
- scopestack.push(var);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- @Override
- void leavestructurevariable(SaxEvent close) throws ParseException {
- if (debug)
- report("leavestructurevariable");
- openclosematch(close, DapSort.VARIABLE);
- leavevariable();
- }
-
- @Override
- void entersequencevariable(XMLAttributeMap attrs) throws ParseException {
- if (debug)
- report("entersequencevariable");
- SaxEvent name = pull(attrs, "name");
- if (isempty(name))
- throw new ParseException("Sequence: Empty sequence name");
- try {
- DapVariable var = null;
- DapType type = null;
- type = new DapSequence(name.value);
- passReserved(attrs, type);
- var = new DapVariable(name.value, type);
- // Look at the parent scope
- DapNode parent = scopestack.peek();
- if (parent == null)
- throw new ParseException("Variable has no parent");
- switch (parent.getSort()) {
- case DATASET:
- case GROUP:
- ((DapGroup) parent).addDecl(var);
- var.getGroup().addDecl(type);
- break;
- case VARIABLE:
- addField((DapVariable) parent, var);
- var.getGroup().addDecl(type);
- break;
- default:
- assert false : "Structure variable in illegal scope";
- }
- scopestack.push(var);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- @Override
- void leavesequencevariable(SaxEvent close) throws ParseException {
- if (debug)
- report("leavesequencevariable");
- openclosematch(close, DapSort.VARIABLE);
- leavevariable();
- }
-
- @Override
- void enteratomicattribute(XMLAttributeMap attrs, NamespaceList nslist) throws ParseException {
- if (debug)
- report("enteratomicattribute");
- try {
- DapNode parent = getMetadataScope();
- DapAttribute attr = null;
- attr = createatomicattribute(attrs, nslist, parent);
- scopestack.push(attr);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- @Override
- void leaveatomicattribute() throws ParseException {
- if (debug)
- report("leaveatomicattribute");
- DapAttribute attr = (DapAttribute) scopestack.pop();
- // Ensure that the attribute has at least one value
- if (java.lang.reflect.Array.getLength(attr.getValues()) == 0)
- throw new ParseException("AtomicAttribute: attribute has no values");
- }
-
- @Override
- void entercontainerattribute(XMLAttributeMap attrs, NamespaceList nslist) throws ParseException {
- if (debug)
- report("entercontainerattribute");
- try {
- DapNode parent = getMetadataScope();
- DapAttribute attr = null;
- attr = createcontainerattribute(attrs, nslist, parent);
- scopestack.push(attr);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- @Override
- void leavecontainerattribute() throws ParseException {
- if (debug)
- report("leavecontainerattribute");
- scopestack.pop();
- }
-
- /**
- * This is called for ...
- *
- * @param value
- * @throws ParseException
- */
- @Override
- void value(String value) throws ParseException {
- if (debug)
- report("value");
- try {
- DapAttribute parent = (DapAttribute) getScope(DapSort.ATTRIBUTE);
- createvalue(value, parent);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- /**
- * This is called for
- *
- * @param value
- * @throws ParseException
- */
- @Override
- void value(SaxEvent value) throws ParseException {
- if (debug)
- report("value");
- try {
- DapAttribute parent = (DapAttribute) getScope(DapSort.ATTRIBUTE);
- createvalue(value, parent);
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- @Override
- void otherxml(XMLAttributeMap attrs, DapXML root) throws ParseException {
- if (debug)
- report("enterotherxml");
- try {
- DapNode parent = getMetadataScope();
- DapOtherXML other = createotherxml(attrs, parent);
- parent.setAttribute(other);
- other.setRoot(root);
- if (debug)
- report("leaveotherxml");
- } catch (DapException de) {
- throw new ParseException(de);
- }
- }
-
- @Override
- DapXML.XMLList xml_body(DapXML.XMLList body, DapXML elemortext) throws ParseException {
- if (debug)
- report("xml_body.enter");
- if (body == null)
- body = new DapXML.XMLList();
- if (elemortext != null)
- body.add(elemortext);
- if (debug)
- report("xml_body.exit");
- return body;
- }
-
- @Override
- DapXML element_or_text(SaxEvent open, XMLAttributeMap map, DapXML.XMLList body, SaxEvent close)
- throws ParseException {
- try {
- if (debug)
- report("element_or_text.enter");
- if (!open.name.equalsIgnoreCase(close.name))
- throw new ParseException(String.format("OtherXML: mismatch: <%s> vs %s>", open.name, close.name));
- DapXML thisxml = createxmlelement(open, map);
- for (DapXML xml : body) {
- thisxml.addElement(xml);
- }
- if (debug)
- report("element_or_text.exit");
- return thisxml;
- } catch (DapException e) {
- throw new ParseException(e);
- }
- }
-
- @Override
- DapXML xmltext(SaxEvent text) throws ParseException {
- try {
- if (debug)
- report("xmltext");
- DapXML txt = createxmltext(text.text);
- return txt;
- } catch (DapException e) {
- throw new ParseException(e);
- }
- }
-
- @Override
- void entererror(XMLAttributeMap attrs) throws ParseException {
- if (debug)
- report("entererror");
- SaxEvent xhttpcode = pull(attrs, "httpcode");
- String shttpcode = (xhttpcode == null ? "400" : xhttpcode.value);
- int httpcode = 0;
- try {
- httpcode = Integer.parseInt(shttpcode);
- } catch (NumberFormatException nfe) {
- throw new ParseException("Error Response; illegal http code: " + shttpcode);
- }
- this.errorresponse = new ErrorResponse();
- this.errorresponse.setCode(httpcode);
- }
-
- @Override
- void leaveerror() throws ParseException {
- if (debug)
- report("leaveerror");
- assert (this.errorresponse != null) : "Internal Error";
- }
-
- @Override
- void errormessage(String value) throws ParseException {
- if (debug)
- report("errormessage");
- assert (this.errorresponse != null) : "Internal Error";
- String message = value;
- message = Escape.entityUnescape(message); // Remove XML encodings
- this.errorresponse.setMessage(message);
- }
-
- @Override
- void errorcontext(String value) throws ParseException {
- if (debug)
- report("errorcontext");
- assert (this.errorresponse != null) : "Internal Error";
- String context = value;
- context = Escape.entityUnescape(context); // Remove XML encodings
- this.errorresponse.setContext(context);
- }
-
- @Override
- void errorotherinfo(String value) throws ParseException {
- if (debug)
- report("errorotherinfo");
- assert (this.errorresponse != null) : "Internal Error";
- String other = value;
- other = Escape.entityUnescape(other); // Remove XML encodings
- this.errorresponse.setOtherInfo(other);
- }
-
- @Override
- String textstring(String prefix, SaxEvent text) throws ParseException {
- if (debug)
- report("text");
- if (prefix == null)
- return text.text;
- else
- return prefix + text.text;
- }
-
- //////////////////////////////////////////////////
- // Utilities
-
- void addField(DapVariable instance, DapVariable field) throws DapException {
- DapType t = instance.getBaseType();
- switch (t.getTypeSort()) {
- case Structure:
- case Sequence:
- ((DapStructure) t).addField(field);
- field.setParent(instance);
- break;
- default:
- assert false : "Container cannot be atomic variable";
- }
- }
-
- void report(String action) {
- getDebugStream().println("ACTION: " + action);
- getDebugStream().flush();
- }
-
- static boolean isReserved(String name) {
- for (String tag : RESERVEDTAGS) {
- if (name.startsWith(tag))
- return true;
- }
- return false;
- }
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4Token.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4Token.java
deleted file mode 100644
index 5fb23a9334..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Dap4Token.java
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr.parser.bison;
-
-public class Dap4Token extends SaxEvent {
-
- public Dap4Token() {}
-
-} // class Dap4Token
-
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Debug.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Debug.java
deleted file mode 100644
index e3346eab08..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Debug.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr.parser.bison;
-
-import dap4.core.dmr.parser.ParseUtil;
-import dap4.core.util.Escape;
-import java.util.Map;
-
-public abstract class Debug {
-
- static void addtext(StringBuilder dst, String txt, int flags) {
- int len;
- int pos;
- boolean shortened = false;
-
- if (txt == null) {
- dst.append("null");
- return;
- }
- if ((flags & ParseUtil.FLAG_TRIMTEXT) != 0) {
- txt = txt.trim();
- }
- len = txt.length();
- if ((flags & ParseUtil.FLAG_ELIDETEXT) != 0 && len > ParseUtil.MAXTEXT) {
- len = ParseUtil.MAXTEXT;
- shortened = true;
- }
- dst.append('|');
- for (int i = 0; i < txt.length(); i++) {
- char c = txt.charAt(i);
- if (len-- <= 0)
- continue;
- if ((flags & ParseUtil.FLAG_ESCAPE) != 0 && c < ' ') {
- dst.append('\\');
- switch (c) {
- case '\n':
- dst.append('n');
- break;
- case '\r':
- dst.append('r');
- break;
- case '\f':
- dst.append('f');
- break;
- case '\t':
- dst.append('t');
- break;
- default: {// convert to octal
- int uc = c;
- int oct;
- oct = ((uc >> 6) & 077);
- dst.append((char) ('0' + oct));
- oct = ((uc >> 3) & 077);
- dst.append((char) ('0' + oct));
- oct = ((uc) & 077);
- dst.append((char) ('0' + oct));
- }
- break;
- }
- } else if ((flags & ParseUtil.FLAG_NOCR) != 0 && c == '\r') {
- continue;
- } else {
- dst.append((char) c);
- }
- }
- if (shortened) {
- dst.append("...");
- }
- dst.append('|');
- }
-
- // Trace a SAX Token
- public static String trace(SaxEvent token) {
- return trace(token, ParseUtil.DEFAULTFLAGS);
- }
-
- public static String trace(SaxEvent token, int flags) {
- StringBuilder result = new StringBuilder();
- String name = "UNDEFINED";
- String value = "";
- String text = "";
- SaxEventType event = null;
-
- name = token.name;
- value = token.value;
- text = token.text;
- event = token.eventtype;
-
- result.append("[" + event.name() + "] ");
-
- switch (event) {
- case STARTELEMENT:
- case ENDELEMENT:
- result.append(": element=|");
- result.append(name);
- result.append("|");
- break;
- case CHARACTERS:
- result.append(" text=");
- addtext(result, text, flags);
- String trans = Escape.entityUnescape(text);
- result.append(" translation=");
- addtext(result, trans, flags);
- break;
- case ATTRIBUTE:
- result.append(": name=");
- addtext(result, name, flags);
- result.append(" value=");
- addtext(result, value, flags);
- break;
- case STARTDOCUMENT:
- break;
- case ENDDOCUMENT:
- break;
- default:
- assert (false) : "Unexpected tokentype";
- }
- result.append(" eventtype=" + event.name());
- return result.toString();
- }
-
- static String traceList(Dap4Actions.XMLAttributeMap map) {
- StringBuilder result = new StringBuilder();
- for (Map.Entry entry : map.entrySet()) {
- SaxEvent event = entry.getValue();
- String trace = trace(event);
- if (result.length() != 0)
- result.append("\n");
- result.append(entry.getKey());
- result.append(": ");
- result.append(trace);
- }
- return result.toString();
- }
-
-
-}// Debug
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/LexException.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/LexException.java
deleted file mode 100644
index 714dd2acc4..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/LexException.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 1998 - 2010. University Corporation for Atmospheric Research/Unidata
- * Portions of this software were developed by the Unidata Program at the
- * University Corporation for Atmospheric Research.
- *
- * Access and use of this software shall impose the following obligations
- * and understandings on the user. The user is granted the right, without
- * any fee or cost, to use, copy, modify, alter, enhance and distribute
- * this software, and any derivative works thereof, and its supporting
- * documentation for any purpose whatsoever, provided that this entire
- * notice appears in all copies of the software, derivative works and
- * supporting documentation. Further, UCAR requests that the user credit
- * UCAR/Unidata in any publications that result from the use of this
- * software or in any product that includes this software. The names UCAR
- * and/or Unidata, however, may not be used in any advertising or publicity
- * to endorse or promote any products or commercial entity unless specific
- * written permission is obtained from UCAR/Unidata. The user also
- * understands that UCAR/Unidata is not obligated to provide the user with
- * any support, consulting, training or assistance of any kind with regard
- * to the use, operation and performance of this software nor to provide
- * the user with any updates, revisions, new versions or "bug fixes."
- *
- * THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
- * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
- * WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-//////////////////////////////////////////////////
-
-package dap4.core.dmr.parser.bison;
-
-public class LexException extends java.lang.Exception {
- public LexException(String msg) {
- super(msg);
- }
-
- public LexException(Throwable e) {
- super(e);
- }
-
- public LexException(String msg, Throwable e) {
- super(msg, e);
- }
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Lexeme.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Lexeme.java
deleted file mode 100644
index 985b99dbc1..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/Lexeme.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr.parser.bison;
-
-public class Lexeme {
- public String name; // element or attribute name
- public int open; // Bison token for element open
- public int close; // Bison token for element close
- public int atoken; // Bison token if this is an attribute
- public String[] legalAttributes; /* not currently used */
-
- public Lexeme(String name, int atoken) {
- this(name, 0, 0, atoken, null);
- }
-
- public Lexeme(String name, int open, int close) {
- this(name, open, close, 0, null);
- }
-
- public Lexeme(String name, int open, int close, String[] alist) {
- this(name, open, close, 0, alist);
- }
-
- public Lexeme(String name, int open, int close, int atoken, String[] alist) {
- this.name = name;
- this.open = open;
- this.close = close;
- this.atoken = atoken;
- legalAttributes = alist;
- }
-
- public void attribute(String[] alist) {
- legalAttributes = alist;
- // check for duplicates
- for (int i = 0; i < legalAttributes.length; i++) {
- for (int j = i + 1; j < legalAttributes.length; j++)
- assert (!legalAttributes[i].equals(legalAttributes[j]));
- }
- }
-
- public String toString() {
- StringBuilder text = new StringBuilder();
- text.append(String.format("%s open=%d close=%d a=%d", name, open, close, atoken));
- if (legalAttributes != null && legalAttributes.length > 0) {
- text.append(" attributes=");
- for (String s : legalAttributes) {
- text.append(" ");
- text.append(s);
- }
- }
- return text.toString();
- }
-} // class Lexeme
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/SaxEvent.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/SaxEvent.java
deleted file mode 100644
index 3d5e139a21..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/SaxEvent.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr.parser.bison;
-
-import org.xml.sax.Locator;
-
-/**
- * Define a class to hold information provided to each kind of eventtype
- */
-public class SaxEvent {
- public SaxEventType eventtype = null;
- public String name = null;
- public String fullname = null;
- public String namespace = null;
-
- public String value = null; // for attributes
- public String text = null; // for text
-
- // public String publicid = null;
- // public String systemid = null;
-
- // Coverity[FB.URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD]
- public Locator locator = null;
-
- public SaxEvent() {}
-
- public SaxEvent(SaxEventType eventtype, Locator locator) {
- this.eventtype = eventtype;
- this.locator = locator;
- }
-
- public SaxEvent(SaxEventType eventtype, Locator locator, String name) {
- this(eventtype, locator);
- this.name = name;
- }
-
- public SaxEvent(SaxEventType eventtype, Locator locator, String name, String fullname, String uri) {
- this(eventtype, locator, name);
- this.fullname = fullname;
- this.namespace = uri;
- }
-
- public String toString() {
- StringBuilder text = new StringBuilder();
- if (eventtype == null)
- text.append("notype");
- else
- text.append(eventtype.toString());
- text.append(" ");
- if (fullname != null)
- text.append(fullname);
- else if (name != null)
- text.append(name);
- else
- text.append("noname");
- if (value != null) {
- text.append(" = ");
- text.append(value);
- }
- if (this.text != null) {
- text.append(" = ");
- text.append(this.text);
- }
- return text.toString();
- }
-
-} // class SaxEvent
-
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/SaxEventHandler.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/SaxEventHandler.java
deleted file mode 100644
index 418837c52c..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/SaxEventHandler.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr.parser.bison;
-
-import javax.xml.XMLConstants;
-import org.xml.sax.*;
-import org.xml.sax.helpers.DefaultHandler;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import java.io.ByteArrayInputStream;
-import java.nio.charset.Charset;
-
-public abstract class SaxEventHandler extends DefaultHandler {
- //////////////////////////////////////////////////
- // Constants
-
- static boolean TRACE = false;
-
- static Charset UTF8 = Charset.forName("UTF-8");
-
- static final String LOAD_EXTERNAL_DTD = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
-
- //////////////////////////////////////////////////
- // static types
-
- //////////////////////////////////////////////////
- // static fields
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected String document = null;
-
- // Sax parser state
- protected Locator locator = null;
- protected SAXParserFactory spf = null;
- protected SAXParser saxparser = null;
- protected ByteArrayInputStream input = null;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public SaxEventHandler() {
-
- }
-
- //////////////////////////////////////////////////
- // Abstract method(s)
-
- // Send the lexeme to the the subclass to process
- public abstract void yyevent(SaxEvent token) throws SAXException;
-
- //////////////////////////////////////////////////
- // Get/Set
- public Locator getLocator() {
- return this.locator;
- }
- //////////////////////////////////////////////////
- // Public API
-
- public boolean parse(String document) throws SAXException {
- // Trim and strip any leading
- StringBuilder doc = new StringBuilder(document.trim());
- int index = doc.indexOf("");
- if (index < 0)
- throw new SAXException("Document has malformed prefix");
- doc.delete(0, index + 2);
- // remove any leading crlf
- while (doc.length() > 0 && "\r\n".indexOf(doc.charAt(0)) >= 0)
- doc.deleteCharAt(0);
- document = doc.toString();
- }
- this.document = document;
- // Create the sax parser that will drive us with events
- try {
- spf = SAXParserFactory.newInstance();
- spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
- spf.setValidating(false);
- spf.setNamespaceAware(true);
- spf.setFeature(LOAD_EXTERNAL_DTD, false);
- saxparser = spf.newSAXParser();
- // Set up for the parse
- input = new ByteArrayInputStream(document.getBytes(UTF8));
- saxparser.parse(input, this); // 'this' is link to subclass parser
- return true;
- } catch (Exception e) {
- throw new SAXException(e);
- }
- }
-
- //////////////////////////////////////////////////
- // DefaultHandler Overrides
-
- // We feed only a subset of the possible events into
- // the subclass handler. This can be changed by
- // overriding the suppressing eventtype handlers below.
-
- @Override
- public void setDocumentLocator(Locator locator) {
- this.locator = locator;
- }
-
- @Override
- public void startDocument() throws SAXException {
- SaxEvent token = new SaxEvent(SaxEventType.STARTDOCUMENT, locator);
- if (TRACE)
- trace("eventtype.%s: %s%n", token.eventtype.name(), token.toString());
- locatedEvent(token);
- }
-
- @Override
- public void endDocument() throws SAXException {
- SaxEvent token = new SaxEvent(SaxEventType.ENDDOCUMENT, locator);
- if (TRACE)
- trace("eventtype.%s: %s%n", token.eventtype.name(), token.toString());
- locatedEvent(token);
- }
-
- @Override
- public void startElement(String nsuri, String name, String qualname, Attributes attributes) throws SAXException {
- SaxEvent token = new SaxEvent(SaxEventType.STARTELEMENT, locator, name, qualname, nsuri);
- if (TRACE)
- trace("eventtype.%s: %s%n", token.eventtype.name(), token.toString());
- locatedEvent(token);
- // Now pass the attributes as tokens
- int nattr = attributes.getLength();
- for (int i = 0; i < nattr; i++) {
- String aname = attributes.getLocalName(i);
- if ("".equals(aname))
- aname = attributes.getQName(i);
- String value = attributes.getValue(i);
- token = new SaxEvent(SaxEventType.ATTRIBUTE, locator, aname);
- token.value = value;
- if (TRACE)
- trace("eventtype.%s: %s%n", token.eventtype.name(), token.toString());
- locatedEvent(token);
- }
- }
-
- @Override
- public void endElement(String nsuri, String name, String qualname) throws SAXException {
- SaxEvent token = new SaxEvent(SaxEventType.ENDELEMENT, locator, name, qualname, nsuri);
- if (TRACE)
- trace("eventtype.%s: %s%n", token.eventtype.name(), token.toString());
- locatedEvent(token);
- }
-
- @Override
- public void characters(char[] ch, int start, int length) throws SAXException {
- SaxEvent token = new SaxEvent(SaxEventType.CHARACTERS, locator);
- token.text = new String(ch, start, length);
- if (TRACE)
- trace("eventtype.%s: %s%n", token.eventtype.name(), token.toString());
- locatedEvent(token);
- }
-
- // Following events are suppressed
-
- @Override
- public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
- // should never see this since not validating
- return;
- }
-
- @Override
- public void endPrefixMapping(String prefix) throws SAXException {
- return;
- }
-
- @Override
- public void notationDecl(String name, String publicId, String systemId) throws SAXException {
- return;
- }
-
- @Override
- public void processingInstruction(String target, String data) throws SAXException {
- return;
- }
-
- @Override
- public void skippedEntity(String name) throws SAXException {
- return;
- }
-
- @Override
- public void startPrefixMapping(String prefix, String uri) throws SAXException {
- return;
- }
-
- @Override
- public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName)
- throws SAXException {
- return;
- }
-
- //////////////////////////////////////////////////
- // Entity resolution (Ignored)
-
- @Override
- public InputSource resolveEntity(String publicId, String systemId) {
- if (TRACE)
- trace("eventtype.RESOLVEENTITY: %s.%s%n", publicId, systemId);
- return null;
- }
-
- //////////////////////////////////////////////////
- // Error handling Events
-
- @Override
- public void fatalError(SAXParseException e) throws SAXException {
- throw new SAXParseException(String.format("Sax fatal error: %s; %s%n", e, report(this.locator)), this.locator);
- }
-
- @Override
- public void error(SAXParseException e) throws SAXException {
- System.err.printf("Sax error: %s; %s%n", e, report(this.locator));
- }
-
- @Override
- public void warning(SAXParseException e) throws SAXException {
- System.err.printf("Sax warning: %s; %s%n", e, report(this.locator));
- }
-
- protected String report(Locator locator) {
- int lineno = locator.getLineNumber();
- int colno = locator.getColumnNumber();
- String text = this.document;
- String[] lines = text.split("[\n]");
- for (int i = lines.length; i <= lineno + 1; i++) {
- // Coverity[FB.SBSC_USE_STRINGBUFFER_CONCATENATION]
- text = text + " \n";
- }
- lines = text.split("[\n]");
- String msg;
- try {
- msg = lines[lineno];
- while (msg.length() <= colno) {
- msg = msg + ' ';
- }
- msg = msg.substring(0, colno) + '^' + msg.substring(colno, msg.length());
- msg = locator.toString() + '|' + msg + '|';
- } catch (ArrayIndexOutOfBoundsException t) {
- msg = locator.toString();
- }
- return msg;
- }
-
-
- //////////////////////////////////////////////////
- // Location printing
-
- protected void locatedEvent(SaxEvent token) throws SAXException {
- try {
- yyevent(token);
- } catch (SAXException se) {
- throw new SAXException(locatedError(se.getMessage()));
- }
- }
-
-
- protected String locatedError(String msg) {
- String locmsg =
- msg + String.format("; near %d::%d%n", this.locator.getLineNumber(), this.locator.getColumnNumber());
- return locmsg;
- }
-
-
- protected void trace(String msg, Object... args) {
- if (TRACE)
- System.err.printf(locatedError(String.format(msg, args)));
- }
-
-} // class SaxEventHandler
diff --git a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/SaxEventType.java b/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/SaxEventType.java
deleted file mode 100644
index 8d4eb953d1..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/SaxEventType.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.dmr.parser.bison;
-
-/**
- * Provide an enumeration to mark all the possible Sax Parser
- * generated events (except error events)
- */
-
-/**
- * This should be essentially 1-1 for all the handler callbacks.
- * Exceptions: TBD
- */
-
-public enum SaxEventType {
- CHARACTERS, ENDDOCUMENT, ENDELEMENT, ENDPREFIXMAPPING, IGNORABLEWHITESPACE, NOTATIONDECL, PROCESSINGINSTRUCTION, SETDOCUMENTLOCATOR, SKIPPEDENTITY, STARTDOCUMENT, STARTELEMENT, STARTPREFIXMAPPING, UNPARSEDENTITYDECL,
- // Following is added to support each attribute as an eventtype
- ATTRIBUTE;
-}; // enum SaxEventType
diff --git a/dap4/d4core/src/main/java/dap4/core/util/Index.java b/dap4/d4core/src/main/java/dap4/core/util/Index.java
deleted file mode 100644
index 9a1049e527..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/util/Index.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.util;
-
-import java.util.Arrays;
-
-public class Index {
- public static final Index SCALAR = new Index(0);
-
- public int rank;
- public long[] indices; // allow direct access
- public long[] dimsizes; // allow direct access
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public Index(int rank) {
- this.rank = rank;
- this.dimsizes = new long[rank];
- indices = new long[rank];
- if (this.rank > 0) {
- Arrays.fill(indices, 0);
- Arrays.fill(dimsizes, 0);
- }
- }
-
- public Index(Index index) {
- this(index.getRank());
- if (this.rank > 0) {
- System.arraycopy(index.indices, 0, this.indices, 0, this.rank);
- System.arraycopy(index.dimsizes, 0, this.dimsizes, 0, this.rank);
- }
- }
-
- public Index(long[] indices, long[] dimsizes) {
- this(dimsizes.length);
- if (this.rank > 0) {
- System.arraycopy(indices, 0, this.indices, 0, this.rank);
- System.arraycopy(dimsizes, 0, this.dimsizes, 0, this.rank);
- }
- }
-
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append('[');
- for (int i = 0; i < this.rank; i++) {
- if (i > 0)
- buf.append(',');
- buf.append(indices[i]);
- buf.append('/');
- buf.append(dimsizes[i]);
- }
- buf.append("](");
- buf.append(this.index());
- buf.append(")");
- return buf.toString();
- }
-
-
- /**
- * Compute the linear index
- * from the current odometer indices.
- */
- public long index() {
- long offset = 0;
- for (int i = 0; i < this.indices.length; i++) {
- offset *= this.dimsizes[i];
- offset += this.indices[i];
- }
- return offset;
- }
-
- public int getRank() {
- return this.rank;
- }
-
- public long get(int i) {
- if (i < 0 || i >= this.rank)
- throw new IllegalArgumentException();
- return this.indices[i];
- }
-
- public long getSize(int i) {
- if (i < 0 || i >= this.rank)
- throw new IllegalArgumentException();
- return this.dimsizes[i];
- }
-
- public boolean isScalar() {
- return (rank == 0 && indices.length == 1 && index() == 1);
- }
-
-
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/util/MultiOdometer.java b/dap4/d4core/src/main/java/dap4/core/util/MultiOdometer.java
deleted file mode 100644
index 99c82ada73..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/util/MultiOdometer.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.util;
-
-import dap4.core.dmr.DapDimension;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * An odometer capable of dealing with a Multi-slices.
- */
-
-public class MultiOdometer extends Odometer {
-
- protected static boolean DEBUG = false;
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected int current; // pointers into multslice list
- protected long[] sizes; // # of subslices in each slice
- protected List> slicesets; // Set of all combinations of slices
- protected List odomset; // Odometers created from slicesets
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public MultiOdometer() {}
-
- public MultiOdometer(List set) throws DapException {
- this(set, null);
- }
-
- public MultiOdometer(List set, List dimset) throws DapException {
- super(set, dimset);
- super.ismulti = true;
- this.sizes = new long[this.rank];
- this.odomset = new ArrayList<>();
- for (int i = 0; i < this.rank; i++) {
- Slice sl = set.get(i);
- List subslices = sl.getSubSlices();
- this.sizes[i] = subslices.size();
- }
- int truerank = this.rank;
- if (truerank == 0) {
- this.slicesets = null;
- this.odomset = null;
- } else {
- PowerSet ps = new PowerSet(this.sizes);
- long pssize = ps.getTotalSize();
- long[][] setindices = ps.getPowerSet();
- assert setindices.length == pssize;
- this.slicesets = new ArrayList<>();
- if (DEBUG) {
- System.err.printf("Multi: |slicesets| = %d%n", setindices.length);
- System.err.println(ps.toString());
- }
- // Create set of slicsets comprising this MultiOdometer
- for (int i = 0; i < pssize; i++) {
- long[] indexset = setindices[i];
- assert indexset.length == truerank;
- // Pick out the desired set of slices
- List subset = new ArrayList<>();
- for (int j = 0; j < this.rank; j++) {
- Slice s0 = set.get(j);
- Slice ss = s0.getSubSlice((int) indexset[j]);
- subset.add(ss);
- }
- this.slicesets.add(subset);
- }
- assert this.slicesets.size() == pssize;
- // Create set of odometers comprising this MultiOdometer
- for (int i = 0; i < pssize; i++) {
- Odometer sslodom = Odometer.factory(this.slicesets.get(i), dimset);
- this.odomset.add(sslodom);
- }
- }
- this.current = 0;
- }
-
- //////////////////////////////////////////////////
-
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- for (int i = 0; i < rank; i++) {
- Slice s = slice(i);
- if (i == current)
- buf.append("*");
- buf.append(s.toString());
- buf.append(String.format("(%d)", s.getCount()));
- }
- return buf.toString();
- }
-
- //////////////////////////////////////////////////
- // Iterator API Overrides
-
- @Override
- public boolean hasNext() {
- if (this.current >= odomset.size())
- return false;
- Odometer ocurrent = odomset.get(this.current);
- if (ocurrent.hasNext())
- return true;
- // Try to move to next odometer
- this.current++;
- return hasNext();
- }
-
- @Override
- public Index next() {
- if (this.current >= odomset.size())
- throw new NoSuchElementException();
- Odometer ocurrent = odomset.get(this.current);
- assert ocurrent.hasNext();
- return ocurrent.next();
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Compute the total number of elements.
- */
- @Override
- public long totalSize() {
- long size = 1;
- for (int i = 0; i < this.rank; i++) {
- size *= slice(i).getCount();
- }
- return size;
- }
-
- @Override
- public List getSubOdometers() {
- return this.odomset;
- }
-
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/util/Odometer.java b/dap4/d4core/src/main/java/dap4/core/util/Odometer.java
deleted file mode 100644
index bccd69e1f5..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/util/Odometer.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.util;
-
-import dap4.core.dmr.DapDimension;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * A classic implementation of an odometer
- * taken from the netcdf-c code.
- * Extended to provide iterator interface
- */
-
-public class Odometer implements Iterator {
-
- //////////////////////////////////////////////////
- // Constants
-
- // Mnemonic
-
- protected static enum STATE {
- INITIAL, STARTED, DONE;
- }
-
- //////////////////////////////////////////////////
- // factories
-
- public static Odometer factoryScalar() {
- return new ScalarOdometer();
- }
-
- public static Odometer factory(List slices) throws DapException {
- return factory(slices, null);
- }
-
- public static Odometer factory(List slices, List dimset) throws DapException {
- // check for scalar case
- if (dimset != null && dimset.size() == 0) {
- if (!DapUtil.isScalarSlices(slices))
- throw new DapException("Cannot build scalar odometer with non-scalar slices");
- return factoryScalar();
- }
- boolean multi = false;
- if (slices != null) {
- for (int i = 0; i < slices.size(); i++) {
- if (slices.get(i).getSort() == Slice.Sort.Multi) {
- multi = true;
- break;
- }
- }
- }
- if (slices == null || slices.size() == 0)
- return factoryScalar();
- else if (multi)
- return new MultiOdometer(slices, dimset);
- else
- return new Odometer(slices, dimset);
- }
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected STATE state = STATE.INITIAL;
-
- protected boolean ismulti = false;
-
- protected int rank = 0;
- protected List slices = null;
- protected List dimset = null;
-
- // The current odometer indices
- protected Index index;
-
- // precompute this.slices[i].getLast() - this.slices[i].getStride()
- protected long[] endpoint;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public Odometer() {}
-
- public Odometer(List set) throws DapException {
- this(set, null);
- }
-
- public Odometer(List set, List dimset) throws DapException {
- if (set == null)
- throw new DapException("Null slice list");
- if (dimset != null && set.size() != dimset.size())
- throw new DapException("Rank mismatch");
- this.rank = set.size();
- if (this.rank == 0)
- throw new DapException("Rank == 0; use Scalar Odometer");
- this.slices = new ArrayList<>();
- this.slices.addAll(set);
- if (dimset != null) {
- this.dimset = new ArrayList<>();
- this.dimset.addAll(dimset);
- }
- this.endpoint = new long[this.rank];
- this.index = new Index(rank);
- for (int i = 0; i < this.rank; i++) {
- this.index.dimsizes[i] = slices.get(i).getMax();
- }
- reset();
- }
-
- protected void reset() {
- for (int i = 0; i < this.rank; i++) {
- try {
- slices.get(i).finish();
- this.index.indices[i] = this.slices.get(i).getFirst();
- this.endpoint[i] = this.slices.get(i).getLast() - this.slices.get(i).getStride();
- } catch (DapException de) {
- throw new IllegalArgumentException(de);
- }
- }
- }
-
- public String toString() {
- StringBuilder buf = new StringBuilder();
- for (int i = 0; i < rank; i++) {
- if (i > 0)
- buf.append(",");
- if (dimset != null)
- buf.append(dimset.get(i) != null ? dimset.get(i).getShortName() : "null");
- buf.append(this.slices.get(i).toString());
- buf.append(String.format("(%d)", this.slices.get(i).getCount()));
- if (this.index != null)
- buf.append(String.format("@%d", this.index.indices[i]));
- }
- return buf.toString();
- }
-
- //////////////////////////////////////////////////
- // Odometer API
-
- /**
- * Return odometer rank
- */
- public int rank() {
- return this.rank;
- }
-
- /**
- * Return ith slice
- */
- public Slice slice(int i) {
- if (i < 0 || i >= this.rank)
- throw new IllegalArgumentException();
- return this.slices.get(i);
- }
-
-
- public List getSlices() {
- return this.slices;
- }
-
- /**
- * Compute the linear index
- * from the current odometer indices.
- */
- public long index() {
- return index.index();
- }
-
- /**
- * Return current set of indices
- */
- public Index indices() {
- return this.index;
- }
-
- /**
- * Compute the total number of elements.
- */
- public long totalSize() {
- long size = 1;
- for (int i = 0; i < this.rank; i++) {
- size *= this.slices.get(i).getCount();
- }
- return size;
- }
-
- //////////////////////////////////////////////////
- // Iterator API
-
- @Override
- public boolean hasNext() {
- int stop = this.rank;
- switch (this.state) {
- case INITIAL:
- return true;
- case STARTED:
- int i;
- for (i = stop - 1; i >= 0; i--) { // walk backwards
- if (this.index.indices[i] <= this.endpoint[i])
- return true;
- }
- this.state = STATE.DONE;
- break;
- case DONE:
- }
- return false;
- }
-
- @Override
- public Index next() {
- int i;
- int lastpos = this.rank;
- int firstpos = 0;
- switch (this.state) {
- case INITIAL:
- this.state = STATE.STARTED;
- break;
- case STARTED:
- i = step(firstpos, lastpos);
- if (i < 0)
- this.state = STATE.DONE;
- break;
- case DONE:
- break;
- }
- if (this.state == STATE.DONE)
- throw new NoSuchElementException();
- return indices();
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- //////////////////////////////////////////////////
-
- // on entry: indices are the last index set
- // on exit, the indices are the next value
- // return index of place where we have room to step;
- // return -1 if we have completed.
- public int step(int firstpos, int lastpos) {
- for (int i = lastpos - 1; i >= firstpos; i--) { // walk backwards
- if (this.index.indices[i] > this.endpoint[i])
- this.index.indices[i] = this.slices.get(i).getFirst(); // reset this position
- else {
- this.index.indices[i] += this.slices.get(i).getStride(); // move to next indices
- return i;
- }
- }
- return -1;
- }
-
- public List getSubOdometers() {
- List list = new ArrayList<>();
- list.add(this);
- return list;
- }
-
- public boolean isMulti() {
- return this.ismulti;
- }
-
-
-}
diff --git a/dap4/d4core/src/main/java/dap4/core/util/ScalarOdometer.java b/dap4/d4core/src/main/java/dap4/core/util/ScalarOdometer.java
deleted file mode 100644
index bafc9a5436..0000000000
--- a/dap4/d4core/src/main/java/dap4/core/util/ScalarOdometer.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.core.util;
-
-import java.util.NoSuchElementException;
-
-/**
- * A implementation of an odometer for scalar variables.
- */
-
-public class ScalarOdometer extends Odometer {
- //////////////////////////////////////////////////
- // Constants
-
- public ScalarOdometer() {
- this.state = STATE.INITIAL;
- this.index = new Index(0);
- this.slices = Slice.SCALARSLICES;
- }
-
- public long index() {
- return 0;
- }
-
- public long totalSize() {
- return 1;
- }
-
- public boolean hasNext() {
- return this.state != STATE.DONE;
- }
-
- public Index next() {
- if (this.state == STATE.DONE)
- throw new NoSuchElementException();
- this.state = STATE.DONE;
- return Index.SCALAR;
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/dap4/d4lib/build.gradle b/dap4/d4lib/build.gradle
deleted file mode 100644
index 0c84380c55..0000000000
--- a/dap4/d4lib/build.gradle
+++ /dev/null
@@ -1,16 +0,0 @@
-apply from: "$rootDir/gradle/any/dependencies.gradle"
-apply from: "$rootDir/gradle/any/java-library.gradle"
-
-dependencies {
- api enforcedPlatform(project(':netcdf-java-platform'))
-
- compile project(':dap4:d4core')
- compile project(':httpservices')
- compile project(':netcdf4')
-
- compile 'org.apache.httpcomponents:httpclient'
- compile 'org.apache.httpcomponents:httpcore'
- compile 'net.java.dev.jna:jna'
- compile 'com.beust:jcommander'
- compile 'org.slf4j:slf4j-api'
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/AbstractCursor.java b/dap4/d4lib/src/main/java/dap4/dap4lib/AbstractCursor.java
deleted file mode 100644
index c98c51c763..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/AbstractCursor.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib;
-
-import dap4.core.data.DSP;
-import dap4.core.data.DataCursor;
-import dap4.core.dmr.DapNode;
-import dap4.core.dmr.DapStructure;
-import dap4.core.dmr.DapType;
-import dap4.core.dmr.DapVariable;
-import dap4.core.util.DapException;
-import dap4.core.util.DapSort;
-import dap4.core.util.Index;
-import dap4.core.util.Slice;
-import java.util.List;
-
-public abstract class AbstractCursor implements DataCursor {
- //////////////////////////////////////////////////
- // Constants
-
- //////////////////////////////////////////////////
- // Instance Variables
-
- protected Scheme scheme;
-
- protected DSP dsp;
- protected DapNode template;
-
- protected Index arrayindex = null;
- protected long recordindex = -1; // scheme == record
-
- protected AbstractCursor container = null;
-
- protected long recordcount = -1;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public AbstractCursor(Scheme scheme, DSP dsp, DapNode template, AbstractCursor container) {
- setScheme(scheme);
- setDSP(dsp);
- setTemplate(template);
- setContainer(container);
- }
-
- public AbstractCursor(AbstractCursor orig) {
- this(orig.getScheme(), orig.getDSP(), orig.getTemplate(), (AbstractCursor) orig.getContainer());
- }
-
-
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append(getScheme().toString());
- if (getScheme() == Scheme.STRUCTARRAY || getScheme() == Scheme.SEQARRAY)
- buf.append("[]");
- buf.append(":");
- buf.append(getTemplate().toString());
- if (this.arrayindex != null) {
- buf.append("::");
- buf.append(this.arrayindex.toString());
- }
- if (this.recordindex >= 0) {
- buf.append("*");
- buf.append(this.recordindex);
- }
- return buf.toString();
- }
-
- //////////////////////////////////////////////////
- // Unimplemented DataCursor API methods
-
- @Override
- public abstract Object read(List slices) throws DapException;
-
- @Override
- public abstract Object read(Index index) throws DapException;
-
- @Override
- public abstract AbstractCursor readRecord(long i) throws DapException;
-
- @Override
- public abstract AbstractCursor readField(int fieldindex) throws DapException;
-
- //////////////////////////////////////////////////
- // Selected DataCursor API overrides
-
- @Override
- public int fieldIndex(String name) throws DapException {
- DapStructure ds;
- if (getTemplate().getSort().isCompound())
- ds = (DapStructure) getTemplate();
- else if (getTemplate().getSort().isVar() && (((DapVariable) getTemplate()).getBaseType().getSort().isCompound()))
- ds = (DapStructure) ((DapVariable) getTemplate()).getBaseType();
- else
- throw new DapException("Attempt to get field name on non-compound object");
- int i = ds.indexByName(name);
- if (i < 0)
- throw new DapException("Unknown field name: " + name);
- return i;
- }
-
- @Override
- public Scheme getScheme() {
- return this.scheme;
- }
-
- @Override
- public DSP getDSP() {
- return this.dsp;
- }
-
- @Override
- public DapNode getTemplate() {
- return this.template;
- }
-
- @Override
- public Index getIndex() throws DapException {
- if (this.scheme != Scheme.STRUCTURE && this.scheme != Scheme.SEQUENCE)
- throw new DapException("Not a Sequence|Structure instance");
- return this.arrayindex;
- }
-
- @Override
- public long getRecordIndex() throws DapException {
- if (this.scheme != Scheme.RECORD)
- throw new DapException("Not a Record instance");
- return this.recordindex;
- }
-
- @Override
- public long getRecordCount() throws DapException {
- if (this.scheme != Scheme.SEQUENCE)
- throw new DapException("Not a SEQUENCE instance");
- return this.recordcount;
- }
-
-
- @Override
- public AbstractCursor getContainer() {
- return this.container;
- }
-
- @Override
- public boolean isScalar() {
- if (getTemplate().getSort().isVar()) {
- return ((DapVariable) getTemplate()).getRank() == 0;
- } else
- return false;
- }
-
- public boolean isField() {
- return getTemplate().getContainer() != null;
- }
-
- public boolean isAtomic() {
- boolean is = this.scheme == Scheme.ATOMIC;
- assert !is || getTemplate().getSort() == DapSort.ATOMICTYPE || (getTemplate().getSort() == DapSort.VARIABLE
- && ((DapVariable) getTemplate()).getBaseType().getTypeSort().isAtomic());
- return is;
- }
-
- public boolean isCompound() {
- boolean is = (this.scheme == Scheme.SEQUENCE || this.scheme == Scheme.STRUCTURE);
- assert !is || getTemplate().getSort() == DapSort.SEQUENCE || getTemplate().getSort() == DapSort.STRUCTURE
- || (getTemplate().getSort() == DapSort.VARIABLE
- && ((DapVariable) getTemplate()).getBaseType().getTypeSort().isCompoundType());
- return is;
- }
-
- public boolean isCompoundArray() {
- boolean is = (this.scheme == Scheme.SEQARRAY || this.scheme == Scheme.STRUCTARRAY);
- assert !is || getTemplate().getSort() == DapSort.SEQUENCE || getTemplate().getSort() == DapSort.STRUCTURE
- || (getTemplate().getSort() == DapSort.VARIABLE
- && ((DapVariable) getTemplate()).getBaseType().getTypeSort().isCompoundType());
- return is;
- }
-
- //////////////////////////////////////////////////
- // AbstractCursor extensions
-
- public AbstractCursor setIndex(Index index) {
- this.arrayindex = index;
- return this;
- }
-
- public AbstractCursor setRecordIndex(long index) {
- this.recordindex = index;
- return this;
- }
-
- public AbstractCursor setRecordCount(long count) {
- this.recordcount = count;
- return this;
- }
-
- public AbstractCursor setContainer(AbstractCursor container) {
- this.container = container;
- return this;
- }
-
- public AbstractCursor setScheme(Scheme scheme) {
- this.scheme = scheme;
- return this;
- }
-
-
- public AbstractCursor setDSP(DSP dsp) {
- this.dsp = dsp;
- return this;
- }
-
- public AbstractCursor setTemplate(DapNode template) {
- this.template = template;
- return this;
- }
-
-
- //////////////////////////////////////////////////
- // Utilities
-
- public static Scheme schemeFor(DapVariable field) {
- DapType ftype = field.getBaseType();
- Scheme scheme = null;
- boolean isscalar = field.getRank() == 0;
- if (ftype.getTypeSort().isAtomic())
- scheme = Scheme.ATOMIC;
- else {
- if (ftype.getTypeSort().isStructType())
- scheme = Scheme.STRUCTARRAY;
- else if (ftype.getTypeSort().isSeqType())
- scheme = Scheme.SEQARRAY;
- }
- return scheme;
- }
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/AbstractDSP.java b/dap4/d4lib/src/main/java/dap4/dap4lib/AbstractDSP.java
deleted file mode 100644
index ce17c50a3d..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/AbstractDSP.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib;
-
-import dap4.core.data.ChecksumMode;
-import dap4.core.data.DSP;
-import dap4.core.data.DataCursor;
-import dap4.core.dmr.DapAttribute;
-import dap4.core.dmr.DapDataset;
-import dap4.core.dmr.DapNode;
-import dap4.core.dmr.DapVariable;
-import dap4.core.dmr.parser.DOM4Parser;
-import dap4.core.dmr.parser.Dap4Parser;
-import dap4.core.util.DapContext;
-import dap4.core.util.DapException;
-import dap4.core.util.DapUtil;
-import org.xml.sax.SAXException;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.nio.ByteOrder;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Provide a superclass for DSPs.
- */
-
-public abstract class AbstractDSP implements DSP {
- public static boolean TESTING = false; /* Turned on by test programs */
-
- //////////////////////////////////////////////////
- // constants
-
- protected static final boolean DEBUG = false;
- protected static final boolean PARSEDEBUG = false;
-
- public static final boolean USEDOM = false;
-
- protected static final String DAPVERSION = "4.0";
- protected static final String DMRVERSION = "1.0";
- protected static final String DMRNS = "http://xml.opendap.org/ns/DAP/4.0#";
-
- // Define reserved attributes
- public static final String UCARTAGVLEN = "_edu.ucar.isvlen";
- public static final String UCARTAGOPAQUE = "_edu.ucar.opaque.size";
- public static final String UCARTAGORIGTYPE = "_edu.ucar.orig.type";
- public static final String UCARTAGUNLIMITED = "_edu.ucar.isunlimited";
-
-
- protected DapContext context = null;
- protected DapDataset dmr = null;
- protected String location = null;
- private ByteOrder order = null;
- private ChecksumMode checksummode = ChecksumMode.DAP;
-
- protected Map variables = new HashMap<>();
- protected DataCursor rootcursor = null;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public AbstractDSP() /* must have a parameterless constructor */
- {}
-
- //////////////////////////////////////////////////
- // DSP Interface
-
- // Subclass defined
-
- /**
- * "open" a reference to a data source and return the DSP wrapper.
- *
- * @param location - Object that defines the data source
- * @return = wrapping dsp
- * @throws DapException
- */
- @Override
- public abstract AbstractDSP open(String location) throws DapException;
-
- /**
- * @throws IOException
- */
- public abstract void close() throws IOException;
-
- //////////////////////////////////////////////////
- // Implemented
-
- @Override
- public DataCursor getVariableData(DapVariable var) throws DapException {
- return this.variables.get(var);
- }
-
- @Override
- public DapContext getContext() {
- return this.context;
- }
-
- @Override
- public String getLocation() {
- return this.location;
- }
-
- @Override
- public AbstractDSP setLocation(String loc) {
- this.location = loc;
- return this;
- }
-
- @Override
- public DapDataset getDMR() {
- return this.dmr;
- }
-
- // DSP Extensions
-
- @Override
- public void setContext(DapContext context) {
- this.context = context;
- // Extract some things from the context
- Object o = this.context.get(Dap4Util.DAP4ENDIANTAG);
- if (o != null)
- setOrder((ByteOrder) o);
- o = this.context.get(Dap4Util.DAP4CSUMTAG);
- if (o != null)
- setChecksumMode(ChecksumMode.modeFor(o.toString()));
- }
-
- public void setDMR(DapDataset dmr) {
- this.dmr = dmr;
- if (getDMR() != null) {
- // Add some canonical attributes to the
- getDMR().setDataset(getDMR());
- getDMR().setDapVersion(DAPVERSION);
- getDMR().setDMRVersion(DMRVERSION);
- getDMR().setNS(DMRNS);
- }
- }
-
- protected void setDataset(DapDataset dataset) throws DapException {
- this.dmr = dataset;
- }
-
- public ByteOrder getOrder() {
- return this.order;
- }
-
- public AbstractDSP setOrder(ByteOrder order) {
- this.order = order;
- return this;
- }
-
- public ChecksumMode getChecksumMode() {
- return this.checksummode;
- }
-
- public AbstractDSP setChecksumMode(ChecksumMode mode) {
- if (mode != null)
- this.checksummode = mode;
- return this;
- }
-
- public void addVariableData(DapVariable var, DataCursor cursor) {
- this.variables.put(var, cursor);
- }
-
- //////////////////////////////////////////////////
- // Utilities
-
- /**
- * It is common to want to parse a DMR text to a DapDataset,
- * so provide this utility.
- *
- * @param document the dmr to parse
- * @return the parsed dmr
- * @throws DapException on parse errors
- */
-
- protected DapDataset parseDMR(String document) throws DapException {
- // Parse the dmr
- Dap4Parser parser;
- // if(USEDOM)
- parser = new DOM4Parser(null);
- // else
- // parser = new DOM4Parser(new DefaultDMRFactory());
- if (PARSEDEBUG)
- parser.setDebugLevel(1);
- try {
- if (!parser.parse(document))
- throw new DapException("DMR Parse failed");
- } catch (SAXException se) {
- throw new DapException(se);
- }
- if (parser.getErrorResponse() != null)
- throw new DapException("Error Response Document not supported");
- DapDataset result = parser.getDMR();
- processAttributes(result);
- return result;
- }
-
- /**
- * Walk the dataset tree and remove selected attributes
- * such as _Unsigned
- *
- * @param dataset
- */
- protected void processAttributes(DapDataset dataset) throws DapException {
- List nodes = dataset.getNodeList();
- for (DapNode node : nodes) {
- switch (node.getSort()) {
- case GROUP:
- case DATASET:
- case VARIABLE:
- Map attrs = node.getAttributes();
- if (attrs.size() > 0) {
- List suppressed = new ArrayList<>();
- for (DapAttribute dattr : attrs.values()) {
- if (suppress(dattr.getShortName()))
- suppressed.add(dattr);
- }
- for (DapAttribute dattr : suppressed) {
- node.removeAttribute(dattr);
- }
- }
- break;
- default:
- break; /* ignore */
- }
- }
- // Try to extract the byte order
- getEndianAttribute(dataset);
- }
-
- /**
- * Some attributes that are added by the NetcdfDataset
- * need to be kept out of the DMR. This function
- * defines that set.
- *
- * @param attrname A non-escaped attribute name to be tested for suppression
- * @return true if the attribute should be suppressed, false otherwise.
- */
-
- protected boolean suppress(String attrname) {
- if (attrname.startsWith("_Coord"))
- return true;
- if (attrname.equals("_Unsigned"))
- return true;
- return false;
- }
-
- void getEndianAttribute(DapDataset dataset) {
- DapAttribute a = dataset.findAttribute(DapUtil.LITTLEENDIANATTRNAME);
- if (a == null)
- this.order = (ByteOrder.LITTLE_ENDIAN);
- else {
- Object v = a.getValues();
- int len = java.lang.reflect.Array.getLength(v);
- if (len == 0)
- this.order = (ByteOrder.nativeOrder());
- else {
- String onezero = java.lang.reflect.Array.get(v, 0).toString();
- int islittle = 1;
- try {
- islittle = Integer.parseInt(onezero);
- } catch (NumberFormatException e) {
- islittle = 1;
- }
- if (islittle == 0)
- this.order = (ByteOrder.BIG_ENDIAN);
- else
- this.order = (ByteOrder.LITTLE_ENDIAN);
- }
- }
- }
-
- public static String printDMR(DapDataset dmr) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- DMRPrinter printer = new DMRPrinter(dmr, pw);
- try {
- printer.print();
- pw.close();
- sw.close();
- } catch (IOException e) {
- }
- return sw.toString();
- }
-
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/ChunkInputStream.java b/dap4/d4lib/src/main/java/dap4/dap4lib/ChunkInputStream.java
deleted file mode 100644
index bb03247809..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/ChunkInputStream.java
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib;
-
-import dap4.core.util.DapException;
-import dap4.core.util.DapUtil;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-/**
- * This class wraps a chunked source of databuffer
- * as an InputStream. It is mostly pass-thru
- * in the sense that reads on this class are
- * turned into a series of reads of the underlying stream.
- */
-
-public class ChunkInputStream extends InputStream {
- //////////////////////////////////////////////////
- // Constants
-
- static final int DFALTCHUNKSIZE = 0x00FFFFFF;
-
- static final byte CR8 = DapUtil.extract(DapUtil.UTF8.encode("\r"))[0];
- static final byte LF8 = DapUtil.extract(DapUtil.UTF8.encode("\n"))[0];
-
- //////////////////////////////////////////////////
- // Type Decls
-
- //////////////////////////////////////////////////
- // static variables
-
- //////////////////////////////////////////////////
- // static methods
-
- //////////////////////////////////////////////////
- // Type declarations
-
- enum State {
- ERROR, // after error chunk
- END, // after last databuffer chunk
- DATA, // when at start of a databuffer chunk
- INDATA, // when reading a databuffer chunk
- INITIAL; // before anything is written
- }
-
- //////////////////////////////////////////////////
- // Instance variable
-
- protected InputStream input = null;
- protected State state = State.INITIAL;
- protected RequestMode requestmode = null;
-
- protected ByteOrder localorder = null;
- protected ByteOrder remoteorder = null;
- protected boolean nochecksum = false;
-
- // State info for current chunk
- protected int flags = 0;
- protected int chunksize = 0;
- protected int avail = 0;
-
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public ChunkInputStream(InputStream input, RequestMode requestmode) {
- this(input, requestmode, ByteOrder.nativeOrder());
- }
-
- public ChunkInputStream(InputStream input, RequestMode requestmode, ByteOrder order) {
- this.input = input;
- this.requestmode = requestmode;
- this.localorder = order;
- }
-
- //////////////////////////////////////////////////
- // Accessors
-
- public ByteOrder getHostByteOrder() {
- return this.localorder;
- }
-
- public ByteOrder getRemoteByteOrder() {
- return this.remoteorder;
- }
-
- public boolean getNoChecksum() {
- return this.nochecksum;
- }
-
- //////////////////////////////////////////////////
-
- /**
- * Read the DMR, trimmed.
- *
- * @return the DMR as a Java String
- */
-
- public String readDMR() throws DapException {
- try {
- if (state != State.INITIAL)
- throw new DapException("Attempt to read DMR twice");
-
- byte[] dmr8 = null;
-
- if (requestmode == RequestMode.DMR) {
- // The whole buffer is the dmr;
- // but we do not know the length
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- int c;
- while ((c = input.read()) >= 0) {
- baos.write(c);
- }
- baos.close();
- dmr8 = baos.toByteArray();
- } else if (requestmode == RequestMode.DAP) {
- // Pull in the DMR chunk header
- if (!readHeader(input))
- throw new DapException("Malformed chunk count");
- // Read the DMR databuffer
- dmr8 = new byte[this.chunksize];
- int red = read(dmr8, 0, this.chunksize);
- if (red < this.chunksize)
- throw new DapException("Short chunk");
- } else
- assert false : "Internal error";
-
- // Convert DMR to a string
- String dmr = new String(dmr8, DapUtil.UTF8);
- // Clean it up
- dmr = dmr.trim();
- // Make sure it has trailing \r\n"
- if (dmr.endsWith("\r\n")) {
- // do nothing
- } else if (dmr.endsWith("\n"))
- dmr = dmr.substring(0, dmr.length() - 2) + "\r\n";
- else
- dmr = dmr + "\r\n";
-
- // Figure out the endian-ness of the response
- this.remoteorder = (flags & DapUtil.CHUNK_LITTLE_ENDIAN) == 0 ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
- this.nochecksum = (flags & DapUtil.CHUNK_NOCHECKSUM) != 0;
-
- // Set the state
- if ((flags & DapUtil.CHUNK_ERROR) != 0)
- state = State.ERROR;
- else if ((flags & DapUtil.CHUNK_END) != 0)
- state = State.END;
- else
- state = State.DATA;
- return dmr; // return the DMR
-
- } catch (IOException ioe) {
- throw new DapException(ioe.getMessage());
- }
- }
-
- /**
- * Convert an error chunk to an exception
- *
- * @param document XML representation of the error
- * @throws DapException containing the contents of the error chunk
- */
- public void throwError(String document) throws ErrorException {
- throw new ErrorException("Error chunk encountered").setDocument(document);
- }
-
- /**
- * Read an error chunk
- *
- * @return the error document as a string
- */
- public String readError() throws IOException {
- state = State.ERROR;
- // Read the error body databuffer
- byte[] bytes = new byte[this.chunksize];
- try {
- if (read(bytes, 0, this.chunksize) < this.chunksize)
- throw new ErrorException("Short chunk");
- } catch (IOException ioe) {
- throw new ErrorException(ioe);
- }
- String document = new String(bytes, DapUtil.UTF8);
- return document;
- }
-
- //////////////////////////////////////////////////
- // InputStream abstract methods
-
- /**
- * Reads the next byte of databuffer from the input stream. The value byte is
- * returned as an int in the range 0 to
- * 255. If no byte is available because the end of the stream
- * has been reached, the value -1 is returned. This method
- * blocks until input databuffer is available, the end of the stream is detected,
- * or an exception is thrown.
- *
- * Operates by loading chunk by chunk. If an error chunk is detected,
- * then return ErrorException (which is a subclass of IOException).
- *
- * @return the next byte of databuffer, or -1 if the end of the
- * stream is reached.
- * @throws IOException if an I/O error occurs.
- */
- public int read() throws IOException {
- if (requestmode == RequestMode.DMR)
- throw new UnsupportedOperationException("Attempt to read databuffer when DMR only"); // Runtime
- if (avail <= 0) {
- if ((flags & DapUtil.CHUNK_END) != 0)
- return -1; // Treat as EOF
- if (!readHeader(input))
- return -1; // EOF
- // See if we have an error chunk,
- // and if so, turn it into an exception
- if ((flags & DapUtil.CHUNK_ERROR) != 0) {
- String document = readError();
- throwError(document);
- }
- }
- avail--;
- return input.read();
- }
-
- //////////////////////////////////////////////////
- // InputStream method overrides
-
- /**
- * Reads up to len databuffer of databuffer from the input stream into an
- * array of databuffer. An attempt is made to read as many as len
- * databuffer, but a smaller number may be read. The number of databuffer
- * actually read is returned as an integer.
- *
- * @param buf the byte array into which databuffer is read
- * @param off the offset in the byte array at which to write
- * @param len the amount to read
- * @return the actual number of databuffer read
- * @throws IOException
- */
-
- public int read(byte[] buf, int off, int len) throws IOException {
- // Sanity check
- if (off < 0 || len < 0)
- throw new IndexOutOfBoundsException();// Runtime
- if (off >= buf.length || buf.length < (off + len))
- throw new IndexOutOfBoundsException(); // Runtime
- if (requestmode == RequestMode.DMR)
- throw new UnsupportedOperationException("Attempt to read databuffer when DMR only"); // Runtime
-
- // Attempt to read len bytes out of a sequence of chunks
- int count = len;
- int pos = off;
- while (count > 0) {
- if (avail <= 0) {
- if ((flags & DapUtil.CHUNK_END) != 0 || !readHeader(input))
- return (len - count); // return # databuffer read
- // See if we have an error chunk,
- // and if so, turn it into an exception
- if ((flags & DapUtil.CHUNK_ERROR) != 0) {
- String document = readError();
- throwError(document);
- }
- } else {
- int actual = (this.avail < count ? this.avail : count);
- int red = input.read(buf, pos, actual);
- if (red < 0)
- throw new IOException("Unexpected EOF");
- pos += red;
- count -= red;
- this.avail -= red;
- }
- }
- return len;
- }
-
- /**
- * Returns an estimate of the number of databuffer that can be read
- * (or skipped over) from this input stream without
- * blocking by the next invocation of a method for this
- * input stream.
- *
- * Repurposed here to do equivalent of peek().
- *
- * @return 0 if at eof, some number > 0 otherwise.
- */
-
- public int available() {
- if (this.avail > 0)
- return this.avail;
- if ((flags & DapUtil.CHUNK_END) != 0)
- return 0;
- return 1; // should be some unknown amount left.
- }
-
- /**
- * Closes this output stream and releases any system resources
- * associated with this stream. The underlying servlet stream is
- * not closed; that is left to the level above.
- */
-
- public void close() throws IOException {
- state = State.END;
- }
-
- //////////////////////////////////////////////////
- // Utilities
-
- /**
- * Read the size+flags header from the input stream and use it to
- * initialize the chunk state
- *
- * @param input The input streamfrom which to read
- * @return true if header read false if immediate eof encountered
- */
-
- boolean readHeader(InputStream input) throws IOException {
- byte[] bytehdr = new byte[4];
- int red = input.read(bytehdr);
- if (red == -1)
- return false;
- if (red < 4)
- throw new IOException("Short binary chunk count");
- this.flags = ((int) bytehdr[0]) & 0xFF; // Keep unsigned
- bytehdr[0] = 0;
- ByteBuffer buf = ByteBuffer.wrap(bytehdr).order(ByteOrder.BIG_ENDIAN);
- this.chunksize = buf.getInt();
- this.avail = this.chunksize;
- return true;
- }
-
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/DSPPrinter.java b/dap4/d4lib/src/main/java/dap4/dap4lib/DSPPrinter.java
deleted file mode 100644
index daa41e15a8..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/DSPPrinter.java
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-package dap4.dap4lib;
-
-import dap4.core.ce.CEConstraint;
-import dap4.core.data.DSP;
-import dap4.core.data.DataCursor;
-import dap4.core.dmr.*;
-import dap4.core.util.*;
-import java.io.PrintWriter;
-import java.io.Writer;
-import java.lang.reflect.Array;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.util.EnumSet;
-import java.util.List;
-
-/**
- * DAP DSP Printer.
- * Given a constraint and a DSP print the constrained
- * subset of the data in text form.
- */
-
-public class DSPPrinter {
- //////////////////////////////////////////////////
- // Printer Control flags
-
- public enum Flags {
- CONTROLCHAR;
- }
-
- //////////////////////////////////////////////////
- // Constants
-
- protected static final int COLUMNS = 8;
-
- protected static final char LPAREN = '(';
- protected static final char RPAREN = ')';
- protected static final char LBRACE = '{';
- protected static final char RBRACE = '}';
- protected static final char LBRACKET = '[';
- protected static final char RBRACKET = ']';
-
- // Could use enumset, but it is so ugly,
- // so use good old OR'able flags
- protected static final int NILFLAGS = 0;
- protected static final int PERLINE = 1; // print xml attributes 1 per line
- protected static final int NONAME = 2; // do not print name xml attribute
- protected static final int NONNIL = 4; // print empty xml attributes
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected PrintWriter writer = null;
- protected IndentWriter printer = null;
-
- protected DSP dsp = null;
- protected CEConstraint ce = null;
-
- protected EnumSet flags = EnumSet.noneOf(Flags.class);
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- protected DSPPrinter() {}
-
- public DSPPrinter(DSP dsp, Writer writer) {
- this(dsp, null, writer);
- }
-
- public DSPPrinter(DSP dsp, CEConstraint ce, Writer writer) {
- this.dsp = dsp;
- this.ce = ce;
- this.writer = new PrintWriter(writer);
- this.printer = new IndentWriter(this.writer);
- }
-
- //////////////////////////////////////////////////
- // External API
-
- public DSPPrinter flag(Flags flag) {
- this.flags.add(flag);
- return this;
- }
-
- public DSPPrinter flush() {
- this.printer.flush();
- return this;
- }
-
- public DSPPrinter close() {
- this.flush();
- return this;
- }
-
- /**
- * Print data from a DSP
- * - optionally constrained
- *
- * @throws DapException
- */
-
- public DSPPrinter print() throws DapException {
- DapDataset dmr = this.dsp.getDMR();
- if (this.ce == null)
- this.ce = CEConstraint.getUniversal(dmr);
- this.printer.setIndent(0);
- List topvars = dmr.getTopVariables();
- for (int i = 0; i < topvars.size(); i++) {
- DapVariable top = topvars.get(i);
- List slices = this.ce.getConstrainedSlices(top);
- if (this.ce.references(top)) {
- DataCursor data = dsp.getVariableData(top);
- printVariable(data, slices);
- }
- }
- printer.eol();
- return this;
- }
-
- //////////////////////////////////////////////////
-
- /**
- * Print an arbitrary DataVariable using a constraint.
- *
- * Handling newlines is a bit tricky
- * so the rule is that the
- * last newline is elided and left
- * for the caller to print.
- * Exceptions: ?
- *
- * @param data - the cursor to print
- * @throws DapException Note that the PrintWriter and CEConstraint are global.
- */
-
- protected void printVariable(DataCursor data, List slices) throws DapException {
- DapVariable dapv = (DapVariable) data.getTemplate();
- if (data.isScalar()) {
- assert slices == Slice.SCALARSLICES;
- printScalar(data);
- } else {// not scalar
- printArray(data, slices);
- }
- }
-
- protected void printScalar(DataCursor data) throws DapException {
- DapVariable dapv = (DapVariable) data.getTemplate();
- printer.marginPrint(dapv.getFQN() + " = ");
- switch (data.getScheme()) {
- case ATOMIC:
- printAtomicInstance(data, Index.SCALAR);
- break;
- case STRUCTARRAY:
- case SEQARRAY: // remember that scalars are treated as 1-element arrays
- DataCursor[] scalar = (DataCursor[]) data.read(Index.SCALAR);
- assert scalar.length == 1;
- data = scalar[0]; // fall thru
- case STRUCTURE:
- case SEQUENCE:
- case RECORD:
- printer.marginPrint("{");
- printer.eol();
- printer.indent();
- printCompoundInstance(data);
- printer.outdent();
- printer.marginPrint("}");
- printer.eol();
- break;
- default:
- throw new DapException("Unexpected data cursor type: " + data.getScheme());
- }
- }
-
- protected void printArray(DataCursor data, List slices) throws DapException {
- DapVariable dapv = (DapVariable) data.getTemplate();
- Odometer odom = Odometer.factory(slices);
- switch (data.getScheme()) {
- case ATOMIC:
- if (DapUtil.isContiguous(slices))
- printAtomicVector(data, slices, odom);
- else {
- while (odom.hasNext()) {
- Index pos = odom.next();
- String s = indicesToString(pos);
- printer.marginPrint(dapv.getFQN() + s + " = ");
- printAtomicInstance(data, pos);
- }
- }
- break;
- case STRUCTARRAY:
- case SEQARRAY:
- DapStructure ds = (DapStructure) ((DapVariable) data.getTemplate()).getBaseType();
- DataCursor[] instances = (DataCursor[]) data.read(slices);
- while (odom.hasNext()) {
- Index pos = odom.next();
- String s = indicesToString(pos);
- printer.marginPrint(ds.getFQN() + s + " = {");
- printer.eol();
- printer.indent();
- printCompoundInstance(instances[(int) pos.index()]);
- printer.outdent();
- printer.marginPrint("}");
- printer.eol();
- }
- break;
- default:
- throw new DapException("Unexpected data cursor type: " + data.getScheme());
- }
- }
-
- protected void printAtomicVector(DataCursor data, List slices, Odometer odom) throws DapException {
- assert data.getScheme() == DataCursor.Scheme.ATOMIC;
- Object values = data.read(slices);
- DapVariable atom = (DapVariable) data.getTemplate();
- String name = atom.getFQN();
- if (Array.getLength(values) == 0) {// zero length case
- printer.marginPrint(name + " = ");
- printer.eol();
- } else
- for (int i = 0; odom.hasNext(); i++) {
- Index index = odom.next();
- String prefix = (odom.rank() == 0 ? name : name + indicesToString(index));
- printer.marginPrint(prefix + " = ");
- printer.print(valueString(values, i, atom.getBaseType()));
- printer.eol();
- }
- }
-
- protected void printAtomicInstance(DataCursor datav, Index pos) throws DapException {
- assert datav.getScheme() == DataCursor.Scheme.ATOMIC;
- Object value = datav.read(pos);
- DapVariable av = (DapVariable) datav.getTemplate();
- printer.print(valueString(value, 0, av.getBaseType()));
- printer.eol();
- }
-
- /**
- * Print a single structure or sequence or record instance
- *
- * @param datav
- * @throws DapException
- */
- protected void printCompoundInstance(DataCursor datav) throws DapException {
- // Index index = datav.getIndex();
- DapStructure dstruct = (DapStructure) ((DapVariable) datav.getTemplate()).getBaseType();
- switch (datav.getScheme()) {
- case STRUCTURE:
- case RECORD:
- List dfields = dstruct.getFields();
- for (int f = 0; f < dfields.size(); f++) {
- DapVariable field = dfields.get(f);
- List fieldslices = this.ce.getConstrainedSlices(field);
- DataCursor fdata = datav.readField(f);
- printVariable(fdata, fieldslices);
- }
- break;
-
- case SEQUENCE:
- DapSequence dseq = (DapSequence) dstruct;
- long count = datav.getRecordCount();
- for (long r = 0; r < count; r++) {
- DataCursor dr = datav.readRecord(r);
- printer.marginPrint("[");
- printer.eol();
- printer.indent();
- printCompoundInstance(dr);
- printer.outdent();
- printer.marginPrint("]");
- }
- break;
- default:
- throw new DapException("Unexpected data cursor scheme:" + datav.getScheme());
- }
- }
-
- protected String indicesToString(Index indices) throws DapException {
- StringBuilder buf = new StringBuilder();
- if (indices != null && indices.getRank() > 0) {
- for (int i = 0; i < indices.getRank(); i++) {
- buf.append(i == 0 ? LBRACKET : ",");
- buf.append(String.format("%d", indices.get(i)));
- }
- buf.append(RBRACKET);
- }
- return buf.toString();
- }
-
- protected String valueString(Object vector, long pos, DapType basetype) throws DapException {
- if (vector == null)
- return "null";
- TypeSort atype = basetype.getTypeSort();
- boolean unsigned = atype.isUnsigned();
- int ipos = (int) pos;
- switch (atype) {
- case Int8:
- case UInt8:
- long lvalue = ((byte[]) vector)[ipos];
- if (unsigned)
- lvalue &= 0xFFL;
- return String.format("%d", lvalue);
- case Int16:
- case UInt16:
- lvalue = ((short[]) vector)[ipos];
- if (unsigned)
- lvalue &= 0xFFFFL;
- return String.format("%d", lvalue);
- case Int32:
- case UInt32:
- lvalue = ((int[]) vector)[ipos];
- if (unsigned)
- lvalue &= 0xFFFFFFFFL;
- return String.format("%d", lvalue);
- case Int64:
- case UInt64:
- lvalue = ((long[]) vector)[ipos];
- if (unsigned) {
- BigInteger b = BigInteger.valueOf(lvalue);
- b = b.and(DapUtil.BIG_UMASK64);
- return b.toString();
- } else
- return String.format("%d", lvalue);
- case Float32:
- return String.format("%f", ((float[]) vector)[ipos]);
- case Float64:
- return String.format("%f", ((double[]) vector)[ipos]);
- case Char:
- return String.format("'%c'", ((char[]) vector)[ipos]);
- case String:
- case URL:
- String s = (((String[]) vector)[ipos]);
- if (flags.contains(Flags.CONTROLCHAR)) {
- s = s.replace("\r", "\\r");
- s = s.replace("\n", "\\n");
- s = s.replace("\t", "\\t");
- }
- return "\"" + s + "\"";
- case Opaque:
- ByteBuffer opaque = ((ByteBuffer[]) vector)[ipos];
- StringBuilder buf = new StringBuilder();
- buf.append("0x");
- for (int i = 0; i < opaque.limit(); i++) {
- byte b = opaque.get(i);
- char c = hexchar((b >> 4) & 0xF);
- buf.append(c);
- c = hexchar((b) & 0xF);
- buf.append(c);
- }
- return buf.toString();
- case Enum:
- DapEnumeration de = (DapEnumeration) basetype;
- Object newvec = CoreTypeFcns.createVector(de.getBaseType().getTypeSort(), 1);
- Object v = java.lang.reflect.Array.get(vector, ipos);
- java.lang.reflect.Array.set(newvec, 0, v);
- long[] lv = (long[]) Convert.convert(DapType.INT64, de, newvec);
- DapEnumConst dec = de.lookup(lv[0]);
- return dec.getShortName();
- default:
- break;
- }
- throw new DapException("Unknown type: " + basetype);
- }
-
-
- //////////////////////////////////////////////////
- // Misc. Utilities
-
- protected static char hexchar(int i) {
- return "0123456789ABCDEF".charAt((i & 0xF));
- }
-
-
- protected static String getPrintValue(Object value) {
- if (value instanceof String) {
- return Escape.entityEscape((String) value, null);
- } else
- return value.toString();
- }
-
-}
-
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/Dap4Util.java b/dap4/d4lib/src/main/java/dap4/dap4lib/Dap4Util.java
deleted file mode 100644
index 557a1ba76b..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/Dap4Util.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib;
-
-/**
- * Constants and utilities
- * either top-level or for a member.
- */
-
-public abstract class Dap4Util {
- /////////////////////////////////////////////////////
- // Constants
-
- public static final String DAP4ENDIANTAG = "ucar.littleendian"; // value = 1 | 0
- public static final String DAP4CSUMTAG = "ucar.checksummode"; // value = NONE|DAP|DMR|ALL
- public static final String DAP4TESTTAG = "ucar.testing"; // value = NONE|DAP|DMR|ALL
-
- //////////////////////////////////////////////////
- // Static utility methods
-
-
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/DapProtocol.java b/dap4/d4lib/src/main/java/dap4/dap4lib/DapProtocol.java
deleted file mode 100644
index 8436fa464d..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/DapProtocol.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib;
-
-import dap4.core.util.DapException;
-import dap4.core.util.ResponseFormat;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Store protocol related constants
- */
-
-public abstract class DapProtocol implements DapCodes {
- public static final String X_DAP_SERVER = "TDS-4";
- public static final String X_DAP_VERSION = "4.0";
-
- public static final String CONSTRAINTTAG = "dap4.ce";
-
- public static Map contenttypes;
-
- static {
- contenttypes = new HashMap();
- contenttypes.put(RequestMode.DMR, new ContentType(RequestMode.DMR,
- "application/vnd.opendap.dap4.dataset-metadata+xml", "text/xml", "text/plain", "text/html"));
- contenttypes.put(RequestMode.DAP,
- new ContentType(RequestMode.DAP, "application/vnd.opendap.dap4.data", "text/xml", "text/plain", "text/html"));
- contenttypes.put(RequestMode.DSR, new ContentType(RequestMode.DSR,
- "application/vnd.opendap.dap4.dataset-services+xml", "text/xml", "text/plain", "text/html"));
- contenttypes.put(RequestMode.CAPABILITIES,
- new ContentType(RequestMode.CAPABILITIES, "text/xml", "text/xml", "text/plain", "text/html"));
- contenttypes.put(RequestMode.ERROR, new ContentType(RequestMode.ERROR, "application/vnd.opendap.dap4.error+xml",
- "text/xml", "text/plain", "text/html"));
- }
-
- //////////////////////////////////////////////////
-
- public static class ContentType {
- public RequestMode mode;
- public String contenttype;
- public String xmltype;
- public String texttype;
- public String htmltype;
-
- public ContentType(RequestMode mode, String contenttype, String xmltype, String texttype, String htmltype) {
- this.mode = mode;
- this.contenttype = contenttype;
- this.xmltype = xmltype;
- this.texttype = texttype;
- this.htmltype = htmltype;
- }
-
- public String getFormat(ResponseFormat format) throws DapException {
- if (format == null)
- format = ResponseFormat.NONE;
- switch (format) {
- case XML:
- return xmltype;
- case TEXT:
- return texttype;
- case HTML:
- return htmltype;
- case NONE:
- return contenttype;
- }
- throw new DapException(String.format("Unsupported format request: %s for Mode %s", format, this.mode))
- .setCode(org.apache.http.HttpStatus.SC_BAD_REQUEST);
- }
- }
-
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/FileDSP.java b/dap4/d4lib/src/main/java/dap4/dap4lib/FileDSP.java
deleted file mode 100644
index 26f0bf061b..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/FileDSP.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib;
-
-import dap4.core.util.DapContext;
-import dap4.core.util.DapException;
-import dap4.core.util.DapUtil;
-import dap4.dap4lib.serial.D4DSP;
-import java.io.ByteArrayInputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-/**
- * Provide a DSP interface to raw data
- */
-
-public class FileDSP extends D4DSP {
- //////////////////////////////////////////////////
- // Constants
-
- protected static final String[] EXTENSIONS = new String[] {".dap", ".raw"};
-
- //////////////////////////////////////////////////
- // Instance variables
-
- // Coverity[FB.URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD]
- protected byte[] raw = null; // Complete serialized binary databuffer
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public FileDSP() {
- super();
- }
-
- //////////////////////////////////////////////////
- // DSP API
-
- /**
- * A path is file if it has no base protocol or is file:
- *
- * @param location file:/ or possibly an absolute path
- * @param context Any parameters that may help to decide.
- * @return true if this path appears to be processible by this DSP
- */
- public boolean dspMatch(String location, DapContext context) {
- try {
- XURI xuri = new XURI(location);
- if (xuri.isFile()) {
- String path = xuri.getPath();
- for (String ext : EXTENSIONS) {
- if (path.endsWith(ext))
- return true;
- }
- }
- } catch (URISyntaxException use) {
- return false;
- }
- return false;
- }
-
- @Override
- public void close() {}
-
- @Override
- public FileDSP open(String filepath) throws DapException {
- try {
- if (filepath.startsWith("file:"))
- try {
- XURI xuri = new XURI(filepath);
- filepath = xuri.getPath();
- } catch (URISyntaxException use) {
- throw new DapException("Malformed filepath: " + filepath).setCode(DapCodes.SC_NOT_FOUND);
- }
- try (FileInputStream stream = new FileInputStream(filepath)) {
- this.raw = DapUtil.readbinaryfile(stream);
- }
- try (FileInputStream stream = new FileInputStream(filepath)) { // == rewind
- ChunkInputStream rdr = new ChunkInputStream(stream, RequestMode.DAP);
- String document = rdr.readDMR();
- byte[] serialdata = DapUtil.readbinaryfile(rdr);
- super.build(document, serialdata, rdr.getRemoteByteOrder());
- }
- return this;
- } catch (IOException ioe) {
- throw new DapException(ioe).setCode(DapCodes.SC_INTERNAL_SERVER_ERROR);
- }
- }
-
- //////////////////////////////////////////////////
- // Extension to access a raw byte stream
-
- public FileDSP open(byte[] rawdata) throws DapException {
- try {
- this.raw = rawdata;
- ByteArrayInputStream stream = new ByteArrayInputStream(this.raw);
- ChunkInputStream rdr = new ChunkInputStream(stream, RequestMode.DAP);
- String document = rdr.readDMR();
- byte[] serialdata = DapUtil.readbinaryfile(rdr);
- super.build(document, serialdata, rdr.getRemoteByteOrder());
- return this;
- } catch (IOException ioe) {
- throw new DapException(ioe).setCode(DapCodes.SC_INTERNAL_SERVER_ERROR);
- }
- }
-
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/HttpDSP.java b/dap4/d4lib/src/main/java/dap4/dap4lib/HttpDSP.java
deleted file mode 100644
index 1d27ca8e86..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/HttpDSP.java
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib;
-
-import dap4.core.dmr.DapDataset;
-import dap4.core.util.DapContext;
-import dap4.core.util.DapDump;
-import dap4.core.util.DapException;
-import dap4.core.util.DapUtil;
-import dap4.dap4lib.serial.D4DSP;
-import org.apache.http.HttpStatus;
-import ucar.httpservices.HTTPException;
-import ucar.httpservices.HTTPFactory;
-import ucar.httpservices.HTTPMethod;
-import ucar.httpservices.HTTPUtil;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-/**
- * Make a request to a server and convert the reply
- * to a DapDataset from the returned bytes.
- */
-
-public class HttpDSP extends D4DSP {
-
- //////////////////////////////////////////////////
- // Constants
-
- protected static final boolean DEBUG = false;
-
- protected static final String DAPVERSION = "4.0";
- protected static final String DMRVERSION = "1.0";
-
- protected static final String DAP4PROTO = "dap4";
- protected static final String FILEPROTO = "file";
-
- protected static final String DMRSUFFIX = "dmr";
- protected static final String DATASUFFIX = "dap";
- protected static final String DSRSUFFIX = "dsr";
-
- protected static final String QUERYSTART = "?";
- protected static final String CONSTRAINTTAG = "dap4.ce";
- protected static final String PROTOTAG = "protocol";
-
- protected static final int DFALTPRELOADSIZE = 50000; // databuffer
-
- protected static final String[] DAPEXTENSIONS = new String[] {"dmr", "dap", "dds", "das", "ddx", "dods"};
-
- protected static final String[] DAP4EXTENSIONS = new String[] {"dmr", "dap"};
-
- protected static final String[][] DAP4QUERYMARKERS = new String[][] {{"proto", "dap4"}, {"dap4.ce", null},};
- protected static final String[][] DAP4FRAGMARKERS = new String[][] {{"protocol", "dap4"}, {"dap4", null},};
-
- protected static final String[] DAP4SCHEMES = {"dap4", "http", "https"};
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected boolean allowCompression = true;
- protected String basece = null; // the constraint(s) from the original url
-
- protected int status = HttpStatus.SC_OK; // response
- protected XURI xuri = null;
-
- protected Object context = null;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public HttpDSP() {
- super();
- }
-
- //////////////////////////////////////////////////
- // DSP API
-
- /**
- * A path is a DAP4 path if at least one of the following is true.
- * 1. it has "dap4:" as its leading protocol
- * 2. it has #protocol=dap4 in its fragment
- *
- * @param url
- * @param context Any parameters that may help to decide.
- * @return true if this url appears to be processible by this DSP
- */
- public boolean dspMatch(String url, DapContext context) {
- try {
- XURI xuri = new XURI(url);
- if (true) {
- boolean found = false;
- for (String scheme : DAP4SCHEMES) {
- if (scheme.equalsIgnoreCase(xuri.getBaseProtocol()) || scheme.equalsIgnoreCase(xuri.getFormatProtocol())) {
- found = true;
- break;
- }
- }
- if (!found)
- return false;
- // Might still be a non-dap4 url
- String formatproto = xuri.getFormatProtocol();
- if (DAP4PROTO.equalsIgnoreCase(formatproto))
- return true;
- for (String[] pair : DAP4QUERYMARKERS) {
- String tag = xuri.getQueryFields().get(pair[0]);
- if (tag != null && (pair[1] == null || pair[1].equalsIgnoreCase(tag)))
- return true;
- }
- for (String[] pair : DAP4FRAGMARKERS) {
- String tag = xuri.getFragFields().get(pair[0]);
- if (tag != null && (pair[1] == null || pair[1].equalsIgnoreCase(tag)))
- return true;
- }
- } else
- return true;
- } catch (URISyntaxException use) {
- return false;
- }
- return false;
- }
-
- @Override
- public HttpDSP open(String url) throws DapException {
- setLocation(url);
- parseURL(url);
-
- /*
- * Take from the incoming data
- * String s = xuri.getFragFields().get(Dap4Util.DAP4CSUMTAG);
- * ChecksumMode mode = ChecksumMode.modeFor(s);
- * if(mode == null)
- * throw new DapException(String.format("Illegal %s: %s",Dap4Util.DAP4CSUMTAG,s));
- * setChecksumMode(mode);
- * s = xuri.getFragFields().get(Dap4Util.DAP4ENDIANTAG);
- * Integer oz = DapUtil.stringToInteger(s);
- * if(oz == null)
- * throw new DapException(String.format("Illegal %s: %s",Dap4Util.DAP4ENDIANTAG,s));
- * ByteOrder order = (oz != 0 ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
- * setOrder(order);
- */
-
- // See if this is a local vs remote request
- this.basece = this.xuri.getQueryFields().get(CONSTRAINTTAG);
- build();
- return this;
- }
-
- @Override
- public void close() {}
-
- /////////////////////////////////////////
- // AbstractDSP extensions
-
- /*
- * @Override
- * public String getPath()
- * {
- * return this.originalurl;
- * }
- */
-
- //////////////////////////////////////////////////
- // Request/Response methods
-
- /**
- * Open a connection and make a request for the (possibly constrained) DMR.
- *
- * @throws DapException
- */
-
- protected void build() throws DapException {
- String methodurl = buildURL(this.xuri.assemble(XURI.URLONLY), DATASUFFIX, this.dmr, this.basece);
-
- InputStream stream;
- // Make the request and return an input stream for accessing the databuffer
- // Should fill in bigendian and stream fields
- stream = callServer(methodurl);
-
- try {
- ChunkInputStream reader;
- if (DEBUG) {
- byte[] raw = DapUtil.readbinaryfile(stream);
- ByteArrayInputStream bis = new ByteArrayInputStream(raw);
- DapDump.dumpbytestream(raw, getOrder(), "httpdsp.build");
- reader = new ChunkInputStream(bis, RequestMode.DAP, getOrder());
- } else {
- // Wrap the input stream as a ChunkInputStream
- reader = new ChunkInputStream(stream, RequestMode.DAP, getOrder());
- }
-
- // Extract and "compile" the server response
- String document = reader.readDMR();
- // Extract all the remaining bytes
- byte[] bytes = DapUtil.readbinaryfile(reader);
- // use super.build to compile
- super.build(document, bytes, getOrder());
- } catch (Throwable t) {
- t.printStackTrace();
- throw new DapException(t);
- } finally {
- try {
- stream.close();
- } catch (IOException ioe) {
- /* ignore */}
- }
- }
-
- protected InputStream callServer(String methodurl) throws DapException {
- URI uri;
-
- try {
- uri = HTTPUtil.parseToURI(methodurl);
- } catch (URISyntaxException mue) {
- throw new DapException("Malformed url: " + methodurl);
- }
-
- long start = System.currentTimeMillis();
- long stop = 0;
- this.status = 0;
- if (false) {
- HTTPMethod method = null; // Implicitly passed out to caller via stream
- try { // Note that we cannot use try with resources because we export the method stream, so method
- // must not be closed.
- method = HTTPFactory.Get(methodurl);
- if (allowCompression)
- method.setCompression("deflate,gzip");
- this.status = method.execute();
- if (this.status != HttpStatus.SC_OK) {
- String msg = method.getResponseAsString();
- throw new DapException("Request failure: " + status + ": " + methodurl).setCode(status);
- }
- // Get the response body stream => do not close the method
- return method.getResponseAsStream();
- } catch (HTTPException e) {
- if (method != null)
- method.close();
- throw new DapException(e);
- }
- } else {// read whole input
- try {
- try (HTTPMethod method = HTTPFactory.Get(methodurl)) {
- if (allowCompression)
- method.setCompression("deflate,gzip");
- this.status = method.execute();
- if (this.status != HttpStatus.SC_OK) {
- String msg = method.getResponseAsString();
- throw new DapException("Request failure: " + status + ": " + methodurl).setCode(status);
- }
- byte[] body = method.getResponseAsBytes();
- return new ByteArrayInputStream(body);
- }
- } catch (HTTPException e) {
- throw new DapException(e);
- }
- }
- }
-
- /**
- * Provide a method for getting the capabilities document.
- *
- * @param url for accessing the document
- * @throws DapException
- */
-
- public String getCapabilities(String url) throws IOException {
- // Save the original url
- String saveurl = this.xuri.getOriginal();
- parseURL(url);
- String fdsurl = buildURL(this.xuri.assemble(XURI.URLALL), DSRSUFFIX, null, null);
- try {
- // Make the request and return an input stream for accessing the databuffer
- // Should fill in context bigendian and stream fields
- InputStream stream = callServer(fdsurl);
- // read the result, convert to string and return.
- byte[] bytes = DapUtil.readbinaryfile(stream);
- String document = new String(bytes, DapUtil.UTF8);
- return document;
- } finally {
- parseURL(saveurl);
- }
- }
-
- //////////////////////////////////////////////////
- // Utilities
-
- protected static String buildURL(String baseurl, String suffix, DapDataset template, String ce) {
- StringBuilder methodurl = new StringBuilder();
- methodurl.append(baseurl);
- if (suffix != null) {
- methodurl.append('.');
- methodurl.append(suffix);
- }
- if (ce != null && ce.length() > 0) {
- methodurl.append(QUERYSTART);
- methodurl.append(CONSTRAINTTAG);
- methodurl.append('=');
- methodurl.append(ce);
- }
- return methodurl.toString();
- }
-
- protected void parseURL(String url) throws DapException {
- try {
- this.xuri = new XURI(url);
- } catch (URISyntaxException use) {
- throw new DapException(use);
- }
- }
-
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/XURI.java b/dap4/d4lib/src/main/java/dap4/dap4lib/XURI.java
deleted file mode 100644
index 1fce4061d2..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/XURI.java
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib;
-
-import dap4.core.util.DapUtil;
-import dap4.core.util.Escape;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Provide an extended form of URI parser that can handle
- * multiple protocols and can parse the query and fragment parts.
- */
-
-public class XURI {
-
- //////////////////////////////////////////////////
- // Constants
- static final String QUERYSEP = "&";
- static final String FRAGMENTSEP = "&";
-
- // Define assembly flags
-
- public static enum Parts {
- FORMAT, // format protocol
- BASE, // base protocol
- PWD, // including user
- HOST, // including port
- PATH, QUERY, FRAG;
- }
-
- // Mnemonics
- public static final EnumSet URLONLY = EnumSet.of(Parts.BASE, Parts.PWD, Parts.HOST, Parts.PATH);
- public static final EnumSet URLALL =
- EnumSet.of(Parts.FORMAT, Parts.BASE, Parts.PWD, Parts.HOST, Parts.PATH, Parts.QUERY, Parts.FRAG);
- public static final EnumSet URLBASE =
- EnumSet.of(Parts.BASE, Parts.PWD, Parts.HOST, Parts.PATH, Parts.QUERY, Parts.FRAG);
- public static final EnumSet URLPATH = EnumSet.of(Parts.PATH, Parts.QUERY, Parts.FRAG);
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected String originaluri = null;
- protected boolean isfile = false;
-
- protected String baseprotocol = null; // rightmost protocol
- protected String formatprotocol = null; // leftmost protocol
- protected String userinfo = null;
- protected String host = null;
- protected String path = null;
- protected String query = null;
- protected String frag = null;
-
- // Following are url decoded
- protected Map queryfields // decomposed query
- = new HashMap();
- protected Map fragfields // decomposed fragment
- = new HashMap();
-
- //////////////////////////////////////////////////
- // Constructor
-
- public XURI(String xurl) throws URISyntaxException {
- if (xurl == null)
- throw new URISyntaxException(xurl, "Null URI");
- // save the original uri
- this.originaluri = xurl;
- // The uri may be multi-protocol: e.g. dap4:file:...
- // Additionally, this may be a windows path, so it
- // will look like it has a single character protocol
- // that is really the drive letter.
-
- int[] breakpoint = new int[1];
- List protocols = DapUtil.getProtocols(xurl, breakpoint); // should handle drive letters also
- String remainder = xurl.substring(breakpoint[0], xurl.length());
- switch (protocols.size()) {
- case 0: // pretend it is a file
- this.formatprotocol = "file";
- this.baseprotocol = "file";
- break;
- case 1:
- this.formatprotocol = protocols.get(0);
- if ("file".equalsIgnoreCase(this.formatprotocol))
- this.baseprotocol = "file"; // default conversion
- else
- this.baseprotocol = "http"; // default conversion
- break;
- case 2:
- this.baseprotocol = protocols.get(0);
- this.formatprotocol = protocols.get(1);
- break;
- default:
- throw new URISyntaxException(xurl, "Too many protocols: at most 2 allowed");
- }
- this.isfile = "file".equals(this.baseprotocol);
- // The standard URI parser does not handle 'file:' very well,
- // so handle specially
- URI uri;
- if (this.isfile)
- parsefile(remainder);
- else
- parsenonfile(remainder); // not a file: url
- if (this.query != null)
- parseQuery(this.query);
- if (this.frag != null)
- parseFragment(this.frag);
- }
-
- protected void parsenonfile(String remainder) throws URISyntaxException {
- // Construct a usable url and parse it
- URI uri = new URI(baseprotocol + ":" + remainder);
- // Extract the parts of the uri so they can
- // be modified and later reassembled
- this.userinfo = canonical(uri.getUserInfo());
- this.host = canonical(uri.getHost());
- if (uri.getPort() > 0)
- this.host += (":" + uri.getPort());
- this.path = canonical(uri.getPath());
- // Parse the raw query (before decoding)
- this.query = uri.getRawQuery();
- // Parse the raw fragment (before decoding)
- this.frag = canonical(uri.getFragment());
- }
-
- protected void parsefile(String remainder) {
- // Pull off the query and fragment parts, if any.
- String query = null;
- String fragment = null;
- int qindex = remainder.indexOf("?");
- int findex = remainder.lastIndexOf("#");
- if (qindex >= 0) { // query and maybe fragment
- if (findex >= 0 && findex > qindex) {// both
- fragment = remainder.substring(findex + 1, remainder.length());
- remainder = remainder.substring(0, findex);
- }
- query = remainder.substring(qindex + 1, remainder.length());
- remainder = remainder.substring(0, qindex);
- } else if (findex >= 0) { // fragment, no query
- fragment = remainder.substring(findex + 1, remainder.length());
- remainder = remainder.substring(0, findex);
- }
-
- // Standardize path part to be absolute
- // => single leading '/' or windows drive letter
- StringBuilder buf = new StringBuilder(remainder);
- for (int i = 0; i < remainder.length(); i++) { // remove all leading '/'
- if (buf.charAt(i) != '/')
- break;
- buf.deleteCharAt(i);
- }
- // check for drive letter
- if (DapUtil.DRIVELETTERS.indexOf(buf.charAt(0)) < 0 || buf.charAt(1) != ':') { // no drive letter, prepend '/'
- buf.insert(0, '/');
- }
-
- remainder = buf.toString();
- this.path = remainder;
- this.frag = fragment;
- this.query = query;
- }
-
- //////////////////////////////////////////////////
- // Accessors
-
- public String getOriginal() {
- return originaluri;
- }
-
- public String getBaseProtocol() {
- return baseprotocol;
- }
-
- public String getFormatProtocol() {
- return this.formatprotocol;
- }
-
- public void setBaseProtocol(String base) {
- this.baseprotocol = base;
- }
-
- public boolean isFile() {
- return this.isfile;
- }
-
- public String getUserinfo() {
- return this.userinfo;
- }
-
- public String getHost() {
- return this.host;
- }
-
- public String getPath() {
- return this.path;
- }
-
- public String getQuery() {
- return this.query;
- }
-
- public String getFrag() {
- return this.frag;
- }
-
- public Map getQueryFields() {
- return this.queryfields;
- }
-
- public Map getFragFields() {
- return this.fragfields;
- }
-
- public XURI parseQuery(String q) {
- if (q == null || q.length() == 0)
- return this;
- String[] params = q.split(QUERYSEP);
- this.query = q;
- for (String param : params) {
- String[] pair = param.split("[=]");
- String name = Escape.urlDecode(pair[0]);
- name = name.toLowerCase(); // for consistent lookup
- String value = "";
- if (pair.length > 1) {
- value = Escape.urlDecode(pair[1]);
- this.queryfields.put(name, value);
- }
- }
- return this;
- }
-
- public XURI parseFragment(String f) {
- if (f == null || f.length() == 0)
- return this;
- String[] params = f.split(FRAGMENTSEP);
- if (params != null && params.length > 0) {
- this.frag = f;
- for (String param : params) {
- String[] pair = param.split("=");
- String name = Escape.urlDecode(pair[0]);
- name = name.toLowerCase(); // for consistent lookup
- String value = (pair.length == 2 ? Escape.urlDecode(pair[1]) : "");
- this.fragfields.put(name, value);
- }
- }
- return this;
- }
-
- //////////////////////////////////////////////////
- // API
-
- /**
- * Reassemble the url using the specified parts
- *
- * @param parts to include
- * @return the assembled uri
- */
-
- public String assemble(EnumSet parts) {
- StringBuilder uri = new StringBuilder();
- // Note that format and base may be same, so case it out
- int useformat = (parts.contains(Parts.FORMAT) ? 1 : 0);
- int usebase = (parts.contains(Parts.BASE) ? 2 : 0);
- switch (useformat + usebase) {
- case 0 + 0: // neither
- break;
- case 1 + 0: // FORMAT only
- uri.append(this.formatprotocol + ":");
- break;
- case 2 + 0: // BASE only
- uri.append(this.baseprotocol + ":");
- break;
- case 2 + 1: // both
- uri.append(this.formatprotocol + ":");
- if (!this.baseprotocol.equals(this.formatprotocol))
- uri.append(this.formatprotocol + ":");
- break;
- }
- uri.append(this.baseprotocol.equals("file") ? "/" : "//");
-
- if (userinfo != null && parts.contains(Parts.PWD))
- uri.append(this.userinfo + ":");
- if (this.host != null && parts.contains(Parts.HOST))
- uri.append(this.host);
- if (this.path != null && parts.contains(Parts.PATH))
- uri.append(this.path);
- if (this.query != null && parts.contains(Parts.QUERY))
- uri.append("?" + this.query);
- if (this.frag != null && parts.contains(Parts.FRAG))
- uri.append("#" + this.frag);
- return uri.toString();
- }
-
-
- /**
- * Canonicalize a part of a URL
- *
- * @param s part of the url
- */
- public static String canonical(String s) {
- if (s != null) {
- s = s.trim();
- if (s.length() == 0)
- s = null;
- }
- return s;
- }
-
- public String toString() {
- return originaluri;
- }
-}
-
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/keep.jar b/dap4/d4lib/src/main/java/dap4/dap4lib/keep.jar
deleted file mode 100644
index deb03e6d00..0000000000
Binary files a/dap4/d4lib/src/main/java/dap4/dap4lib/keep.jar and /dev/null differ
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4Cursor.java b/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4Cursor.java
deleted file mode 100644
index ef41bbb618..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4Cursor.java
+++ /dev/null
@@ -1,655 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib.netcdf;
-
-import com.sun.jna.Native;
-import dap4.core.data.DataCursor;
-import dap4.core.dmr.*;
-import dap4.core.util.*;
-import dap4.dap4lib.AbstractCursor;
-import dap4.dap4lib.LibTypeFcns;
-import ucar.nc2.jni.netcdf.Nc4prototypes;
-import ucar.nc2.jni.netcdf.SizeT;
-import java.lang.reflect.Array;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import static dap4.dap4lib.netcdf.Nc4DSP.Nc4Pointer;
-import static dap4.dap4lib.netcdf.Nc4Notes.*;
-
-
-public class Nc4Cursor extends AbstractCursor {
-
- //////////////////////////////////////////////////
-
- public static boolean DEBUG = false;
-
- // if the default charset being used by java isn't UTF-8, then we will
- // need to transcode any string read into netCDf-Java via netCDF-C
- private static final boolean transcodeStrings = Charset.defaultCharset() != StandardCharsets.UTF_8;
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected Nc4Pointer memory = null;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public Nc4Cursor(Scheme scheme, Nc4DSP dsp, DapVariable template, Nc4Cursor container) throws DapException {
- super(scheme, dsp, template, container);
- if (DEBUG)
- debug();
- }
-
- public Nc4Cursor(Nc4Cursor c) {
- super(c);
- assert false;
- this.memory = c.getMemory();
- }
-
- //////////////////////////////////////////////////
- // AbstractCursor Interface API Implementations
-
- @Override
- public Object read(Index index) throws DapException {
- return read(DapUtil.indexToSlices(index));
- }
-
- @Override
- public Object read(List slices) throws DapException {
- switch (this.scheme) {
- case ATOMIC:
- return readAtomic(slices);
- case STRUCTURE:
- case SEQUENCE:
- if (((DapVariable) this.getTemplate()).getRank() > 0 || DapUtil.isScalarSlices(slices))
- throw new DapException("Cannot slice a scalar variable");
- return this;
- case STRUCTARRAY:
- Odometer odom = Odometer.factory(slices);
- DataCursor[] instances = new DataCursor[(int) odom.totalSize()];
- for (int i = 0; odom.hasNext(); i++) {
- instances[i] = readStructure(odom.next());
- }
- return instances;
- case SEQARRAY:
- odom = Odometer.factory(slices);
- instances = new DataCursor[(int) odom.totalSize()];
- for (int i = 0; odom.hasNext(); i++) {
- instances[i] = readSequence(odom.next());
- }
- return instances;
- default:
- throw new DapException("Attempt to slice a scalar object");
- }
- }
-
- @Override
- public Nc4Cursor readField(int findex) throws DapException {
- // Preliminaries
- DapVariable template = (DapVariable) getTemplate();
- DapStructure struct = (DapStructure) template.getBaseType();
- if (findex < 0 || findex >= struct.getFields().size())
- throw new DapException("Field index out of range: " + findex);
- DapVariable field = struct.getField(findex);
- // Get VarNotes and TypeNotes
- VarNotes fi = (VarNotes) ((Nc4DSP) getDSP()).find(field);
- TypeNotes ti = fi.getBaseType();
- Nc4Cursor cursor = new Nc4Cursor(schemeFor(field), (Nc4DSP) this.dsp, field, this);
- Nc4Pointer mem = getMemory();
- // Handle records and structures somewhat differently
- if (this.scheme == scheme.STRUCTURE) {
- // do nothing
- } else if (this.getScheme() == Scheme.RECORD) {
- if (findex != 0) // need to use the first field of the sequence
- throw new DapException("Field index out of range: " + findex);
- // For fields, the record memory and the field memory are the same
- // because the record contains only 1 rank-0 field.
- } else // Error
- throw new DapException("readfield expected STRUCTURE or RECORD cursor");
- cursor.setMemory(mem);
- return cursor;
- }
-
- @Override
- public long getRecordCount() {
- assert (this.scheme == scheme.SEQUENCE);
- if (this.recordcount < 0)
- throw new IllegalStateException("Sequence has no record count");
- return this.recordcount;
- }
-
- @Override
- public Nc4Cursor readRecord(long recno) throws DapException {
- assert (this.scheme == scheme.SEQUENCE);
- DapVariable template = (DapVariable) getTemplate();
- if (recno < 0 || recno >= getRecordCount())
- throw new ArrayIndexOutOfBoundsException("Illegal record id: " + recno);
- VarNotes vn = (VarNotes) ((Nc4DSP) getDSP()).find(template);
- TypeNotes ti = vn.getBaseType();
- assert (ti.isVlen());
- DapStructure ds = (DapStructure) template.getBaseType();
- DapVariable field = ds.getField(0);
- DapType ftype = field.getBaseType();
- TypeNotes fnotes = (TypeNotes) ((Nc4DSP) getDSP()).find(ftype);
- // The memory is a vector of objects, where the object type
- // is the type of the first field of the sequence
- // We need to extract the recno'th object from our memory
- Nc4Pointer record = getMemory(); // should be the vector of records
- long recsize = getElementSize(fnotes);
- // point to the recno element in the vector
- record = record.share(recno * recsize, recsize);
- Nc4Cursor rec = new Nc4Cursor(Scheme.RECORD, (Nc4DSP) getDSP(), (DapVariable) getTemplate(), this);
- /*
- * Nc4Pointer seqvlen = getMemory();
- * long vlensize = Nc4prototypes.Vlen_t.VLENSIZE;
- * Nc4Pointer recnovlen = seqvlen.share(vlensize*recno,vlensize); // recno'th vlen
- * Nc4prototypes.Vlen_t vleninstance = new Nc4prototypes.Vlen_t(recnovlen.p);
- * vleninstance.read(); // get the actual vlen contents for this sequence
- * Pointer vlenmem = vleninstance.p;
- * int vlencount = vleninstance.len;
- * TypeNotes fvtype = getVlenType(field);
- * long elemsize = fvtype.getSize(); // vlen.p is vector of objects of this size
- * Nc4Pointer objectvec = new Nc4Pointer(vlenmem, elemsize * vlencount);
- * // Now, we want the recno'th object in the vector
- * Nc4Pointer record = objectvec.share(elemsize * recno, elemsize);
- */
- rec.setMemory(record).setRecordIndex(recno);
- return rec;
- }
-
-
- @Override
- public Index getIndex() throws DapException {
- if (this.scheme != Scheme.STRUCTURE && this.scheme != Scheme.SEQUENCE)
- throw new DapException("Not a Sequence|Structure instance");
- return this.arrayindex;
- }
-
- //////////////////////////////////////////////////
- // Support Methods
-
- protected Object readAtomic(List slices) throws DapException {
- if (slices == null)
- throw new DapException("DataCursor.read: null set of slices");
- assert (this.scheme == scheme.ATOMIC);
- DapVariable atomvar = (DapVariable) getTemplate();
- int rank = atomvar.getRank();
- assert slices != null && ((rank == 0 && slices.size() == 1) || (slices.size() == rank));
- // Get VarNotes and TypeNotes
- Notes n = ((Nc4DSP) this.dsp).find(this.template);
- Object result = null;
- long count = DapUtil.sliceProduct(slices);
- VarNotes vn = (VarNotes) n;
- TypeNotes ti = vn.getBaseType();
- if (getContainer() == null) {
- if (rank == 0) { // scalar
- result = readAtomicScalar(vn, ti);
- } else {
- result = readAtomicVector(vn, ti, count, slices);
- }
- } else {// field of a structure instance or record
- long elemsize = ((DapType) ti.get()).getSize();
- assert (this.container != null);
- long trueoffset = computeTrueOffset(this);
- Nc4Pointer varmem = getMemory();
- Nc4Pointer mem = varmem.share(trueoffset, count * elemsize);
- result = getatomicdata(ti.getType(), count, elemsize, mem);
- }
- return result;
- }
-
- /**
- * Read a top-level scalar atomic variable
- *
- * @param vi
- * @param ti
- * @return Object scalar
- * @throws DapException
- */
- protected Object readAtomicScalar(VarNotes vi, TypeNotes ti) throws DapException {
- DapVariable atomvar = (DapVariable) getTemplate();
- // Get into memory
- Nc4prototypes nc4 = ((Nc4DSP) this.dsp).getJNI();
- int ret;
- DapType basetype = ti.getType();
- Object result = null;
- if (basetype.isFixedSize()) {
- long memsize = ((DapType) ti.get()).getSize();
- Nc4Pointer mem = Nc4Pointer.allocate(memsize);
- readcheck(nc4, ret = nc4.nc_get_var(vi.gid, vi.id, mem.p));
- setMemory(mem);
- result = getatomicdata(ti.getType(), 1, mem.size, mem);
- } else if (basetype.isStringType()) {
- String[] s = new String[1];
- readcheck(nc4, ret = nc4.nc_get_var_string(vi.gid, vi.id, s));
- if (transcodeStrings) {
- s = transcodeString(s);
- }
- result = s;
- } else if (basetype.isOpaqueType()) {
- Nc4Pointer mem = Nc4Pointer.allocate(ti.getSize());
- readcheck(nc4, ret = nc4.nc_get_var(vi.gid, vi.id, mem.p));
- setMemory(mem);
- ByteBuffer[] buf = new ByteBuffer[1];
- buf[0] = mem.p.getByteBuffer(0, ti.getSize());
- result = buf;
- } else
- throw new DapException("Unexpected atomic type: " + basetype);
- return result;
- }
-
- protected Object readAtomicVector(VarNotes vi, TypeNotes ti, long count, List slices) throws DapException {
- DapVariable atomvar = (DapVariable) getTemplate();
- DapType basetype = ti.getType();
- if (atomvar.getCount() == 0)
- return LibTypeFcns.newVector(basetype, 0);
- // Convert slices to (start,count,stride);
- int rank = atomvar.getRank();
- List dimset = atomvar.getDimensions();
- Odometer odom = Odometer.factory(slices, dimset);
- List subodoms = odom.getSubOdometers();
- // Compute the total size of returned objects
- long totalsize = 0;
- for (int i = 0; i < subodoms.size(); i++) {
- Odometer ithodom = subodoms.get(i);
- totalsize += ithodom.totalSize();
- }
- Nc4prototypes nc4 = ((Nc4DSP) this.dsp).getJNI();
- SizeT[] startp = new SizeT[rank];
- SizeT[] countp = new SizeT[rank];
- SizeT[] stridep = new SizeT[rank];
- int ret;
- long edgecount;
- Odometer ithodom;
- Object partialresult;
- Object result = LibTypeFcns.newVector(basetype, totalsize);
- int pos = 0;
- for (int i = 0; i < subodoms.size(); i++) {
- ithodom = subodoms.get(i);
- edgecount = odomToEdges(ithodom, startp, countp, stridep);
- if (basetype.isFixedSize()) {
- long elemsize = ti.getSize();
- long memsize = edgecount * elemsize;
- Nc4Pointer mem = Nc4Pointer.allocate(memsize);
- readcheck(nc4, ret = nc4.nc_get_vars(vi.gid, vi.id, startp, countp, stridep, mem.p));
- partialresult = getatomicdata(ti.getType(), edgecount, elemsize, mem);
- } else if (basetype.isStringType()) {
- String[] ss = new String[(int) edgecount];
- readcheck(nc4, ret = nc4.nc_get_vars_string(vi.gid, vi.id, startp, countp, stridep, ss));
- if (transcodeStrings) {
- ss = transcodeString(ss);
- }
- partialresult = ss;
- } else if (basetype.isOpaqueType()) {
- long elemsize = ti.getSize();
- edgecount = odomToEdges(ithodom, startp, countp, stridep);
- long memsize = edgecount * elemsize;
- Nc4Pointer mem = Nc4Pointer.allocate(memsize);
- readcheck(nc4, ret = nc4.nc_get_vars(vi.gid, vi.id, startp, countp, stridep, mem.p));
- partialresult = new ByteBuffer[(int) edgecount];
- for (int ec = 0; ec < edgecount; ec++) {
- byte[] buf = mem.p.getByteArray(ec * ti.getSize(), (int) ti.getSize());
- ((ByteBuffer[]) partialresult)[ec] = ByteBuffer.wrap(buf);
- }
- } else
- throw new DapException("Unexpected atomic type: " + basetype);
- int len = Array.getLength(partialresult);
- System.arraycopy(partialresult, 0, result, pos, len);
- pos += len;
- }
- return result;
- }
-
- protected Nc4Cursor readStructure(Index index) throws DapException {
- assert (index != null);
- assert this.scheme == Scheme.STRUCTARRAY;
- DapVariable template = (DapVariable) getTemplate();
- VarNotes vi = (VarNotes) ((Nc4DSP) this.dsp).find(template);
- TypeNotes ti = vi.basetype;
- Nc4Pointer mem;
- Nc4Cursor cursor = null;
- if (template.isTopLevel()) {
- int ret;
- mem = Nc4Pointer.allocate(ti.getSize());
- Nc4prototypes nc4 = ((Nc4DSP) this.dsp).getJNI();
- if (index.getRank() == 0) {
- readcheck(nc4, ret = nc4.nc_get_var(vi.gid, vi.id, mem.p));
- } else {
- SizeT[] sizes = indexToSizes(index);
- readcheck(nc4, ret = nc4.nc_get_var1(vi.gid, vi.id, sizes, mem.p));
- }
- cursor = new Nc4Cursor(Scheme.STRUCTURE, (Nc4DSP) this.dsp, template, this);
- } else {// field of a structure instance or record
- long pos = index.index();
- if (pos < 0 || pos >= template.getCount())
- throw new IndexOutOfBoundsException("read: " + index);
- cursor = new Nc4Cursor(Scheme.STRUCTURE, (Nc4DSP) this.dsp, template, this);
- // Ok, we need to operate relative to the parent's memory
- // move to the appropriate offset
- mem = ((Nc4Cursor) getContainer()).getMemory().share(pos * ti.getSize(), ti.getSize());
- }
- cursor.setIndex(index);
- cursor.setMemory(mem);
- return cursor;
- }
-
- protected Nc4Cursor readSequence(Index index) throws DapException {
- assert (index != null);
- assert this.scheme == Scheme.SEQARRAY;
- DapVariable template = (DapVariable) getTemplate();
- VarNotes vi = (VarNotes) ((Nc4DSP) this.dsp).find(template);
- TypeNotes ti = vi.basetype;
- Nc4Pointer mem;
- Nc4Cursor cursor = null;
- Nc4prototypes.Vlen_t[] vlen = new Nc4prototypes.Vlen_t[1];
- // Given a seq var e.g v(d1,d2), where we have an index argument,
- // get that object, which will be a vlen
- if (template.isTopLevel()) {
- int ret;
- Nc4prototypes nc4 = ((Nc4DSP) this.dsp).getJNI();
- SizeT[] extents = indexToSizes(index);
- // read te index't vlen
- readcheck(nc4, ret = nc4.nc_get_var1(vi.gid, vi.id, extents, vlen));
- } else {// field of a structure instance or record
- long pos = index.index();
- if (pos < 0 || pos >= template.getCount())
- throw new IndexOutOfBoundsException("read: " + index);
- // The memory for a sequence field is the vector of vlen objects.
- // We need to extract the index'th vlen for this field
- Nc4Pointer pp = getMemory(); // should be the vector
- int vlensize = Nc4prototypes.Vlen_t.VLENSIZE;
- // point to the index'th element in the vector
- pp = pp.share(pos * vlensize, vlensize);
- // convert to a Vlen_T object
- vlen[0] = new Nc4prototypes.Vlen_t(pp.p);
- vlen[0].read();
- }
- // At this point, vlen[0] is the index'th vlen
- // Construct a sequence cursor whose memory is the memory of the vlen
- // (which is the vector of records)
- cursor = new Nc4Cursor(Scheme.SEQUENCE, (Nc4DSP) this.dsp, template, this);
- cursor.setRecordCount(vlen[0].len);
- long memsize = ti.getSize() * cursor.getRecordCount();
- mem = new Nc4Pointer(vlen[0].p, memsize);
- cursor.setMemory(mem);
- cursor.setIndex(index);
- return cursor;
- }
-
- //////////////////////////////////////////////////
- // Nc4Cursor Extensions
-
- public long getOffset() {
- DapVariable dv = (DapVariable) getTemplate();
- Notes n = ((Nc4DSP) this.dsp).find(dv);
- return n.getOffset();
- }
-
- public long getElementSize() {
- DapVariable dv = (DapVariable) getTemplate();
- Notes n = ((Nc4DSP) this.dsp).find(dv);
- return n.getSize();
- }
-
- public Nc4Pointer getMemory() {
- return this.memory;
- }
-
- public Nc4Cursor setMemory(Nc4Pointer p) {
- this.memory = p;
- return this;
- }
-
- //////////////////////////////////////////////////
- // Utilities
-
- protected long getElementSize(TypeNotes ti) {
- DapType type = ti.getType();
- switch (type.getTypeSort()) {
- case Structure:
- case Sequence:
- return ti.getSize();
- case String:
- case URL:
- // 8/16/2019 jlcaron upgrade to jna 5.4.0
- // com.sun.jna.Pointer#SIZE is removed. Its use is replaced by
- // com.sun.jna.Native#POINTER_SIZE to prevent a class loading deadlock, when JNA is initialized from multiple
- // threads
- return Native.POINTER_SIZE;
- case Enum:
- return getElementSize((TypeNotes) ((Nc4DSP) getDSP()).find(ti.enumbase, NoteSort.TYPE));
- case Opaque:
- return ti.getSize();
- default:
- return type.getSize();
- }
- }
-
- protected Object getatomicdata(DapType basetype, long lcount, long elemsize, Nc4Pointer mem) {
- Object result = null;
- TypeSort sort = basetype.getTypeSort();
- int icount = (int) lcount;
- switch (sort) {
- case Char:
- // need to extract and convert utf8(really ascii) -> utf16
- byte[] bresult = mem.p.getByteArray(0, icount);
- char[] cresult = new char[bresult.length];
- for (int i = 0; i < icount; i++) {
- int ascii = bresult[i];
- ascii = ascii & 0x7F;
- cresult[i] = (char) ascii;
- }
- result = cresult;
- break;
- case UInt8:
- case Int8:
- result = mem.p.getByteArray(0, icount);
- break;
- case Int16:
- case UInt16:
- result = mem.p.getShortArray(0, icount);
- break;
- case Int32:
- case UInt32:
- result = mem.p.getIntArray(0, icount);
- break;
- case Int64:
- case UInt64:
- result = mem.p.getLongArray(0, icount);
- break;
- case Float32:
- result = mem.p.getFloatArray(0, icount);
- break;
- case Float64:
- result = mem.p.getDoubleArray(0, icount);
- break;
- case String:
- case URL:
- // TODO: properly free underlying strings
- result = mem.p.getStringArray(0, icount);
- break;
- case Opaque:
- ByteBuffer[] ops = new ByteBuffer[icount];
- result = ops;
- for (int i = 0; i < icount; i++) {
- ops[i] = mem.p.getByteBuffer(i * elemsize, elemsize);
- }
- break;
- case Enum:
- DapEnumeration de = (DapEnumeration) basetype;
- result = getatomicdata((DapType) de.getBaseType(), lcount, elemsize, mem);
- break;
- }
- return result;
- }
-
- static long odomToEdges(Odometer odom, SizeT[] startp, SizeT[] countp, SizeT[] stridep) {
- assert !odom.isMulti();
- int rank = odom.rank();
- List slices = odom.getSlices();
- for (int i = 0; i < rank; i++) {
- Slice slice = slices.get(i);
- startp[i] = new SizeT(slice.getFirst());
- countp[i] = new SizeT(slice.getCount());
- stridep[i] = new SizeT(slice.getStride());
- }
- return DapUtil.sliceProduct(slices);
- }
-
- public static void errcheck(Nc4prototypes nc4, int ret) throws DapException {
- if (ret != 0) {
- String msg = String.format("Netcdf: errno=%d; %s", ret, nc4.nc_strerror(ret));
- throw new DapException(msg);
- }
- }
-
- public static void readcheck(Nc4prototypes nc4, int ret) throws DapException {
- try {
- errcheck(nc4, ret);
- } catch (DapException de) {
- throw new DapException(de);
- }
- }
-
- static SizeT[] indexToSizes(Index index) {
- SizeT[] sizes = new SizeT[index.getRank()];
- for (int i = 0; i < sizes.length; i++) {
- sizes[i] = new SizeT(index.get(i));
- }
- return sizes;
- }
-
- /**
- * Given a field ref, compute the true offset with respect to
- * it top-level containing structure/record
- *
- * @param f field cursor
- * @return
- * @throws DapException
- */
- long computeTrueOffset(Nc4Cursor f) throws DapException {
- List path = getCursorPath(f);
- long totaloffset = 0;
- Nc4Cursor current;
-
- // First element is presumed to be a structure ore record variable,
- // and that its memory covers only it's instance.
- // Walk intermediate nodes
- for (int i = 1; i < (path.size() - 1); i++) {
- current = path.get(i);
- DapVariable template = (DapVariable) current.getTemplate();
- VarNotes vi = (VarNotes) ((Nc4DSP) getDSP()).find(template);
-
- long size = vi.getSize();
- long offset = current.getOffset();
- long pos = 0;
- switch (current.getScheme()) {
- case SEQUENCE:
- case STRUCTURE:
- pos = current.getIndex().index();
- break;
- case RECORD:
- // readrecord will have set our memory to the start of the record
- pos = 0;
- break;
- default:
- throw new DapException("Illegal cursor type: " + current.getScheme());
- }
- long delta = size * pos + offset;
- totaloffset += delta;
- }
- assert path.get(path.size() - 1) == f;
- totaloffset += f.getOffset();
- return totaloffset;
- }
-
- /**
- * Given a cursor, get a list of "containing" cursors
- * with the following constraints.
- * 1. the first element in the path is a top-level variable.
- * 2. the remaining elements are the enclosing compound variables
- * 3. the last element is the incoming cursor.
- *
- * @param cursor
- * @return
- */
- static List getCursorPath(Nc4Cursor cursor) {
- List path = new ArrayList<>();
- for (;;) {
- if (!cursor.getScheme().isCompoundArray()) // suppress
- path.add(0, cursor);
- if (cursor.getScheme() == Scheme.SEQUENCE) {
- // Stop here because the sequence has the vlen mem as its mem
- break;
- }
- Nc4Cursor next = (Nc4Cursor) cursor.getContainer();
- if (next == null) {
- assert cursor.getTemplate().isTopLevel();
- break;
- }
- assert next.getTemplate().getSort() == DapSort.VARIABLE;
- cursor = next;
- }
- return path;
- }
-
-
- static Nc4Pointer getVarMemory(Nc4Cursor cursor) {
- while (cursor.getContainer() != null) {
- cursor = (Nc4Cursor) cursor.getContainer();
- }
- return cursor.getMemory();
- }
-
- /**
- * If the basetype is sequence (=> isVlen()),
- * then return the type of the first field of this sequence.
- * Otherwise return null.
- *
- * @return the type of the first field
- */
- public TypeNotes getVlenType(DapVariable v) {
- DapType t = v.getBaseType();
- if (t.getSort() != DapSort.SEQUENCE || ((DapSequence) t).getFields().size() != 1)
- throw new IllegalArgumentException(t.getFQN());
- DapSequence ds = (DapSequence) t;
- DapVariable f0 = ds.getField(0);
- DapType f0type = f0.getBaseType();
- return (TypeNotes) ((Nc4DSP) this.dsp).find(f0type);
- }
-
- /**
- * By default, JNA assumes strings coming into java from the C side are using
- * the system encoding. However, netCDF-C encodes using UTF-8. Because of this,
- * if we are on a platform where java is not using UTF-8 as the default encoding,
- * we will need to transcode the incoming strings fix the incorrect assumption
- * made by JNA.
- *
- * Note, we could set the system property jna.encode=UTF-8, but would impact the
- * behavior of other libraries that use JNA, and would not be very nice of us to
- * set globally (and often times isn't the right thing to set anyways, since the
- * default in C to use the system encoding).
- *
- * @param systemStrings String array encoded using the default charset
- * @return String array encoded using the UTF-8 charset
- */
- private String[] transcodeString(String[] systemStrings) {
- return Arrays.stream(systemStrings).map(systemString -> {
- byte[] byteArray = systemString.getBytes(Charset.defaultCharset());
- return new String(byteArray, StandardCharsets.UTF_8);
- }).toArray(String[]::new);
- }
-
- protected void debug() {
- System.err.printf("CURSOR: %s%n", this.toString());
- }
-
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4DMR.java b/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4DMR.java
deleted file mode 100644
index 3534f35845..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4DMR.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib.netcdf;
-
-import dap4.core.dmr.*;
-
-public abstract class Nc4DMR {
- //////////////////////////////////////////////////
-
- public static class Nc4Attribute extends DapAttribute {
- public Nc4Attribute(String name, DapType basetype) {
- super(name, basetype);
- }
- }
-
- public static class Nc4AttributeSet extends DapAttributeSet {
- public Nc4AttributeSet(String name) {
- super(name);
- }
- }
-
- public static class Nc4Dimension extends DapDimension {
- public Nc4Dimension(String name, long size) {
- super(name, size);
- }
- }
-
- public static class Nc4Map extends DapMap {
- public Nc4Map(DapVariable target) {
- super(target);
- }
- }
-
- public static class Nc4Variable extends DapVariable {
- public Nc4Variable(String name, DapType t) {
- super(name, t);
- }
- }
-
- public static class Nc4Group extends DapGroup {
- public Nc4Group(String name) {
- super(name);
- }
- }
-
- public static class Nc4Dataset extends DapDataset {
- public Nc4Dataset(String name) {
- super(name);
- }
- }
-
- public static class Nc4Enumeration extends DapEnumeration {
- public Nc4Enumeration(String name, DapType basetype) {
- super(name, basetype);
- }
- }
-
- public static class Nc4EnumConst extends DapEnumConst {
- public Nc4EnumConst(String name, long value) {
- super(name, value);
- }
- }
-
- public static class Nc4Structure extends DapStructure {
- public Nc4Structure(String name) {
- super(name);
- }
- }
-
- public static class Nc4Sequence extends DapSequence {
- public Nc4Sequence(String name) {
- super(name);
- }
- }
-
- public static class Nc4OtherXML extends DapOtherXML {
- public Nc4OtherXML(String name) {
- super(name);
- }
- }
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4DMRCompiler.java b/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4DMRCompiler.java
deleted file mode 100644
index cb8a546e59..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4DMRCompiler.java
+++ /dev/null
@@ -1,740 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib.netcdf;
-
-import com.sun.jna.Native;
-import com.sun.jna.ptr.IntByReference;
-import dap4.core.dmr.*;
-import dap4.core.util.Convert;
-import dap4.core.util.DapContext;
-import dap4.core.util.DapException;
-import dap4.core.util.DapUtil;
-import ucar.nc2.ffi.netcdf.NetcdfClibrary;
-import ucar.nc2.jni.netcdf.Nc4prototypes;
-import ucar.nc2.jni.netcdf.SizeTByReference;
-import static ucar.nc2.jni.netcdf.Nc4prototypes.*;
-import static dap4.dap4lib.netcdf.Nc4DSP.*;
-import static dap4.dap4lib.netcdf.Nc4Notes.*;
-
-
-/**
- * Compile netcdf file info into DMR
- */
-public class Nc4DMRCompiler {
- //////////////////////////////////////////////////
- // Constants
-
- public static final boolean DEBUG = false;
-
- // Define reserved attributes
- public static final String UCARTAGVLEN = Nc4DSP.UCARTAGVLEN;
- public static final String UCARTAGOPAQUE = Nc4DSP.UCARTAGOPAQUE;
-
- static final int NC_FALSE = 0;
- static final int NC_TRUE = 1;
- // "null" id(s)
- public static final int NC_GRPNULL = 0;
- public static final int NC_IDNULL = -1;
- public static final int NC_NOERR = 0;
-
- static int NC_INT_BYTES = (java.lang.Integer.SIZE / java.lang.Byte.SIZE);
- static int NC_LONG_BYTES = (Native.LONG_SIZE);
- static int NC_POINTER_BYTES = (Native.POINTER_SIZE);
- static int NC_SIZET_BYTES = (Native.SIZE_T_SIZE);
-
- protected static Nc4prototypes nc4 = NetcdfClibrary.getForeignFunctionInterface();
-
- //////////////////////////////////////////////////
- // Static methods
-
- /**
- * A path is file if it has no base protocol or is file:
- *
- * @param path
- * @param context Any parameters that may help to decide.
- * @return true if this path appears to be processible by this DSP
- */
- public static boolean dspMatch(String path, DapContext context) {
- for (String s : EXTENSIONS) {
- if (path.endsWith(s))
- return true;
- }
- return false;
- }
-
- //////////////////////////////////////////////////
- // Instance Variables
-
- protected boolean trace = false;
- protected boolean closed = false;
-
- protected int ncid = -1; // file id
- protected int format = 0; // from nc_inq_format
- protected int mode = 0;
- protected String path = null;
-
- protected String pathprefix = null;
-
- protected DMRFactory factory = null;
- protected Nc4DSP dsp = null;
- protected DapDataset dmr = null;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public Nc4DMRCompiler(Nc4DSP dsp, int ncid, DMRFactory factory) throws DapException {
- this.dsp = dsp;
- this.path = dsp.getLocation();
- this.ncid = ncid;
- this.factory = factory;
- }
-
-
- //////////////////////////////////////////////////
- // Main entry point
-
- public DapDataset compile() throws DapException {
- // create and fill the root group
- buildrootgroup(this.ncid);
- if (this.dmr != null)
- dmr.finish();
- return this.dmr;
- }
-
- //////////////////////////////////////////////////
-
- protected void buildrootgroup(int ncid) throws DapException {
- int ret;
- byte[] namep = new byte[NC_MAX_NAME + 1];
- errcheck(ret = nc4.nc_inq_grpname(ncid, namep));
- String[] pieces = DapUtil.canonicalpath(this.path).split("[/]");
- DapDataset g = factory.newDataset(pieces[pieces.length - 1]);
- GroupNotes gi = (GroupNotes) Nc4Notes.factory(NoteSort.GROUP, ncid, ncid, this.dsp);
- gi.set(g);
- this.dsp.note(gi);
- this.dmr = g;
- fillgroup(ncid);
- }
-
- protected void fillgroup(int gid) throws DapException {
- int ret, mode;
- int[] dims = getDimensions(gid);
- int[] udims = getUnlimitedDimensions(gid);
- for (int dimid : dims) {
- builddim(gid, dimid, udims);
- }
- int[] typeids = getUserTypes(gid);
- for (int i = 0; i < typeids.length; i++) {
- for (int j = 0; j < i; j++) {
- if (typeids[i] == typeids[j])
- assert false;
- }
- }
-
- for (int typeid : typeids) {
- buildusertype(gid, typeid);
- }
- int[] varids = getVars(gid);
- for (int varid : varids) {
- buildvar(gid, varid);
- }
- // globalattributes
- String[] gattnames = getAttributes(gid, NC_GLOBAL);
- for (String ga : gattnames) {
- buildattr(gid, NC_GLOBAL, ga);
- }
- int[] groupids = getGroups(gid);
- for (int groupid : groupids) {
- buildgroup(gid, groupid);
- }
- }
-
- protected void buildgroup(int parent, int gid) throws DapException {
- int ret;
- byte[] namep = new byte[NC_MAX_NAME + 1];
- errcheck(ret = nc4.nc_inq_grpname(gid, namep));
- DapGroup g = factory.newGroup(Nc4DSP.makeString(namep));
- GroupNotes gi = (GroupNotes) Nc4Notes.factory(NoteSort.GROUP, parent, gid, this.dsp);
- gi.set(g);
- this.dsp.note(gi);
- GroupNotes gp = (GroupNotes) this.dsp.find(parent, NoteSort.GROUP);
- gp.get().addDecl(g);
- fillgroup(gid);
- }
-
- protected void builddim(int gid, int did, int[] udims) throws DapException {
- int ret = NC_NOERR;
- byte[] namep = new byte[NC_MAX_NAME + 1];
- SizeTByReference lenp = new SizeTByReference();
- errcheck(ret = nc4.nc_inq_dim(gid, did, namep, lenp));
- String name = Nc4DSP.makeString(namep);
- int len = lenp.intValue();
- boolean isunlimited = contains(udims, did);
- DapDimension dim = factory.newDimension(name, lenp.longValue());
- dim.setUnlimited(isunlimited);
- DimNotes di = (DimNotes) Nc4Notes.factory(NoteSort.DIM, gid, did, this.dsp);
- di.set(dim);
- this.dsp.note(di);
- GroupNotes gp = (GroupNotes) this.dsp.find(gid, NoteSort.GROUP);
- gp.get().addDecl(dim);
- if (trace)
- System.out.printf("Nc4DSP: dimension: %s size=%d%n", name, dim.getSize());
- }
-
- protected void buildusertype(int gid, int tid) throws DapException {
- int ret = NC_NOERR;
- byte[] namep = new byte[NC_MAX_NAME + 1];
- SizeTByReference lenp = new SizeTByReference();
- IntByReference basetypep = new IntByReference();
- IntByReference classp = new IntByReference();
- SizeTByReference nfieldsp = new SizeTByReference();
- errcheck(ret = nc4.nc_inq_user_type(gid, tid, namep, lenp, basetypep, nfieldsp, classp));
- String name = Nc4DSP.makeString(namep);
- int basetype = basetypep.getValue();
- long len = lenp.longValue();
- long nfields = nfieldsp.longValue();
- TypeNotes ti = (TypeNotes) Nc4Notes.factory(NoteSort.TYPE, gid, tid, this.dsp);
- switch (classp.getValue()) {
- case NC_OPAQUE:
- buildopaquetype(ti, name, len);
- break;
- case NC_ENUM:
- buildenumtype(ti, name, basetype);
- break;
- case NC_COMPOUND:
- buildcompoundtype(ti, name, nfields, len);
- break;
- case NC_VLEN:
- buildvlentype(ti, name, basetype, len);
- break;
- default:
- throw new DapException("Unknown class: " + classp.getValue());
- }
- }
-
- protected void buildopaquetype(TypeNotes ti, String name, long len) throws DapException {
- int ret;
- ti.setOpaque(len);
- DapType dt = DapType.lookup(TypeSort.Opaque);
- ti.set(dt);
- this.dsp.note(ti);
- }
-
- protected void buildenumtype(TypeNotes ti, String name, int basetype) throws DapException {
- int ret;
- SizeTByReference nmembersp = new SizeTByReference();
- SizeTByReference sizep = new SizeTByReference();
- byte[] namep = new byte[NC_MAX_NAME + 1];
- IntByReference basetypep = new IntByReference();
- IntByReference valuep = new IntByReference();
- TypeNotes base = (TypeNotes) this.dsp.find(basetype, NoteSort.TYPE);
- if (!isintegertype(base))
- throw new DapException("Enum base type must be integer type");
- errcheck(ret = nc4.nc_inq_enum(ti.gid, ti.id, namep, basetypep, sizep, nmembersp));
- DapEnumeration de = factory.newEnumeration(name, DapType.lookup(base.getType().getTypeSort()));
- ti.set(de);
- this.dsp.note(ti);
- ti.setEnumBaseType(basetype);
- ti.group().addDecl(de);
- // build list of enum consts
- int nconsts = nmembersp.intValue();
- for (int i = 0; i < nconsts; i++) {
- // Get info about the ith const
- errcheck(ret = nc4.nc_inq_enum_member(ti.gid, ti.id, i, namep, valuep));
- String ecname = Nc4DSP.makeString(namep);
- long ecval = (long) valuep.getValue();
- DapEnumConst dec = factory.newEnumConst(ecname, ecval);
- de.addEnumConst(dec);
- }
- }
-
- protected void buildcompoundtype(TypeNotes ti, String name, long nfields, long len) throws DapException {
- DapStructure ds = factory.newStructure(name);
- ti.set(ds);
- this.dsp.note(ti);
- ti.group().addDecl(ds);
- for (int i = 0; i < nfields; i++) {
- buildfield(ti, i, ds);
- }
- // Finally, extract the size of the structure
- int ret;
- SizeTByReference sizep = new SizeTByReference();
- SizeTByReference nfieldsp = new SizeTByReference();
- byte[] namep = new byte[NC_MAX_NAME + 1];
- errcheck(ret = nc4.nc_inq_compound(ti.gid, ti.id, namep, sizep, nfieldsp));
- ti.setSize(sizep.longValue());
- assert len == sizep.longValue();
- assert name.equals(Nc4DSP.makeString(namep));
- // Add the netcdf4 name as an xml attribute.
- ds.addXMLAttribute(UCARTAGORIGTYPE, name);
- }
-
- protected void buildfield(TypeNotes ti, int fid, DapStructure container) throws DapException {
- int ret;
- byte[] namep = new byte[NC_MAX_NAME + 1];
- SizeTByReference offsetp = new SizeTByReference();
- IntByReference fieldtypep = new IntByReference();
- IntByReference ndimsp = new IntByReference();
-
- // Get everything but actual dims
- errcheck(ret = nc4.nc_inq_compound_field(ti.gid, ti.id, fid, namep, offsetp, fieldtypep, ndimsp, null));
- int fieldtype = fieldtypep.getValue();
- TypeNotes baset = (TypeNotes) this.dsp.find(fieldtype, NoteSort.TYPE);
- if (baset == null)
- throw new DapException("Undefined field base type: " + fieldtype);
- int[] dimsizes = getFieldDimsizes(ti.gid, ti.id, fid, ndimsp.getValue());
- VarNotes fieldnotes = makeField(ti, fid, Nc4DSP.makeString(namep), baset, offsetp.intValue(), dimsizes);
- assert baset.getSize() > 0;
- }
-
- protected VarNotes makeField(TypeNotes container, int fieldid, String name, TypeNotes baset, int offset,
- int[] dimsizes) throws DapException {
- DapVariable field;
- DapStructure ds = (DapStructure) container.getType();
- field = factory.newVariable(name, baset.getType());
- field.setParent(ds);
- field.setFieldIndex(fieldid);
- VarNotes notes = (VarNotes) Nc4Notes.factory(NoteSort.VAR, container.gid, container.id, this.dsp);
- notes.setOffset(offset).setBaseType(baset).setContainer(container);
- notes.set(field);
- this.dsp.note(notes);
- // set dimsizes
- if (dimsizes.length > 0) {
- for (int i = 0; i < dimsizes.length; i++) {
- DapDimension dim = factory.newDimension(null, dimsizes[i]);
- field.addDimension(dim);
- }
- }
- ds.addField(field);
- return notes;
- }
-
- protected DapVariable buildvar(int gid, int vid) throws DapException {
- int ret;
- byte[] namep = new byte[NC_MAX_NAME + 1];
- IntByReference ndimsp = new IntByReference();
- IntByReference xtypep = new IntByReference();
- IntByReference nattsp = new IntByReference();
- errcheck(ret = nc4.nc_inq_var(gid, vid, namep, xtypep, ndimsp, null, nattsp));
- String name = Nc4DSP.makeString(namep);
- TypeNotes xtype = (TypeNotes) this.dsp.find(xtypep.getValue(), NoteSort.TYPE);
- if (DEBUG) {
- System.err.printf("NC4: inqvar: name=%s gid=%d vid=%d xtype=%d ndims=%d natts=%d%n", name, gid, vid, xtype.id,
- ndimsp.getValue(), nattsp.getValue());
- }
- if (xtype == null)
- throw new DapException("Unknown type id: " + xtype.id);
- DapVariable var;
- switch (((DapType) xtype.node).getTypeSort()) {
- default: /* atomic */
- var = factory.newVariable(name, xtype.getType());
- break;
- case Enum:
- var = factory.newVariable(name, xtype.getType());
- break;
- case Structure:
- DapStructure st = (DapStructure) xtype.get();
- var = factory.newVariable(name, xtype.getType());
- break;
- case Sequence:
- DapSequence seq = (DapSequence) xtype.get();
- var = factory.newVariable(name, xtype.getType());
- break;
- }
- VarNotes vi = (VarNotes) Nc4Notes.factory(NoteSort.VAR, gid, vid, this.dsp);
- vi.set(var);
- this.dsp.note(vi);
- vi.setBaseType(xtype);
- vi.group().addDecl(var);
- int[] dimids = getVardims(gid, vid, ndimsp.getValue());
- for (int i = 0; i < dimids.length; i++) {
- DimNotes di = (DimNotes) this.dsp.find(dimids[i], NoteSort.DIM);
- if (di == null)
- throw new DapException("Undefined variable dimension id: " + dimids[i]);
- var.addDimension(di.get());
- }
- // Now, if this is of type opaque, tag it with the size
- if (xtype.isOpaque()) {
- var.addXMLAttribute(UCARTAGOPAQUE, Long.toString(xtype.getSize()));
- }
- // fill in any attributes
- String[] attnames = getAttributes(gid, vid);
- for (String a : attnames) {
- buildattr(gid, vid, a);
- }
- return var;
- }
-
- protected void buildvlentype(TypeNotes ti, String vname, int basetypeid, long len) throws DapException {
- int ref;
- // We map vlen to a sequence with a single field of the
- // basetype of the vlen. Field name is same as the vlen type.
- // So we need to build two things:
- // 1. a Sequence object
- // 2. a Field
- DapSequence ds = factory.newSequence(vname);
- ti.set(ds);
- this.dsp.note(ti);
- ti.group().addDecl(ds);
- ti.markVlen();
- TypeNotes fieldtype = (TypeNotes) this.dsp.find(basetypeid, NoteSort.TYPE);
- if (fieldtype == null)
- throw new DapException("Undefined vlen basetype: " + basetypeid);
- VarNotes fieldnotes = makeField(ti, 0, vname, fieldtype, 0, new int[0]);
- // Annotate to indicate that this came from a vlen
- ds.addXMLAttribute(UCARTAGVLEN, "1");
-
- // Annotate to indicate that the original type name
- ds.addXMLAttribute(UCARTAGORIGTYPE, ds.getFQN());
-
- // Finally, extract the size of the structure, which is the same
- // as the size of the singleton field
- ti.setRecordSize(fieldtype.getSize());
- ti.setSize(Nc4prototypes.Vlen_t.VLENSIZE);
- }
-
- protected void buildattr(int gid, int vid, String name) throws DapException {
- int ret;
- boolean isglobal = (vid == NC_GLOBAL);
- IntByReference basetypep = new IntByReference();
- errcheck(ret = nc4.nc_inq_atttype(gid, vid, name, basetypep));
- int basetype = basetypep.getValue();
- TypeNotes base = (TypeNotes) this.dsp.find(basetype, NoteSort.TYPE);
- if (!islegalattrtype(base))
- throw new DapException("Non-atomic attribute types not supported: " + name);
- SizeTByReference countp = new SizeTByReference();
- errcheck(ret = nc4.nc_inq_attlen(gid, vid, name, countp));
- // Get the values of the attribute
- String[] values = getAttributeValues(gid, vid, name, base, countp.intValue());
- DapAttribute da = factory.newAttribute(name, (DapType) base.getType());
- da.setValues(values);
- if (isglobal) {
- GroupNotes gi = (GroupNotes) this.dsp.find(gid, NoteSort.GROUP);
- gi.get().addAttribute(da);
- } else {
- VarNotes vi = this.dsp.findVar(gid, vid);
- vi.get().addAttribute(da);
- }
- }
-
- //////////////////////////////////////////////////
-
- int[] getGroups(int gid) throws DapException {
- int ret, n;
- IntByReference ip = new IntByReference();
- errcheck(ret = nc4.nc_inq_grps(gid, ip, null));
- n = ip.getValue();
- int[] grpids = null;
- if (n > 0) {
- grpids = new int[n];
- errcheck(ret = nc4.nc_inq_grps(gid, ip, grpids));
- } else
- grpids = new int[0];
- return grpids;
- }
-
- int[] getDimensions(int gid) throws DapException {
- int ret, n;
- IntByReference ip = new IntByReference();
- errcheck(ret = nc4.nc_inq_ndims(gid, ip));
- n = ip.getValue();
- int[] dimids = new int[n];
- if (n > 0)
- errcheck(ret = nc4.nc_inq_dimids(gid, ip, dimids, NC_FALSE));
- return dimids;
- }
-
- int[] getUnlimitedDimensions(int gid) throws DapException {
- int ret, n;
- IntByReference ip = new IntByReference();
- errcheck(ret = nc4.nc_inq_unlimdims(gid, ip, null));
- n = ip.getValue();
- int[] dimids = new int[n];
- if (n > 0)
- errcheck(ret = nc4.nc_inq_unlimdims(gid, ip, dimids));
- return dimids;
- }
-
- int[] getUserTypes(int gid) throws DapException {
- int ret, n;
- IntByReference ip = new IntByReference();
- errcheck(ret = nc4.nc_inq_typeids(gid, ip, null));
- n = ip.getValue();
- int[] typeids = new int[n];
- if (n > 0)
- errcheck(ret = nc4.nc_inq_typeids(gid, ip, typeids));
- return typeids;
- }
-
- int[] getVars(int gid) throws DapException {
- int ret, n;
- IntByReference ip = new IntByReference();
- errcheck(ret = nc4.nc_inq_nvars(gid, ip));
- n = ip.getValue();
- int[] ids = new int[n];
- if (n > 0)
- errcheck(ret = nc4.nc_inq_varids(gid, ip, ids));
- return ids;
- }
-
- int[] getVardims(int gid, int vid, int ndims) throws DapException {
- int ret;
- int[] dimids = new int[ndims];
-
- if (ndims > 0) {
- byte[] namep = new byte[NC_MAX_NAME + 1];
- IntByReference ndimsp = new IntByReference();
- errcheck(ret = nc4.nc_inq_var(gid, vid, null, null, ndimsp, dimids, null));
- }
- return dimids;
- }
-
- int[] getFieldDimsizes(int gid, int tid, int fid, int ndims) throws DapException {
- int ret;
- int[] dimsizes = new int[ndims];
- if (ndims > 0) {
- IntByReference ndimsp = new IntByReference();
- errcheck(ret = nc4.nc_inq_compound_field(gid, tid, fid, null, null, null, ndimsp, dimsizes));
- }
- return dimsizes;
- }
-
- String[] getAttributes(int gid, int vid) throws DapException {
- int ret, n;
- boolean isglobal = (vid == NC_GLOBAL);
- IntByReference nattsp = new IntByReference();
- byte[] namep = new byte[NC_MAX_NAME + 1];
- IntByReference ndimsp = new IntByReference();
- IntByReference xtypep = new IntByReference();
- if (isglobal)
- errcheck(ret = nc4.nc_inq_natts(gid, nattsp));
- else {
- errcheck(ret = nc4.nc_inq_var(gid, vid, namep, xtypep, ndimsp, null, nattsp));
- }
- n = nattsp.getValue();
- String[] names = new String[n];
- for (int i = 0; i < n; i++) {
- errcheck(ret = nc4.nc_inq_attname(gid, vid, i, namep));
- names[i] = Nc4DSP.makeString(namep);
- }
- return names;
- }
-
- String[] getAttributeValues(int gid, int vid, String name, TypeNotes tn, int count) throws DapException {
- int ret;
- // Currently certain types only are allowed.
- if (!islegalattrtype(tn))
- throw new DapException("Unsupported attribute type: " + tn.getType().getShortName());
- if (isenumtype(tn))
- tn = enumbasetype(tn);
- Object vector = getRawAttributeValues(tn, count, gid, vid, name);
- DapType basetype = tn.getType();
- // basetype == Char requires special pre-conversion
- // since the nc file data is coming back as utf-8, not utf-16.
- if (basetype.isCharType()) {
- byte[] data = (byte[]) vector; // raw utf-8
- String sdata = new String(data, DapUtil.UTF8);
- char[] cdata = sdata.toCharArray();
- count = cdata.length;
- vector = cdata;
- }
- String[] values = (String[]) Convert.convert(DapType.STRING, basetype, vector);
- return values;
- }
-
- Object getRawAttributeValues(TypeNotes base, int count, int gid, int vid, String name) throws DapException {
- int nativetypesize = base.getType().getSize();
- if (isstringtype(base))
- nativetypesize = NC_POINTER_BYTES;
- else if (nativetypesize == 0)
- throw new DapException("Illegal Type Sort:" + base.get().getShortName());
- Object values = null;
- if (count > 0) {
- int ret;
- long totalsize = nativetypesize * count;
- Nc4Pointer mem = Nc4Pointer.allocate(totalsize);
- errcheck(ret = nc4.nc_get_att(gid, vid, name, mem.p));
- switch (base.getType().getTypeSort()) {
- case Char:
- values = mem.p.getByteArray(0, count);
- break;
- case Int8:
- values = mem.p.getByteArray(0, count);
- break;
- case UInt8:
- values = mem.p.getByteArray(0, count);
- break;
- case Int16:
- values = mem.p.getShortArray(0, count);
- break;
- case UInt16:
- values = mem.p.getShortArray(0, count);
- break;
- case Int32:
- values = mem.p.getIntArray(0, count);
- break;
- case UInt32:
- values = mem.p.getIntArray(0, count);
- break;
- case Int64:
- values = mem.p.getLongArray(0, count);
- break;
- case UInt64:
- values = mem.p.getLongArray(0, count);
- break;
- case Float32:
- values = mem.p.getFloatArray(0, count);
- break;
- case Float64:
- values = mem.p.getDoubleArray(0, count);
- break;
- case String:
- values = mem.p.getStringArray(0, count);
- break;
- case Opaque:
- values = mem.p.getByteArray(0, (int) totalsize);
- break;
- case Enum:
- break;
- default:
- throw new IllegalArgumentException("Unexpected sort: " + base.getType().getShortName());
- }
- }
- return values;
- }
-
- /*
- * Object[]
- * convert(int count, Object src, TypeNotes basetype)
- * throws DapException
- * {
- * boolean isenum = isenumtype(basetype);
- * boolean isopaque = basetype.isOpaque();
- * TypeNotes truetype = basetype;
- * if(isenum)
- * truetype = enumbasetype(basetype);
- *
- * Object[] dst;
- * if(ischartype(basetype))
- * dst = new Character[count];
- * else
- * dst = new Object[count];
- * try {
- * for(int i = 0; i < dst.length; i++) {
- * switch (basetype.getType().getTypeSort()) {
- * case Char:
- * if(src instanceof char[])
- * dst[i] = ((char[]) src)[i];
- * else
- * dst[i] = (char) (((byte[]) src)[i]);
- * break;
- * case Int8:
- * case UInt8:
- * dst[i] = ((byte[]) src)[i];
- * break;
- * case Int16:
- * case UInt16:
- * dst[i] = ((short[]) src)[i];
- * break;
- * case Int32:
- * case UInt32:
- * dst[i] = ((int[]) src)[i];
- * break;
- * case Int64:
- * case UInt64:
- * dst[i] = ((long[]) src)[i];
- * break;
- * case Float32:
- * dst[i] = ((float[]) src)[i];
- * break;
- * case Float64:
- * dst[i] = ((double[]) src)[i];
- * break;
- * case String:
- * dst[i] = ((String[]) src)[i];
- * break;
- * case Opaque:
- * byte[] alldata = (byte[]) src;
- * int oplen = alldata.length / count;
- * for(i = 0; i < count; i++) {
- * dst[i] = new byte[oplen];
- * System.arraycopy(alldata, oplen * i, dst[i], 0, oplen);
- * }
- * break;
- * case Enum:
- * dst = convert(count, src, truetype);
- * break;
- * default:
- * throw new IllegalArgumentException("Unexpected sort: " + basetype.getType().getShortName());
- * }
- * }
- * return dst;
- * } catch (IllegalArgumentException |
- * ArrayIndexOutOfBoundsException e
- * ) {
- * throw new DapException(e);
- * }
- * }
- */
-
- protected void errcheck(int ret) throws DapException {
- if (ret != 0) {
- String msg = String.format("TestNetcdf: errno=%d; %s", ret, nc4.nc_strerror(ret));
- if (DEBUG)
- System.err.println(msg);
- throw new DapException(msg);
- }
- }
-
- boolean contains(int[] list, int value) {
- for (int i = 0; i < list.length; i++) {
- if (list[i] == value)
- return true;
- }
- return false;
- }
-
- boolean islegalattrtype(TypeNotes nctype) {
- return isatomictype(nctype) || isenumtype(nctype) || nctype.isOpaque();
- }
-
- boolean isatomictype(TypeNotes t) {
- return (t.id <= NC_MAX_ATOMIC_TYPE);
- }
-
- boolean isstringtype(TypeNotes nctype) {
- return (nctype.id == NC_STRING);
- }
-
- boolean ischartype(TypeNotes t) {
- return (t.id == NC_CHAR);
- }
-
- boolean isintegertype(TypeNotes t) {
- return (t.id <= NC_UINT64 && t.id != NC_CHAR);
- }
-
- boolean isenumtype(TypeNotes nctype) {
- return (nctype == null ? false : nctype.getType().isEnumType());
- }
-
- TypeNotes enumbasetype(TypeNotes etype) {
- if (etype == null || !etype.getType().isEnumType())
- return null;
- DapType dt = ((DapEnumeration) etype.getType()).getBaseType();
- return (TypeNotes) this.dsp.find(dt);
- }
-
- protected String Nc4FQN(TypeNotes t) throws DapException {
- int ret = 0;
- // get enclosing ncid fqn
- SizeTByReference lenp = new SizeTByReference();
- errcheck(ret = nc4.nc_inq_grpname_len(t.gid, lenp));
- byte[] namep = new byte[lenp.intValue() + 1];
- errcheck(ret = nc4.nc_inq_grpname_full(t.gid, lenp, namep));
- return Nc4DSP.makeString(namep);
- }
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4DSP.java b/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4DSP.java
deleted file mode 100644
index 6c05c40251..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4DSP.java
+++ /dev/null
@@ -1,405 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-/*
- * TODO:
- * 1. make sure all nodes areproperly annotated
- */
-
-
-package dap4.dap4lib.netcdf;
-
-import com.sun.jna.Memory;
-import com.sun.jna.Native;
-import com.sun.jna.Pointer;
-import com.sun.jna.ptr.IntByReference;
-import dap4.core.data.DataCursor;
-import dap4.core.dmr.DMRFactory;
-import dap4.core.dmr.DapNode;
-import dap4.core.dmr.DapType;
-import dap4.core.dmr.DapVariable;
-import dap4.core.util.DapContext;
-import dap4.core.util.DapException;
-import dap4.core.util.DapUtil;
-import dap4.dap4lib.AbstractDSP;
-import dap4.dap4lib.DapCodes;
-import dap4.dap4lib.XURI;
-import ucar.nc2.ffi.netcdf.NetcdfClibrary;
-import ucar.nc2.jni.netcdf.Nc4prototypes;
-import ucar.nc2.jni.netcdf.SizeTByReference;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
-import static dap4.dap4lib.netcdf.Nc4Notes.*;
-import static ucar.nc2.jni.netcdf.Nc4prototypes.*;
-
-/**
- * DSP for reading netcdf files through jni interface to netcdf4 library
- */
-public class Nc4DSP extends AbstractDSP {
- //////////////////////////////////////////////////
- // Constants
-
- public static final boolean DEBUG = false;
- public static final boolean DUMPDMR = false;
-
- static String PATHSUFFIX = "/src/data";
-
- public static String[] EXTENSIONS = new String[] {".nc", ".hdf5"};
-
- static final Pointer NC_NULL = Pointer.NULL;
- static final int NC_FALSE = 0;
- static final int NC_TRUE = 1;
- // "null" id(s)
- public static final int NC_GRPNULL = 0;
- public static final int NC_IDNULL = -1;
- public static final int NC_NOERR = 0;
-
- static int NC_INT_BYTES = (java.lang.Integer.SIZE / java.lang.Byte.SIZE);
- static int NC_LONG_BYTES = (Native.LONG_SIZE);
- static int NC_POINTER_BYTES = (Native.POINTER_SIZE);
- static int NC_SIZET_BYTES = (Native.SIZE_T_SIZE);
-
- protected static Nc4prototypes nc4 = NetcdfClibrary.getForeignFunctionInterface();
-
- //////////////////////////////////////////////////
- // com.sun.jna.Memory control
-
- /**
- * Provide a wrapper for pointers that tracks the size.
- * Also allows for allocation.
- */
- public static class Nc4Pointer {
- public static Nc4Pointer allocate(long size) {
- if (size == 0)
- throw new IllegalArgumentException("Attempt to allocate zero bytes");
- Memory m = new Memory(size);
- return new Nc4Pointer(m, size);
- }
-
- public Pointer p; // alow direct access
- public long size; // allow direct access
-
- public Nc4Pointer(Pointer p, long size) {
- this.p = p;
- this.size = size;
- }
-
- public Nc4Pointer share(long offset, long size) {
- try {
- Pointer ps = p.share(offset, size);
- Nc4Pointer newp = new Nc4Pointer(ps, size);
- return newp;
- } catch (IndexOutOfBoundsException e) {
- return null;
- }
- }
-
- public String toString() {
- return String.format("0x%016x/%d", Pointer.nativeValue(this.p), this.size);
- }
-
- public static boolean validate(Nc4Pointer mem, long require) {
- if (mem == null || mem.p == null || mem.size == 0)
- return false;
- return (mem.size > require);
- }
- }
-
- //////////////////////////////////////////////////
- // DSP Match API
-
- /**
- * A path is file if it has no base protocol or is file:
- *
- * @param path
- * @param context Any parameters that may help to decide.
- * @return true if this path appears to be processible by this DSP
- */
- public boolean dspMatch(String path, DapContext context) {
- for (String s : EXTENSIONS) {
- if (path.endsWith(s))
- return true;
- }
- return false;
- }
-
- //////////////////////////////////////////////////
- // Notes Management
-
- protected Map> allnotes = null;
-
- /* package */ void note(Notes note) {
- assert (this.allnotes != null);
- int gid = note.gid;
- int id = note.id;
- NoteSort sort = note.getSort();
- Map sortnotes = this.allnotes.get(sort);
- assert sortnotes != null;
- switch (sort) {
- case TYPE:
- case GROUP:
- case DIM:
- assert sortnotes.get(id) == null;
- sortnotes.put((long) id, note);
- break;
- case VAR:
- long gv = Nc4Notes.getVarId((VarNotes) note);
- assert sortnotes.get(gv) == null;
- sortnotes.put(gv, note);
- break;
- }
- }
-
- /* package */ VarNotes findVar(int gid, int varid) {
- long gv = Nc4Notes.getVarId(gid, varid, -1);
- return (VarNotes) find(gv, NoteSort.VAR);
- }
-
- /* package */ VarNotes findField(int gid, int varid, int fid) {
- long gv = Nc4Notes.getVarId(gid, varid, fid);
- return (VarNotes) find(gv, NoteSort.VAR);
- }
-
- public Notes find(long id, NoteSort sort) {
- assert (this.allnotes != null);
- Map sortnotes = this.allnotes.get(sort);
- assert sortnotes != null;
- return sortnotes.get((long) id);
- }
-
- /* package */Notes find(DapNode node) {
- NoteSort sort = noteSortFor(node);
- assert (this.allnotes != null);
- Map sortnotes = this.allnotes.get(sort);
- assert sortnotes != null;
- for (Map.Entry entries : sortnotes.entrySet()) {
- Notes note = entries.getValue();
- if (note.get() == node)
- return note;
- }
- return null;
- }
-
- protected NoteSort noteSortFor(DapNode node) {
- switch (node.getSort()) {
- case ATOMICTYPE:
- case STRUCTURE:
- case SEQUENCE:
- return NoteSort.TYPE;
- case VARIABLE:
- return NoteSort.VAR;
- case GROUP:
- case DATASET:
- return NoteSort.GROUP;
- case DIMENSION:
- return NoteSort.DIM;
- default:
- break;
- }
- return null;
- }
-
- protected void allnotesInit() {
- this.allnotes = new HashMap<>();
- for (NoteSort s : NoteSort.values()) {
- this.allnotes.put(s, new HashMap());
- }
- Notes n;
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_BYTE, this);
- n.set(DapType.INT8);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_CHAR, this);
- n.set(DapType.CHAR);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_SHORT, this);
- n.set(DapType.INT16);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_INT, this);
- n.set(DapType.INT32);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_FLOAT, this);
- n.set(DapType.FLOAT32);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_DOUBLE, this);
- n.set(DapType.FLOAT64);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_UBYTE, this);
- n.set(DapType.UINT8);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_USHORT, this);
- n.set(DapType.UINT16);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_UINT, this);
- n.set(DapType.UINT32);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_INT64, this);
- n.set(DapType.INT64);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_UINT64, this);
- n.set(DapType.UINT64);
- this.note(n);
- n = Nc4Notes.factory(NoteSort.TYPE, 0, NC_STRING, this);
- n.set(DapType.STRING);
- this.note(n);
-
- for (int i = NC_BYTE; i <= NC_MAX_ATOMIC_TYPE; i++) {
- Nc4Notes.TypeNotes tn = (Nc4Notes.TypeNotes) find(i, NoteSort.TYPE);
- assert tn != null;
- int ret = 0;
- byte[] namep = new byte[NC_MAX_NAME + 1];
- if (i == NC_STRING) {
- // There is a bug in some versions of netcdf that does not
- // handle NC_STRING correctly when the gid is invalid.
- // Handle specially ; this is a temporary hack
- //
- // 8/16/2019 jlcaron upgrade to jna 5.4.0
- // com.sun.jna.Pointer#SIZE is removed. Its use is replaced by
- // com.sun.jna.Native#POINTER_SIZE to prevent a class loading deadlock, when JNA is initialized from multiple
- // threads
- tn.setSize(Native.POINTER_SIZE);
- } else {
- SizeTByReference sizep = new SizeTByReference();
- try {
- Nc4Cursor.errcheck(getJNI(), ret = nc4.nc_inq_type(0, i, namep, sizep));
- } catch (DapException e) {
- e.printStackTrace();
- assert false; // should never happen
- }
- tn.setSize(sizep.intValue());
- }
- }
- }
-
- //////////////////////////////////////////////////
- // Instance Variables
-
- protected boolean trace = false;
- protected boolean closed = false;
-
- protected int ncid = -1; // file id ; also set as DSP.source
- protected int format = 0; // from nc_inq_format
- protected int mode = 0;
- protected String filepath = null; // real path to the dataset
-
- protected DMRFactory dmrfactory = null;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public Nc4DSP() throws DapException {
- super();
- if (nc4 == null) {
- throw new DapException("Could not load libnetcdf");
- }
- dmrfactory = new DMRFactory();
- allnotesInit();
- }
-
- //////////////////////////////////////////////////
- // DSP API
-
- @Override
- public Nc4DSP open(String filepath) throws DapException {
- if (filepath.startsWith("file:"))
- try {
- XURI xuri = new XURI(filepath);
- filepath = xuri.getPath();
- } catch (URISyntaxException use) {
- throw new DapException("Malformed filepath: " + filepath).setCode(DapCodes.SC_NOT_FOUND);
- }
- int ret, mode;
- IntByReference ncidp = new IntByReference();
- this.filepath = filepath;
- try {
- mode = NC_NOWRITE;
- Nc4Cursor.errcheck(nc4, ret = nc4.nc_open(this.filepath, mode, ncidp));
- this.ncid = ncidp.getValue();
- // Figure out what kind of file
- IntByReference formatp = new IntByReference();
- Nc4Cursor.errcheck(nc4, ret = nc4.nc_inq_format(ncid, formatp));
- this.format = formatp.getValue();
- if (DEBUG)
- System.out.printf("TestNetcdf: open: %s; ncid=%d; format=%d%n", this.filepath, ncid, this.format);
- // Compile the DMR
- Nc4DMRCompiler dmrcompiler = new Nc4DMRCompiler(this, ncid, dmrfactory);
- setDMR(dmrcompiler.compile());
- if (DEBUG || DUMPDMR) {
- System.err.println("+++++++++++++++++++++");
- System.err.println(printDMR(getDMR()));
- System.err.println("+++++++++++++++++++++");
- }
- return this;
- } catch (Exception t) {
- t.printStackTrace();
- }
- return null;
- }
-
- @Override
- public void close() throws DapException {
- if (this.closed)
- return;
- if (this.ncid < 0)
- return;
- int ret = nc4.nc_close(ncid);
- Nc4Cursor.errcheck(nc4, ret);
- closed = true;
- if (trace)
- System.out.printf("Nc4DSP: closed: %s%n", this.filepath);
- }
-
- @Override
- public Nc4Cursor getVariableData(DapVariable var) throws DapException {
- assert (var.isTopLevel());
- DapType type = var.getBaseType();
- Nc4Cursor vardata = (Nc4Cursor) super.getVariableData(var);
- if (vardata == null) {
- switch (type.getTypeSort()) {
- case Structure:
- vardata = new Nc4Cursor(DataCursor.Scheme.STRUCTARRAY, this, var, null);
- break;
- case Sequence:
- vardata = new Nc4Cursor(DataCursor.Scheme.SEQARRAY, this, var, null);
- break;
- default:
- if (!type.isAtomic())
- throw new DapException("Unexpected cursor type: " + type);
- vardata = new Nc4Cursor(DataCursor.Scheme.ATOMIC, this, var, null);
- break;
- }
- super.addVariableData(var, vardata);
- }
- assert var.isTopLevel();
- return vardata;
- }
-
- //////////////////////////////////////////////////
- // Accessors
-
-
- public Nc4prototypes getJNI() {
- return nc4;
- }
-
- @Override
- public String getLocation() {
- return this.filepath;
- }
-
- //////////////////////////////////////////////////
- // Utilities
-
- public static String makeString(byte[] b) {
- // null terminates
- int count;
- for (count = 0; (count < b.length && b[count] != 0); count++) {
- ;
- }
- return new String(b, 0, count, DapUtil.UTF8);
- }
-
-
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4Notes.java b/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4Notes.java
deleted file mode 100644
index a2f571a07a..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/netcdf/Nc4Notes.java
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib.netcdf;
-
-import dap4.core.dmr.*;
-import dap4.core.util.DapSort;
-import dap4.core.util.DapUtil;
-
-/**
- * Note that ideally, this info should be part of the
- * Nc4DMR classes, but that would require multiple inheritance.
- * Hence, we isolate that info here and add it to the instances
- * via annotation
- */
-
-public abstract class Nc4Notes {
- //////////////////////////////////////////////////
- // Constants
-
- // Mnemonics
- public static final int NOGROUP = -1;
- public static final int NOID = -1;
- public static final int NOFIELDID = -1;
-
- //////////////////////////////////////////////////
- // Use a factory so we can debug constructor calls
-
- static Notes factory(NoteSort ns, int g, int id, Nc4DSP dsp) {
- Notes note = null;
- switch (ns) {
- case TYPE:
- note = new TypeNotes(g, id, dsp);
- break;
- case VAR:
- note = new VarNotes(g, id, dsp);
- break;
- case DIM:
- note = new DimNotes(g, id, dsp);
- break;
- case GROUP:
- note = new GroupNotes(g, id, dsp);
- break;
- }
- return note;
- }
-
- //////////////////////////////////////////////////
- // Manage the compound id for variables
-
- public static long getVarId(VarNotes note) {
- return getVarId(note.gid, note.id, note.getFieldIndex());
- }
-
- public static long getVarId(int gid, int varid, int ifid) {
- long gv = ((long) gid) << 32;
- assert varid < 0x100000;
- gv = gv | ((long) varid) << 20;
- long fid = (long) ifid;
- if (fid >= 0)
- gv |= fid;
- return gv;
- }
-
- //////////////////////////////////////////////////
- // Type Decls
-
- public static enum NoteSort {
- TYPE, VAR, GROUP, DIM;
- }
-
- public static class Notes implements Cloneable {
- Nc4DSP dsp; // Need a place to store global state
- NoteSort sort;
- int gid;
- int id;
- DapNode node = null;
- protected String name = null;
- protected Notes parent = null;
- protected TypeNotes basetype = null;
- protected long offset = 0;
- // For most types, there is only one size,
- // but for vlen/sequence, there are two sizes:
- // (1) the record size and (2) the instance size (= |vlen_t|);
- protected long size = 0;
- protected long recordsize = 0;
-
- protected Notes(NoteSort sort, int gid, int id, Nc4DSP dsp) {
- this.sort = sort;
- this.dsp = dsp;
- this.gid = gid;
- this.id = id;
- }
-
- public NoteSort getSort() {
- return this.sort;
- }
-
- public Notes setName(String name) {
- this.name = name;
- return this;
- }
-
- public Notes set(DapNode node) {
- this.node = node;
- if (this.name == null)
- setName(node.getShortName());
- return this;
- }
-
- public DapNode get() {
- return this.node;
- }
-
- public Notes setContainer(Notes parent) {
- this.parent = parent;
- return this;
- }
-
- public Notes getContainer() {
- return this.parent;
- }
-
- public long getOffset() {
- return this.offset;
- }
-
- public Notes setOffset(long offset) {
- this.offset = offset;
- return this;
- }
-
- public long getSize() {
- return this.size;
- }
-
- public Notes setSize(long size) {
- this.size = size;
- return this;
- }
-
- public long getRecordSize() {
- return this.recordsize;
- }
-
- public Notes setRecordSize(long size) {
- this.recordsize = size;
- return this;
- }
-
- public Notes setBaseType(TypeNotes t) {
- this.basetype = t;
- return this;
- }
-
- public TypeNotes getBaseType() {
- return this.basetype;
- }
-
- DapGroup group() {
- GroupNotes g = (GroupNotes) dsp.find(gid, NoteSort.GROUP);
- return (g == null ? null : g.get());
- }
-
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append(this.getClass().getName());
- buf.append("{");
- if (name != null) {
- buf.append("name=");
- buf.append(name);
- }
- buf.append(" node=");
- buf.append(this.node != null ? this.node.getShortName() : "null");
- if (this.basetype != null) {
- buf.append(" type=");
- buf.append(this.node.getShortName());
- }
- buf.append("}");
- return buf.toString();
- }
- }
-
- public static class GroupNotes extends Notes {
- protected GroupNotes(int p, int g, Nc4DSP dsp) {
- super(NoteSort.GROUP, p, g, dsp);
- }
-
- public DapGroup get() {
- return (DapGroup) super.get();
- }
-
- public GroupNotes set(DapNode node) {
- return (GroupNotes) super.set(node);
- }
-
- }
-
- public static class DimNotes extends Notes {
- protected DimNotes(int g, int id, Nc4DSP dsp) {
- super(NoteSort.DIM, g, id, dsp);
- }
-
- public DapDimension get() {
- return (DapDimension) super.get();
- }
-
- public DimNotes set(DapNode node) {
- return (DimNotes) super.set(node);
- }
-
- }
-
- public static class TypeNotes extends Notes {
- public int enumbase = -1;
- public boolean isvlen = false;
-
- protected TypeNotes(int g, int id, Nc4DSP dsp) {
- super(NoteSort.TYPE, g, id, dsp);
- }
-
- public DapType getType() {
- DapSort sort = this.node.getSort();
- switch (sort) {
- case ATOMICTYPE:
- case STRUCTURE:
- case SEQUENCE:
- return (DapType) super.get();
- case ENUMERATION:
- return (DapEnumeration) super.get();
- case VARIABLE:
- return ((DapVariable) super.get()).getBaseType();
- default:
- break;
- }
- return null;
- }
-
- public TypeNotes setOpaque(long len) {
- super.setSize(len);
- return this;
- }
-
- public TypeNotes setEnumBaseType(int bt) {
- this.enumbase = bt;
- TypeNotes btt = (TypeNotes) this.dsp.find(bt, NoteSort.TYPE);
- setSize(btt.getSize());
- return this;
- }
-
- public boolean isOpaque() {
- return getType().getTypeSort().isOpaqueType();
- }
-
- public boolean isEnum() {
- return getType().getTypeSort().isEnumType();
- }
-
- public boolean isSeq() {
- return getType().getTypeSort().isSeqType();
- }
-
- public boolean isCompound() {
- return getType().getTypeSort().isCompoundType();
- }
-
- public boolean isVlen() {
- return this.isvlen;
- }
-
- public TypeNotes markVlen() {
- this.isvlen = true;
- return this;
- }
-
- public DapType get() {
- return (DapType) super.get();
- }
-
- public TypeNotes set(DapNode node) {
- return (TypeNotes) super.set(node);
- }
-
- }
-
- public static class VarNotes extends Notes {
- protected VarNotes(int g, int v, Nc4DSP dsp) {
- super(NoteSort.VAR, g, v, dsp);
- }
-
- public VarNotes setBaseType(TypeNotes ti) {
- return (VarNotes) super.setBaseType(ti);
- }
-
- public DapVariable get() {
- return (DapVariable) super.get();
- }
-
- public VarNotes set(DapNode node) {
- return (VarNotes) super.set(node);
- }
-
- public int getFieldIndex() {
- assert this.get() != null;
- return this.get().getFieldIndex();
- }
-
- @Override
- public long getSize() {
- return this.getBaseType().getSize() * DapUtil.dimProduct(get().getDimensions());
- }
-
- }
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/serial/D4Cursor.java b/dap4/d4lib/src/main/java/dap4/dap4lib/serial/D4Cursor.java
deleted file mode 100644
index 82979ab524..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/serial/D4Cursor.java
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib.serial;
-
-import dap4.core.dmr.*;
-import dap4.core.util.*;
-import dap4.dap4lib.AbstractCursor;
-import dap4.dap4lib.LibTypeFcns;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-
-public class D4Cursor extends AbstractCursor {
- //////////////////////////////////////////////////
- // Mnemonics
- static final long NULLOFFSET = -1;
-
- static final int D4LENSIZE = 8;
-
- //////////////////////////////////////////////////
- // Instance Variables
-
- protected long offset = NULLOFFSET;
-
- protected long[] bytestrings = null;
-
- // For debugging purposes, we keep these separate,
- // but some merging could be done .
-
- // Track the array elements for a structure array
- protected D4Cursor[] elements = null; // scheme == STRUCTARRAY|SEQARRAY
-
- // Track the fields of a structure instance
- protected D4Cursor[] fieldcursors = null; // scheme == STRUCTURE|SEQUENCE
-
- // Track the records of a sequence instance
- protected List records = null; // scheme == SEQUENCE
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public D4Cursor(Scheme scheme, D4DSP dsp, DapNode template, D4Cursor container) {
- super(scheme, dsp, template, container);
- }
-
- /**
- * Effectively a clone of c
- *
- * @param c cursor to clone
- */
- public D4Cursor(D4Cursor c) {
- super(c);
- assert false;
- this.offset = c.offset;
- this.bytestrings = c.bytestrings;
- this.fieldcursors = new D4Cursor[c.fieldcursors.length];
- for (int i = 0; i < c.fieldcursors.length; i++) {
- D4Cursor dc = c.fieldcursors[i];
- this.fieldcursors[i] = new D4Cursor(dc);
- this.fieldcursors[i].setContainer(this); // Change the parent in the clone
- }
- this.elements = new D4Cursor[c.elements.length];
- for (int i = 0; i < c.elements.length; i++) {
- D4Cursor dc = c.elements[i];
- this.elements[i] = new D4Cursor(dc);
- this.elements[i].setContainer(this); // Change the parent in the clone
- }
- this.records = new ArrayList<>();
- for (int i = 0; i < c.records.size(); i++) {
- D4Cursor dc = c.records.get(i);
- this.records.add(new D4Cursor(dc));
- this.records.get(i).setContainer(this); // Change the parent in the clone
- }
- }
-
- //////////////////////////////////////////////////
- // DataCursor API (Except as Implemented in AbstractCursor)
-
-
- @Override
- public Object read(Index index) throws DapException {
- return read(DapUtil.indexToSlices(index));
- }
-
- @Override
- public Object read(List slices) throws DapException {
- switch (this.scheme) {
- case ATOMIC:
- return readAtomic(slices);
- case STRUCTURE:
- case SEQUENCE:
- if (((DapVariable) this.getTemplate()).getRank() == 0 || DapUtil.isScalarSlices(slices))
- throw new DapException("Cannot slice a scalar variable");
- return new D4Cursor(this);
- case STRUCTARRAY:
- // Read the structures specified by slices
- Odometer odom = Odometer.factory(slices);
- D4Cursor[] instances = new D4Cursor[(int) odom.totalSize()];
- for (int i = 0; odom.hasNext(); i++) {
- instances[i] = readStructure(odom.next());
- }
- return instances;
- case SEQARRAY:
- odom = Odometer.factory(slices);
- instances = new D4Cursor[(int) odom.totalSize()];
- for (int i = 0; odom.hasNext(); i++) {
- instances[i] = readSequence(odom.next());
- }
- return instances;
- default:
- throw new DapException("Attempt to slice a scalar object");
- }
- }
-
- @Override
- public D4Cursor readField(int findex) throws DapException {
- assert (this.scheme == scheme.RECORD || this.scheme == scheme.STRUCTURE);
- DapStructure basetype = (DapStructure) ((DapVariable) getTemplate()).getBaseType();
- if (findex < 0 || findex >= basetype.getFields().size())
- throw new DapException("Field index out of range: " + findex);
- D4Cursor field = this.fieldcursors[findex];
- return field;
- }
-
- @Override
- public D4Cursor readRecord(long i) {
- assert (this.scheme == Scheme.SEQUENCE);
- if (this.records == null || i < 0 || i > this.records.size())
- throw new IndexOutOfBoundsException("No such record: " + i);
- return this.records.get((int) i);
- }
-
- @Override
- public long getRecordCount() {
- assert (this.scheme == Scheme.SEQUENCE);
- return this.records == null ? 0 : this.records.size();
- }
-
- //////////////////////////////////////////////////
- // Support methods
-
- protected Object readAtomic(List slices) throws DapException {
- if (slices == null)
- throw new DapException("DataCursor.read: null set of slices");
- assert this.scheme == Scheme.ATOMIC;
- DapVariable atomvar = (DapVariable) getTemplate();
- int rank = atomvar.getRank();
- assert slices != null && ((rank == 0 && slices.size() == 1) || (slices.size() == rank));
- DapType basetype = atomvar.getBaseType();
- return readAs(atomvar, basetype, slices);
- }
-
- /**
- * Allow specification of basetype to use; used for enumerations
- *
- * @param atomvar
- * @param basetype
- * @param slices
- * @return Object of basetype
- * @throws DapException
- */
- protected Object readAs(DapVariable atomvar, DapType basetype, List slices) throws DapException {
- if (basetype.getTypeSort() == TypeSort.Enum) {// short circuit this case
- basetype = ((DapEnumeration) basetype).getBaseType();
- return readAs(atomvar, basetype, slices);
- }
- long count = DapUtil.sliceProduct(slices);
- Object result = LibTypeFcns.newVector(basetype, count);
- Odometer odom = Odometer.factory(slices);
- if (DapUtil.isContiguous(slices) && basetype.isFixedSize())
- readContig(slices, basetype, count, odom, result);
- else
- readOdom(slices, basetype, odom, result);
- return result;
- }
-
- protected void readContig(List slices, DapType basetype, long count, Odometer odom, Object result)
- throws DapException {
- ByteBuffer alldata = ((D4DSP) this.dsp).getBuffer();
- long off = this.offset;
- long ix = odom.indices().index();
- int elemsize = basetype.getSize();
- alldata.position((int) (off + (ix * elemsize)));
- int icount = (int) count;
- long totalsize = count * basetype.getSize();
- switch (basetype.getTypeSort()) {
- case Int8:
- case UInt8:
- alldata.get((byte[]) result);
- break;
- case Char: // remember, we are reading 7-bit ascii, not utf-8 or utf-16
- byte[] ascii = new byte[icount];
- alldata.get(ascii);
- for (int i = 0; i < icount; i++) {
- ((char[]) result)[i] = (char) (ascii[i] & 0x7f);
- }
- break;
- case Int16:
- case UInt16:
- alldata.asShortBuffer().get((short[]) result);
- skip(totalsize, alldata);
- break;
- case Int32:
- case UInt32:
- alldata.asIntBuffer().get((int[]) result);
- skip(totalsize, alldata);
- break;
- case Int64:
- case UInt64:
- alldata.asLongBuffer().get((long[]) result);
- skip(totalsize, alldata);
- break;
- case Float32:
- alldata.asFloatBuffer().get((float[]) result);
- skip(totalsize, alldata);
- break;
- case Float64:
- alldata.asDoubleBuffer().get((double[]) result);
- skip(totalsize, alldata);
- break;
- default:
- throw new DapException("Contiguous read not supported for type: " + basetype.getTypeSort());
- }
- }
-
- protected Object readOdom(List slices, DapType basetype, Odometer odom, Object result) throws DapException {
- ByteBuffer alldata = ((D4DSP) this.dsp).getBuffer();
- alldata.position((int) this.offset);
- ByteBuffer slice = alldata.slice();
- slice.order(alldata.order());
- for (int i = 0; odom.hasNext(); i++) {
- Index index = odom.next();
- int ipos = (int) index.index();
- switch (basetype.getTypeSort()) {
- case Int8:
- case UInt8:
- ((byte[]) result)[i] = slice.get(ipos);
- break;
- case Char: // remember, we are reading 7-bit ascii, not utf-8 or utf-16
- byte ascii = slice.get(ipos);
- ((char[]) result)[i] = (char) ascii;
- break;
- case Int16:
- case UInt16:
- ((short[]) result)[i] = slice.getShort(ipos);
- break;
- case Int32:
- case UInt32:
- ((int[]) result)[i] = slice.getInt(ipos);
- break;
- case Int64:
- case UInt64:
- ((long[]) result)[i] = slice.getLong(ipos);
- break;
- case Float32:
- ((float[]) result)[i] = slice.getFloat(ipos);
- break;
- case Float64:
- ((double[]) result)[i] = slice.getDouble(ipos);
- break;
- case String:
- case URL:
- int savepos = alldata.position();
- long pos = bytestrings[i];
- alldata.position((int) pos); // bytestring offsets are absolute
- long n = getLength(alldata);
- byte[] data = new byte[(int) n];
- alldata.get(data);
- ((String[]) result)[i] = new String(data, DapUtil.UTF8);
- alldata.position(savepos);
- break;
- case Opaque:
- savepos = alldata.position();
- pos = bytestrings[i];
- alldata.position((int) pos); // bytestring offsets are absolute
- n = getLength(alldata);
- data = new byte[(int) n];
- alldata.get(data);
- ByteBuffer buf = ByteBuffer.wrap(data);
- ((ByteBuffer[]) result)[i] = buf;
- alldata.position(savepos);
- break;
- default:
- throw new DapException("Attempt to read non-atomic value of type: " + basetype.getTypeSort());
- }
- }
- return result;
- }
-
- protected D4Cursor readStructure(Index index) throws DapException {
- assert (this.scheme == Scheme.STRUCTARRAY);
- long pos = index.index();
- long avail = (this.elements == null ? 0 : this.elements.length);
- if (pos < 0 || pos > avail)
- throw new IndexOutOfBoundsException("read: " + index);
- return this.elements[(int) pos];
- }
-
- public D4Cursor readSequence(Index index) throws DapException {
- assert (this.scheme == Scheme.SEQARRAY);
- long pos = index.index();
- long avail = (this.elements == null ? 0 : this.elements.length);
- if (pos < 0 || pos > avail)
- throw new IndexOutOfBoundsException("read: " + index);
- return this.elements[(int) pos];
- }
-
- //////////////////////////////////////////////////
- // D4Cursor Extensions
-
- public D4Cursor setElements(D4Cursor[] instances) {
- if (!(getScheme() == Scheme.SEQARRAY || getScheme() == Scheme.STRUCTARRAY))
- throw new IllegalStateException("Adding element to !(structure|sequence array) object");
- DapVariable var = (DapVariable) getTemplate();
- this.elements = instances;
- return this;
- }
-
- public D4Cursor setOffset(long pos) {
- this.offset = pos;
- return this;
- }
-
- public D4Cursor setByteStringOffsets(long total, long[] positions) {
- this.bytestrings = positions;
- return this;
- }
-
- public D4Cursor addField(int m, D4Cursor field) {
- if (getScheme() != Scheme.RECORD && getScheme() != Scheme.STRUCTURE)
- throw new IllegalStateException("Adding field to non-(structure|record) object");
- if (this.fieldcursors == null) {
- DapStructure ds = (DapStructure) ((DapVariable) getTemplate()).getBaseType();
- List fields = ds.getFields();
- this.fieldcursors = new D4Cursor[fields.size()];
- }
- if (this.fieldcursors[m] != null)
- throw new IndexOutOfBoundsException("Adding duplicate fields at position:" + m);
- this.fieldcursors[m] = field;
- return this;
- }
-
- public D4Cursor addRecord(D4Cursor rec) {
- if (getScheme() != Scheme.SEQUENCE)
- throw new IllegalStateException("Adding record to non-sequence object");
- if (this.records == null)
- this.records = new ArrayList<>();
- this.records.add(rec);
- return this;
- }
-
- public long getElementSize(DapVariable v) {
- return v.getBaseType().isFixedSize() ? v.getBaseType().getSize() : 0;
- }
-
- static ByteBuffer skip(long n, ByteBuffer b) {
- if (b.position() + ((int) n) > b.limit())
- throw new IllegalArgumentException();
- b.position(b.position() + ((int) n));
- return b;
- }
-
- public static long getLength(ByteBuffer b) {
- if (b.position() + D4LENSIZE > b.limit())
- throw new IllegalArgumentException();
- long n = b.getLong();
- return n;
- }
-
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/serial/D4DSP.java b/dap4/d4lib/src/main/java/dap4/dap4lib/serial/D4DSP.java
deleted file mode 100644
index a841cc9e6b..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/serial/D4DSP.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-package dap4.dap4lib.serial;
-
-import dap4.core.dmr.DapDataset;
-import dap4.core.util.DapDump;
-import dap4.core.util.DapException;
-import dap4.dap4lib.AbstractDSP;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-/**
- * DAP4 Serial to DSP interface
- * This code should be completely independent of thredds.
- * Its goal is to provide a DSP interface to
- * a sequence of bytes representing serialized data, possibly
- * including a leading DMR.
- */
-
-public abstract class D4DSP extends AbstractDSP {
- //////////////////////////////////////////////////
- // Constants
-
- public static boolean DEBUG = false;
- public static boolean DUMPDMR = false;
- public static boolean DUMPDAP = false;
-
- protected static final String DAPVERSION = "4.0";
- protected static final String DMRVERSION = "1.0";
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected ByteBuffer databuffer = null; // local copy of AbstractDSP.getSource
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- public D4DSP() {
- super();
- }
-
- //////////////////////////////////////////////////
- // DSP API
- // Most is left to be subclass defined;
-
- //////////////////////////////////////////////////
- // (Other) Accessors
-
- /* packge */ ByteBuffer getBuffer() {
- return databuffer;
- }
-
- //////////////////////////////////////////////////
- // Compilation
-
- protected void build(String document, byte[] serialdata, ByteOrder order) throws DapException {
- DapDataset dmr = parseDMR(document);
-
- if (DEBUG || DUMPDMR) {
- System.err.println("\n+++++++++++++++++++++");
- System.err.println(dmr);
- System.err.println("+++++++++++++++++++++\n");
- }
- if (DEBUG || DUMPDAP) {
- ByteBuffer data = ByteBuffer.wrap(serialdata);
- System.err.println("+++++++++++++++++++++");
- System.err.println("\n---------------------");
- DapDump.dumpbytes(data, false);
- System.err.println("\n---------------------\n");
- }
- build(dmr, serialdata, order);
- }
-
- /**
- * Build the data from the incoming serial data
- * Note that some DSP's will not use
- *
- * @param dmr
- * @param serialdata
- * @param order
- * @throws DapException
- */
- protected void build(DapDataset dmr, byte[] serialdata, ByteOrder order) throws DapException {
- setDMR(dmr);
- // "Compile" the databuffer section of the server response
- this.databuffer = ByteBuffer.wrap(serialdata).order(order);
- D4DataCompiler compiler = new D4DataCompiler(this, getChecksumMode(), getOrder(), this.databuffer);
- compiler.compile();
- }
-
-}
diff --git a/dap4/d4lib/src/main/java/dap4/dap4lib/serial/D4DataCompiler.java b/dap4/d4lib/src/main/java/dap4/dap4lib/serial/D4DataCompiler.java
deleted file mode 100644
index c3c9bdb3ca..0000000000
--- a/dap4/d4lib/src/main/java/dap4/dap4lib/serial/D4DataCompiler.java
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * Copyright 2012, UCAR/Unidata.
- * See the LICENSE file for more information.
- */
-
-
-package dap4.dap4lib.serial;
-
-import dap4.core.data.ChecksumMode;
-import dap4.core.dmr.*;
-import dap4.core.util.*;
-import dap4.dap4lib.LibTypeFcns;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.List;
-import static dap4.core.data.DataCursor.Scheme;
-
-public class D4DataCompiler {
- public static boolean DEBUG = false;
-
- //////////////////////////////////////////////////
- // Constants
-
- public static final int COUNTSIZE = 8; // databuffer as specified by the DAP4 spec
-
- static String LBRACE = "{";
- static String RBRACE = "}";
-
-
- //////////////////////////////////////////////////
- // Instance variables
-
- protected DapDataset dataset = null;
-
- // Make compile arguments global
- protected ByteBuffer databuffer;
-
- protected ChecksumMode checksummode = null;
- protected ByteOrder order = null;
-
- protected D4DSP dsp;
-
- //////////////////////////////////////////////////
- // Constructor(s)
-
- /**
- * Constructor
- *
- * @param dsp the D4DSP
- * @param checksummode
- * @param databuffer the source of serialized databuffer
- */
-
- public D4DataCompiler(D4DSP dsp, ChecksumMode checksummode, ByteOrder order, ByteBuffer databuffer)
- throws DapException {
- this.dsp = dsp;
- this.dataset = this.dsp.getDMR();
- this.databuffer = databuffer;
- this.checksummode = checksummode;
- this.order = order;
- }
-
- //////////////////////////////////////////////////
- // DataCompiler API
-
- /**
- * The goal here is to process the serialized
- * databuffer and locate top-level variable positions
- * in the serialized databuffer. Access to non-top-level
- * variables is accomplished on the fly.
- *
- * @throws DapException
- */
- public void compile() throws DapException {
- assert (this.dataset != null && this.databuffer != null);
- // iterate over the variables represented in the databuffer
- for (DapVariable vv : this.dataset.getTopVariables()) {
- D4Cursor data = compileVar(vv, null);
- this.dsp.addVariableData(vv, data);
- }
- }
-
- protected D4Cursor compileVar(DapVariable dapvar, D4Cursor container) throws DapException {
- boolean isscalar = dapvar.getRank() == 0;
- D4Cursor array = null;
- DapType type = dapvar.getBaseType();
- if (type.isAtomic())
- array = compileAtomicVar(dapvar, container);
- else if (type.isStructType()) {
- array = compileStructureArray(dapvar, container);
- } else if (type.isSeqType()) {
- array = compileSequenceArray(dapvar, container);
- }
- if (dapvar.isTopLevel() && this.checksummode.enabled(ChecksumMode.DAP)) {
- // extract the checksum from databuffer src,
- // attach to the array, and make into an attribute
- int checksum = extractChecksum(databuffer);
- dapvar.setChecksum(checksum);
- }
- return array;
- }
-
- /**
- * @param var
- * @param container
- * @return data
- * @throws DapException
- */
-
- protected D4Cursor compileAtomicVar(DapVariable var, D4Cursor container) throws DapException {
- DapType daptype = var.getBaseType();
- D4Cursor data = new D4Cursor(Scheme.ATOMIC, (D4DSP) this.dsp, var, container);
- data.setOffset(getPos(this.databuffer));
- long total = 0;
- long dimproduct = var.getCount();
- if (!daptype.isEnumType() && !daptype.isFixedSize()) {
- // this is a string, url, or opaque
- long[] positions = new long[(int) dimproduct];
- int savepos = databuffer.position();
- // Walk the bytestring and return the instance count (in databuffer)
- total = walkByteStrings(positions, databuffer);
- databuffer.position(savepos);// leave position unchanged
- data.setByteStringOffsets(total, positions);
- } else {
- total = dimproduct * daptype.getSize();
- }
- skip(databuffer, (int) total);
- return data;
- }
-
- /**
- * Compile a structure array.
- *
- * @param var the template
- * @param container if inside a compound object
- * @return A DataCompoundArray for the databuffer for this struct.
- * @throws DapException
- */
- protected D4Cursor compileStructureArray(DapVariable var, D4Cursor container) throws DapException {
- DapStructure dapstruct = (DapStructure) var.getBaseType();
- D4Cursor structarray =
- new D4Cursor(Scheme.STRUCTARRAY, this.dsp, var, container).setOffset(getPos(this.databuffer));
- List dimset = var.getDimensions();
- long dimproduct = DapUtil.dimProduct(dimset);
- D4Cursor[] instances = new D4Cursor[(int) dimproduct];
- Odometer odom = Odometer.factory(DapUtil.dimsetToSlices(dimset), dimset);
- while (odom.hasNext()) {
- Index index = odom.next();
- D4Cursor instance = compileStructure(var, dapstruct, structarray);
- instance.setIndex(index);
- instances[(int) index.index()] = instance;
- }
- structarray.setElements(instances);
- return structarray;
- }
-
- /**
- * Compile a structure instance.
- *
- * @param dapstruct The template
- * @param container
- * @return A DataStructure for the databuffer for this struct.
- * @throws DapException
- */
- protected D4Cursor compileStructure(DapVariable var, DapStructure dapstruct, D4Cursor container) throws DapException {
- int pos = getPos(this.databuffer);
- D4Cursor d4ds = new D4Cursor(Scheme.STRUCTURE, (D4DSP) this.dsp, var, container).setOffset(pos);
- List dfields = dapstruct.getFields();
- for (int m = 0; m < dfields.size(); m++) {
- DapVariable dfield = dfields.get(m);
- D4Cursor dvfield = compileVar(dfield, d4ds);
- d4ds.addField(m, dvfield);
- assert dfield.getParent() != null;
- }
- return d4ds;
- }
-
- /**
- * Compile a sequence array.
- *
- * @param var the template
- * @return A DataCompoundArray for the databuffer for this sequence.
- * @throws DapException
- */
- protected D4Cursor compileSequenceArray(DapVariable var, D4Cursor container) throws DapException {
- DapSequence dapseq = (DapSequence) var.getBaseType();
- D4Cursor seqarray = new D4Cursor(Scheme.SEQARRAY, this.dsp, var, container).setOffset(getPos(this.databuffer));
- List dimset = var.getDimensions();
- long dimproduct = DapUtil.dimProduct(dimset);
- D4Cursor[] instances = new D4Cursor[(int) dimproduct];
- Odometer odom = Odometer.factory(DapUtil.dimsetToSlices(dimset), dimset);
- while (odom.hasNext()) {
- Index index = odom.next();
- D4Cursor instance = compileSequence(var, dapseq, seqarray);
- instance.setIndex(index);
- instances[(int) index.index()] = instance;
- }
- seqarray.setElements(instances);
- return seqarray;
- }
-
- /**
- * Compile a sequence as a set of records.
- *
- * @param dapseq
- * @param container
- * @return sequence
- * @throws DapException
- */
- public D4Cursor compileSequence(DapVariable var, DapSequence dapseq, D4Cursor container) throws DapException {
- int pos = getPos(this.databuffer);
- D4Cursor seq = new D4Cursor(Scheme.SEQUENCE, this.dsp, var, container).setOffset(pos);
- List dfields = dapseq.getFields();
- // Get the count of the number of records
- long nrecs = getCount(this.databuffer);
- for (int r = 0; r < nrecs; r++) {
- pos = getPos(this.databuffer);
- D4Cursor rec =
- (D4Cursor) new D4Cursor(D4Cursor.Scheme.RECORD, this.dsp, var, container).setOffset(pos).setRecordIndex(r);
- for (int m = 0; m < dfields.size(); m++) {
- DapVariable dfield = dfields.get(m);
- D4Cursor dvfield = compileVar(dfield, rec);
- rec.addField(m, dvfield);
- assert dfield.getParent() != null;
- }
- seq.addRecord(rec);
- }
- return seq;
- }
-
- //////////////////////////////////////////////////
- // Utilities
-
- protected int extractChecksum(ByteBuffer data) throws DapException {
- assert ChecksumMode.DAP.enabled(this.checksummode);
- if (data.remaining() < DapUtil.CHECKSUMSIZE)
- throw new DapException("Short serialization: missing checksum");
- return data.getInt();
- }
-
- protected static void skip(ByteBuffer data, int count) {
- data.position(data.position() + count);
- }
-
- protected static int getCount(ByteBuffer data) {
- long count = data.getLong();
- count = (count & 0xFFFFFFFF);
- return (int) count;
- }
-
- protected static int getPos(ByteBuffer data) {
- return data.position();
- }
-
- /**
- * Compute the size in databuffer of the serialized form
- *
- * @param daptype
- * @return type's serialized form size
- */
- protected static int computeTypeSize(DapType daptype) {
- return LibTypeFcns.size(daptype);
- }
-
- protected static long walkByteStrings(long[] positions, ByteBuffer databuffer) {
- int count = positions.length;
- long total = 0;
- int savepos = databuffer.position();
- // Walk each bytestring
- for (int i = 0; i < count; i++) {
- int pos = databuffer.position();
- positions[i] = pos;
- int size = getCount(databuffer);
- total += COUNTSIZE;
- total += size;
- skip(databuffer, size);
- }
- databuffer.position(savepos);// leave position unchanged
- return total;
- }
-
-}
diff --git a/dap4/d4tests/build.gradle b/dap4/d4tests/build.gradle
deleted file mode 100644
index d86da229a8..0000000000
--- a/dap4/d4tests/build.gradle
+++ /dev/null
@@ -1,44 +0,0 @@
-apply from: "$rootDir/gradle/any/dependencies.gradle"
-apply from: "$rootDir/gradle/any/test-only-projects.gradle"
-apply from: "$rootDir/gradle/any/gretty.gradle"
-
-dependencies {
- // I bet some of these dependencies could be in the testRuntimeOnly config, not testImplementation.
- compile enforcedPlatform(project(':netcdf-java-platform'))
- testImplementation enforcedPlatform(project(':netcdf-java-testing-platform'))
-
- testImplementation project(':dap4:d4core')
- testImplementation project(':dap4:d4lib')
- testImplementation project(':dap4:d4cdm')
- testImplementation project(':cdm:cdm-core')
- testImplementation project(':cdm-test-utils')
- testImplementation project(':httpservices')
-
- testImplementation 'junit:junit'
- testImplementation 'org.slf4j:slf4j-api'
-
- testRuntimeOnly 'ch.qos.logback:logback-classic'
-}
-
-test {
- systemProperties['testargs'] = System.getProperty('testargs', '')
-
- include 'dap4/test/TestCDMClient.class'
- include 'dap4/test/TestConstraints.class'
- include 'dap4/test/TestDSP.class'
- include 'dap4/test/TestDSR.class'
- include 'dap4/test/TestNc4Iosp.class'
- include 'dap4/test/TestParserCE.class'
- include 'dap4/test/TestParserDMR.class'
- include 'dap4/test/TestServlet.class'
- include 'dap4/test/TestServletConstraints.class'
- include 'dap4/test/TestFrontPage.class'
- //include 'dap4/test/TestFilters.class'
- //include 'dap4/test/TestH5Iosp.class'
- //include 'dap4/test/TestHyrax.class'
- //include 'dap4/test/TestPrinter.class'
- //include 'dap4/test/TestSerial.class'
-
- dependsOn('farmBeforeIntegrationTest')
- finalizedBy('farmAfterIntegrationTest')
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_anon_dim.syn.2.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_anon_dim.syn.2.raw.txt
deleted file mode 100644
index 3aec08b1c9..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_anon_dim.syn.2.raw.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-netcdf test_anon_dim.syn.2 {
- variables:
- int vu32(4);
- string vu32:_DAP4_Checksum_CRC32 = "0x417bc794";
-
- // global attributes:
- string :_dap4.ce = "/vu32[0:3]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-vu32 =
- {-1169720286, -920699049, -2088732436, 1060190036}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_anon_dim.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_anon_dim.syn.raw.txt
deleted file mode 100644
index 0819467d8f..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_anon_dim.syn.raw.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-netcdf test_anon_dim.syn {
- variables:
- int vu32(6);
- string vu32:_DAP4_Checksum_CRC32 = "0x1aca2718";
-
- // global attributes:
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-vu32 =
- {-1169720286, -920699049, -2088732436, 1060190036, -1123468835, 922940053}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_array.nc.5.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_array.nc.5.raw.txt
deleted file mode 100644
index bfc1a9a698..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_array.nc.5.raw.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-netcdf test_atomic_array.nc.5 {
- variables:
- ubyte vu8(1, 2);
- string vu8:_DAP4_Checksum_CRC32 = "0x1a9eb5b3";
-
- double vd(1);
- string vd:_DAP4_Checksum_CRC32 = "0x74c1a1f1";
-
- string vs(1, 1);
- string vs:_DAP4_Checksum_CRC32 = "0x15293f21";
-
- opaque vo(1, 1);
- string vo:_DAP4_Checksum_CRC32 = "0x225778dc";
-
- // global attributes:
- string :_dap4.ce = "/vu8[1][0:2:2];/vd[1];/vs[1][0];/vo[0][1]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-vu8 =
- {
- {3, 5}
- }
-vd =
- {1024.8}
-vs =
- { "Καλημέα"
- }
-vo = 0xabcdef0000000000;
-
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_array.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_array.nc.raw.txt
deleted file mode 100644
index 4aafbcac3b..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_array.nc.raw.txt
+++ /dev/null
@@ -1,63 +0,0 @@
-netcdf test_atomic_array {
- types:
- byte enum cloud_class_t { Clear = 0, Cumulonimbus = 1, Stratus = 2, Stratocumulus = 3, Cumulus = 4, Altostratus = 5, Nimbostratus = 6, Altocumulus = 7, Cirrostratus = 8, Cirrocumulus = 9, Cirrus = 10, Missing = 127};
-
- dimensions:
- d1 = 1;
- d2 = 2;
- d3 = 3;
- d4 = 4;
- d5 = 5;
- variables:
- ubyte vu8(d2, d3);
- string vu8:_DAP4_Checksum_CRC32 = "0xd42f6486";
-
- short v16(d4);
- string v16:_DAP4_Checksum_CRC32 = "0x92991416";
-
- uint vu32(d2, d3);
- string vu32:_DAP4_Checksum_CRC32 = "0x0c56f0f2";
-
- double vd(d2);
- string vd:_DAP4_Checksum_CRC32 = "0x7c09cbae";
-
- char vc(d2);
- string vc:_DAP4_Checksum_CRC32 = "0x63add807";
-
- string vs(d2, d2);
- string vs:_DAP4_Checksum_CRC32 = "0x672f70c4";
-
- opaque vo(d1, d2);
- string vo:_DAP4_Checksum_CRC32 = "0x2757560d";
-
- enum cloud_class_t primary_cloud(d5);
- string primary_cloud:_FillValue = "Missing";
- string primary_cloud:_DAP4_Checksum_CRC32 = "0xb58a627a";
-
- // global attributes:
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-vu8 =
- {
- {255, 1, 2},
- {3, 4, 5}
- }
-v16 =
- {1, 2, 3, 4}
-vu32 =
- {
- {5, 4, 3},
- {2, 1, 0}
- }
-vd =
- {17.9, 1024.8}
-vc = "@&"
-vs =
- { "hello world", "hello world", "hello world", "hello world"
- }
-vo = 0x0123456789abcdef,
- 0x0123456789abcdef;
-
-primary_cloud =
- {0, 2, 0, 1, 127}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_array.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_array.syn.raw.txt
deleted file mode 100644
index e1388d3f78..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_array.syn.raw.txt
+++ /dev/null
@@ -1,63 +0,0 @@
-netcdf test_atomic_array.syn {
- types:
- byte enum cloud_class_t { Clear = 0, Cumulonimbus = 1, Stratus = 2, Stratocumulus = 3, Cumulus = 4, Altostratus = 5, Nimbostratus = 6, Altocumulus = 7, Cirrostratus = 8, Cirrocumulus = 9, Cirrus = 10, Missing = 127};
-
- dimensions:
- d1 = 1;
- d2 = 2;
- d3 = 3;
- d4 = 4;
- d5 = 5;
- variables:
- ubyte vu8(d2, d3);
- string vu8:_DAP4_Checksum_CRC32 = "0xd79bd598";
-
- short v16(d4);
- string v16:_DAP4_Checksum_CRC32 = "0xa40ee271";
-
- uint vu32(d2, d3);
- string vu32:_DAP4_Checksum_CRC32 = "0xa06ca308";
-
- double vd(d2);
- string vd:_DAP4_Checksum_CRC32 = "0x7ee0fb67";
-
- char vc(d2);
- string vc:_DAP4_Checksum_CRC32 = "0x7cee5238";
-
- string vs(d2, d2);
- string vs:_DAP4_Checksum_CRC32 = "0x9d474c4c";
-
- opaque vo(d1, d2);
- string vo:_DAP4_Checksum_CRC32 = "0xd4809521";
-
- enum cloud_class_t primary_cloud(d5);
- string primary_cloud:_FillValue = "Missing";
- string primary_cloud:_DAP4_Checksum_CRC32 = "0x94b74cf7";
-
- // global attributes:
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-vu8 =
- {
- {186, 201, 131},
- {63, 189, 55}
- }
-v16 =
- {-341, -21899, -13413, -22144}
-vu32 =
- {
- {2367803413, 3586730583, 511843988},
- {3754752863, 2950934681, 2366232135}
- }
-vd =
- {0.21787008119279183, 0.6024507919967678}
-vc = "CO"
-vs =
- { "{S", "{S", "{S", "{S"
- }
-vo = 0xa2177aa7287c04fa8bb57bcdf76ec80f,
- 0xa2177aa7287c04fa8bb57bcdf76ec80f;
-
-primary_cloud =
- {2, 9, 6, 8, 3}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_types.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_types.nc.raw.txt
deleted file mode 100644
index a6cd1e1933..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_types.nc.raw.txt
+++ /dev/null
@@ -1,72 +0,0 @@
-netcdf test_atomic_types {
- types:
- byte enum cloud_class_t { Clear = 0, Cumulonimbus = 1, Stratus = 2, Stratocumulus = 3, Cumulus = 4, Altostratus = 5, Nimbostratus = 6, Altocumulus = 7, Cirrostratus = 8, Cirrocumulus = 9, Cirrus = 10, Missing = 127};
-
- variables:
- byte v8;
- string v8:_DAP4_Checksum_CRC32 = "0x3fba6cad";
-
- ubyte vu8;
- string vu8:_DAP4_Checksum_CRC32 = "0xff000000";
-
- short v16;
- string v16:_DAP4_Checksum_CRC32 = "0xac6191df";
-
- ushort vu16;
- string vu16:_DAP4_Checksum_CRC32 = "0xffff0000";
-
- int v32;
- string v32:_DAP4_Checksum_CRC32 = "0x12477cdf";
-
- uint vu32;
- string vu32:_DAP4_Checksum_CRC32 = "0xffffffff";
-
- long v64;
- string v64:_DAP4_Checksum_CRC32 = "0xccfc5c3c";
-
- ulong vu64;
- string vu64:_DAP4_Checksum_CRC32 = "0x2144df1c";
-
- float vf;
- string vf:_DAP4_Checksum_CRC32 = "0x8c2a1365";
-
- double vd;
- string vd:_DAP4_Checksum_CRC32 = "0xf2bacb72";
-
- char vc;
- string vc:_DAP4_Checksum_CRC32 = "0xa4deae1d";
-
- string vs;
- string vs:_DAP4_Checksum_CRC32 = "0x3691a6d4";
-
- opaque vo;
- string vo:_DAP4_Checksum_CRC32 = "0xd24ddadd";
-
- enum cloud_class_t primary_cloud;
- string primary_cloud:_FillValue = "Missing";
- string primary_cloud:_DAP4_Checksum_CRC32 = "0x3c0c8ea1";
-
- enum cloud_class_t secondary_cloud;
- string secondary_cloud:_FillValue = "Missing";
- string secondary_cloud:_DAP4_Checksum_CRC32 = "0x12b88320";
-
- // global attributes:
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-v8 =-128
-vu8 =255
-v16 =-32768
-vu16 =65535
-v32 =2147483647
-vu32 =4294967295
-v64 =9223372036854775807
-vu64 =18446744073709551615
-vf =3.1415927
-vd =3.141592653589793
-vc =@
-vs = "hello world"
-vo = 0x0123456789abcdef;
-
-primary_cloud =2
-secondary_cloud =127
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_types.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_types.syn.raw.txt
deleted file mode 100644
index 3c302ef4a6..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_atomic_types.syn.raw.txt
+++ /dev/null
@@ -1,72 +0,0 @@
-netcdf test_atomic_types.syn {
- types:
- byte enum cloud_class_t { Clear = 0, Cumulonimbus = 1, Stratus = 2, Stratocumulus = 3, Cumulus = 4, Altostratus = 5, Nimbostratus = 6, Altocumulus = 7, Cirrostratus = 8, Cirrocumulus = 9, Cirrus = 10, Missing = 127};
-
- variables:
- byte v8;
- string v8:_DAP4_Checksum_CRC32 = "0x140e363f";
-
- ubyte vu8;
- string vu8:_DAP4_Checksum_CRC32 = "0x30ba9599";
-
- short v16;
- string v16:_DAP4_Checksum_CRC32 = "0xe353db0e";
-
- ushort vu16;
- string vu16:_DAP4_Checksum_CRC32 = "0x31e23870";
-
- int v32;
- string v32:_DAP4_Checksum_CRC32 = "0xbad2143f";
-
- uint vu32;
- string vu32:_DAP4_Checksum_CRC32 = "0x32e54381";
-
- long v64;
- string v64:_DAP4_Checksum_CRC32 = "0x915dfe6e";
-
- ulong vu64;
- string vu64:_DAP4_Checksum_CRC32 = "0x9233006a";
-
- float vf;
- string vf:_DAP4_Checksum_CRC32 = "0x3d571922";
-
- double vd;
- string vd:_DAP4_Checksum_CRC32 = "0xffd91cad";
-
- char vc;
- string vc:_DAP4_Checksum_CRC32 = "0x09b9265b";
-
- string vs;
- string vs:_DAP4_Checksum_CRC32 = "0x81827ad8";
-
- opaque vo;
- string vo:_DAP4_Checksum_CRC32 = "0x2d29db8e";
-
- enum cloud_class_t primary_cloud;
- string primary_cloud:_FillValue = "Missing";
- string primary_cloud:_DAP4_Checksum_CRC32 = "0x4c667a2e";
-
- enum cloud_class_t secondary_cloud;
- string secondary_cloud:_FillValue = "Missing";
- string secondary_cloud:_DAP4_Checksum_CRC32 = "0x4b0bbe37";
-
- // global attributes:
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-v8 =58
-vu8 =201
-v16 =896
-vu16 =16177
-v32 =-1123468835
-vu32 =2125143125
-v64 =3059391736915381031
-vu64 =11577488182652895291
-vf =0.5512972
-vd =0.7902673011288164
-vc =*
-vs = "O,L?c8A%V"
-vo = 0x46f169ef23cbaf9b1febd99e4e16cec9;
-
-primary_cloud =7
-secondary_cloud =3
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_fill.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_fill.nc.raw.txt
deleted file mode 100644
index 839f800bfe..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_fill.nc.raw.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-netcdf test_fill {
- variables:
- ubyte uv8;
- string uv8:_DAP4_Checksum_CRC32 = "0x6fbf1d91";
-
- short v16;
- string v16:_DAP4_Checksum_CRC32 = "0xc9139fe6";
-
- uint uv32;
- uv32:_FillValue = 17;
- string uv32:_DAP4_Checksum_CRC32 = "0x8437b331";
-
- // global attributes:
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-uv8 =240
-v16 =32700
-uv32 =111000
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_one_var.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_one_var.nc.raw.txt
deleted file mode 100644
index 2b376e08ab..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_one_var.nc.raw.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-netcdf test_one_var {
- variables:
- int t;
- string t:_DAP4_Checksum_CRC32 = "0xc9e1efe6";
-
- // global attributes:
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-t =17
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_one_vararray.nc.3.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_one_vararray.nc.3.raw.txt
deleted file mode 100644
index 7e65c1a454..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_one_vararray.nc.3.raw.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-netcdf test_one_vararray.nc.3 {
- dimensions:
- d2 = 2;
- variables:
- int t(d2);
- string t:_DAP4_Checksum_CRC32 = "0x42dfb1d0";
-
- // global attributes:
- string :_dap4.ce = "/t[0:1]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-t =
- {17, 37}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_sequence_1.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_sequence_1.syn.raw.txt
deleted file mode 100644
index 8fd1eb64bf..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_sequence_1.syn.raw.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-netcdf test_sequence_1.syn {
- variables:
-
- Sequence {
- int i1;
- short sh1;
- } s(*);
- string s:_DAP4_Checksum_CRC32 = "0x4ac0ac5e";
-
-
- // global attributes:
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
- s =
- {
- i1 =
- {-920699049
- }
- sh1 =
- {896
- }
- } s
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_struct_array.nc.6.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_struct_array.nc.6.raw.txt
deleted file mode 100644
index 5ca77032b5..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_struct_array.nc.6.raw.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-netcdf test_struct_array.nc.6 {
- variables:
-
- Structure {
- int x;
- string x:_CoordinateAxisType = "GeoX";
- int y;
- string y:_CoordinateAxisType = "GeoY";
- } s(2, 2);
- string s:_DAP4_Checksum_CRC32 = "0x324d0ea6";
-
-
- // global attributes:
- string :_dap4.ce = "/s[0:2:3][0:1]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-s =
- {
- x =1
- y =-1
- } s(0)
- {
- x =17
- y =37
- } s(1)
- {
- x =-4
- y =12
- } s(2)
- {
- x =-8
- y =8
- } s(3)
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_struct_array.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_struct_array.syn.raw.txt
deleted file mode 100644
index 76531f1451..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestCDMClient/baseline/test_struct_array.syn.raw.txt
+++ /dev/null
@@ -1,78 +0,0 @@
-netcdf test_struct_array.syn {
- dimensions:
- dx = 4;
- dy = 3;
- variables:
- float z(dx);
- string z:_DAP4_Checksum_CRC32 = "0xbef06d05";
-
- float t(dy);
- string t:_DAP4_Checksum_CRC32 = "0x165934f0";
-
-
- Structure {
- int x;
- string x:_CoordinateAxisType = "GeoX";
- int y;
- string y:_CoordinateAxisType = "GeoY";
- } s(dx, dy);
- string s:_DAP4_Checksum_CRC32 = "0xd91a250e";
-
-
- // global attributes:
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-z =
- {0.72765326, 0.785633, 0.513679, 0.24684471}
-t =
- {0.738422, 0.21488869, 0.49479842}
-s =
- {
- x =712320147
- y =1268468519
- } s(0)
- {
- x =696298400
- y =989876086
- } s(1)
- {
- x =-1927163883
- y =-900795134
- } s(2)
- {
- x =-708236713
- y =1377500019
- } s(3)
- {
- x =511843988
- y =1699265896
- } s(4)
- {
- x =-540214433
- y =-914532520
- } s(5)
- {
- x =-1344032615
- y =-871416961
- } s(6)
- {
- x =-1928735161
- y =935744880
- } s(7)
- {
- x =-1509955773
- y =-1707460853
- } s(8)
- {
- x =1145911788
- y =-415231529
- } s(9)
- {
- x =-278269626
- y =-1682978013
- } s(10)
- {
- x =-1629885665
- y =-909240754
- } s(11)
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_anon_dim.syn.raw b/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_anon_dim.syn.raw
deleted file mode 100644
index 90cf83423e..0000000000
Binary files a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_anon_dim.syn.raw and /dev/null differ
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_atomic_types.syn.raw b/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_atomic_types.syn.raw
deleted file mode 100644
index 906759bc74..0000000000
Binary files a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_atomic_types.syn.raw and /dev/null differ
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_one_vararray.nc.raw b/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_one_vararray.nc.raw
deleted file mode 100644
index 15ca928b3d..0000000000
Binary files a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_one_vararray.nc.raw and /dev/null differ
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_opaque.nc.raw b/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_opaque.nc.raw
deleted file mode 100644
index 983427b986..0000000000
Binary files a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_opaque.nc.raw and /dev/null differ
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_sequence_1.syn.raw b/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_sequence_1.syn.raw
deleted file mode 100644
index 6b83150005..0000000000
Binary files a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_sequence_1.syn.raw and /dev/null differ
diff --git a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_sequence_2.syn.raw b/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_sequence_2.syn.raw
deleted file mode 100644
index 2b7c5072b7..0000000000
Binary files a/dap4/d4tests/src/test/data/resources/TestCDMClient/testinput/test_sequence_2.syn.raw and /dev/null differ
diff --git a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_anon_dim.syn.2.raw.txt b/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_anon_dim.syn.2.raw.txt
deleted file mode 100644
index 3aec08b1c9..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_anon_dim.syn.2.raw.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-netcdf test_anon_dim.syn.2 {
- variables:
- int vu32(4);
- string vu32:_DAP4_Checksum_CRC32 = "0x417bc794";
-
- // global attributes:
- string :_dap4.ce = "/vu32[0:3]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-vu32 =
- {-1169720286, -920699049, -2088732436, 1060190036}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_atomic_array.nc.5.raw.txt b/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_atomic_array.nc.5.raw.txt
deleted file mode 100644
index bfc1a9a698..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_atomic_array.nc.5.raw.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-netcdf test_atomic_array.nc.5 {
- variables:
- ubyte vu8(1, 2);
- string vu8:_DAP4_Checksum_CRC32 = "0x1a9eb5b3";
-
- double vd(1);
- string vd:_DAP4_Checksum_CRC32 = "0x74c1a1f1";
-
- string vs(1, 1);
- string vs:_DAP4_Checksum_CRC32 = "0x15293f21";
-
- opaque vo(1, 1);
- string vo:_DAP4_Checksum_CRC32 = "0x225778dc";
-
- // global attributes:
- string :_dap4.ce = "/vu8[1][0:2:2];/vd[1];/vs[1][0];/vo[0][1]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-vu8 =
- {
- {3, 5}
- }
-vd =
- {1024.8}
-vs =
- { "Καλημέα"
- }
-vo = 0xabcdef0000000000;
-
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_atomic_array.nc.8.raw.txt b/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_atomic_array.nc.8.raw.txt
deleted file mode 100644
index 6c79c85f94..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_atomic_array.nc.8.raw.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-netcdf test_atomic_array.nc.8 {
- variables:
- short v16(3);
- string v16:_DAP4_Checksum_CRC32 = "0xc592fc85";
-
- // global attributes:
- string :_dap4.ce = "/v16[1:2,2]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-v16 =
- {2, 3, 3}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_atomic_array.nc.9.raw.txt b/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_atomic_array.nc.9.raw.txt
deleted file mode 100644
index b367f16522..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_atomic_array.nc.9.raw.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-netcdf test_atomic_array.nc.9 {
- variables:
- short v16(3);
- string v16:_DAP4_Checksum_CRC32 = "0xb6724845";
-
- // global attributes:
- string :_dap4.ce = "/v16[2,1:2]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-v16 =
- {3, 2, 3}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_enum_array.nc.4.raw.txt b/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_enum_array.nc.4.raw.txt
deleted file mode 100644
index 82933a50d3..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_enum_array.nc.4.raw.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-netcdf test_enum_array.nc.4 {
- types:
- byte enum cloud_class_t { Clear = 0, Cumulonimbus = 1, Stratus = 2, Stratocumulus = 3, Cumulus = 4, Altostratus = 5, Nimbostratus = 6, Altocumulus = 7, Cirrostratus = 8, Cirrocumulus = 9, Cirrus = 10, Missing = 127};
-
- variables:
- enum cloud_class_t primary_cloud(2);
- string primary_cloud:_FillValue = "Missing";
- string primary_cloud:_DAP4_Checksum_CRC32 = "0x04e840eb";
-
- // global attributes:
- string :_dap4.ce = "/primary_cloud[1:2:4]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-primary_cloud =
- {2, 1}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_one_vararray.nc.1.raw.txt b/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_one_vararray.nc.1.raw.txt
deleted file mode 100644
index 4b380edb65..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_one_vararray.nc.1.raw.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-netcdf test_one_vararray.nc.1 {
- variables:
- int t(1);
- string t:_DAP4_Checksum_CRC32 = "0xb6a88010";
-
- // global attributes:
- string :_dap4.ce = "/t[1]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-t =
- {37}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_one_vararray.nc.3.raw.txt b/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_one_vararray.nc.3.raw.txt
deleted file mode 100644
index 7e65c1a454..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_one_vararray.nc.3.raw.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-netcdf test_one_vararray.nc.3 {
- dimensions:
- d2 = 2;
- variables:
- int t(d2);
- string t:_DAP4_Checksum_CRC32 = "0x42dfb1d0";
-
- // global attributes:
- string :_dap4.ce = "/t[0:1]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-t =
- {17, 37}
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_opaque_array.nc.7.raw.txt b/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_opaque_array.nc.7.raw.txt
deleted file mode 100644
index f7e6996969..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestConstraints/baseline/test_opaque_array.nc.7.raw.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-netcdf test_opaque_array.nc.7 {
- variables:
- opaque vo2(1, 2);
- string vo2:_DAP4_Checksum_CRC32 = "0x3f3fa5d4";
-
- // global attributes:
- string :_dap4.ce = "/vo2[1][0,0]";
- string :_CoordSysBuilder = "ucar.nc2.dataset.conv.DefaultConvention";
- data:
-vo2 = 0xfedcba9876543210,
- 0xfedcba9876543210;
-
-}
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_anon_dim.syn.2.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_anon_dim.syn.2.raw.txt
deleted file mode 100644
index 25034c5a30..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_anon_dim.syn.2.raw.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-/vu32[0] = -1169720286
-/vu32[1] = -920699049
-/vu32[2] = -2088732436
-/vu32[3] = 1060190036
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_anon_dim.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_anon_dim.syn.raw.txt
deleted file mode 100644
index f6dd09784a..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_anon_dim.syn.raw.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-/vu32[0] = -1169720286
-/vu32[1] = -920699049
-/vu32[2] = -2088732436
-/vu32[3] = 1060190036
-/vu32[4] = -1123468835
-/vu32[5] = 922940053
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.5.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.5.raw.txt
deleted file mode 100644
index b4d1d6ce75..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.5.raw.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/vu8[0,0] = 3
-/vu8[0,1] = 5
-/vd[0] = 1024.800000
-/vs[0,0] = "Καλημέα"
-/vo[0,0] = 0xABCDEF0000000000
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.8.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.8.raw.txt
deleted file mode 100644
index 447e729347..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.8.raw.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-/v16[0] = 1
-/v16[1] = 2
-/v16[2] = 4
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.9.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.9.raw.txt
deleted file mode 100644
index 769a4618ee..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.9.raw.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-/v16[0] = 4
-/v16[1] = 1
-/v16[2] = 2
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.raw.txt
deleted file mode 100644
index 2e2bea3dd0..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.nc.raw.txt
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/vu8[0,0] = 255
-/vu8[0,1] = 1
-/vu8[0,2] = 2
-/vu8[1,0] = 3
-/vu8[1,1] = 4
-/vu8[1,2] = 5
-/v16[0] = 1
-/v16[1] = 2
-/v16[2] = 3
-/v16[3] = 4
-/vu32[0,0] = 5
-/vu32[0,1] = 4
-/vu32[0,2] = 3
-/vu32[1,0] = 2
-/vu32[1,1] = 1
-/vu32[1,2] = 0
-/vd[0] = 17.900000
-/vd[1] = 1024.800000
-/vc[0] = '@'
-/vc[1] = '&'
-/vs[0,0] = "hello\tworld"
-/vs[0,1] = "\r\n"
-/vs[1,0] = "Καλημέα"
-/vs[1,1] = "abc"
-/vo[0,0] = 0x0123456789ABCDEF
-/vo[0,1] = 0xABCDEF0000000000
-/primary_cloud[0] = Clear
-/primary_cloud[1] = Stratus
-/primary_cloud[2] = Clear
-/primary_cloud[3] = Cumulonimbus
-/primary_cloud[4] = Missing
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.syn.raw.txt
deleted file mode 100644
index 04ad7521e5..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_array.syn.raw.txt
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/vu8[0,0] = 186
-/vu8[0,1] = 201
-/vu8[0,2] = 131
-/vu8[1,0] = 63
-/vu8[1,1] = 189
-/vu8[1,2] = 55
-/v16[0] = -341
-/v16[1] = -21899
-/v16[2] = -13413
-/v16[3] = -22144
-/vu32[0,0] = 2367803413
-/vu32[0,1] = 3586730583
-/vu32[0,2] = 511843988
-/vu32[1,0] = 3754752863
-/vu32[1,1] = 2950934681
-/vu32[1,2] = 2366232135
-/vd[0] = 0.217870
-/vd[1] = 0.602451
-/vc[0] = 'C'
-/vc[1] = 'O'
-/vs[0,0] = "{S"
-/vs[0,1] = "gb8^OE$"
-/vs[1,0] = "4a/q%n9;5Y"
-/vs[1,1] = "{fIl?T"\A["
-/vo[0,0] = 0xA2177AA7287C04FA8BB57BCDF76EC80F
-/vo[0,1] = 0x34FA472AA9404DD543143CADED303A75
-/primary_cloud[0] = Stratus
-/primary_cloud[1] = Cirrocumulus
-/primary_cloud[2] = Nimbostratus
-/primary_cloud[3] = Cirrostratus
-/primary_cloud[4] = Stratocumulus
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_types.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_types.nc.raw.txt
deleted file mode 100644
index cff7ae5f4d..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_types.nc.raw.txt
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/v8 = -128
-/vu8 = 255
-/v16 = -32768
-/vu16 = 65535
-/v32 = 2147483647
-/vu32 = 4294967295
-/v64 = 9223372036854775807
-/vu64 = 18446744073709551615
-/vf = 3.141593
-/vd = 3.141593
-/vc = '@'
-/vs = "hello\tworld"
-/vo = 0x0123456789ABCDEF
-/primary_cloud = Stratus
-/secondary_cloud = Missing
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_types.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_types.syn.raw.txt
deleted file mode 100644
index 6a7adb4fd4..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_atomic_types.syn.raw.txt
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/v8 = 58
-/vu8 = 201
-/v16 = 896
-/vu16 = 16177
-/v32 = -1123468835
-/vu32 = 2125143125
-/v64 = 3059391736915381031
-/vu64 = 11577488182652895291
-/vf = 0.551297
-/vd = 0.790267
-/vc = '*'
-/vs = "O,L?c8A%V"
-/vo = 0x46F169EF23CBAF9B1FEBD99E4E16CEC9
-/primary_cloud = Altocumulus
-/secondary_cloud = Stratocumulus
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum.nc.raw.txt
deleted file mode 100644
index 8c8ce9ebb4..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum.nc.raw.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/primary_cloud = Stratus
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum_2.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum_2.nc.raw.txt
deleted file mode 100644
index f0402352be..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum_2.nc.raw.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/h/primary_cloud = Stratus
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum_array.nc.4.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum_array.nc.4.raw.txt
deleted file mode 100644
index 0217409df8..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum_array.nc.4.raw.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/primary_cloud[0] = Stratus
-/primary_cloud[1] = Cumulonimbus
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum_array.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum_array.nc.raw.txt
deleted file mode 100644
index c23486baff..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_enum_array.nc.raw.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/primary_cloud[0] = Clear
-/primary_cloud[1] = Stratus
-/primary_cloud[2] = Clear
-/primary_cloud[3] = Cumulonimbus
-/primary_cloud[4] = Missing
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_fill.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_fill.nc.raw.txt
deleted file mode 100644
index dd457986b4..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_fill.nc.raw.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-/uv8 = 240
-/v16 = 32700
-/uv32 = 111000
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_groups1.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_groups1.nc.raw.txt
deleted file mode 100644
index 431c26d8ea..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_groups1.nc.raw.txt
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/g/h/v1[0] = -876354855
-/g/h/v1[1] = -1761252264
-/g/h/v1[2] = 1723477387
-/g/h/v1[3] = -46827465
-/g/h/v1[4] = 1475147969
-/g/h/v2[0] = 12.000000
-/g/h/v2[1] = -100.000000
-/g/h/v2[2] = 9969209968386869000000000000000000000.000000
-/g/i/v1[0] = 2
-/g/i/v1[1] = 3
-/g/i/v1[2] = 5
-/g/i/v1[3] = 7
-/g/i/v1[4] = 11
-/g/i/v3[0] = 23.000000
-/g/i/v3[1] = 29.000000
-/g/i/v3[2] = 19.000000
-/g/i/v3[3] = 31.000000
-/g/i/v3[4] = 17.000000
-/g/i/v3[5] = 37.000000
-/g/i/v3[6] = 13.000000
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_one_var.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_one_var.nc.raw.txt
deleted file mode 100644
index c74172bddb..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_one_var.nc.raw.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-/t = 17
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_one_vararray.nc.1.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_one_vararray.nc.1.raw.txt
deleted file mode 100644
index 18bedc8d51..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_one_vararray.nc.1.raw.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-
-
-
-/t[0] = 37
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_one_vararray.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_one_vararray.nc.raw.txt
deleted file mode 100644
index 1d2f858e48..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_one_vararray.nc.raw.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-/t[0] = 17
-/t[1] = 37
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_opaque.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_opaque.nc.raw.txt
deleted file mode 100644
index a0dbfd2e55..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_opaque.nc.raw.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-/vo1 = 0x0123456789ABCDEF
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_opaque_array.nc.7.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_opaque_array.nc.7.raw.txt
deleted file mode 100644
index 157a621f2a..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_opaque_array.nc.7.raw.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-/vo2[0,0] = 0xFEDCBA9876543210
-/vo2[0,1] = 0xFEDCBA9999999999
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_opaque_array.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_opaque_array.nc.raw.txt
deleted file mode 100644
index 91da77c407..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_opaque_array.nc.raw.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-/vo2[0,0] = 0x0123456789ABCDEF
-/vo2[0,1] = 0xABCDEF0000000000
-/vo2[1,0] = 0xFEDCBA9876543210
-/vo2[1,1] = 0xFEDCBA9999999999
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_sequence_1.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_sequence_1.syn.raw.txt
deleted file mode 100644
index 0e347626ef..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_sequence_1.syn.raw.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-/s = {
- [
- /s.i1 = -920699049
- /s.sh1 = 896
- ]}
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_sequence_2.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_sequence_2.syn.raw.txt
deleted file mode 100644
index bc5c5110e6..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_sequence_2.syn.raw.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
-
-
-
-
-
-/s[0] = {
- [
- /s.i1 = -920699049
- /s.sh1 = 896
- ]}
-/s[1] = {
- [
- /s.i1 = -1123468835
- /s.sh1 = -18686
- ] [
- /s.i1 = 2125143125
- /s.sh1 = -21899
- ] [
- /s.i1 = 1268468519
- /s.sh1 = -22144
- ] [
- /s.i1 = 989876086
- /s.sh1 = 3361
- ]}
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_array.nc.6.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_array.nc.6.raw.txt
deleted file mode 100644
index e142a33713..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_array.nc.6.raw.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-/s[0,0] = {
- /s.x = 1
- /s.y = -1
-}
-/s[0,1] = {
- /s.x = 17
- /s.y = 37
-}
-/s[1,0] = {
- /s.x = -4
- /s.y = 12
-}
-/s[1,1] = {
- /s.x = -8
- /s.y = 8
-}
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_array.syn.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_array.syn.raw.txt
deleted file mode 100644
index 0b856f51d9..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_array.syn.raw.txt
+++ /dev/null
@@ -1,77 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/z[0] = 0.727653
-/z[1] = 0.785633
-/z[2] = 0.513679
-/z[3] = 0.246845
-/t[0] = 0.738422
-/t[1] = 0.214889
-/t[2] = 0.494798
-/s[0,0] = {
- /s.x = 712320147
- /s.y = 1268468519
-}
-/s[0,1] = {
- /s.x = 696298400
- /s.y = 989876086
-}
-/s[0,2] = {
- /s.x = -1927163883
- /s.y = -900795134
-}
-/s[1,0] = {
- /s.x = -708236713
- /s.y = 1377500019
-}
-/s[1,1] = {
- /s.x = 511843988
- /s.y = 1699265896
-}
-/s[1,2] = {
- /s.x = -540214433
- /s.y = -914532520
-}
-/s[2,0] = {
- /s.x = -1344032615
- /s.y = -871416961
-}
-/s[2,1] = {
- /s.x = -1928735161
- /s.y = 935744880
-}
-/s[2,2] = {
- /s.x = -1509955773
- /s.y = -1707460853
-}
-/s[3,0] = {
- /s.x = 1145911788
- /s.y = -415231529
-}
-/s[3,1] = {
- /s.x = -278269626
- /s.y = -1682978013
-}
-/s[3,2] = {
- /s.x = -1629885665
- /s.y = -909240754
-}
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_nested.hdf5.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_nested.hdf5.raw.txt
deleted file mode 100644
index 57c8557ac2..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_nested.hdf5.raw.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-/x = {
- /x.field1 = {
- /x.field1.x = 1
- /x.field1.y = -2
- }
- /x.field2 = {
- /x.field2.x = 255
- /x.field2.y = 90
- }
-}
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_nested3.hdf5.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_nested3.hdf5.raw.txt
deleted file mode 100644
index ed42456ce6..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_nested3.hdf5.raw.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
-/x = {
- /x.field3 = {
- /x.field3.field2 = {
- /x.field3.field2.field1 = 17
- }
- }
-}
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_type.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_type.nc.raw.txt
deleted file mode 100644
index f15f61d6b3..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_struct_type.nc.raw.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-/s = {
- /s.x = 1
- /s.y = -2
-}
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_utf8.nc.raw.txt b/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_utf8.nc.raw.txt
deleted file mode 100644
index 4df9309d37..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSP/baseline/test_utf8.nc.raw.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-/vs[0] = "Καλημέα"
-/vs[1] = "abc"
-
diff --git a/dap4/d4tests/src/test/data/resources/TestDSR/baseline/test1.dsr b/dap4/d4tests/src/test/data/resources/TestDSR/baseline/test1.dsr
deleted file mode 100644
index 125939c27c..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestDSR/baseline/test1.dsr
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
- 4.0
- TDS-4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/dap4/d4tests/src/test/data/resources/TestFilters/baseline/test_sequence_1.syn.1.dap b/dap4/d4tests/src/test/data/resources/TestFilters/baseline/test_sequence_1.syn.1.dap
deleted file mode 100644
index f36a08093f..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestFilters/baseline/test_sequence_1.syn.1.dap
+++ /dev/null
@@ -1,3 +0,0 @@
-count=5
- -1169720286 18719 -2088732436 -16591 -1123468835 -18686 2125143125 -21899 1268468519 -22144
- checksum = 4aad97d4
diff --git a/dap4/d4tests/src/test/data/resources/TestFilters/baseline/test_sequence_1.syn.1.dmr b/dap4/d4tests/src/test/data/resources/TestFilters/baseline/test_sequence_1.syn.1.dmr
deleted file mode 100644
index 29109a2c04..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestFilters/baseline/test_sequence_1.syn.1.dmr
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
diff --git a/dap4/d4tests/src/test/data/resources/TestFilters/baseline/test_sequence_1.syn.2.dap b/dap4/d4tests/src/test/data/resources/TestFilters/baseline/test_sequence_1.syn.2.dap
deleted file mode 100644
index 7d7d18b90f..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestFilters/baseline/test_sequence_1.syn.2.dap
+++ /dev/null
@@ -1,3 +0,0 @@
-count=3
- -1169720286 18719 -2088732436 -16591 -1123468835 -18686
- checksum = 6a9c6608
diff --git a/dap4/d4tests/src/test/data/resources/TestFrontPage/baseline/test_frontpage.html b/dap4/d4tests/src/test/data/resources/TestFrontPage/baseline/test_frontpage.html
deleted file mode 100644
index 51e228d2dd..0000000000
--- a/dap4/d4tests/src/test/data/resources/TestFrontPage/baseline/test_frontpage.html
+++ /dev/null
@@ -1,296 +0,0 @@
-
-
-DAP4 Test Files
-
-
-
-