Package ucar.nc2.internal.ncml
Class NcmlReader
- java.lang.Object
-
- ucar.nc2.internal.ncml.NcmlReader
-
public class NcmlReader extends Object
Read NcML and create NetcdfDataset.Builder, using builders and immutable objects.This is an internal class, users should usually call
NetcdfDatasets.openDataset(String)
-
-
Constructor Summary
Constructors Constructor Description NcmlReader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
getLocationFromNcml(String ncml)
Find the location attribute in a NcML stringstatic NetcdfDataset.Builder
mergeNcml(NetcdfFile ref, org.jdom2.Element ncmlElem)
Use NCML to modify the referenced dataset, create a new dataset with the merged info Used to wrap each dataset of an aggregation before its aggregated.static Set<NetcdfDataset.Enhance>
parseEnhanceMode(String enhanceMode)
Retrieve the set of Enhancements that is associated with the given NcML string.static Array
readAttributeValues(org.jdom2.Element s)
Parse the values elementstatic NetcdfDataset.Builder
readNcml(Reader r, String ncmlLocation, CancelTask cancelTask)
Read NcML doc from a Reader, and construct a NetcdfDataset.Builder.static NetcdfDataset.Builder
readNcml(String ncmlLocation, String referencedDatasetUri, CancelTask cancelTask)
Read an NcML file from a URL location, and construct a NetcdfDataset.static void
setDebugFlags(DebugFlags debugFlag)
static void
wrapNcml(NetcdfDataset.Builder ncDataset, String ncmlLocation, CancelTask cancelTask)
Use NCML to modify the dataset, getting NcML from a URL.static void
wrapNcmlResource(NetcdfDataset.Builder ncDataset, String ncmlResourceLocation, CancelTask cancelTask)
Use NCML to modify a dataset, getting the NcML document as a resource stream.
-
-
-
Method Detail
-
setDebugFlags
public static void setDebugFlags(DebugFlags debugFlag)
-
parseEnhanceMode
public static Set<NetcdfDataset.Enhance> parseEnhanceMode(String enhanceMode)
Retrieve the set of Enhancements that is associated with the given NcML string.String Enhancements All ConvertEnums, ConvertUnsigned, ApplyScaleOffset, ConvertMissing, CoordSystems None <empty> ConvertEnums ConvertEnums ConvertUnsigned ConvertUnsigned ApplyScaleOffset ApplyScaleOffset ConvertMissing ConvertMissing CoordSystems CoordSystems IncompleteCoordSystems CoordSystems true Alias for "All" ScaleMissingDefer Alias for "None" AllDefer ConvertEnums, CoordSystems ScaleMissing ConvertUnsigned, ApplyScaleOffset, ConvertMissing - Parameters:
enhanceMode
- a string from the above table.- Returns:
- the set corresponding to
enhanceMode
, ornull
if there is no correspondence.
-
wrapNcml
public static void wrapNcml(NetcdfDataset.Builder ncDataset, String ncmlLocation, CancelTask cancelTask) throws IOException
Use NCML to modify the dataset, getting NcML from a URL. Used by CoordSysFactory.- Parameters:
ncDataset
- modify this datasetncmlLocation
- URL location of NcMLcancelTask
- allow user to cancel task; may be null- Throws:
IOException
- on read error
-
wrapNcmlResource
public static void wrapNcmlResource(NetcdfDataset.Builder ncDataset, String ncmlResourceLocation, CancelTask cancelTask) throws IOException
Use NCML to modify a dataset, getting the NcML document as a resource stream. Uses ClassLoader.getResourceAsStream(ncmlResourceLocation), so the NcML can be inside of a jar file, for example.- Parameters:
ncDataset
- modify this datasetncmlResourceLocation
- resource location of NcMLcancelTask
- allow user to cancel task; may be null- Throws:
IOException
- on read error
-
mergeNcml
public static NetcdfDataset.Builder mergeNcml(NetcdfFile ref, @Nullable org.jdom2.Element ncmlElem) throws IOException
Use NCML to modify the referenced dataset, create a new dataset with the merged info Used to wrap each dataset of an aggregation before its aggregated.- Parameters:
ref
- referenced datasetncmlElem
- parent element - usually the aggregation element of the ncml- Returns:
- new dataset with the merged info
- Throws:
IOException
- on read error
-
readNcml
public static NetcdfDataset.Builder readNcml(Reader r, String ncmlLocation, CancelTask cancelTask) throws IOException
Read NcML doc from a Reader, and construct a NetcdfDataset.Builder. This is an internal method, users should useNetcdfDatasets.openNcmlDataset(Reader, String, CancelTask)
- Parameters:
r
- the Reader containing the NcML documentncmlLocation
- the URL location string of the NcML document, used to resolve relative path of the referenced dataset, or may be just a unique name for caching purposes.cancelTask
- allow user to cancel the task; may be null- Returns:
- the resulting NetcdfDataset.Builder
- Throws:
IOException
- on read error, or bad referencedDatasetUri URI
-
readNcml
public static NetcdfDataset.Builder readNcml(String ncmlLocation, String referencedDatasetUri, CancelTask cancelTask) throws IOException
Read an NcML file from a URL location, and construct a NetcdfDataset.- Parameters:
ncmlLocation
- the URL location string of the NcML documentreferencedDatasetUri
- if null (usual case) get this from NcML, otherwise use URI as the location of the referenced dataset.cancelTask
- allow user to cancel the task; may be null- Returns:
- the resulting NetcdfDataset
- Throws:
IOException
- on read error, or bad referencedDatasetUri URI
-
getLocationFromNcml
public static String getLocationFromNcml(String ncml)
Find the location attribute in a NcML string- Parameters:
ncml
- the NcML as a string- Returns:
- the resulting location attribute, or null if not found or if the NcML cannot be read
-
readAttributeValues
public static Array readAttributeValues(org.jdom2.Element s) throws IllegalArgumentException
Parse the values element- Parameters:
s
- JDOM element to parse- Returns:
- Array with parsed values
- Throws:
IllegalArgumentException
- if string values not parsable to specified data type
-
-