boolean process1(Testcase testcase) throws Exception { DODSNetcdfFile ncfile = new DODSNetcdfFile(testcase.url); if(ncfile == null) throw new Exception("Cannot read: " + testcase.url); StringWriter ow = new StringWriter(); PrintWriter pw = new PrintWriter(ow); ncfile.writeCDL(pw, false); pw.close(); ow.close(); String captured = ow.toString(); boolean pass = true; visual(testcase.title, captured); if(System.getProperty("baseline") != null) { baseline(testcase, captured); } else pass = diff(testcase, captured); return pass; }
@org.junit.Test public void testGrid() throws IOException, InvalidRangeException { System.setProperty("httpservices.urlencode", "false"); try (DODSNetcdfFile dodsfile = TestDODSRead.openAbs("http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NCEP/.CPC/.GLOBAL/.daily/dods")) { Variable dataV = null; // array assert (null != (dataV = dodsfile.findVariable("olr"))); assert dataV instanceof DODSVariable; // maps Variable v = null; assert (null != (v = dodsfile.findVariable("time"))); assert (null != (v = dodsfile.findVariable("lat"))); assert (null != (v = dodsfile.findVariable("lon"))); // read data Array data = dataV.read("0, 0:72:1, 0:143:1"); assert null != data; } System.setProperty("httpservices.urlencode", "true"); }
public List getData(CancelTask cancel) throws IOException { String CE = outerSequence.getFullName(); ArrayStructure as = (ArrayStructure) dodsFile.readWithCE(outerSequence, CE); extractMembers(as); int n = (int) as.getSize(); List<SeqPointObs> dataList = new ArrayList<SeqPointObs>(n); for (int i=0; i<n; i++) dataList.add( new SeqPointObs( i, as.getStructureData(i))); return dataList; }
Variable addVariable(Group parentGroup, Structure parentStructure, DodsV dodsV) throws IOException { Variable v = makeVariable(parentGroup, parentStructure, dodsV); if (v != null) { addAttributes(v, dodsV); if (parentStructure != null) parentStructure.addMemberVariable(v); else { parentGroup = computeGroup(v.getDODSName(), v, parentGroup); parentGroup.addVariable(v); } dodsV.isDone = true; } return v; }
private int addParents(StringBuilder buff, Variable s, List<Range> section, int start) { Structure parent = s.getParentStructure(); if (parent != null) { start = addParents(buff, parent, section, start); buff.append("."); } List<Range> subSection = section.subList(start, start + s.getRank()); buff.append(getDODSConstraintName(s)); if (!s.isVariableLength()) // have to get the whole thing for a sequence !! makeSelector(buff, subSection); return start + s.getRank(); }
static DODSNetcdfFile openAbs(String filename) throws IOException { System.out.println("TestDODSRead = "+filename); DODSNetcdfFile dodsfile = new DODSNetcdfFile(filename); if (showFileDebug) System.out.println(dodsfile.getDetailInfo()); if (showFile) System.out.println(dodsfile.toString()); return dodsfile; }
static void testConvertDDS( String urlName, DataDDS dataDDS, PrintStream out) throws IOException, DAP2Exception { DODSNetcdfFile dodsfile = new DODSNetcdfFile(urlName); System.out.println(dodsfile.toString()); if (useNC) { List vars = dodsfile.getVariables(); for (int i = 0; i < vars.size(); i++) { Variable v = (Variable) vars.get(i); Array data = v.read(); if (showData) logger.debug(NCdumpW.toString(data, v.getFullName() + data.shapeToString(), null)); } } ConvertD2N converter = new ConvertD2N(); DodsV root = DodsV.parseDataDDS( dataDDS); for (int i = 0; i < root.children.size(); i++) { DodsV dodsV = root.children.get(i); Variable v = dodsfile.findVariable( dodsV.getFullName()); Array data = converter.convertTopVariable(v, null, dodsV); showArray( v.getFullName(), data, out, ""); if (useNC) { Array data2 = v.read(); UtilsMa2Test.testEquals(data, data2); } if (showData) logger.debug(NCdumpW.toString(data, v.getFullName()+data.shapeToString(), null)); } }
constructTopVariables(rootDodsV, cancelTask); if (cancelTask != null && cancelTask.isCancel()) return; constructConstructors(rootDodsV, cancelTask); if (cancelTask != null && cancelTask.isCancel()) return; finish(); parseGlobalAttributes(das, rootDodsV, this); if (cancelTask != null && cancelTask.isCancel()) return; reGroup(); } catch (DAP2Exception dodsE) { dodsE.printStackTrace(System.err); String vCE = proj.substring(subsetPos); if (debugCE) System.out.println(" vCE = <" + vname + "><" + vCE + ">"); DODSVariable dodsVar = (DODSVariable) findVariable(vname); if (dodsVar == null) throw new IOException("Variable not found: " + vname); readArrays(preloadList); finish(); if (showNCfile) System.out.println("DODS nc file = " + this);
final List<Variable> variables = sourceNetcdfFile.getVariables(); final List<String> variableNames = new ArrayList<String>(); for (Variable variable : variables) { final Variable variable = sourceNetcdfFile.findVariable(varName); final Variable targetVariable = targetNetCDF.addVariable(null, variable.getFullName(), variable.getDataType(), variable.getDimensions()); for (Attribute attribute : sourceNetcdfFile.getGlobalAttributes()) { targetNetCDF.addGroupAttribute(null, attribute); final Variable sourceVariable = sourceNetcdfFile.findVariable(varName); String ceForVariable = getConstraintExpression(filteredVariable, constraintExpression); final Array values = sourceNetcdfFile.readWithCE(sourceVariable, ceForVariable); final int[] origin = getOrigin(filteredVariable, constraintExpression, sourceVariable.getDimensions().size());
static void testArray(String urlName) throws IOException, opendap.dap.DAP2Exception { System.out.println("checkArray ="+urlName); DConnect2 dodsConnection = new DConnect2(urlName, true); // get the DataDDS DataDDS dataDDS = dodsConnection.getData("?", null); dataDDS.print(System.out); System.out.println(); DodsV root = DodsV.parseDataDDS( dataDDS); ConvertD2N converter = new ConvertD2N(); DODSNetcdfFile dodsfile = new DODSNetcdfFile(urlName); List vars = dodsfile.getVariables(); for (int i = 0; i < vars.size(); i++) { Variable v = (Variable) vars.get(i); String name = DODSNetcdfFile.getDODSConstraintName(v); DodsV dodsV = root.findByDodsShortName( name); if (dodsV == null) { System.out.println("Cant find "+name); continue; } Array data = converter.convertTopVariable(v, null, dodsV); showArray( v.getFullName(), data, System.out, ""); } /* for (int i = 0; i < root.children.size(); i++) { DodsV dodsV = (DodsV) root.children.get(i); Variable v = dodsfile.findVariable( dodsV.getNetcdfShortName()); Array data = converter.convertTopVariable(v, null, dodsV); showArray( data, System.out, ""); } */ System.out.println("============"); }
public static void main(String arg[]) { String url = "http://localhost:8080/thredds/dodsC/testContent/testData.nc.ascii?reftime[0:1:0]"; // "http://ingrid.ldeo.columbia.edu/expert/SOURCES/.LEVITUS94/dods"; try (DODSNetcdfFile df = new DODSNetcdfFile(url, null)) { System.out.println("dods file = " + url + "\n" + df); } catch (Exception ioe) { System.out.println("error = " + url); ioe.printStackTrace(); } }
try dfs = new DODSNetcdfFile( dfsURL); DODSStructure struct = (DODSStructure) dfs.findVariable( seqName); if ( struct == null)
Group rootgroup = this.getRootGroup(); Attribute ncatt = (Attribute) att; String dodsname = ncatt.getDODSName(); NamePieces pieces = parseName(dodsname); if (pieces.var != null) { Variable v = findVariable(searchname); if (v != null) { reGroupVariableAttributes(rootgroup, (Variable) var);
public void utestCE() throws IOException, InvalidRangeException { DODSNetcdfFile dodsFile = TestDODSRead.open("NestedSeq2"); Variable outerSequence = dodsFile.findVariable("person1"); String CE = "person1.age,person1.stuff&person1.age=3"; ArrayStructure as = (ArrayStructure) dodsFile.readWithCE(outerSequence, CE); assert as.getSize() == 1; StructureData outerStructure = as.getStructureData(0); StructureMembers outerMembers = outerStructure.getStructureMembers(); assert outerMembers.findMember("age") != null; assert outerMembers.findMember("stuff") != null; // get at the inner sequence ArrayStructure asInner = (ArrayStructure) outerStructure.getArray("stuff"); StructureMembers innerMembers = asInner.getStructureMembers(); assert innerMembers.findMember("foo") != null; assert innerMembers.findMember("bar") != null; assert asInner.getSize() == 3 : asInner.getSize(); StructureData firstInner = asInner.getStructureData(0); StructureMembers firstMembers = firstInner.getStructureMembers(); assert firstMembers.findMember("foo") != null; assert firstMembers.findMember("bar") != null; //StructureMembers.Member timeMember = innerMembers.findMember(timeVar.getShortName()); }
String shortName = DODSNetcdfFile.makeShortName(map.bt.getEncodedName()); mapV = addVariable(parentGroup, parentStructure, map); makeCoordinateVariable(parentGroup, mapV, map.data); DStructure dstruct = (DStructure) dodsBT; if (dodsV.darray == null) { if (useGroups && (parentStructure == null) && isGroup(dstruct)) { // turn into a group if (debugConstruct) System.out.println(" assigned to Group <" + dodsShortName + ">"); Group g = new Group(this, parentGroup, DODSNetcdfFile.makeShortName(dodsShortName)); addAttributes(g, dodsV); parentGroup.addGroup(g); addVariable(g, null, nested);
@Test public void testScalarReadUncached() throws IOException { DODSNetcdfFile.setPreload( false); DODSNetcdfFile dodsfile = TestDODSRead.open("test.04"); DODSNetcdfFile.setPreload( true); Variable v = null; assert null != (v = dodsfile.findVariable("types")); assert v instanceof Structure; v.setCaching(false); scalarRead((Structure) v); }
@Test public void testSubset() throws IOException { DODSNetcdfFile dodsfile = TestDODSRead.open("test.05?types.integers"); Variable v = null; Array a = null; // byte assert null != (v = dodsfile.findVariable("types.integers.b")); CheckByte( v); // int16 assert null != (v = dodsfile.findVariable("types.integers.i16")); CheckInt16( v); // int32 assert null != (v = dodsfile.findVariable("types.integers.i32")); CheckInt32( v); // uint32 assert null != (v = dodsfile.findVariable("types.integers.ui32")); CheckUint32( v); // uint16 assert null != (v = dodsfile.findVariable("types.integers.ui16")); CheckUint16( v); // uint32 assert null != (v = dodsfile.findVariable("types.integers.ui32")); CheckUint32( v); dodsfile.close(); }
buff.append(getDODSConstraintName(v)); dodsSection = dodsSection.subList(0, n - 1); makeSelector(buff, dodsSection); DataDDS dataDDS = readDataDDSfromServer(buff.toString()); DodsV root = DodsV.parseDataDDS(dataDDS); DodsV want = root.children.get(0); // can only be one
private void addAttributes(Variable v, DodsV dodsV) { List<DODSAttribute> atts = dodsV.attributes; for (Attribute ncatt : atts) { v.addAttribute(ncatt); } // this is the case where its (probably) a Grid, and so _Coordinate.Axes has been assigned, but if // theres also a coordinates attribute, need to add that info Attribute axes = v.findAttribute(CF.COORDINATES); Attribute _axes = v.findAttribute(_Coordinate.Axes); if ((null != axes) && (null != _axes)) { v.addAttribute(combineAxesAttrs(axes, _axes)); } }
private void downloadDapFile(File targetDir, String dapURI, boolean isLargeFile) throws IOException { String[] uriComponents = dapURI.split("\\?"); String constraintExpression = ""; String fileName = dapURI.substring(uriComponents[0].lastIndexOf("/") + 1); if (uriComponents.length > 1) { constraintExpression = uriComponents[1]; } updateProgressBar(fileName, 0); DODSNetcdfFile netcdfFile = new DODSNetcdfFile(dapURI); writeNetcdfFile(targetDir, fileName, constraintExpression, netcdfFile, isLargeFile); }