private void createStations(List<ucar.unidata.geoloc.Station> stnList) throws IOException { int nstns = stnList.size(); // see if there's altitude, wmoId for any stations for (int i = 0; i < nstns; i++) { ucar.unidata.geoloc.Station stn = stnList.get(i); // if (!Double.isNaN(stn.getAltitude())) // useAlt = true; if ((stn.getWmoId() != null) && (stn.getWmoId().trim().length() > 0)) useWmoId = true; } /* if (useAlt) ncfile.addGlobalAttribute("altitude_coordinate", altName); */ // find string lengths for (int i = 0; i < nstns; i++) { ucar.unidata.geoloc.Station station = stnList.get(i); name_strlen = Math.max(name_strlen, station.getName().length()); desc_strlen = Math.max(desc_strlen, station.getDescription().length()); if (useWmoId) wmo_strlen = Math.max(wmo_strlen, station.getName().length()); } LatLonRect llbb = getBoundingBox(stnList); ncfile.addGlobalAttribute( "geospatial_lat_min", Double.toString(llbb.getLowerLeftPoint().getLatitude())); ncfile.addGlobalAttribute( "geospatial_lat_max", Double.toString(llbb.getUpperRightPoint().getLatitude())); ncfile.addGlobalAttribute( "geospatial_lon_min", Double.toString(llbb.getLowerLeftPoint().getLongitude())); ncfile.addGlobalAttribute( "geospatial_lon_max", Double.toString(llbb.getUpperRightPoint().getLongitude())); // add the dimensions Dimension recordDim = ncfile.addUnlimitedDimension(recordDimName); recordDims.add(recordDim); Dimension stationDim = ncfile.addDimension(stationDimName, nstns); stationDims.add(stationDim); // add the station Variables using the station dimension Variable v = ncfile.addVariable(latName, DataType.DOUBLE, stationDimName); ncfile.addVariableAttribute(v, new Attribute("units", "degrees_north")); ncfile.addVariableAttribute(v, new Attribute("long_name", "station latitude")); v = ncfile.addVariable(lonName, DataType.DOUBLE, stationDimName); ncfile.addVariableAttribute(v, new Attribute("units", "degrees_east")); ncfile.addVariableAttribute(v, new Attribute("long_name", "station longitude")); if (useAlt) { v = ncfile.addVariable(altName, DataType.DOUBLE, stationDimName); ncfile.addVariableAttribute(v, new Attribute("units", "meters")); ncfile.addVariableAttribute(v, new Attribute("long_name", "station altitude")); } v = ncfile.addStringVariable(idName, stationDims, name_strlen); ncfile.addVariableAttribute(v, new Attribute("long_name", "station identifier")); v = ncfile.addStringVariable(descName, stationDims, desc_strlen); ncfile.addVariableAttribute(v, new Attribute("long_name", "station description")); if (useWmoId) { v = ncfile.addStringVariable(wmoName, stationDims, wmo_strlen); ncfile.addVariableAttribute(v, new Attribute("long_name", "station WMO id")); } v = ncfile.addVariable(numProfilesName, DataType.INT, stationDimName); ncfile.addVariableAttribute( v, new Attribute("long_name", "number of profiles in linked list for this station")); v = ncfile.addVariable(firstProfileName, DataType.INT, stationDimName); ncfile.addVariableAttribute( v, new Attribute("long_name", "index of first profile in linked list for this station")); }
private NetcdfFileWriteable writeNetcdfMetadata( NetcdfFileWriteable ncFile, String variableName, ArrayList<ArrayList<VariableEntry>> variableListList) throws IOException { int suffixInt = 1; for (ArrayList<VariableEntry> variableList : variableListList) { ArrayList<Dimension> dims = new ArrayList<Dimension>(); // add coordinate variables for each dimension for (int i = 0; i < variableList.size(); i++) { VariableEntry temp = variableList.get(i); Dimension tempDim; System.out.println("writing metadata for dim " + temp.getVariableName()); if (temp.isUnlimited()) { // see if there is already an unlimited dimension in this filea, // if so, use it. If not, add it // if ( ncFile.hasUnlimitedDimension() ) { if (this._unlimitedDim == null) { tempDim = ncFile.addUnlimitedDimension(temp.getVariableName()); this._unlimitedDim = tempDim; } else { // tempDim = this._unlimitedDim; dims.add(this._unlimitedDim); continue; } } else { tempDim = ncFile.addDimension(temp.getVariableName(), temp.getSize()); } // add a coordinate variable Dimension[] tempDimArray = {tempDim}; ncFile.addVariable(temp.getVariableName(), temp.getType(), tempDimArray); ncFile.addVariableAttribute(temp.getVariableName(), "units", temp.getUnits()); ncFile.addVariableAttribute(temp.getVariableName(), "long_name", temp.getLongName()); dims.add(tempDim); } // add the main variable System.out.println("adding variable " + (variableName + Integer.toString(suffixInt))); ncFile.addVariable(variableName + Integer.toString(suffixInt), DataType.INT, dims); suffixInt++; } /* ArrayList<Dimension> dims = new ArrayList<Dimension>(); Dimension tempDim; String localName = "dim"; for( int i = 0; i < dimensions.length; i++){ if ( (0 == i) && variableDim) { tempDim = ncFile.addUnlimitedDimension("dim" + Integer.toString(i)); } else { tempDim = ncFile.addDimension("dim" + Integer.toString(i), dimensions[i]); } dims.add( tempDim); } ncFile.addVariable(varName, dataType, dims); */ return ncFile; }