Package ucar.nc2
Class NetcdfFile
- java.lang.Object
-
- ucar.nc2.NetcdfFile
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,FileCacheable
- Direct Known Subclasses:
CdmRemote
,DapNetcdfFile
,DODSNetcdfFile
,NetcdfDataset
,NetcdfFileSubclass
,NetcdfFileWriteable
public class NetcdfFile extends Object implements FileCacheable, Closeable
Read-only scientific datasets that are accessible through the netCDF API. Immutable after
setImmutable()
is called. Reading data is not thread-safe because of the use ofRandomAccessFile
.Using this class's
Builder
scheme to create aNetcdfFile
object could, for example, be accomplished as follows, using a try/finally block to ensure that theNetcdfFile
is closed when done.NetcdfFile ncfile = null; try { ncfile = NetcdfFile.builder().setLocation(fileName).build(); // do stuff } finally { if (ncfile != null) { ncfile.close(); } }
More conveniently, aNetcdfFile
object may be created using one of the static methods inNetcdfFiles
:NetcdfFile ncfile = null; try { ncfile = NetcdfFiles.open(fileName); // do stuff } finally { if (ncfile != null) { ncfile.close(); } }
Or better yet, use try-with-resources:try (NetcdfFile ncfile = NetcdfFiles.open(fileName)) { // do stuff }
Naming
Each object has a name (aka "full name") that is unique within the entire netcdf file, and a "short name" that is unique within the parent group. These coincide for objects in the root group, and so are backwards compatible with version 3 files.- Variable: group1/group2/varname
- Structure member Variable: group1/group2/varname.s1.s2
- Group Attribute: group1/group2@attName
- Variable Attribute: group1/group2/varName@attName
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NetcdfFile.Builder<T extends NetcdfFile.Builder<T>>
A builder of NetcdfFile objects.
-
Field Summary
Fields Modifier and Type Field Description protected FileCacheIF
cache
protected List<Dimension>
dimensions
Deprecated.protected List<Attribute>
gattributes
Deprecated.protected String
id
protected IOServiceProvider
iosp
static String
IOSP_MESSAGE_ADD_RECORD_STRUCTURE
Deprecated.static String
IOSP_MESSAGE_CONVERT_RECORD_STRUCTURE
Deprecated.static String
IOSP_MESSAGE_GET_NETCDF_FILE_FORMAT
static String
IOSP_MESSAGE_RANDOM_ACCESS_FILE
static String
IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE
Deprecated.protected String
location
protected Group
rootGroup
protected String
title
protected List<Variable>
variables
Deprecated.
-
Constructor Summary
Constructors Modifier Constructor Description protected
NetcdfFile()
Deprecated.use NetcdfFile.builder()NetcdfFile(String filename)
Deprecated.use NetcdfFiles.open( location) or NetcdfDatasets.openFile( location)protected
NetcdfFile(String iospClassName, Object iospParam, String location, int buffer_size, CancelTask cancelTask)
Deprecated.use NetcdfFile.builder()NetcdfFile(URL url)
Deprecated.use NetcdfFiles.open( http:location) or NetcdfDatasets.openFile( http:location)protected
NetcdfFile(IOServiceProvider spi, String location)
Deprecated.use NetcdfFile.builder()protected
NetcdfFile(IOServiceProvider spi, RandomAccessFile raf, String location, CancelTask cancelTask)
Deprecated.use NetcdfFile.builder()protected
NetcdfFile(NetcdfFile ncfile)
Deprecated.use NetcdfFile.builder()protected
NetcdfFile(NetcdfFile.Builder<?> builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Attribute
addAttribute(Group parent, String name, String value)
Deprecated.Use NetcdfFile.builder()Attribute
addAttribute(Group parent, Attribute att)
Deprecated.Use NetcdfFile.builder()Dimension
addDimension(Group parent, Dimension d)
Deprecated.Use NetcdfFile.builder()Group
addGroup(Group parent, Group g)
Deprecated.Use NetcdfFile.builder()protected NetcdfFile.Builder<?>
addLocalFieldsToBuilder(NetcdfFile.Builder<? extends NetcdfFile.Builder<?>> b)
Variable
addStringVariable(Group g, String shortName, String dims, int strlen)
Deprecated.Use NetcdfFile.builder()Variable
addVariable(Group g, String shortName, DataType dtype, String dims)
Deprecated.Use NetcdfFile.builder()Variable
addVariable(Group g, Variable v)
Deprecated.Use NetcdfFile.builder()Attribute
addVariableAttribute(Variable v, Attribute att)
Deprecated.Use NetcdfFile.builder()static NetcdfFile.Builder<?>
builder()
Get Builder for this class.static String
canonicalizeUriString(String location)
Deprecated.use NetcdfFiles.canonicalizeUriStringstatic boolean
canOpen(String location)
Deprecated.use NetcdfFiles.canOpenvoid
close()
Close all resources (files, sockets, etc) associated with this file.void
empty()
Deprecated.Attribute
findAttribute(String fullNameEscaped)
Find an attribute, with the specified (escaped full) name.String
findAttValueIgnoreCase(Variable v, String attName, String defaultValue)
Deprecated.use getRootGroup() or Variable attributes().findAttributeString().Dimension
findDimension(String fullName)
Finds a Dimension with the specified full name.Attribute
findGlobalAttribute(String attName)
Look up an Attribute by (short) name in the root Group or nested Groups, exact match.Attribute
findGlobalAttributeIgnoreCase(String name)
Look up an Attribute by (short) name in the root Group or nested Groups, ignore case.Group
findGroup(String fullName)
Find a Group, with the specified (full) name.Variable
findVariable(String fullNameEscaped)
Find a Variable, with the specified (escaped full) name.Variable
findVariable(Group g, String shortName)
Deprecated.use g.findVariable(shortName)Variable
findVariableByAttribute(Group g, String attName, String attValue)
Deprecated.use g.findVariableByAttribute(String attName, String attValue)void
finish()
Deprecated.Use NetcdfFile.builder()String
getCacheName()
Deprecated.do not useString
getDetailInfo()
Show debug / underlying implementation detailsvoid
getDetailInfo(Formatter f)
com.google.common.collect.ImmutableList<Dimension>
getDimensions()
Deprecated.use ncfile.getRootGroup().getDimensions() for files without nested groups, or recurse through nested groups to get dimensions.String
getFileTypeDescription()
Get a human-readable description for this file type.String
getFileTypeId()
Get the file type id for the underlying data source.String
getFileTypeVersion()
Get the version of this file type.com.google.common.collect.ImmutableList<Attribute>
getGlobalAttributes()
Returns the set of global attributes associated with this file, which are the attributes associated with the root group, or any subgroup.String
getId()
Get the globally unique dataset identifier, if it exists.IOServiceProvider
getIosp()
Deprecated.do not use.long
getLastModified()
Deprecated.String
getLocation()
Get the NetcdfFile location.Group
getRootGroup()
Get the root group.protected StructureDataIterator
getStructureIterator(Structure s, int bufferSize)
String
getTitle()
Get the human-readable title, if it exists.Dimension
getUnlimitedDimension()
Return the unlimited (record) dimension, or null if not exist.com.google.common.collect.ImmutableList<Variable>
getVariables()
Get all of the variables in the file, in all groups.boolean
hasUnlimitedDimension()
Return true if this file has one or more unlimited (record) dimension.static boolean
iospDeRegister(Class iospClass)
Deprecated.use NetcdfFiles.iospDeRegisterstatic boolean
iospRegistered(Class iospClass)
Deprecated.use NetcdfFiles.iospRegisteredprotected static String
makeFullName(CDMNode v)
Deprecated.use NetcdfFiles.makeFullNameprotected static String
makeFullName(CDMNode node, String reservedChars)
Deprecated.use NetcdfFiles.makeFullNameprotected static String
makeFullNameSectionSpec(CDMNode v)
Deprecated.use NetcdfFiles.makeFullNameSectionSpecprotected String
makeFullNameWithString(Group parent, String name)
Deprecated.use NetcdfFiles.makeFullNameWithStringstatic String
makeNameUnescaped(String vname)
Deprecated.use NetcdfFiles.makeNameUnescapedprotected Boolean
makeRecordStructure()
Deprecated.static String
makeValidCDLName(String vname)
Deprecated.use NetcdfFiles.makeValidCDLNamestatic String
makeValidCdmObjectName(String shortName)
Deprecated.use NetcdfFiles.makeValidCdmObjectNamestatic String
makeValidPathName(String vname)
Deprecated.use NetcdfFiles.makeValidPathNamestatic String
makeValidSectionSpecName(String vname)
Deprecated.use NetcdfFiles.makeValidSectionSpecNamestatic NetcdfFile
open(String location)
Deprecated.use NetcdfFiles.openstatic NetcdfFile
open(String location, int buffer_size, CancelTask cancelTask)
Deprecated.use NetcdfFiles.openstatic NetcdfFile
open(String location, int buffer_size, CancelTask cancelTask, Object iospMessage)
Deprecated.use NetcdfFiles.openstatic NetcdfFile
open(String location, String iospClassName, int bufferSize, CancelTask cancelTask, Object iospMessage)
Deprecated.use NetcdfFiles.openstatic NetcdfFile
open(String location, CancelTask cancelTask)
Deprecated.use NetcdfFiles.openstatic NetcdfFile
open(RandomAccessFile raf, String location, CancelTask cancelTask, Object iospMessage)
Deprecated.use NetcdfFiles.openstatic NetcdfFile
openInMemory(String filename)
Deprecated.use NetcdfFiles.openInMemorystatic NetcdfFile
openInMemory(String name, byte[] data)
Deprecated.use NetcdfFiles.openInMemorystatic NetcdfFile
openInMemory(String name, byte[] data, String iospClassName)
Deprecated.use NetcdfFiles.openInMemorystatic NetcdfFile
openInMemory(URI uri)
Deprecated.use NetcdfFiles.openInMemoryvoid
reacquire()
Deprecated.do not useArray
read(String variableSection, boolean flatten)
Deprecated.use readSection(), flatten=false no longer supportedList<Array>
readArrays(List<Variable> variables)
Deprecated.will be moved to DODSNetcdfFile in version 6.double
readAttributeDouble(Variable v, String attName, double defValue)
Deprecated.use use getRootGroup() or Variable attributes().findAttributeDoubleint
readAttributeInteger(Variable v, String attName, int defValue)
Deprecated.use use getRootGroup() or Variable attributes().findAttributeIntegerprotected Array
readData(Variable v, Section ranges)
Do not call this directly, use Variable.read() !! Ranges must be filled (no nulls)Array
readSection(String variableSection)
Read a variable using the given section specification.protected long
readToByteChannel(Variable v, Section section, WritableByteChannel wbc)
Deprecated.do not useprotected long
readToOutputStream(Variable v, Section section, OutputStream out)
static void
registerIOProvider(Class iospClass)
Deprecated.use NetcdfFiles.registerIOProviderstatic void
registerIOProvider(Class iospClass, boolean last)
Deprecated.use NetcdfFiles.registerIOProviderstatic void
registerIOProvider(String className)
Deprecated.use NetcdfFiles.registerIOProviderstatic void
registerIOProviderPreferred(Class iospClass, Class target)
Deprecated.use NetcdfFiles.registerIOProvidervoid
release()
Deprecated.do not useboolean
removeDimension(Group g, String dimName)
Deprecated.Use NetcdfFile.builder()protected Boolean
removeRecordStructure()
Deprecated.boolean
removeVariable(Group g, String varName)
Deprecated.Use NetcdfFile.builder()Object
sendIospMessage(Object message)
Generic way to send a "message" to the underlying IOSP.protected void
setCacheName(String cacheName)
Deprecated.do not usestatic void
setDebugFlags(DebugFlags debugFlag)
Deprecated.do not usevoid
setFileCache(FileCacheIF cache)
Deprecated.do not usevoid
setId(String id)
Deprecated.Use NetcdfFile.builder()NetcdfFile
setImmutable()
Deprecated.Use NetcdfFile.builder()void
setLocation(String location)
Deprecated.Use NetcdfFile.builder()static void
setProperty(String name, String value)
Deprecated.do not usevoid
setRootGroup(Group rootGroup)
Deprecated.Use NetcdfFile.builder()void
setTitle(String title)
Deprecated.Use NetcdfFile.builder()protected void
showCached(Formatter f)
Deprecated.do not useprotected void
showProxies(Formatter f)
boolean
syncExtend()
Deprecated.do not useNetcdfFile.Builder<?>
toBuilder()
Turn into a mutable Builder.String
toNcml(String url)
NcML representation of Netcdf header info, non strictString
toString()
CDL representation of Netcdf header info, non strictprotected String
toStringDebug(Object o)
Access to iosp debugging info.void
writeCDL(OutputStream out, boolean strict)
Deprecated.use CDLWritervoid
writeCDL(PrintWriter pw, boolean strict)
Deprecated.use CDLWriterprotected void
writeCDL(Formatter f, Indent indent, boolean strict)
void
writeNcml(OutputStream os, String uri)
Write the NcML representation: dont show coordinate valuesvoid
writeNcml(Writer writer, String uri)
Write the NcML representation: dont show coordinate values
-
-
-
Field Detail
-
IOSP_MESSAGE_ADD_RECORD_STRUCTURE
@Deprecated public static final String IOSP_MESSAGE_ADD_RECORD_STRUCTURE
Deprecated.- See Also:
- Constant Field Values
-
IOSP_MESSAGE_CONVERT_RECORD_STRUCTURE
@Deprecated public static final String IOSP_MESSAGE_CONVERT_RECORD_STRUCTURE
Deprecated.- See Also:
- Constant Field Values
-
IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE
@Deprecated public static final String IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE
Deprecated.- See Also:
- Constant Field Values
-
IOSP_MESSAGE_RANDOM_ACCESS_FILE
public static final String IOSP_MESSAGE_RANDOM_ACCESS_FILE
- See Also:
- Constant Field Values
-
IOSP_MESSAGE_GET_NETCDF_FILE_FORMAT
public static final String IOSP_MESSAGE_GET_NETCDF_FILE_FORMAT
- See Also:
- Constant Field Values
-
location
protected String location
-
id
protected String id
-
title
protected String title
-
rootGroup
protected Group rootGroup
-
iosp
protected IOServiceProvider iosp
-
cache
protected FileCacheIF cache
-
variables
@Deprecated protected List<Variable> variables
Deprecated.
-
dimensions
@Deprecated protected List<Dimension> dimensions
Deprecated.
-
gattributes
@Deprecated protected List<Attribute> gattributes
Deprecated.
-
-
Constructor Detail
-
NetcdfFile
@Deprecated public NetcdfFile(String filename) throws IOException
Deprecated.use NetcdfFiles.open( location) or NetcdfDatasets.openFile( location)This is can only be used for local netcdf-3 files.- Parameters:
filename
- location- Throws:
IOException
- if error
-
NetcdfFile
@Deprecated public NetcdfFile(URL url) throws IOException
Deprecated.use NetcdfFiles.open( http:location) or NetcdfDatasets.openFile( http:location)This can only be used for netcdf-3 files served over HTTP- Parameters:
url
- HTTP URL location- Throws:
IOException
- if error
-
NetcdfFile
@Deprecated protected NetcdfFile(String iospClassName, Object iospParam, String location, int buffer_size, CancelTask cancelTask) throws IOException, IllegalAccessException, InstantiationException, ClassNotFoundException
Deprecated.use NetcdfFile.builder()Open an existing netcdf file (read only), using the specified iosp. The ClassLoader for the NetcdfFile class is used. Use NetcdfFileSubclass to access this constructor- Parameters:
iospClassName
- the name of the class implementing IOServiceProvideriospParam
- parameter to pass to the IOSP (before open is called)location
- location of file. This is a URL string, or a local pathname.buffer_size
- use this buffer size on the RandomAccessFilecancelTask
- allow user to cancel- Throws:
ClassNotFoundException
- if the iospClassName cannot be foundIllegalAccessException
- if the class or its nullary constructor is not accessible.InstantiationException
- if the class cannot be instatiated, eg if it has no nullary constructorIOException
- if I/O error
-
NetcdfFile
@Deprecated protected NetcdfFile(IOServiceProvider spi, RandomAccessFile raf, String location, CancelTask cancelTask) throws IOException
Deprecated.use NetcdfFile.builder()Open an existing netcdf file, passing in the iosp and the raf. Use NetcdfFileSubclass to access this constructor- Parameters:
spi
- use this IOServiceProvider instanceraf
- read from this RandomAccessFilecancelTask
- allow user to cancellocation
- location of data- Throws:
IOException
- if I/O error
-
NetcdfFile
@Deprecated protected NetcdfFile(IOServiceProvider spi, String location)
Deprecated.use NetcdfFile.builder()Open an existing netcdf file (read only) , but dont do nuttin else Use NetcdfFileSubclass to access this constructor- Parameters:
spi
- use this IOServiceProvider instancelocation
- location of data
-
NetcdfFile
@Deprecated protected NetcdfFile()
Deprecated.use NetcdfFile.builder()For subclass construction. Use NetcdfFileSubclass to access this constructor
-
NetcdfFile
@Deprecated protected NetcdfFile(NetcdfFile ncfile)
Deprecated.use NetcdfFile.builder()Copy constructor, used by NetcdfDataset. Shares the iosp.- Parameters:
ncfile
- copy from here
-
NetcdfFile
protected NetcdfFile(NetcdfFile.Builder<?> builder)
-
-
Method Detail
-
setDebugFlags
@Deprecated public static void setDebugFlags(DebugFlags debugFlag)
Deprecated.do not use
-
registerIOProvider
@Deprecated public static void registerIOProvider(String className) throws IllegalAccessException, InstantiationException, ClassNotFoundException
Deprecated.use NetcdfFiles.registerIOProviderRegister an IOServiceProvider, using its class string name.- Parameters:
className
- Class that implements IOServiceProvider.- Throws:
IllegalAccessException
- if class is not accessible.InstantiationException
- if class doesnt have a no-arg constructor.ClassNotFoundException
- if class not found.
-
registerIOProvider
@Deprecated public static void registerIOProvider(Class iospClass) throws IllegalAccessException, InstantiationException
Deprecated.use NetcdfFiles.registerIOProviderRegister an IOServiceProvider. A new instance will be created when one of its files is opened.- Parameters:
iospClass
- Class that implements IOServiceProvider.- Throws:
IllegalAccessException
- if class is not accessible.InstantiationException
- if class doesnt have a no-arg constructor.ClassCastException
- if class doesnt implement IOServiceProvider interface.
-
registerIOProvider
@Deprecated public static void registerIOProvider(Class iospClass, boolean last) throws IllegalAccessException, InstantiationException
Deprecated.use NetcdfFiles.registerIOProviderRegister an IOServiceProvider. A new instance will be created when one of its files is opened.- Parameters:
iospClass
- Class that implements IOServiceProvider.last
- true=>insert at the end of the list; otherwise front- Throws:
IllegalAccessException
- if class is not accessible.InstantiationException
- if class doesnt have a no-arg constructor.ClassCastException
- if class doesnt implement IOServiceProvider interface.
-
registerIOProviderPreferred
@Deprecated public static void registerIOProviderPreferred(Class iospClass, Class target) throws IllegalAccessException, InstantiationException
Deprecated.use NetcdfFiles.registerIOProviderRegister an IOServiceProvider. A new instance will be created when one of its files is opened. This differs from the above in that it specifically locates the target iosp and inserts the new one in front of it in order to override the target. If the iospclass is already registered, remove it and reinsert. If the target class is not present, then insert at front of the registry- Parameters:
iospClass
- Class that implements IOServiceProvider.target
- Class to override- Throws:
IllegalAccessException
- if class is not accessible.InstantiationException
- if class doesnt have a no-arg constructor.ClassCastException
- if class doesnt implement IOServiceProvider interface.
-
iospRegistered
@Deprecated public static boolean iospRegistered(Class iospClass)
Deprecated.use NetcdfFiles.iospRegisteredSee if a specific IOServiceProvider is registered- Parameters:
iospClass
- Class for which to search
-
iospDeRegister
@Deprecated public static boolean iospDeRegister(Class iospClass)
Deprecated.use NetcdfFiles.iospDeRegisterSee if a specific IOServiceProvider is registered and if so, remove it.- Parameters:
iospClass
- Class for which to search and remove- Returns:
- true if class was present
-
setProperty
@Deprecated public static void setProperty(String name, String value)
Deprecated.do not useSet properties. Currently recognized: "syncExtendOnly", "true" or "false" (default). if true, can only extend file on a sync.- Parameters:
name
- name of propertyvalue
- value of property
-
open
@Deprecated public static NetcdfFile open(String location) throws IOException
Deprecated.use NetcdfFiles.openOpen an existing netcdf file (read only).- Parameters:
location
- location of file.- Returns:
- the NetcdfFile.
- Throws:
IOException
- if error
-
open
@Deprecated public static NetcdfFile open(String location, CancelTask cancelTask) throws IOException
Deprecated.use NetcdfFiles.openOpen an existing file (read only), with option of cancelling.- Parameters:
location
- location of the file.cancelTask
- allow task to be cancelled; may be null.- Returns:
- NetcdfFile object, or null if cant find IOServiceProver
- Throws:
IOException
- if error
-
open
@Deprecated public static NetcdfFile open(String location, int buffer_size, CancelTask cancelTask) throws IOException
Deprecated.use NetcdfFiles.openOpen an existing file (read only), with option of cancelling, setting the RandomAccessFile buffer size for efficiency.- Parameters:
location
- location of file.buffer_size
- RandomAccessFile buffer size, if <= 0, use default sizecancelTask
- allow task to be cancelled; may be null.- Returns:
- NetcdfFile object, or null if cant find IOServiceProver
- Throws:
IOException
- if error
-
open
@Deprecated public static NetcdfFile open(String location, int buffer_size, CancelTask cancelTask, Object iospMessage) throws IOException
Deprecated.use NetcdfFiles.openOpen an existing file (read only), with option of cancelling, setting the RandomAccessFile buffer size for efficiency, with an optional special object for the iosp.- Parameters:
location
- location of file. This may be a- local netcdf-3 filename (with a file: prefix or no prefix)
- remote netcdf-3 filename (with an http: prefix)
- local netcdf-4 filename (with a file: prefix or no prefix)
- local hdf-5 filename (with a file: prefix or no prefix)
- local iosp filename (with a file: prefix or no prefix)
buffer_size
- RandomAccessFile buffer size, if <= 0, use default sizecancelTask
- allow task to be cancelled; may be null.iospMessage
- special iosp tweaking (sent before open is called), may be null- Returns:
- NetcdfFile object, or null if cant find IOServiceProver
- Throws:
IOException
- if error
-
canOpen
@Deprecated public static boolean canOpen(String location) throws IOException
Deprecated.use NetcdfFiles.canOpenFind out if the file can be opened, but dont actually open it. Experimental.- Parameters:
location
- same as open- Returns:
- true if can be opened
- Throws:
IOException
- on read error
-
open
@Deprecated public static NetcdfFile open(String location, String iospClassName, int bufferSize, CancelTask cancelTask, Object iospMessage) throws ClassNotFoundException, IllegalAccessException, InstantiationException, IOException
Deprecated.use NetcdfFiles.openOpen an existing file (read only), specifying which IOSP is to be used.- Parameters:
location
- location of fileiospClassName
- fully qualified class name of the IOSP class to handle this filebufferSize
- RandomAccessFile buffer size, if <= 0, use default sizecancelTask
- allow task to be cancelled; may be null.iospMessage
- special iosp tweaking (sent before open is called), may be null- Returns:
- NetcdfFile object, or null if cant find IOServiceProver
- Throws:
IOException
- if read errorClassNotFoundException
- cannat find iospClassName in thye class pathInstantiationException
- if class cannot be instantiatedIllegalAccessException
- if class is not accessible
-
canonicalizeUriString
@Deprecated public static String canonicalizeUriString(String location)
Deprecated.use NetcdfFiles.canonicalizeUriStringRemoves the"file:"
or"file://"
prefix from the location, if necessary. Also replaces back slashes with forward slashes.- Parameters:
location
- a URI string.- Returns:
- a canonical URI string.
-
openInMemory
@Deprecated public static NetcdfFile openInMemory(String name, byte[] data, String iospClassName) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException
Deprecated.use NetcdfFiles.openInMemoryOpen an in-memory netcdf file, with a specific iosp.- Parameters:
name
- name of the dataset. Typically use the filename or URI.data
- in-memory netcdf fileiospClassName
- fully qualified class name of the IOSP class to handle this file- Returns:
- NetcdfFile object, or null if cant find IOServiceProver
- Throws:
IOException
- if read errorClassNotFoundException
- cannat find iospClassName in the class pathInstantiationException
- if class cannot be instantiatedIllegalAccessException
- if class is not accessible
-
openInMemory
@Deprecated public static NetcdfFile openInMemory(String name, byte[] data) throws IOException
Deprecated.use NetcdfFiles.openInMemoryOpen an in-memory netcdf file.- Parameters:
name
- name of the dataset. Typically use the filename or URI.data
- in-memory netcdf file- Returns:
- memory-resident NetcdfFile
- Throws:
IOException
- if error
-
openInMemory
@Deprecated public static NetcdfFile openInMemory(String filename) throws IOException
Deprecated.use NetcdfFiles.openInMemoryRead a local CDM file into memory. All reads are then done from memory.- Parameters:
filename
- location of CDM file, must be a local file.- Returns:
- a NetcdfFile, which is completely in memory
- Throws:
IOException
- if error reading file
-
openInMemory
@Deprecated public static NetcdfFile openInMemory(URI uri) throws IOException
Deprecated.use NetcdfFiles.openInMemoryRead a remote CDM file into memory. All reads are then done from memory.- Parameters:
uri
- location of CDM file, must be accessible through url.toURL().openStream().- Returns:
- a NetcdfFile, which is completely in memory
- Throws:
IOException
- if error reading file
-
open
@Deprecated public static NetcdfFile open(RandomAccessFile raf, String location, CancelTask cancelTask, Object iospMessage) throws IOException
Deprecated.use NetcdfFiles.openOpen a RandomAccessFile as a NetcdfFile, if possible.- Parameters:
raf
- The open raf, is not cloised by this method.location
- human readable locatoin of this dataset.cancelTask
- used to monitor user cancellation; may be null.iospMessage
- send this message to iosp; may be null.- Returns:
- NetcdfFile or throw an Exception.
- Throws:
IOException
- if cannot open as a CDM NetCDF.
-
close
public void close() throws IOException
Close all resources (files, sockets, etc) associated with this file. If the underlying file was acquired, it will be released, otherwise closed. if isClosed() already, nothing will happen- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceFileCacheable
- Throws:
IOException
- if error when closing
-
release
@Deprecated public void release() throws IOException
Deprecated.do not usePublic by accident. Release any resources like file handles- Specified by:
release
in interfaceFileCacheable
- Throws:
IOException
-
reacquire
@Deprecated public void reacquire() throws IOException
Deprecated.do not usePublic by accident. Reacquire any resources like file handles- Specified by:
reacquire
in interfaceFileCacheable
- Throws:
IOException
-
setFileCache
@Deprecated public void setFileCache(FileCacheIF cache)
Deprecated.do not usePublic by accident. Optional file caching.- Specified by:
setFileCache
in interfaceFileCacheable
- Parameters:
cache
- must store this, use it on close as above.
-
getCacheName
@Deprecated public String getCacheName()
Deprecated.do not usePublic by accident. Get the name used in the cache, if any.- Returns:
- name in the cache.
-
setCacheName
@Deprecated protected void setCacheName(String cacheName)
Deprecated.do not usePublic by accident.- Parameters:
cacheName
- name in the cache, should be unique for this NetcdfFile. Usually the location.
-
getLocation
public String getLocation()
Get the NetcdfFile location. This is a URL, or a file pathname.- Specified by:
getLocation
in interfaceFileCacheable
- Returns:
- location URL or file pathname.
-
getId
@Nullable public String getId()
Get the globally unique dataset identifier, if it exists.- Returns:
- id, or null if none.
-
getTitle
@Nullable public String getTitle()
Get the human-readable title, if it exists.- Returns:
- title, or null if none.
-
getRootGroup
public Group getRootGroup()
Get the root group.- Returns:
- root group
-
findGroup
@Nullable public Group findGroup(@Nullable String fullName)
Find a Group, with the specified (full) name. A full name should start with a '/'. For backwards compatibility, we accept full names that omit the leading '/'. An embedded '/' separates subgroup names.- Parameters:
fullName
- eg "/group/subgroup/wantGroup". Null or empty string returns the root group.- Returns:
- Group or null if not found.
-
findVariable
@Deprecated @Nullable public Variable findVariable(Group g, String shortName)
Deprecated.use g.findVariable(shortName)Find a Variable by short name, in the given group.- Parameters:
g
- A group in this file. Null for root group.shortName
- short name of the Variable.- Returns:
- Variable if found, else null.
-
findVariable
@Nullable public Variable findVariable(String fullNameEscaped)
Find a Variable, with the specified (escaped full) name. It may possibly be nested in multiple groups and/or structures. An embedded "." is interpreted as structure.member. An embedded "/" is interpreted as group/variable. If the name actually has a ".", you must escape it (call NetcdfFiles.makeValidPathName(varname)) Any other chars may also be escaped, as they are removed before testing.- Parameters:
fullNameEscaped
- eg "/group/subgroup/name1.name2.name".- Returns:
- Variable or null if not found.
-
findVariableByAttribute
@Deprecated @Nullable public Variable findVariableByAttribute(Group g, String attName, String attValue)
Deprecated.use g.findVariableByAttribute(String attName, String attValue)Look in the given Group and in its nested Groups for a Variable with a String valued Attribute with the given name and value.- Parameters:
g
- start with this Group, null for the root Group.attName
- look for an Attribuite with this name.attValue
- look for an Attribuite with this value.- Returns:
- the first Variable that matches, or null if none match.
-
findDimension
@Nullable public Dimension findDimension(String fullName)
Finds a Dimension with the specified full name. It may be nested in multiple groups. An embedded "/" is interpreted as a group separator. A leading slash indicates the root group. That slash may be omitted, but thefullName
will be treated as if it were there. In other words, the first name token infullName
is treated as the short name of a Group or Dimension, relative to the root group.- Parameters:
fullName
- Dimension full name, e.g. "/group/subgroup/dim".- Returns:
- the Dimension or
null
if it wasn't found.
-
hasUnlimitedDimension
public boolean hasUnlimitedDimension()
Return true if this file has one or more unlimited (record) dimension.- Returns:
- if this file has an unlimited Dimension(s)
-
getUnlimitedDimension
@Nullable public Dimension getUnlimitedDimension()
Return the unlimited (record) dimension, or null if not exist. If there are multiple unlimited dimensions, it will return the first one.- Returns:
- the unlimited Dimension, or null if none.
-
getDimensions
@Deprecated public com.google.common.collect.ImmutableList<Dimension> getDimensions()
Deprecated.use ncfile.getRootGroup().getDimensions() for files without nested groups, or recurse through nested groups to get dimensions.Get the shared Dimensions used in this file.If the dimensions are in a group, the dimension name will have the group name, in order to disambiguate the dimensions. This means that a Variable's dimensions will not match Dimensions in this list. Therefore it is better to get the shared Dimensions directly from the Groups.
-
getVariables
public com.google.common.collect.ImmutableList<Variable> getVariables()
Get all of the variables in the file, in all groups. Alternatively, use groups.
-
getGlobalAttributes
public com.google.common.collect.ImmutableList<Attribute> getGlobalAttributes()
Returns the set of global attributes associated with this file, which are the attributes associated with the root group, or any subgroup. Alternatively, use groups.
-
findGlobalAttribute
@Nullable public Attribute findGlobalAttribute(String attName)
Look up an Attribute by (short) name in the root Group or nested Groups, exact match.- Parameters:
attName
- the name of the attribute- Returns:
- the first Group attribute with given name, or null if not found
-
findGlobalAttributeIgnoreCase
@Nullable public Attribute findGlobalAttributeIgnoreCase(String name)
Look up an Attribute by (short) name in the root Group or nested Groups, ignore case.- Parameters:
name
- the name of the attribute- Returns:
- the first group attribute with given Attribute name, ignoronmg case, or null if not found
-
findAttribute
@Nullable public Attribute findAttribute(String fullNameEscaped)
Find an attribute, with the specified (escaped full) name. It may possibly be nested in multiple groups and/or structures. An embedded "." is interpreted as structure.member. An embedded "/" is interpreted as group/group or group/variable. An embedded "@" is interpreted as variable@attribute If the name actually has a ".", you must escape it (call NetcdfFiles.makeValidPathName(varname)) Any other chars may also be escaped, as they are removed before testing.- Parameters:
fullNameEscaped
- eg "@attName", "/group/subgroup/@attName" or "/group/subgroup/varname.name2.name@attName"- Returns:
- Attribute or null if not found.
-
findAttValueIgnoreCase
@Deprecated public String findAttValueIgnoreCase(Variable v, String attName, String defaultValue)
Deprecated.use getRootGroup() or Variable attributes().findAttributeString().Find a String-valued global or variable Attribute by Attribute name (ignore case), return the Value of the Attribute. If not found return defaultValue- Parameters:
v
- the variable or null to look in the root group.attName
- the (full) name of the attribute, case insensitivedefaultValue
- return this if attribute not found- Returns:
- the attribute value, or defaultValue if not found
-
readAttributeDouble
@Deprecated public double readAttributeDouble(Variable v, String attName, double defValue)
Deprecated.use use getRootGroup() or Variable attributes().findAttributeDouble
-
readAttributeInteger
@Deprecated public int readAttributeInteger(Variable v, String attName, int defValue)
Deprecated.use use getRootGroup() or Variable attributes().findAttributeInteger
-
toString
public String toString()
CDL representation of Netcdf header info, non strict
-
writeNcml
public void writeNcml(OutputStream os, String uri) throws IOException
Write the NcML representation: dont show coordinate values- Parameters:
os
- : write to this OutputStream. Will be closed at end of the method.uri
- use this for the url attribute; if null use getLocation(). // ??- Throws:
IOException
- if error
-
writeNcml
public void writeNcml(Writer writer, String uri) throws IOException
Write the NcML representation: dont show coordinate values- Parameters:
writer
- : write to this Writer, should have encoding of UTF-8. Will be closed at end of the method.uri
- use this for the url attribute; if null use getLocation().- Throws:
IOException
- if error
-
writeCDL
@Deprecated public void writeCDL(OutputStream out, boolean strict)
Deprecated.use CDLWriterWrite CDL representation to OutputStream.- Parameters:
out
- write to this OutputStreamstrict
- if true, make it stricly CDL, otherwise, add a little extra info
-
writeCDL
@Deprecated public void writeCDL(PrintWriter pw, boolean strict)
Deprecated.use CDLWriterWrite CDL representation to PrintWriter.- Parameters:
pw
- write to this PrintWriterstrict
- if true, make it stricly CDL, otherwise, add a little extra info
-
syncExtend
@Deprecated public boolean syncExtend() throws IOException
Deprecated.do not useExtend the file if needed, in a way that is compatible with the current metadata, that is, does not invalidate structural metadata held by the application. For example, ok if dimension lengths, data has changed. All previous object references (variables, dimensions, etc) remain valid.- Returns:
- true if file was extended.
- Throws:
IOException
- if error
-
getLastModified
@Deprecated public long getLastModified()
Deprecated.Description copied from interface:FileCacheable
Returns the time that the underlying file(s) were last modified. If they've changed since they were stored in the cache, they will be closed and reopened withFileFactory
.- Specified by:
getLastModified
in interfaceFileCacheable
- Returns:
- a
long
value representing the time the file(s) were last modified or0L
if the last-modified time couldn't be determined for any reason.
-
addAttribute
@Deprecated public Attribute addAttribute(Group parent, Attribute att)
Deprecated.Use NetcdfFile.builder()Add an attribute to a group.- Parameters:
parent
- add to this group. If group is null, use root groupatt
- add this attribute- Returns:
- the attribute that was added
-
addAttribute
@Deprecated public Attribute addAttribute(Group parent, String name, String value)
Deprecated.Use NetcdfFile.builder()Add optional String attribute to a group.- Parameters:
parent
- add to this group. If group is null, use root groupname
- attribute name, may not be nullvalue
- attribute value, may be null, in which case, do not addd- Returns:
- the attribute that was added
-
addGroup
@Deprecated public Group addGroup(Group parent, Group g)
Deprecated.Use NetcdfFile.builder()Add a group to the parent group.- Parameters:
parent
- add to this group. If group is null, use root groupg
- add this group- Returns:
- the group that was added
-
setRootGroup
@Deprecated public void setRootGroup(Group rootGroup)
Deprecated.Use NetcdfFile.builder()Public by accident.
-
addDimension
@Deprecated public Dimension addDimension(Group parent, Dimension d)
Deprecated.Use NetcdfFile.builder()Add a shared Dimension to a Group.- Parameters:
parent
- add to this group. If group is null, use root groupd
- add this Dimension- Returns:
- the dimension that was added
-
removeDimension
@Deprecated public boolean removeDimension(Group g, String dimName)
Deprecated.Use NetcdfFile.builder()Remove a shared Dimension from a Group by name.- Parameters:
g
- remove from this group. If group is null, use root groupdimName
- name of Dimension to remove.- Returns:
- true if found and removed.
-
addVariable
@Deprecated public Variable addVariable(Group g, Variable v)
Deprecated.Use NetcdfFile.builder()Add a Variable to the given group.- Parameters:
g
- add to this group. If group is null, use root groupv
- add this Variable- Returns:
- the variable that was added
-
addVariable
@Deprecated public Variable addVariable(Group g, String shortName, DataType dtype, String dims)
Deprecated.Use NetcdfFile.builder()Create a new Variable, and add to the given group.- Parameters:
g
- add to this group. If group is null, use root groupshortName
- short name of the Variabledtype
- data type of the Variabledims
- list of dimension names- Returns:
- the new Variable
-
addStringVariable
@Deprecated public Variable addStringVariable(Group g, String shortName, String dims, int strlen)
Deprecated.Use NetcdfFile.builder()Create a new Variable of type Datatype.CHAR, and add to the given group.- Parameters:
g
- add to this group. If group is null, use root groupshortName
- short name of the Variabledims
- list of dimension namesstrlen
- dimension length of the inner (fastest changing) dimension- Returns:
- the new Variable
-
removeVariable
@Deprecated public boolean removeVariable(Group g, String varName)
Deprecated.Use NetcdfFile.builder()Remove a Variable from the given group by name.- Parameters:
g
- remove from this group. If group is null, use root groupvarName
- name of variable to remove.- Returns:
- true is variable found and removed
-
addVariableAttribute
@Deprecated public Attribute addVariableAttribute(Variable v, Attribute att)
Deprecated.Use NetcdfFile.builder()Add a variable attribute.- Parameters:
v
- add to this Variable.att
- add this attribute- Returns:
- the added Attribute
-
sendIospMessage
public Object sendIospMessage(Object message)
Generic way to send a "message" to the underlying IOSP. This message is sent after the file is open. To affect the creation of the file, use a factory method like NetcdfFile.open(). In ver6, IOSP_MESSAGE_ADD_RECORD_STRUCTURE, IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE will not work here.- Parameters:
message
- iosp specific message- Returns:
- iosp specific return, may be null
-
makeRecordStructure
@Deprecated protected Boolean makeRecordStructure()
Deprecated.If there is an unlimited dimension, make all variables that use it into a Structure. A Variable called "record" is added. You can then access these through the record structure.- Returns:
- true if it has a Nectdf-3 record structure
-
removeRecordStructure
@Deprecated protected Boolean removeRecordStructure()
Deprecated.
-
setId
@Deprecated public void setId(String id)
Deprecated.Use NetcdfFile.builder()Set the globally unique dataset identifier.- Parameters:
id
- the id
-
setTitle
@Deprecated public void setTitle(String title)
Deprecated.Use NetcdfFile.builder()Set the dataset "human readable" title.- Parameters:
title
- the title
-
setLocation
@Deprecated public void setLocation(String location)
Deprecated.Use NetcdfFile.builder()Set the location, a URL or local filename.- Parameters:
location
- the location
-
setImmutable
@Deprecated public NetcdfFile setImmutable()
Deprecated.Use NetcdfFile.builder()Make this immutable.- Returns:
- this
-
empty
@Deprecated public void empty()
Deprecated.Completely empty the objects in the netcdf file. Used for rereading the file on a sync().
-
finish
@Deprecated public void finish()
Deprecated.Use NetcdfFile.builder()Finish constructing the object model. This construsts the "global" variables, attributes and dimensions. It also looks for coordinate variables.
-
readData
protected Array readData(Variable v, Section ranges) throws IOException, InvalidRangeException
Do not call this directly, use Variable.read() !! Ranges must be filled (no nulls)- Throws:
IOException
InvalidRangeException
-
readSection
public Array readSection(String variableSection) throws IOException, InvalidRangeException
Read a variable using the given section specification. The result is always an array of the type of the innermost variable. Its shape is the accumulation of all the shapes of its parent structures.- Parameters:
variableSection
- the constraint expression.- Returns:
- data requested
- Throws:
IOException
- if errorInvalidRangeException
- if variableSection is invalid- See Also:
- SectionSpecification
-
readToByteChannel
@Deprecated protected long readToByteChannel(Variable v, Section section, WritableByteChannel wbc) throws IOException, InvalidRangeException
Deprecated.do not useRead data from a top level Variable and send data to a WritableByteChannel. Experimental.- Parameters:
v
- a top-level Variablesection
- the section of data to read. There must be a Range for each Dimension in the variable, in order. Note: no nulls allowed. IOSP may not modify.wbc
- write data to this WritableByteChannel- Returns:
- the number of bytes written to the channel
- Throws:
IOException
- if read errorInvalidRangeException
- if invalid section
-
readToOutputStream
protected long readToOutputStream(Variable v, Section section, OutputStream out) throws IOException, InvalidRangeException
- Throws:
IOException
InvalidRangeException
-
getStructureIterator
protected StructureDataIterator getStructureIterator(Structure s, int bufferSize) throws IOException
- Throws:
IOException
-
readArrays
@Deprecated public List<Array> readArrays(List<Variable> variables) throws IOException
Deprecated.will be moved to DODSNetcdfFile in version 6.Do a bulk read on a list of Variables and return a corresponding list of Array that contains the results of a full read on each Variable. This is mostly here so DODSNetcdf can override it with one call to the server.- Parameters:
variables
- List of type Variable- Returns:
- List of Array, one for each Variable in the input.
- Throws:
IOException
- if read error
-
read
@Deprecated public Array read(String variableSection, boolean flatten) throws IOException, InvalidRangeException
Deprecated.use readSection(), flatten=false no longer supportedRead a variable using the given section specification.- Parameters:
variableSection
- the constraint expression.flatten
- MUST BE TRUE- Returns:
- Array data read.
- Throws:
IOException
- if errorInvalidRangeException
- if variableSection is invalid- See Also:
- SectionSpecification
-
toStringDebug
protected String toStringDebug(Object o)
Access to iosp debugging info.- Parameters:
o
- must be a Variable, Dimension, Attribute, or Group- Returns:
- debug info for this object.
-
getDetailInfo
public String getDetailInfo()
Show debug / underlying implementation details
-
getDetailInfo
public void getDetailInfo(Formatter f)
-
showCached
@Deprecated protected void showCached(Formatter f)
Deprecated.do not use
-
showProxies
protected void showProxies(Formatter f)
-
getIosp
@Deprecated public IOServiceProvider getIosp()
Deprecated.do not use.
-
getFileTypeId
public String getFileTypeId()
Get the file type id for the underlying data source.- Returns:
- registered id of the file type
- See Also:
- "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
-
getFileTypeDescription
public String getFileTypeDescription()
Get a human-readable description for this file type.- Returns:
- description of the file type
- See Also:
- "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
-
getFileTypeVersion
public String getFileTypeVersion()
Get the version of this file type.- Returns:
- version of the file type
- See Also:
- "https://www.unidata.ucar.edu/software/netcdf-java/formats/FileTypes.html"
-
makeValidCdmObjectName
@Deprecated public static String makeValidCdmObjectName(String shortName)
Deprecated.use NetcdfFiles.makeValidCdmObjectNameCreate a valid CDM object name. Control chars (< 0x20) are not allowed. Trailing and leading blanks are not allowed and are stripped off. A space is converted into an underscore "_". A forward slash "/" is converted into an underscore "_".- Parameters:
shortName
- from this name- Returns:
- valid CDM object name
-
makeValidCDLName
@Deprecated public static String makeValidCDLName(String vname)
Deprecated.use NetcdfFiles.makeValidCDLNameEscape special characters in a netcdf short name when it is intended for use in CDL.- Parameters:
vname
- the name- Returns:
- escaped version of it
-
makeValidPathName
@Deprecated public static String makeValidPathName(String vname)
Deprecated.use NetcdfFiles.makeValidPathNameEscape special characters in a netcdf short name when it is intended for use in a fullname- Parameters:
vname
- the name- Returns:
- escaped version of it
-
makeValidSectionSpecName
@Deprecated public static String makeValidSectionSpecName(String vname)
Deprecated.use NetcdfFiles.makeValidSectionSpecNameEscape special characters in a netcdf short name when it is intended for use in a sectionSpec- Parameters:
vname
- the name- Returns:
- escaped version of it
-
makeNameUnescaped
@Deprecated public static String makeNameUnescaped(String vname)
Deprecated.use NetcdfFiles.makeNameUnescapedUnescape any escaped characters in a name.- Parameters:
vname
- the escaped name- Returns:
- unescaped version of it
-
makeFullName
@Deprecated protected static String makeFullName(CDMNode v)
Deprecated.use NetcdfFiles.makeFullNameGiven a CDMNode, create its full name with appropriate backslash escaping. Warning: do not use for a section spec.- Parameters:
v
- the cdm node- Returns:
- full name
-
makeFullNameSectionSpec
@Deprecated protected static String makeFullNameSectionSpec(CDMNode v)
Deprecated.use NetcdfFiles.makeFullNameSectionSpecGiven a CDMNode, create its full name with appropriate backslash escaping for use in a section spec.- Parameters:
v
- the cdm node- Returns:
- full name
-
makeFullName
@Deprecated protected static String makeFullName(CDMNode node, String reservedChars)
Deprecated.use NetcdfFiles.makeFullNameGiven a CDMNode, create its full name with appropriate backslash escaping of the specified characters.- Parameters:
node
- the cdm nodereservedChars
- the set of characters to escape- Returns:
- full name
-
makeFullNameWithString
@Deprecated protected String makeFullNameWithString(Group parent, String name)
Deprecated.use NetcdfFiles.makeFullNameWithStringCreate a synthetic full name from a group plus a string- Parameters:
parent
- parent groupname
- synthetic name string- Returns:
- synthetic name
-
toBuilder
public NetcdfFile.Builder<?> toBuilder()
Turn into a mutable Builder. Can use toBuilder().build() to copy.
-
addLocalFieldsToBuilder
protected NetcdfFile.Builder<?> addLocalFieldsToBuilder(NetcdfFile.Builder<? extends NetcdfFile.Builder<?>> b)
-
builder
public static NetcdfFile.Builder<?> builder()
Get Builder for this class. Allows subclassing.- See Also:
- "https://community.oracle.com/blogs/emcmanus/2010/10/24/using-builder-pattern-subclasses"
-
-