Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Fix DAP4 code to support its use with e.g. .ncml files #1312

Open
wants to merge 7 commits into
base: 5.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cdm/src/main/java/ucar/nc2/NetcdfFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ static private ucar.unidata.io.RandomAccessFile getRaf(String location, int buff
log.warn("Failed to uncompress {}, err= {}; try as a regular file.", uriString, e.getMessage());
//allow to fall through to open the "compressed" file directly - may be a misnamed suffix
} finally {
stringLocker.release(uriString);
stringLocker.release(uriString);
}

if (uncompressedFileName != null) {
Expand Down
22 changes: 12 additions & 10 deletions cdm/src/main/java/ucar/nc2/dataset/DatasetUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static public DatasetUrl findDatasetUrl(String orgLocation) throws IOException {

// Priority in deciding
// the service type is as follows.
// 1. "protocol" tag in fragment
// 1. "mode" tag in fragment (or "proto" or "protocol" for back compatibility)
// 2. specific protocol in fragment
// 3. leading protocol
// 4. path extension
Expand Down Expand Up @@ -196,22 +196,24 @@ static private ServiceType searchFragment(String fragment) {
return null;
Map<String, String> map = parseFragment(fragment);
if (map == null) return null;
String protocol = map.get("protocol");
if(protocol == null) {
String mode = map.get("mode");
if(mode == null) mode = map.get("proto");
if(mode == null) mode = map.get("protocol");
if(mode == null) {
for(String p: FRAGPROTOCOLS) {
if(map.get(p) != null) {protocol = p; break;}
if(map.get(p) != null) {mode = p; break;}
}
}
if (protocol != null) {
if (protocol.equalsIgnoreCase("dap") || protocol.equalsIgnoreCase("dods"))
if (mode != null) {
if (mode.equalsIgnoreCase("dap") || mode.equalsIgnoreCase("dods"))
return ServiceType.OPENDAP;
if (protocol.equalsIgnoreCase("dap4"))
if (mode.equalsIgnoreCase("dap4"))
return ServiceType.DAP4;
if (protocol.equalsIgnoreCase("cdmremote"))
if (mode.equalsIgnoreCase("cdmremote"))
return ServiceType.CdmRemote;
if (protocol.equalsIgnoreCase("thredds"))
if (mode.equalsIgnoreCase("thredds"))
return ServiceType.THREDDS;
if (protocol.equalsIgnoreCase("ncml"))
if (mode.equalsIgnoreCase("ncml"))
return ServiceType.NCML;
}
return null;
Expand Down
4 changes: 3 additions & 1 deletion dap4/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ext.title = "Data Access Protocol (DAP) version 4.0" // Will be inherited by subprojects.

// WARNING: this is no long accurate

// dap4 has no source code nor any artifacts to publish

// NON-TRANSITIVE Dependency graph:
Expand All @@ -10,7 +12,7 @@ ext.title = "Data Access Protocol (DAP) version 4.0" // Will be inherited by su
// d4lib d4core httpservices
// d4cdm d4lib cdm
// server:
// d4servletshared d4cdmshared netcdf4
// d4servlet d4cdm d4lib netcdf4
// d4ts d4servletshared
// d4tswar d4ts
// tests:
Expand Down
44 changes: 5 additions & 39 deletions dap4/d4cdm/src/main/java/dap4/cdm/dsp/CDMDSP.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,27 @@ 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;
}
public String getLocation() {return this.ncdfile.getLocation();}

/**
* @param filepath - absolute path to a file
* @param ncfile - source netcdf file
* @return CDMDSP instance
* @throws DapException
*/
@Override
public CDMDSP
open(String filepath)
open(NetcdfFile ncfile)
throws DapException
{
try {
NetcdfFile ncfile = createNetcdfFile(filepath, null);
NetcdfDataset ncd = new NetcdfDataset(ncfile, ENHANCEMENT);
this.ncdfile = ncd;
return open(ncd);
} catch (IOException ioe) {
throw new DapException("CDMDSP: cannot process: " + filepath, ioe);
throw new DapException("CDMDSP: cannot process: " + getLocation(), ioe);
}
}

Expand All @@ -132,10 +120,8 @@ public boolean dspMatch(String path, DapContext context)
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;
}
Expand Down Expand Up @@ -1071,26 +1057,6 @@ else if(atype == TypeSort.Float64)
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

Expand Down
1 change: 0 additions & 1 deletion dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

/*package*/ interface CDMArray
{
public DSP getDSP();
public DapVariable getTemplate();
public long getSizeBytes(); // In bytes
public DapType getBaseType();
Expand Down
8 changes: 0 additions & 8 deletions dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayAtomic.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
/////////////////////////////////////////////////////
// Instance variables

protected DSP dsp = null;
protected DapVariable template = null;
protected DapType basetype = null;

Expand All @@ -64,7 +63,6 @@
{
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();
Expand All @@ -83,12 +81,6 @@
return this.basetype;
}

@Override
public DSP getDSP()
{
return this.dsp;
}

@Override
public DapVariable getTemplate()
{
Expand Down
9 changes: 0 additions & 9 deletions dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import dap4.core.dmr.*;
import dap4.core.data.DSP;
import dap4.core.data.DSP;

/**
* Since we can't use AbstractCDMArray,
Expand All @@ -20,7 +19,6 @@

/*package*/ class CDMArrayDelegate implements CDMArray
{
protected DSP dsp = null;
protected DapVariable template = null;
protected long bytesize = 0;
protected DapType basetype = null;
Expand All @@ -31,18 +29,11 @@
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()
{
Expand Down
8 changes: 0 additions & 8 deletions dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArraySequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public int getCurrentRecno()
// Instance variables

protected Group cdmroot = null;
protected DSP dsp;
protected DapVariable template;
protected DapType basetype;
protected long bytesize = 0;
Expand Down Expand Up @@ -143,7 +142,6 @@ public int getCurrentRecno()
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();
Expand Down Expand Up @@ -189,12 +187,6 @@ public DapType getBaseType()
return this.basetype;
}

@Override
public DSP getDSP()
{
return this.dsp;
}

@Override
public DapVariable getTemplate()
{
Expand Down
8 changes: 0 additions & 8 deletions dap4/d4cdm/src/main/java/dap4/cdm/nc2/CDMArrayStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ static protected class FieldArrays

// CDMArry variables
protected Group cdmroot = null;
protected DSP dsp = null;
protected DapVariable template = null;
protected DapType basetype = null;
protected long dimsize = 0;
Expand Down Expand Up @@ -104,7 +103,6 @@ static protected class FieldArrays
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());
Expand Down Expand Up @@ -139,12 +137,6 @@ static protected class FieldArrays
//////////////////////////////////////////////////
// CDMArray Interface

@Override
public DSP getDSP()
{
return this.dsp;
}

@Override
public DapVariable getTemplate()
{
Expand Down
25 changes: 10 additions & 15 deletions dap4/d4cdm/src/main/java/dap4/cdm/nc2/DapNetcdfFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import dap4.cdm.CDMUtil;
import dap4.cdm.NodeMap;
import dap4.core.data.DSP;
import dap4.core.data.DSPRegistry;
import dap4.core.util.DapContext;
import dap4.core.util.DapException;
import dap4.core.util.DapUtil;
Expand All @@ -23,7 +22,9 @@
import ucar.nc2.iosp.IospHelper;
import ucar.nc2.util.CancelTask;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.WritableByteChannel;
import java.util.*;
Expand Down Expand Up @@ -67,16 +68,6 @@ public void setProgress(String msg, int progress)

static protected final NullCancelTask nullcancel = new NullCancelTask();

/**
* Define a map of known DSP classes.
*/
static protected DSPRegistry dspregistry = new DSPRegistry();

static {
dspregistry.register(FileDSP.class, DSPRegistry.FIRST);
dspregistry.register(HttpDSP.class, DSPRegistry.FIRST);
}

//////////////////////////////////////////////////
// Instance Variables

Expand Down Expand Up @@ -109,6 +100,7 @@ public void setProgress(String msg, int progress)
* @param location URL for the request. Note that if this is
* intended to send to a file oriented
* DSP, then if must be converted to an absolute path.
* Connection URLs are assumed to not be % escaped.
* @param cancelTask check if task is cancelled; may be null.
* @throws IOException
*/
Expand All @@ -125,19 +117,22 @@ public DapNetcdfFile(String location, CancelTask cancelTask)
throw new IOException(use);
}
boolean isfile = xuri.isFile();
DapContext cxt = new DapContext();
if(isfile) {
this.dsplocation = DapUtil.absolutize(xuri.getPath());
this.dsp = new FileDSP().open(new File(this.dsplocation));
} else { // Not a file url
this.dsplocation = xuri.assemble(XURI.URLBASE);
try {
this.dsp = new HttpDSP().open(new URI(this.dsplocation));
} catch (URISyntaxException e) {
throw new DapException(e);
}
}
DapContext cxt = new DapContext();
cancel = (cancelTask == null ? nullcancel : cancelTask);
// 1. Get and parse the constrained DMR and Data v-a-v URL
this.dsp = dspregistry.findMatchingDSP(location,cxt); // will set dsp context
if(this.dsp == null)
throw new IOException("No matching DSP: "+this.location);
this.dsp.setContext(cxt);
this.dsp.open(this.dsplocation);

// 2. Construct an equivalent CDM tree and populate
// this NetcdfFile object.
Expand Down
Loading