private static int writeProfileFeatureCollection(FeatureDatasetPoint fdpoint, ProfileFeatureCollection pds, String fileOut, CFPointWriterConfig config) throws IOException { WriterCFProfileCollection cfWriter = new WriterCFProfileCollection(fileOut, fdpoint.getGlobalAttributes(), fdpoint.getDataVariables(), pds.getExtraVariables(), pds.getTimeUnit(), pds.getAltUnits(), config); // LOOK not always needed int count = 0; int name_strlen = 0; int nprofiles = pds.size(); if (nprofiles < 0) { pds.resetIteration(); while (pds.hasNext()) { ProfileFeature pf = pds.next(); name_strlen = Math.max(name_strlen, pf.getName().length()); count++; } nprofiles = count; } cfWriter.setFeatureAuxInfo(nprofiles, name_strlen); count = 0; pds.resetIteration(); while (pds.hasNext()) { ucar.nc2.ft.ProfileFeature profile = pds.next(); count += cfWriter.writeProfile(profile); if (debug && count % 10 == 0) System.out.printf("%d ", count); if (debug && count % 100 == 0) System.out.printf("%n "); } cfWriter.finish(); return count; }
private static int writeProfileFeatureCollection(FeatureDatasetPoint fdpoint, ProfileFeatureCollection fc, String fileOut, CFPointWriterConfig config) throws IOException { try (WriterCFProfileCollection cfWriter = new WriterCFProfileCollection(fileOut, fdpoint.getGlobalAttributes(), fdpoint.getDataVariables(), fc.getTimeUnit(), fc.getAltUnits(), config)) { cfWriter.setExtraVariables( fc.getExtraVariables()); // LOOK not always needed int count = 0; int name_strlen = 0; int nprofiles = fc.size(); if (nprofiles < 0) { for (ProfileFeature pf : fc) { name_strlen = Math.max(name_strlen, pf.getName().length()); count++; } nprofiles = count; } cfWriter.setFeatureAuxInfo(nprofiles, name_strlen); count = 0; for (ProfileFeature profile : fc) { count += cfWriter.writeProfile(profile); if (debug && count % 10 == 0) System.out.printf("%d ", count); if (debug && count % 100 == 0) System.out.printf("%n "); } cfWriter.finish(); return count; } }
private static int writeProfileFeatureCollection(FeatureDatasetPoint fdpoint, ProfileFeatureCollection pds, String fileOut, NetcdfFileWriter.Version version) throws IOException { if (debug) System.out.printf("write to file %s%n ", fileOut); WriterCFProfileCollection writer = new WriterCFProfileCollection(fileOut, fdpoint.getGlobalAttributes(), version); int count = 0; List<String> profiles = new ArrayList<String>(); pds.resetIteration(); while (pds.hasNext()) { profiles.add(pds.next().getName()); } pds.resetIteration(); while (pds.hasNext()) { ucar.nc2.ft.ProfileFeature profile = pds.next(); profile.resetIteration(); while (profile.hasNext()) { ucar.nc2.ft.PointFeature pf = profile.next(); if (count == 0) { writer.writeHeader(profiles, fdpoint.getDataVariables(), pf.getTimeUnit(), null); // LOOK altitude units ?? } writer.writeRecord(profile.getName(), pf, pf.getData()); count++; if (debug && count % 100 == 0) System.out.printf("%d ", count); if (debug && count % 1000 == 0) System.out.printf("%n "); } } writer.finish(); return count; }
PointFeatureCollectionIterator iter = profileCollection.getPointFeatureCollectionIterator(); while (iter.hasNext()) { PointFeatureCollection pfc = iter.next(); ProfileFeatureCollection profileCollection2 = (ProfileFeatureCollection) fc2; PointFeatureCollectionIterator iter2 = profileCollection2.getPointFeatureCollectionIterator(); while (iter2.hasNext()) { PointFeatureCollection pfc = iter2.next();
@Test public void testProfileSingleId() throws Exception { String file = TestDir.cdmLocalTestDataDir + "point/profileSingle.ncml"; Formatter buf = new Formatter(); try (FeatureDatasetPoint pods = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(ucar.nc2.constants.FeatureType.PROFILE, file, null, buf)) { List<DsgFeatureCollection> collectionList = pods.getPointFeatureCollectionList(); assert (collectionList.size() == 1) : "Can't handle point data with multiple collections"; DsgFeatureCollection fc = collectionList.get(0); assert fc instanceof ProfileFeatureCollection; ProfileFeatureCollection pc = (ProfileFeatureCollection) fc; int count = 0; pc.resetIteration(); while (pc.hasNext()) { ProfileFeature pf = pc.next(); assert pf.getName().equals("666") : pf.getName() + " should be '666'"; count++; } assert count == 1; } }