Package dap4.cdm

Class 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.Index cdmIndexToIndex​(ucar.ma2.Index cdmidx)  
      static int[] computeEffectiveShape​(List<dap4.core.dmr.DapDimension> dimset)
      Compute the shape inferred from a set of slices.
      static boolean containsVLEN​(List<ucar.nc2.Dimension> dimset)
      Test if any dimension is variable length
      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
      static 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 CDMRanges
      static List<ucar.ma2.Range> dimsetToRanges​(List<dap4.core.dmr.DapDimension> dimset)
      Convert a Section + variable to a constraint
      static double extractDoubleValue​(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 long extractLongValue​(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 String getChecksumString​(byte[] checksum)
      Given an arbitrary Array (including ArrayStructure), produce a new Array that represents the slice defined by the section.
      static boolean hasVLEN​(List<ucar.ma2.Range> ranges)  
      static boolean hasVLEN​(ucar.nc2.Variable v)
      Test if any dimension is variable length
      static ucar.ma2.Index indexToCcMIndex​(dap4.core.util.Index d4)  
      static boolean isWhole​(List<ucar.ma2.Range> rangelist, List<dap4.core.dmr.DapDimension> dimset, int start, int stop)
      Test a List against a List to see if the range list represents the whole set of dimensions within the specified indices.
      static boolean isWhole​(List<ucar.ma2.Range> rangelist, List<dap4.core.util.Slice> slices)
      Test a List against a List to see if the range list is whole wrt the slices
      static boolean isWhole​(List<ucar.ma2.Range> rangelist, ucar.nc2.Variable var)
      Test a List against 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.Variable unwrap​(ucar.nc2.Variable var)
      NetcdfDataset can end up wrapping a variable in multiple wrapping classes (e.g.
      static ucar.nc2.NetcdfFile unwrapfile​(ucar.nc2.NetcdfFile file)
      NetcdfDataset can wrap a NetcdfFile.
    • Constructor Detail

      • CDMUtil

        public CDMUtil()
    • 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 List against 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.Range
        dimset - the set of DapDimensions
        start - start looking here
        stop - 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 List against a List to see if the range list is whole wrt the slices
        Parameters:
        rangelist - the set of ucar.ma2.Range
        slices - 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 List against the CDM variable's dimensions to see if the range list is whole wrt the dimensions
        Parameters:
        rangelist - the set of ucar.ma2.Range
        var - 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.DapException
        Extract, as a long, value from a (presumably) atomic typed array of values; dataset position is presumed correct.
        Parameters:
        atomtype - type of object to extract
        dataset - Data containing the objects
        index - Which element of dataset to read
        Returns:
        resulting value as a long
        Throws:
        ucar.ma2.ForbiddenConversionException - if cannot convert to long
        dap4.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.DapException
        Extract, as a double, value from a (presumably) atomic typed array of values; dataset position is presumed correct.
        Parameters:
        atomtype - type of object to extract
        dataset - Data containing the objects
        index - Which element of dataset to read
        Returns:
        resulting value as a double
        Throws:
        ucar.ma2.ForbiddenConversionException - if cannot convert to double
        dap4.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 type
        srctype - source type
        src - 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 constraint

        static 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)