@Test void AorcTempImport(){ String inFile = new File(getClass().getResource("/AORC_TMP_MARFC_1984010100.nc4").getFile()).toString(); DataReader reader = DataReader.builder() .path(inFile) .variable("TMP_2maboveground") .build(); List<VortexGrid> grids = reader.getDtos().stream().map(grid -> (VortexGrid) grid).collect(Collectors.toList()); VortexGrid grid = grids.get(0); assertTrue(grid.startTime().isEqual(ZonedDateTime.of(1984, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")))); assertTrue(grid.endTime().isEqual(ZonedDateTime.of(1984, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")))); }
@Override public List<VortexData> getDtos() { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path); Formatter errlog = new Formatter()) { FeatureDataset dataset = FeatureDatasetFactoryManager.wrap(FeatureType.GRID, ncd, null, errlog); if (dataset != null) { FeatureType ftype = dataset.getFeatureType(); if (ftype == FeatureType.GRID) { assert (dataset instanceof GridDataset); GridDataset gridDataset = (GridDataset) dataset; return getData(gridDataset, variableName); } } else { List<Variable> variables = ncd.getVariables(); for (Variable variable : variables) { if (variable.getShortName().equals(variableName) && variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; int count = getDtoCount(variableDS); VariableDsReader reader = VariableDsReader.builder() .setNetcdfFile(ncd) .setVariableName(variableName) .build(); List<VortexData> dataList = new ArrayList<>(); for (int i = 0; i < count; i++) { VortexData data = reader.read(i); dataList.add(data); } return dataList; } } } } catch (IOException e) { logger.log(Level.SEVERE, e, e::getMessage); return Collections.emptyList(); } return Collections.emptyList(); }
NetcdfDataReader extends DataReader { @Override public List<VortexData> getDtos() { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path); Formatter errlog = new Formatter()) { FeatureDataset dataset = FeatureDatasetFactoryManager.wrap(FeatureType.GRID, ncd, null, errlog); if (dataset != null) { FeatureType ftype = dataset.getFeatureType(); if (ftype == FeatureType.GRID) { assert (dataset instanceof GridDataset); GridDataset gridDataset = (GridDataset) dataset; return getData(gridDataset, variableName); } } else { List<Variable> variables = ncd.getVariables(); for (Variable variable : variables) { if (variable.getShortName().equals(variableName) && variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; int count = getDtoCount(variableDS); VariableDsReader reader = VariableDsReader.builder() .setNetcdfFile(ncd) .setVariableName(variableName) .build(); List<VortexData> dataList = new ArrayList<>(); for (int i = 0; i < count; i++) { VortexData data = reader.read(i); dataList.add(data); } return dataList; } } } } catch (IOException e) { logger.log(Level.SEVERE, e, e::getMessage); return Collections.emptyList(); } return Collections.emptyList(); } }
NetcdfDataReader extends DataReader { @Override public List<VortexData> getDtos() { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path); Formatter errlog = new Formatter()) { FeatureDataset dataset = FeatureDatasetFactoryManager.wrap(FeatureType.GRID, ncd, null, errlog); if (dataset != null) { FeatureType ftype = dataset.getFeatureType(); if (ftype == FeatureType.GRID) { assert (dataset instanceof GridDataset); GridDataset gridDataset = (GridDataset) dataset; return getData(gridDataset, variableName); } } else { List<Variable> variables = ncd.getVariables(); for (Variable variable : variables) { if (variable.getShortName().equals(variableName) && variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; int count = getDtoCount(variableDS); VariableDsReader reader = VariableDsReader.builder() .setNetcdfFile(ncd) .setVariableName(variableName) .build(); List<VortexData> dataList = new ArrayList<>(); for (int i = 0; i < count; i++) { VortexData data = reader.read(i); dataList.add(data); } return dataList; } } } } catch (IOException e) { logger.log(Level.SEVERE, e, e::getMessage); return Collections.emptyList(); } return Collections.emptyList(); } NetcdfDataReader(DataReaderBuilder builder); }
NetcdfDataReader extends DataReader { @Override public List<VortexData> getDtos() { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path); Formatter errlog = new Formatter()) { FeatureDataset dataset = FeatureDatasetFactoryManager.wrap(FeatureType.GRID, ncd, null, errlog); if (dataset != null) { FeatureType ftype = dataset.getFeatureType(); if (ftype == FeatureType.GRID) { assert (dataset instanceof GridDataset); GridDataset gridDataset = (GridDataset) dataset; return getData(gridDataset, variableName); } } else { List<Variable> variables = ncd.getVariables(); for (Variable variable : variables) { if (variable.getShortName().equals(variableName) && variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; int count = getDtoCount(variableDS); VariableDsReader reader = VariableDsReader.builder() .setNetcdfFile(ncd) .setVariableName(variableName) .build(); List<VortexData> dataList = new ArrayList<>(); for (int i = 0; i < count; i++) { VortexData data = reader.read(i); dataList.add(data); } return dataList; } } } } catch (IOException e) { logger.log(Level.SEVERE, e, e::getMessage); return Collections.emptyList(); } return Collections.emptyList(); } NetcdfDataReader(DataReaderBuilder builder); @Override List<VortexData> getDtos(); @Override VortexData getDto(int idx); @Override int getDtoCount(); static Set<String> getVariables(String path); }
NetcdfDataReader extends DataReader { @Override public List<VortexData> getDtos() { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path); Formatter errlog = new Formatter()) { FeatureDataset dataset = FeatureDatasetFactoryManager.wrap(FeatureType.GRID, ncd, null, errlog); if (dataset != null) { FeatureType ftype = dataset.getFeatureType(); if (ftype == FeatureType.GRID) { assert (dataset instanceof GridDataset); GridDataset gridDataset = (GridDataset) dataset; return getData(gridDataset, variableName); } } else { List<Variable> variables = ncd.getVariables(); for (Variable variable : variables) { if (variable.getShortName().equals(variableName) && variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; int count = getDtoCount(variableDS); VariableDsReader reader = VariableDsReader.builder() .setNetcdfFile(ncd) .setVariableName(variableName) .build(); List<VortexData> dataList = new ArrayList<>(); for (int i = 0; i < count; i++) { VortexData data = reader.read(i); dataList.add(data); } return dataList; } } } } catch (IOException e) { logger.log(Level.SEVERE, e, e::getMessage); return Collections.emptyList(); } return Collections.emptyList(); } NetcdfDataReader(DataReaderBuilder builder); @Override List<VortexData> getDtos(); @Override VortexData getDto(int idx); @Override int getDtoCount(); static Set<String> getVariables(String path);  }