class 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();
    }

}

class NetcdfDataReaderTest {

    @Test
    void GpcpPrecipImport(){

        String inFile = new File(getClass().getResource("/gpcp_cdr_v23rB1_y2019_m01.nc").getFile()).toString();
        String variableName = "precip";

        DataReader reader = DataReader.builder()
                .path(inFile)
                .variable(variableName)
                .build();

        List<VortexGrid> dtos = reader.getDtos().stream().map(grid -> (VortexGrid) grid).collect(Collectors.toList());
        assertEquals(1, dtos.size());
        assertEquals(10368, dtos.get(0).data().length);
    }

}