public class NetcdfFile
extends java.lang.Object
implements ucar.nc2.util.cache.FileCacheable, java.io.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 of RandomAccessFile
.
Using this class's Builder
scheme to create a NetcdfFile
object could, for
example, be accomplished as follows, using a try/finally block to ensure that the
NetcdfFile
is closed when done.
NetcdfFile ncfile = null; try { ncfile = NetcdfFile.builder().setLocation(fileName).build(); // do stuff } finally { if (ncfile != null) { ncfile.close(); } }More conveniently, a
NetcdfFile
object may be created using one of the static methods
in NetcdfFiles
:
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 }
Modifier and Type | Class and Description |
---|---|
static class |
NetcdfFile.Builder<T extends NetcdfFile.Builder<T>>
A builder of NetcdfFile objects.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
IOSP_MESSAGE_ADD_RECORD_STRUCTURE
Deprecated.
|
static java.lang.String |
IOSP_MESSAGE_CONVERT_RECORD_STRUCTURE
Deprecated.
|
static java.lang.String |
IOSP_MESSAGE_GET_NETCDF_FILE_FORMAT |
static java.lang.String |
IOSP_MESSAGE_RANDOM_ACCESS_FILE |
static java.lang.String |
IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
static NetcdfFile.Builder<?> |
builder()
Get Builder for this class.
|
void |
close()
Close all resources (files, sockets, etc) associated with this file.
|
Attribute |
findAttribute(java.lang.String fullNameEscaped)
Find an attribute, with the specified (escaped full) name.
|
Dimension |
findDimension(java.lang.String fullName)
Finds a Dimension with the specified full name.
|
Attribute |
findGlobalAttribute(java.lang.String attName)
Look up an Attribute by (short) name in the root Group or nested Groups, exact match.
|
Attribute |
findGlobalAttributeIgnoreCase(java.lang.String name)
Look up an Attribute by (short) name in the root Group or nested Groups, ignore case.
|
Group |
findGroup(java.lang.String fullName)
Find a Group, with the specified (full) name.
|
Variable |
findVariable(java.lang.String fullNameEscaped)
Find a Variable, with the specified (escaped full) name.
|
java.lang.String |
getDetailInfo()
Show debug / underlying implementation details
|
void |
getDetailInfo(java.util.Formatter f) |
java.lang.String |
getFileTypeDescription()
Get a human-readable description for this file type.
|
java.lang.String |
getFileTypeId()
Get the file type id for the underlying data source.
|
java.lang.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.
|
java.lang.String |
getId()
Get the globally unique dataset identifier, if it exists.
|
java.lang.String |
getLocation()
Get the NetcdfFile location.
|
Group |
getRootGroup()
Get the root group.
|
java.lang.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.
|
Array |
readSection(java.lang.String variableSection)
Read a variable using the given section specification.
|
java.lang.Object |
sendIospMessage(java.lang.Object message)
Generic way to send a "message" to the underlying IOSP.
|
NetcdfFile.Builder<?> |
toBuilder()
Turn into a mutable Builder.
|
java.lang.String |
toNcml(java.lang.String url)
NcML representation of Netcdf header info, non strict
|
java.lang.String |
toString()
CDL representation of Netcdf header info, non strict
|
void |
writeNcml(java.io.OutputStream os,
java.lang.String uri)
Write the NcML representation: dont show coordinate values
|
void |
writeNcml(java.io.Writer writer,
java.lang.String uri)
Write the NcML representation: dont show coordinate values
|
@Deprecated public static final java.lang.String IOSP_MESSAGE_ADD_RECORD_STRUCTURE
@Deprecated public static final java.lang.String IOSP_MESSAGE_CONVERT_RECORD_STRUCTURE
public static final java.lang.String IOSP_MESSAGE_GET_NETCDF_FILE_FORMAT
public static final java.lang.String IOSP_MESSAGE_RANDOM_ACCESS_FILE
@Deprecated public static final java.lang.String IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE
public static NetcdfFile.Builder<?> builder()
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface ucar.nc2.util.cache.FileCacheable
java.io.IOException
- if error when closing@Nullable public Attribute findAttribute(java.lang.String fullNameEscaped)
fullNameEscaped
- eg "@attName", "/group/subgroup/@attName" or "/group/subgroup/varname.name2.name@attName"@Nullable public Dimension findDimension(java.lang.String fullName)
fullName
will be treated as if it were there. In other words, the first name token in
fullName
is treated as the short name of a Group or Dimension, relative to the root group.fullName
- Dimension full name, e.g. "/group/subgroup/dim".null
if it wasn't found.@Nullable public Attribute findGlobalAttribute(java.lang.String attName)
attName
- the name of the attribute@Nullable public Attribute findGlobalAttributeIgnoreCase(java.lang.String name)
name
- the name of the attribute@Nullable public Group findGroup(@Nullable java.lang.String fullName)
fullName
- eg "/group/subgroup/wantGroup". Null or empty string returns the root group.@Nullable public Variable findVariable(java.lang.String fullNameEscaped)
fullNameEscaped
- eg "/group/subgroup/name1.name2.name".public java.lang.String getDetailInfo()
public void getDetailInfo(java.util.Formatter f)
public java.lang.String getFileTypeDescription()
public java.lang.String getFileTypeId()
public java.lang.String getFileTypeVersion()
public com.google.common.collect.ImmutableList<Attribute> getGlobalAttributes()
@Nullable public java.lang.String getId()
public java.lang.String getLocation()
getLocation
in interface ucar.nc2.util.cache.FileCacheable
public Group getRootGroup()
@Nullable public java.lang.String getTitle()
@Nullable public Dimension getUnlimitedDimension()
public com.google.common.collect.ImmutableList<Variable> getVariables()
public boolean hasUnlimitedDimension()
public Array readSection(java.lang.String variableSection) throws java.io.IOException, InvalidRangeException
variableSection
- the constraint expression.java.io.IOException
- if errorInvalidRangeException
- if variableSection is invalidpublic java.lang.Object sendIospMessage(java.lang.Object message)
message
- iosp specific messagepublic NetcdfFile.Builder<?> toBuilder()
public java.lang.String toNcml(java.lang.String url)
public java.lang.String toString()
toString
in class java.lang.Object
public void writeNcml(java.io.OutputStream os, java.lang.String uri) throws java.io.IOException
os
- : write to this OutputStream. Will be closed at end of the method.uri
- use this for the url attribute; if null use getLocation(). // ??java.io.IOException
- if errorpublic void writeNcml(java.io.Writer writer, java.lang.String uri) throws java.io.IOException
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().java.io.IOException
- if error