public class NetcdfFile extends Object implements ucar.nc2.util.cache.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>>
A builder of NetcdfFile objects.
|
Modifier and Type | Field and Description |
---|---|
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.
|
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(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) |
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.
|
String |
getLocation()
Get the NetcdfFile location.
|
Group |
getRootGroup()
Get the root group.
|
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(String variableSection)
Read a variable using the given section specification.
|
Object |
sendIospMessage(Object message)
Generic way to send a "message" to the underlying IOSP.
|
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
|
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
@Deprecated public static final String IOSP_MESSAGE_CONVERT_RECORD_STRUCTURE
public static final String IOSP_MESSAGE_GET_NETCDF_FILE_FORMAT
public static final String IOSP_MESSAGE_RANDOM_ACCESS_FILE
@Deprecated public static final String IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE
public static NetcdfFile.Builder<?> builder()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in interface ucar.nc2.util.cache.FileCacheable
IOException
- 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 String getDetailInfo()
public void getDetailInfo(Formatter f)
public String getFileTypeDescription()
public String getFileTypeId()
public String getFileTypeVersion()
public com.google.common.collect.ImmutableList<Attribute> getGlobalAttributes()
@Nullable public String getId()
public String getLocation()
getLocation
in interface ucar.nc2.util.cache.FileCacheable
public Group getRootGroup()
@Nullable public String getTitle()
@Nullable public Dimension getUnlimitedDimension()
public com.google.common.collect.ImmutableList<Variable> getVariables()
public boolean hasUnlimitedDimension()
public Array readSection(String variableSection) throws IOException, InvalidRangeException
variableSection
- the constraint expression.IOException
- if errorInvalidRangeException
- if variableSection is invalidpublic Object sendIospMessage(Object message)
message
- iosp specific messagepublic NetcdfFile.Builder<?> toBuilder()
public 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