Class CDMUtil
- java.lang.Object
-
- dap4.cdm.CDMUtil
-
public abstract class CDMUtil extends Object
CDM related Constants and utilities common to client and server code
-
-
Constructor Summary
Constructors Constructor Description CDMUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static dap4.core.util.IndexcdmIndexToIndex(ucar.ma2.Index cdmidx)static int[]computeEffectiveShape(List<dap4.core.dmr.DapDimension> dimset)Compute the shape inferred from a set of slices.static booleancontainsVLEN(List<ucar.nc2.Dimension> dimset)Test if any dimension is variable lengthstatic ObjectconvertVector(dap4.core.dmr.DapType dsttype, dap4.core.dmr.DapType srctype, Object src)Convert an array of one type of values to another typestatic List<ucar.ma2.Range>createCDMRanges(List<dap4.core.util.Slice> slices)static List<dap4.core.util.Slice>createSlices(List<ucar.ma2.Range> rangelist)Convert a list of ucar.ma2.Range to a list of Slice More or less the inverst of create CDMRangesstatic List<ucar.ma2.Range>dimsetToRanges(List<dap4.core.dmr.DapDimension> dimset)Convert a Section + variable to a constraintstatic doubleextractDoubleValue(dap4.core.dmr.TypeSort atomtype, dap4.core.data.DataCursor dataset, dap4.core.util.Index index)Extract, as a double, value from a (presumably) atomic typed array of values; dataset position is presumed correct.static longextractLongValue(dap4.core.dmr.TypeSort atomtype, dap4.core.data.DataCursor dataset, dap4.core.util.Index index)Extract, as a long, value from a (presumably) atomic typed array of values; dataset position is presumed correct.static StringgetChecksumString(byte[] checksum)Given an arbitrary Array (including ArrayStructure), produce a new Array that represents the slice defined by the section.static booleanhasVLEN(List<ucar.ma2.Range> ranges)static booleanhasVLEN(ucar.nc2.Variable v)Test if any dimension is variable lengthstatic ucar.ma2.IndexindexToCcMIndex(dap4.core.util.Index d4)static booleanisWhole(List<ucar.ma2.Range> rangelist, List<dap4.core.dmr.DapDimension> dimset, int start, int stop)Test a Listagainst a List to see if the range list represents the whole set of dimensions within the specified indices. static booleanisWhole(List<ucar.ma2.Range> rangelist, List<dap4.core.util.Slice> slices)Test a Listagainst a List to see if the range list is whole wrt the slices static booleanisWhole(List<ucar.ma2.Range> rangelist, ucar.nc2.Variable var)Test a Listagainst the CDM variable's dimensions to see if the range list is whole wrt the dimensions static List<dap4.core.util.Slice>shapeToSlices(int[] shape)static ucar.nc2.Variableunwrap(ucar.nc2.Variable var)NetcdfDataset can end up wrapping a variable in multiple wrapping classes (e.g.static ucar.nc2.NetcdfFileunwrapfile(ucar.nc2.NetcdfFile file)NetcdfDataset can wrap a NetcdfFile.
-
-
-
Method Detail
-
createSlices
public static List<dap4.core.util.Slice> createSlices(List<ucar.ma2.Range> rangelist) throws dap4.core.util.DapException
Convert a list of ucar.ma2.Range to a list of Slice More or less the inverst of create CDMRanges- Parameters:
rangelist- the set of ucar.ma2.Range- Returns:
- the equivalent list of Slice
- Throws:
dap4.core.util.DapException
-
isWhole
public static boolean isWhole(List<ucar.ma2.Range> rangelist, List<dap4.core.dmr.DapDimension> dimset, int start, int stop) throws dap4.core.util.DapException
Test a Listagainst a List to see if the range list represents the whole set of dimensions within the specified indices. - Parameters:
rangelist- the set of ucar.ma2.Rangedimset- the set of DapDimensionsstart- start looking herestop- stop looking here- Returns:
- true if rangelist is whole; false otherwise.
- Throws:
dap4.core.util.DapException
-
isWhole
public static boolean isWhole(List<ucar.ma2.Range> rangelist, List<dap4.core.util.Slice> slices) throws dap4.core.util.DapException
Test a Listagainst a List to see if the range list is whole wrt the slices - Parameters:
rangelist- the set of ucar.ma2.Rangeslices- the set of slices- Returns:
- true if rangelist is whole wrt slices; false otherwise.
- Throws:
dap4.core.util.DapException
-
isWhole
public static boolean isWhole(List<ucar.ma2.Range> rangelist, ucar.nc2.Variable var) throws dap4.core.util.DapException
Test a Listagainst the CDM variable's dimensions to see if the range list is whole wrt the dimensions - Parameters:
rangelist- the set of ucar.ma2.Rangevar- the cdm var- Returns:
- true if rangelist is whole wrt slices; false otherwise.
- Throws:
dap4.core.util.DapException
-
createCDMRanges
public static List<ucar.ma2.Range> createCDMRanges(List<dap4.core.util.Slice> slices) throws dap4.core.util.DapException
- Throws:
dap4.core.util.DapException
-
unwrap
public static ucar.nc2.Variable unwrap(ucar.nc2.Variable var)
NetcdfDataset can end up wrapping a variable in multiple wrapping classes (e.g. VariableDS). Goal of this procedure is to get down to the lowest level Variable instance- Parameters:
var- possibly wrapped variable- Returns:
- the lowest level Variable instance
-
unwrapfile
public static ucar.nc2.NetcdfFile unwrapfile(ucar.nc2.NetcdfFile file)
NetcdfDataset can wrap a NetcdfFile. Goal of this procedure is to get down to the lowest level NetcdfFile instance.- Parameters:
file- NetcdfFile or NetcdfDataset- Returns:
- the lowest level NetcdfFile instance
-
hasVLEN
public static boolean hasVLEN(List<ucar.ma2.Range> ranges)
-
hasVLEN
public static boolean hasVLEN(ucar.nc2.Variable v)
Test if any dimension is variable length
-
containsVLEN
public static boolean containsVLEN(List<ucar.nc2.Dimension> dimset)
Test if any dimension is variable length
-
computeEffectiveShape
public static int[] computeEffectiveShape(List<dap4.core.dmr.DapDimension> dimset)
Compute the shape inferred from a set of slices. 'Effective' means that any trailing vlen will be ignored.- Parameters:
dimset- from which to generate shape- Returns:
- effective shape
-
extractLongValue
public static long extractLongValue(dap4.core.dmr.TypeSort atomtype, dap4.core.data.DataCursor dataset, dap4.core.util.Index index) throws dap4.core.util.DapExceptionExtract, as a long, value from a (presumably) atomic typed array of values; dataset position is presumed correct.- Parameters:
atomtype- type of object to extractdataset- Data containing the objectsindex- Which element of dataset to read- Returns:
- resulting value as a long
- Throws:
ucar.ma2.ForbiddenConversionException- if cannot convert to longdap4.core.util.DapException
-
extractDoubleValue
public static double extractDoubleValue(dap4.core.dmr.TypeSort atomtype, dap4.core.data.DataCursor dataset, dap4.core.util.Index index) throws dap4.core.util.DapExceptionExtract, as a double, value from a (presumably) atomic typed array of values; dataset position is presumed correct.- Parameters:
atomtype- type of object to extractdataset- Data containing the objectsindex- Which element of dataset to read- Returns:
- resulting value as a double
- Throws:
ucar.ma2.ForbiddenConversionException- if cannot convert to doubledap4.core.util.DapException
-
convertVector
public static Object convertVector(dap4.core.dmr.DapType dsttype, dap4.core.dmr.DapType srctype, Object src)
Convert an array of one type of values to another type- Parameters:
dsttype- target typesrctype- source typesrc- array of values to convert- Returns:
- resulting array of converted values as an object
-
getChecksumString
public static String getChecksumString(byte[] checksum)
Given an arbitrary Array (including ArrayStructure), produce a new Array that represents the slice defined by the section. For now, we create a simple array of the relevant type and fill it by extracting the values specified by the section.param array the array from which the section is extracted param section determines what to extract throws DapException returns the slice array
-
dimsetToRanges
public static List<ucar.ma2.Range> dimsetToRanges(List<dap4.core.dmr.DapDimension> dimset) throws dap4.core.util.DapException
Convert a Section + variable to a constraintstatic public View sectionToView(CDMDSP dsp, Variable v, Section section) throws DapException { if(section == null || section.getRank() == 0) return null; // Get the corresponding DapNode DapVariable dv = (DapVariable) dsp.getNode().get(v); if(dv == null) throw new DapException("Variable has no corresponding dap node: " + v.getFullName()); // Get the structure path wrt DapDataset for dv // and use path plus the Section to construct a constraint List
structpath = DapUtil.getStructurePath(dv); List ranges = section.getRanges(); View view = new View(dmr); int next = 0; for(int i = 0;i < structpath.size();i++) { dv = structpath.get(i); int rank = dv.getRank(); ViewVariable vv = new ViewVariable(dv); List slices = new ArrayList (rank); for(int j = 0;j < rank;j++, next++) { if(next >= ranges.size()) throw new DapException("Range::Rank mismatch"); Range range = ranges.get(next); Slice slice = new Slice(range.first(), range.last(), range.stride()).validate(); slices.add(slice); } vv.setSlices(slices); view.put(dv, vv); } view.validate(View.EXPAND); return view; } - Throws:
dap4.core.util.DapException
-
shapeToSlices
public static List<dap4.core.util.Slice> shapeToSlices(int[] shape) throws dap4.core.util.DapException
- Throws:
dap4.core.util.DapException
-
cdmIndexToIndex
public static dap4.core.util.Index cdmIndexToIndex(ucar.ma2.Index cdmidx)
-
indexToCcMIndex
public static ucar.ma2.Index indexToCcMIndex(dap4.core.util.Index d4)
-
-