dap4/d4cdm/src/main/java/dap4/cdm/CDMUtil.java
static public List<Range>
    dimsetToRanges(List<DapDimension> dimset)
            throws dap4.core.util.DapException
    {
        if(dimset == null)
            return null;
        List<Range> ranges = new ArrayList<>();
        for(int i = 0; i < dimset.size(); i++) {
            DapDimension dim = dimset.get(i);
            try {
                Range r = new Range(dim.getShortName(), 0, (int) dim.getSize() - 1, 1);
                ranges.add(r);
            } catch (InvalidRangeException ire) {
                throw new dap4.core.util.DapException(ire);
            }
        }
        return ranges;
    }
static public List<Range>
    dimsetToRanges(List<DapDimension> dimset)
            throws dap4.core.util.DapException
    {
        if(dimset == null)
            return null;
        List<Range> ranges = new ArrayList<>();
        for(int i = 0; i < dimset.size(); i++) {
            DapDimension dim = dimset.get(i);
            try {
                Range r = new Range(dim.getShortName(), 0, (int) dim.getSize() - 1, 1);
                ranges.add(r);
            } catch (InvalidRangeException ire) {
                throw new dap4.core.util.DapException(ire);
            }
        }
        return ranges;
    }
static public List < Range > dimsetToRanges ( List < DapDimension > dimset ) throws dap4 . core . util . DapException { if ( dimset == null ) return null ; List < Range > ranges = new ArrayList <> ( ) ; for ( int i = 0 ; i < dimset . size ( ) ; i ++ ) { DapDimension dim = dimset . get ( i ) ; try { Range r = new Range ( dim . getShortName ( ) , 0 , ( int ) dim . getSize ( ) - 1 , 1 ) ; ranges . add ( r ) ; } catch ( InvalidRangeException ire ) { throw new dap4 . core . util . DapException ( ire ) ; } } return ranges ; }
Convert a Section + variable to a constraint
<p>
<p>
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<DapVariable> structpath = DapUtil.getStructurePath(dv);
List<Range> 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<Slice> slices = new ArrayList<Slice>(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;
}
Convert a Section + variable to a constraint <p > <p > 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<DapVariable > structpath = DapUtil . getStructurePath ( dv ) ; List<Range > 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<Slice > slices = new ArrayList<Slice > ( 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 ; }