
ucar.nc2.dt.point.CFstationObsDataset Maven / Gradle / Ivy
/*
* Copyright 1998-2009 University Corporation for Atmospheric Research/Unidata
*
* Portions of this software were developed by the Unidata Program at the
* University Corporation for Atmospheric Research.
*
* Access and use of this software shall impose the following obligations
* and understandings on the user. The user is granted the right, without
* any fee or cost, to use, copy, modify, alter, enhance and distribute
* this software, and any derivative works thereof, and its supporting
* documentation for any purpose whatsoever, provided that this entire
* notice appears in all copies of the software, derivative works and
* supporting documentation. Further, UCAR requests that the user credit
* UCAR/Unidata in any publications that result from the use of this
* software or in any product that includes this software. The names UCAR
* and/or Unidata, however, may not be used in any advertising or publicity
* to endorse or promote any products or commercial entity unless specific
* written permission is obtained from UCAR/Unidata. The user also
* understands that UCAR/Unidata is not obligated to provide the user with
* any support, consulting, training or assistance of any kind with regard
* to the use, operation and performance of this software nor to provide
* the user with any updates, revisions, new versions or "bug fixes."
*
* THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package ucar.nc2.dt.point;
import ucar.ma2.*;
import ucar.nc2.*;
import ucar.nc2.constants.AxisType;
import ucar.nc2.constants.FeatureType;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.StructurePseudo;
import ucar.nc2.util.CancelTask;
import ucar.nc2.dt.*;
import java.io.*;
import java.util.*;
import java.text.ParseException;
/**
* This handles station datasets in "Unidata Observation Dataset v1.0"
* Read StationObsDataset in "CF" experimental point/ungridded convention.
*
* @deprecated use ucar.nc2.ft.point
* @author caron
*/
public class CFstationObsDataset extends StationObsDatasetImpl implements TypedDatasetFactoryIF {
static private org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(UnidataStationObsDataset.class);
static public boolean isValidFile(NetcdfFile ds) {
if (!ds.findAttValueIgnoreCase(null, "cdm_datatype", "").equalsIgnoreCase(FeatureType.STATION.toString()))
return false;
String conv = ds.findAttValueIgnoreCase(null, "Conventions", null);
if (conv == null) return false;
StringTokenizer stoke = new StringTokenizer(conv, ",");
while (stoke.hasMoreTokens()) {
String toke = stoke.nextToken().trim();
if (toke.equalsIgnoreCase("CF-1.0"))
return true;
}
return false;
}
// TypedDatasetFactoryIF
public boolean isMine(NetcdfDataset ds) {
return isValidFile(ds);
}
public TypedDataset open(NetcdfDataset ncd, ucar.nc2.util.CancelTask task, StringBuilder errlog) throws IOException {
return new CFstationObsDataset(ncd);
}
public CFstationObsDataset() {
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private Variable latVar, lonVar, altVar, timeVar;
private Variable lastVar, prevVar, firstVar, nextVar, numChildrenVar;
private Variable stationIndexVar, stationIdVar, stationDescVar, numStationsVar;
private boolean hasForwardLinkedList, hasBackwardLinkedList, hasContiguousList;
private Structure recordVar;
private RecordDatasetHelper recordHelper;
private boolean debugRead = false;
private int firstRecord = 0;
public CFstationObsDataset(NetcdfDataset ds) throws IOException {
super(ds);
// coordinate variables
latVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Lat);
lonVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Lon);
altVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Height);
timeVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Time);
if (latVar == null)
throw new IllegalStateException("Missing latitude variable");
if (lonVar == null)
throw new IllegalStateException("Missing longitude coordinate variable");
if (timeVar == null)
throw new IllegalStateException("Missing time coordinate variable");
// variables that link the structures together
lastVar = UnidataObsDatasetHelper.findVariable(ds, "lastChild");
prevVar = UnidataObsDatasetHelper.findVariable(ds, "prevChild");
firstVar = UnidataObsDatasetHelper.findVariable(ds, "firstChild");
nextVar = UnidataObsDatasetHelper.findVariable(ds, "nextChild");
numChildrenVar = UnidataObsDatasetHelper.findVariable(ds, "numChildren");
stationIndexVar = UnidataObsDatasetHelper.findVariable(ds, "parent_index");
if (stationIndexVar == null)
throw new IllegalStateException("Missing parent_index variable");
hasForwardLinkedList = (firstVar != null) && (nextVar != null);
hasBackwardLinkedList = (lastVar != null) && (prevVar != null);
hasContiguousList = (firstVar != null) && (numChildrenVar != null); // ??
// station variables
stationIdVar = UnidataObsDatasetHelper.findVariable(ds, "station_id");
stationDescVar = UnidataObsDatasetHelper.findVariable(ds, "station_description");
numStationsVar = UnidataObsDatasetHelper.findVariable(ds, "number_stations");
if (stationIdVar == null)
throw new IllegalStateException("Missing station id variable");
// fire up the record helper - LOOK assumes its the record dimension
recordHelper = new RecordDatasetHelper(ds, timeVar.getShortName(), null, dataVariables, parseInfo);
recordHelper.setStationInfo(stationIndexVar.getShortName(), stationDescVar == null ? null : stationDescVar.getShortName());
removeDataVariable(stationIndexVar.getShortName());
removeDataVariable(timeVar.getShortName());
if (prevVar != null)
removeDataVariable(prevVar.getShortName());
if (nextVar != null)
removeDataVariable(nextVar.getShortName());
recordVar = recordHelper.recordVar;
timeUnit = recordHelper.timeUnit;
title = ds.findAttValueIgnoreCase(null, "title", "");
desc = ds.findAttValueIgnoreCase(null, "description", "");
readStationTable();
}
private void readStationTable() throws IOException {
Dimension stationDim = ncfile.findDimension("station");
StructurePseudo stationTable = new StructurePseudo( ncfile, null, "stationTable", stationDim);
ArrayStructure stationData = (ArrayStructure) stationTable.read();
// how many are valid stations ?
int nstations = 0;
if (numStationsVar != null)
nstations = numStationsVar.readScalarInt();
else
nstations = stationDim.getLength();
recordHelper.stnHash = new HashMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy