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;
}