Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up DAP4 code plus minor mods to other -- non-dap4 -- code #1133

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
baa8aeb
ckp
DennisHeimbigner Oct 21, 2019
4682acd
Merge remote-tracking branch 'Unidata/master'
DennisHeimbigner Oct 25, 2019
9505a1a
Merge remote-tracking branch 'Unidata/master'
DennisHeimbigner Oct 27, 2019
b3f02b8
Merge remote-tracking branch 'Unidata/master'
DennisHeimbigner Dec 16, 2019
5c9c615
Merge remote-tracking branch 'Unidata/master'
DennisHeimbigner Jan 11, 2020
c863751
partial-update
DennisHeimbigner Apr 18, 2022
987555b
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Apr 28, 2022
ec75faa
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Jun 8, 2022
ce56066
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Jun 11, 2022
1b1eefc
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Jul 23, 2022
99be9c1
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Sep 27, 2022
78ba6e4
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Sep 28, 2022
06b559d
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Oct 3, 2022
4323632
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Oct 16, 2022
5e45b6d
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Oct 22, 2022
90f72c0
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Oct 24, 2022
251fbd2
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Nov 14, 2022
820713e
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Nov 27, 2022
c486e36
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Dec 7, 2022
92b0dab
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Dec 15, 2022
19b2adf
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Dec 21, 2022
f0e5c34
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Jan 1, 2023
ef6d103
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Jan 12, 2023
975b5dc
## Description of Changes
DennisHeimbigner Jan 15, 2023
b2304ca
## Addendum: Additional Commit Changes
DennisHeimbigner Jan 20, 2023
f13fb73
ckp
DennisHeimbigner Jan 21, 2023
c740c77
Minor fix to HTTPSession.java
DennisHeimbigner Jan 23, 2023
2390b5c
Merge remote-tracking branch 'Unidata/maint-5.x'
DennisHeimbigner Jan 28, 2023
4b3af3d
Update to latest main-5.x
DennisHeimbigner Jan 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/deps.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: [pull_request]
on: [push,pull_request]

jobs:
check-dependency-availability:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: [pull_request]
on: [push,pull_request]

jobs:
check-style:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: [pull_request]
on: [push,pull_request]

jobs:
netcdf-java-tests:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<br>
<br>


# netCDF-Java/CDM

The netCDF Java library provides an interface for scientific data access.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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", "");
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
* }
* }
*/
}
2 changes: 1 addition & 1 deletion cdm/core/src/main/java/ucar/ma2/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 0 additions & 23 deletions cdm/core/src/main/java/ucar/nc2/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -59,20 +50,6 @@ public static Map<String, Attribute> makeMap(List<Attribute> 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 */
}

///////////////////////////////////////////////////////////////////////////////////

/**
Expand Down
3 changes: 0 additions & 3 deletions cdm/core/src/main/java/ucar/nc2/Dimension.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions cdm/core/src/main/java/ucar/nc2/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand All @@ -318,7 +319,7 @@ public String findAttributeString(String attName, String defaultValue) {
/** @deprecated Use attributes() */
@Deprecated
public java.util.List<Attribute> getAttributes() {
return AttributeContainer.filter(attributes, Attribute.SPECIALS).getAttributes();
return attributes().getAttributes();
}

/** @deprecated Use attributes() */
Expand Down Expand Up @@ -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(";");
Expand Down
2 changes: 1 addition & 1 deletion cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion cdm/core/src/main/java/ucar/nc2/Structure.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion cdm/core/src/main/java/ucar/nc2/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
27 changes: 24 additions & 3 deletions cdm/core/src/main/java/ucar/nc2/constants/CDM.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package ucar.nc2.constants;

import ucar.nc2.Attribute;

/**
* CDM constants.
*
Expand Down Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions cdm/core/src/main/java/ucar/nc2/dataset/DatasetUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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;
}
Expand Down
Loading