@Immutable 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 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>> |
| Modifier and Type | Field and Description |
|---|---|
protected FileCacheIF |
cache |
static String |
IOSP_MESSAGE_ADD_RECORD_STRUCTURE
Deprecated.
|
static String |
IOSP_MESSAGE_GET_IOSP |
static String |
IOSP_MESSAGE_GET_NETCDF_FILE_FORMAT |
static String |
IOSP_MESSAGE_RANDOM_ACCESS_FILE |
| Modifier | Constructor and Description |
|---|---|
protected |
NetcdfFile(NetcdfFile.Builder<?> builder) |
| Modifier and Type | Method and Description |
|---|---|
protected NetcdfFile.Builder<?> |
addLocalFieldsToBuilder(NetcdfFile.Builder<? extends NetcdfFile.Builder<?>> b) |
static NetcdfFile.Builder<?> |
builder()
Get Builder for this class.
|
void |
close()
Close all resources (files, sockets, etc) associated with this file.
|
Attribute |
findAttribute(String fullNameEscaped)
Find an attribute, with the specified (escaped full) name.
|
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.
|
String |
getDetailInfo()
Show debug / underlying implementation details
|
void |
getDetailInfo(Formatter f)
Show debug / underlying implementation details
|
com.google.common.collect.ImmutableList<Dimension> |
getDimensions()
Get all shared Dimensions used in this file.
|
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.
|
long |
getLastModified()
Deprecated.
|
String |
getLocation()
Get the NetcdfFile location.
|
Group |
getRootGroup()
Get the root group.
|
protected Iterator<StructureData> |
getStructureDataArrayIterator(Sequence s,
int bufferSize) |
protected StructureDataIterator |
getStructureIterator(Structure s,
int bufferSize)
Deprecated.
use getStructureDataArrayIterator()
|
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.
|
void |
reacquire()
Deprecated.
do not use
|
protected Array<?> |
readArrayData(Variable v,
Section ranges)
Do not call this directly, use Variable.readArray() !!
Ranges must be filled (no nulls)
|
protected Array |
readData(Variable v,
Section ranges)
Deprecated.
use readArrayData()
|
Array |
readSection(String variableSection)
Deprecated.
use readSectionArray()
|
Array<?> |
readSectionArray(String variableSection)
Read a variable using the given section specification.
|
protected long |
readToOutputStream(Variable v,
Section section,
OutputStream out) |
void |
release()
Deprecated.
do not use
|
Object |
sendIospMessage(Object message)
Generic way to send a "message" to the underlying IOSP.
|
protected void |
setCachedData(Variable v,
Array<?> cacheData) |
static void |
setDebugFlags(DebugFlags debugFlag)
Deprecated.
do not use
|
void |
setFileCache(FileCacheIF cache)
Deprecated.
do not use
|
protected void |
showCached(Formatter f)
Deprecated.
do not use
|
protected void |
showProxies(Formatter f)
Deprecated.
do not use
|
NetcdfFile.Builder<?> |
toBuilder()
Turn into a mutable Builder.
|
String |
toNcml(String url)
NcML representation of Netcdf header info, non strict
|
String |
toString()
CDL representation of Netcdf header info, non strict
|
protected String |
toStringDebug(Object o)
Deprecated.
do not use
|
void |
writeNcml(OutputStream os,
String uri)
Write the NcML representation: dont show coordinate values
|
void |
writeNcml(Writer writer,
String uri)
Write the NcML representation: dont show coordinate values
|
@Deprecated public static final String IOSP_MESSAGE_ADD_RECORD_STRUCTURE
public static final String IOSP_MESSAGE_RANDOM_ACCESS_FILE
public static final String IOSP_MESSAGE_GET_IOSP
public static final String IOSP_MESSAGE_GET_NETCDF_FILE_FORMAT
protected FileCacheIF cache
protected NetcdfFile(NetcdfFile.Builder<?> builder)
@Deprecated public static void setDebugFlags(DebugFlags debugFlag)
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface FileCacheableIOException - if error when closing@Nullable public Attribute findAttribute(String fullNameEscaped)
fullNameEscaped - eg "@attName", "/group/subgroup/@attName" or "/group/subgroup/varname.name2.name@attName"@Nullable public Dimension findDimension(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(String attName)
attName - the name of the attribute@Nullable public Attribute findGlobalAttributeIgnoreCase(String name)
name - the name of the attribute@Nullable public Group findGroup(@Nullable String fullName)
fullName - eg "/group/subgroup/wantGroup". Null or empty string returns the root group.@Nullable public Variable findVariable(String fullNameEscaped)
fullNameEscaped - eg "/group/subgroup/name1.name2.name".public com.google.common.collect.ImmutableList<Dimension> getDimensions()
@Nullable public String getFileTypeId()
public String getFileTypeDescription()
public String getFileTypeVersion()
public com.google.common.collect.ImmutableList<Attribute> getGlobalAttributes()
public String getLocation()
getLocation in interface FileCacheable@Nullable public String getId()
public Group getRootGroup()
@Nullable public String getTitle()
public com.google.common.collect.ImmutableList<Variable> getVariables()
@Nullable public Dimension getUnlimitedDimension()
public boolean hasUnlimitedDimension()
@Deprecated protected StructureDataIterator getStructureIterator(Structure s, int bufferSize) throws IOException
IOExceptionprotected Iterator<StructureData> getStructureDataArrayIterator(Sequence s, int bufferSize) throws IOException
IOException@Deprecated protected Array readData(Variable v, Section ranges) throws IOException, InvalidRangeException
IOExceptionInvalidRangeException@Nullable protected Array<?> readArrayData(Variable v, Section ranges) throws IOException, InvalidRangeException
IOExceptionInvalidRangeException@Deprecated public Array readSection(String variableSection) throws IOException, InvalidRangeException
variableSection - the constraint expression.IOException - if errorInvalidRangeException - if variableSection is invalidpublic Array<?> readSectionArray(String variableSection) throws IOException, InvalidRangeException
variableSection - the constraint expression.IOExceptionInvalidRangeExceptionprotected long readToOutputStream(Variable v, Section section, OutputStream out) throws IOException, InvalidRangeException
IOExceptionInvalidRangeExceptionpublic Object sendIospMessage(Object message)
message - iosp specific messagepublic String toString()
public void writeNcml(OutputStream os, String uri) throws 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(). // ??IOException - if errorpublic void writeNcml(Writer writer, String uri) throws 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().IOException - if error@Deprecated public long getLastModified()
FileCacheableFileFactory.getLastModified in interface FileCacheablelong value representing the time the file(s) were last modified or 0L if the
last-modified time couldn't be determined for any reason.@Deprecated protected String toStringDebug(Object o)
o - must be a Variable, Dimension, Attribute, or Group@Deprecated public void release() throws IOException
release in interface FileCacheableIOException@Deprecated public void reacquire() throws IOException
reacquire in interface FileCacheableIOException@Deprecated public void setFileCache(FileCacheIF cache)
setFileCache in interface FileCacheablecache - must store this, use it on close as above.public String getDetailInfo()
public void getDetailInfo(Formatter f)
@Deprecated protected void showCached(Formatter f)
@Deprecated protected void showProxies(Formatter f)
public NetcdfFile.Builder<?> toBuilder()
protected NetcdfFile.Builder<?> addLocalFieldsToBuilder(NetcdfFile.Builder<? extends NetcdfFile.Builder<?>> b)
public static NetcdfFile.Builder<?> builder()