Package ucar.nc2.dataset
Class NetcdfDatasets
java.lang.Object
ucar.nc2.dataset.NetcdfDatasets
Static helper methods for NetcdfDataset
- Since:
- 10/3/2019.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic NetcdfDatasetacquireDataset(DatasetUrl location, boolean enhanceMode, CancelTask cancelTask) Same as openDataset, but file is acquired through the File Cache, with defaultEnhanceMode.static NetcdfDatasetacquireDataset(DatasetUrl location, Set<NetcdfDataset.Enhance> enhanceMode, CancelTask cancelTask) Same as openDataset, but file is acquired through the File Cache, with specified enhancements.static NetcdfDatasetacquireDataset(DatasetUrl location, CancelTask cancelTask) Same as openDataset, but file is acquired through the File Cache, with defaultEnhanceMode, without the need of setting the enhanceMode via the signature.static NetcdfDatasetacquireDataset(ucar.nc2.util.cache.FileFactory fac, DatasetUrl durl, Set<NetcdfDataset.Enhance> enhanceMode, int buffer_size, CancelTask cancelTask, Object iospMessage) Same as openDataset, but file is acquired through the File Cache.static NetcdfFileacquireFile(DatasetUrl location, CancelTask cancelTask) Same as openFile, but file is acquired through the File Cache.static NetcdfFileacquireFile(ucar.nc2.util.cache.FileFactory factory, Object hashKey, DatasetUrl location, int buffer_size, CancelTask cancelTask, Object spiObject) Same as openFile, but file is acquired through the File Cache.static voidstatic NetcdfDatasetenhance(NetcdfFile ncfile, Set<NetcdfDataset.Enhance> mode, CancelTask cancelTask) Make NetcdfFile into NetcdfDataset and enhance if neededstatic ucar.nc2.util.cache.FileCacheIFGet the File Cachestatic voidinitNetcdfFileCache(int minElementsInMemory, int maxElementsInMemory, int period) Enable file caching.static voidinitNetcdfFileCache(int minElementsInMemory, int maxElementsInMemory, int hardLimit, int period) Enable file caching.static NetcdfDatasetopenDataset(String location) Factory method for opening a dataset through the netCDF API, and identifying its coordinate variables.static NetcdfDatasetopenDataset(String location, boolean enhance, int buffer_size, CancelTask cancelTask, Object spiObject) Factory method for opening a dataset through the netCDF API, and identifying its coordinate variables.static NetcdfDatasetopenDataset(String location, boolean enhance, CancelTask cancelTask) Factory method for opening a dataset through the netCDF API, and identifying its coordinate variables.static NetcdfDatasetopenDataset(DatasetUrl location, Set<NetcdfDataset.Enhance> enhanceMode, int buffer_size, CancelTask cancelTask, Object spiObject) Factory method for opening a dataset through the netCDF API, and identifying its coordinate variables.static NetcdfFileopenFile(String location, CancelTask cancelTask) static NetcdfFileopenFile(DatasetUrl location, int buffer_size, CancelTask cancelTask, Object spiObject) Factory method for opening a NetcdfFile through the netCDF API.static NetcdfDatasetopenNcmlDataset(Reader reader, String ncmlLocation, CancelTask cancelTask) Read NcML doc from a Reader, and construct a NetcdfDataset.Builder.static voidshutdown()Call when application exits, if you have previously called initNetcdfFileCache.
-
Constructor Details
-
NetcdfDatasets
public NetcdfDatasets()
-
-
Method Details
-
initNetcdfFileCache
public static void initNetcdfFileCache(int minElementsInMemory, int maxElementsInMemory, int period) Enable file caching. call this before calling acquireFile(). When application terminates, call NetcdfDataset.shutdown().- Parameters:
minElementsInMemory- keep this number in the cachemaxElementsInMemory- trigger a cleanup if it goes over this number.period- (secs) do periodic cleanups every this number of seconds. set to < 0 to not cleanup
-
initNetcdfFileCache
public static void initNetcdfFileCache(int minElementsInMemory, int maxElementsInMemory, int hardLimit, int period) Enable file caching. call this before calling acquireFile(). When application terminates, call NetcdfDataset.shutdown().- Parameters:
minElementsInMemory- keep this number in the cachemaxElementsInMemory- trigger a cleanup if it goes over this number.hardLimit- if > 0, never allow more than this many elements. This causes a cleanup to be done in the calling thread.period- (secs) do periodic cleanups every this number of seconds.
-
disableNetcdfFileCache
public static void disableNetcdfFileCache() -
shutdown
public static void shutdown()Call when application exits, if you have previously called initNetcdfFileCache. This shuts down any background threads in order to get a clean process shutdown. -
getNetcdfFileCache
public static ucar.nc2.util.cache.FileCacheIF getNetcdfFileCache()Get the File Cache- Returns:
- File Cache or null if not enabled.
-
openDataset
Factory method for opening a dataset through the netCDF API, and identifying its coordinate variables.- Parameters:
location- location of file- Returns:
- NetcdfDataset object
- Throws:
IOException- on read error
-
openDataset
public static NetcdfDataset openDataset(String location, boolean enhance, CancelTask cancelTask) throws IOException Factory method for opening a dataset through the netCDF API, and identifying its coordinate variables.- Parameters:
location- location of fileenhance- if true, use defaultEnhanceMode, else no enhancementscancelTask- allow task to be cancelled; may be null.- Returns:
- NetcdfDataset object
- Throws:
IOException- on read error
-
openDataset
public static NetcdfDataset openDataset(String location, boolean enhance, int buffer_size, CancelTask cancelTask, Object spiObject) throws IOException Factory method for opening a dataset through the netCDF API, and identifying its coordinate variables.- Parameters:
location- location of fileenhance- if true, use defaultEnhanceMode, else no enhancementsbuffer_size- RandomAccessFile buffer size, if <= 0, use default sizecancelTask- allow task to be cancelled; may be null.spiObject- sent to iosp.setSpecial() if not null- Returns:
- NetcdfDataset object
- Throws:
IOException- on read error
-
openDataset
public static NetcdfDataset openDataset(DatasetUrl location, Set<NetcdfDataset.Enhance> enhanceMode, int buffer_size, CancelTask cancelTask, Object spiObject) throws IOException Factory method for opening a dataset through the netCDF API, and identifying its coordinate variables.- Parameters:
location- location of fileenhanceMode- set of enhancements. If null, then nonebuffer_size- RandomAccessFile buffer size, if <= 0, use default sizecancelTask- allow task to be cancelled; may be null.spiObject- sent to iosp.setSpecial() if not null- Returns:
- NetcdfDataset object
- Throws:
IOException- on read error
-
openNcmlDataset
public static NetcdfDataset openNcmlDataset(Reader reader, String ncmlLocation, CancelTask cancelTask) throws IOException Read NcML doc from a Reader, and construct a NetcdfDataset.Builder. eg: NcmlReader.readNcml(new StringReader(ncml), location, null);- Parameters:
reader- 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
-
enhance
public static NetcdfDataset enhance(NetcdfFile ncfile, Set<NetcdfDataset.Enhance> mode, CancelTask cancelTask) throws IOException Make NetcdfFile into NetcdfDataset and enhance if needed- Parameters:
ncfile- wrap thismode- using this enhance mode (may be null, meaning no enhance)- Returns:
- NetcdfDataset.Builder wrapping the given ncfile
- Throws:
IOException- on io error
-
acquireDataset
public static NetcdfDataset acquireDataset(DatasetUrl location, CancelTask cancelTask) throws IOException Same as openDataset, but file is acquired through the File Cache, with defaultEnhanceMode, without the need of setting the enhanceMode via the signature. You still close with NetcdfDataset.close(), the release is handled automatically. You must first call initNetcdfFileCache() for caching to actually take place.- Parameters:
location- location of file, passed to FileFactorycancelTask- allow task to be cancelled; may be null.- Returns:
- NetcdfDataset object
- Throws:
IOException- on read error
-
acquireDataset
public static NetcdfDataset acquireDataset(DatasetUrl location, boolean enhanceMode, CancelTask cancelTask) throws IOException Same as openDataset, but file is acquired through the File Cache, with defaultEnhanceMode. You still close with NetcdfDataset.close(), the release is handled automatically. You must first call initNetcdfFileCache() for caching to actually take place.- Parameters:
location- location of file, passed to FileFactoryenhanceMode- how to enhance. if null, then no enhancementcancelTask- allow task to be cancelled; may be null.- Returns:
- NetcdfDataset object
- Throws:
IOException- on read error
-
acquireDataset
public static NetcdfDataset acquireDataset(DatasetUrl location, Set<NetcdfDataset.Enhance> enhanceMode, CancelTask cancelTask) throws IOException Same as openDataset, but file is acquired through the File Cache, with specified enhancements. You still close with NetcdfDataset.close(), the release is handled automatically. You must first call initNetcdfFileCache() for caching to actually take place.- Parameters:
location- location of file, passed to FileFactoryenhanceMode- how to enhance. if null, then no enhancementcancelTask- allow task to be cancelled; may be null.- Returns:
- NetcdfDataset object
- Throws:
IOException- on read error
-
acquireDataset
public static NetcdfDataset acquireDataset(ucar.nc2.util.cache.FileFactory fac, DatasetUrl durl, Set<NetcdfDataset.Enhance> enhanceMode, int buffer_size, CancelTask cancelTask, Object iospMessage) throws IOException Same as openDataset, but file is acquired through the File Cache. You must first call initNetcdfFileCache() for caching to actually take place. You still close with NetcdfDataset.close(), the release is handled automatically.- Parameters:
fac- if not null, use this factory if the file is not in the cache. If null, use the default factory.durl- location of file, passed to FileFactoryenhanceMode- how to enhance. if null, then no enhancementbuffer_size- RandomAccessFile buffer size, if <= 0, use default sizecancelTask- allow task to be cancelled; may be null.iospMessage- sent to iosp.setSpecial() if not null- Returns:
- NetcdfDataset or throw Exception
- Throws:
IOException
-
openFile
- Throws:
IOException
-
openFile
public static NetcdfFile openFile(DatasetUrl location, int buffer_size, CancelTask cancelTask, Object spiObject) throws IOException Factory method for opening a NetcdfFile through the netCDF API. May be any kind of file that can be read through the netCDF API, including OpenDAP and NcML.- local filename (with a file: prefix or no prefix) for netCDF (version 3), hdf5 files, or any file type registered with NetcdfFile.registerIOProvider().
- OpenDAP dataset URL (with a dods:, dap4:, or http: prefix).
- NcML file or URL if the location ends with ".xml" or ".ncml"
- NetCDF file through an HTTP server (http: prefix)
- thredds dataset (thredds: prefix), see DataFactory.openDataset(String location, ...));
This does not necessarily return a NetcdfDataset, or enhance the dataset; use NetcdfDatasets.openDataset() method for that.
- Parameters:
location- location of dataset.buffer_size- RandomAccessFile buffer size, if <= 0, use default sizecancelTask- allow task to be cancelled; may be null.spiObject- sent to iosp.setSpecial() if not null- Returns:
- NetcdfFile object
- Throws:
IOException- on read error
-
acquireFile
Same as openFile, but file is acquired through the File Cache. You still close with NetcdfFile.close(), the release is handled automatically. You must first call initNetcdfFileCache() for caching to actually take place.- Parameters:
location- location of file, passed to FileFactorycancelTask- allow task to be cancelled; may be null.- Returns:
- NetcdfFile object
- Throws:
IOException- on read error
-
acquireFile
public static NetcdfFile acquireFile(ucar.nc2.util.cache.FileFactory factory, Object hashKey, DatasetUrl location, int buffer_size, CancelTask cancelTask, Object spiObject) throws IOException Same as openFile, but file is acquired through the File Cache. You still close with NetcdfFile.close(), the release is handled automatically. You must first call initNetcdfFileCache() for caching to actually take place.- Parameters:
factory- if not null, use this factory to read the file. If null, use the default factory.hashKey- if not null, use as the cache key, else use the locationlocation- location of file, passed to FileFactorybuffer_size- RandomAccessFile buffer size, if <= 0, use default sizecancelTask- allow task to be cancelled; may be null.spiObject- sent to iosp.setSpecial(); may be null- Returns:
- NetcdfFile object
- Throws:
IOException- on read error
-