|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectucar.nc2.NetcdfFile
public class NetcdfFile
Read-only scientific datasets that are accessible through the netCDF API.
Be sure to close the file when done, best practive is to enclose in a try/finally block:
NetcdfFile ncfile = null;
try {
ncfile = NetcdfFile.open(fileName);
...
} finally {
ncfile.close();
}
Be sure to close the file after opening, eg:
NetcdfFile ncfile = null;
try {
ncfile = NetcdfFile.open(fileName);
...
} finally {
if (null != ncfile) ncfile.close();
}
| Constructor Summary | |
|---|---|
NetcdfFile(java.lang.String filename)
Deprecated. use NetcdfFile.open( location) or NetcdfFileCache.acquire( location) |
|
NetcdfFile(java.net.URL url)
Deprecated. use NetcdfFile.open( http:location) or NetcdfFileCache.acquire( http:location) |
|
| Method Summary | |
|---|---|
void |
addAttribute(Group parent,
Attribute att)
Add an attribute to a group. |
void |
addDimension(Group parent,
Dimension d)
Add a shared Dimension to a Group. |
void |
addGroup(Group parent,
Group g)
Add a group to the parent group. |
void |
addMemberVariable(Structure s,
Variable v)
Add a Variable to the given structure. |
boolean |
addRecordStructure()
If there is an unlimited dimension, make all variables that use it into an array of structures. |
void |
addVariable(Group g,
Variable v)
Add a Variable to the given group. |
void |
addVariableAttribute(Variable v,
Attribute att)
Add a variable attribute. |
void |
close()
Close all resources (files, sockets, etc) associated with this file. |
static java.lang.String |
createValidNetcdfObjectName(java.lang.String name)
Convert a name to a legal netcdf name. |
void |
empty()
Completely empty the objects in the netcdf file. |
java.lang.String |
findAttValueIgnoreCase(Variable v,
java.lang.String attName,
java.lang.String defaultValue)
Find a String-valued global or variable Attribute by Attribute name (ignore case), return the Value of the Attribute. |
Dimension |
findDimension(java.lang.String name)
Retrieve a dimension by fullName. |
Attribute |
findGlobalAttribute(java.lang.String name)
Look up global Attribute by (full) name. |
Attribute |
findGlobalAttributeIgnoreCase(java.lang.String name)
Look up global Attribute by name, ignore case. |
Variable |
findTopVariable(java.lang.String name)
Retrieve the Variable with the specified (full) name, which is not a member of a Structure. |
Variable |
findVariable(java.lang.String fullName)
Find a variable, with the specified (full) name. |
void |
finish()
Finish constructing the object model. |
java.lang.String |
getCacheName()
Get the name used in the cache, if any. |
int |
getCacheState()
Get the cache state. |
java.lang.String |
getDetailInfo()
Show debug / underlying implementation details |
java.util.List<Dimension> |
getDimensions()
Get the shared Dimensions used in this file. |
java.util.List<Attribute> |
getGlobalAttributes()
Returns the set of global attributes associated with this file. |
java.lang.String |
getId()
Get the globally unique dataset identifier |
IOServiceProvider |
getIosp()
Experimental - DO NOT USE!!! |
java.lang.String |
getLocation()
Get the NetcdfFile location. |
Group |
getRootGroup()
Get the root group. |
java.lang.String |
getTitle()
Get the human-readable title. |
Dimension |
getUnlimitedDimension()
Return the unlimited (record) dimension, or null if not exist. |
static java.lang.String |
getValidNetcdfObjectNamePattern()
Valid Netcdf Object name as a regular expression. |
java.util.List<Variable> |
getVariables()
Get all of the variables in the file, in all groups. |
boolean |
hasRecordStructure()
Find out if if it has a record Structure. |
boolean |
hasUnlimitedDimension()
Return true if this file has an unlimited (record) dimension. |
boolean |
isClosed()
is the dataset already closed? |
static boolean |
isValidNetcdfObjectName(java.lang.String name)
Determine if the given name can be used for a Dimension, Attribute, or Variable name. |
static void |
main(java.lang.String[] arg)
|
static NetcdfFile |
open(java.lang.String location)
Open an existing netcdf file (read only). |
static NetcdfFile |
open(java.lang.String location,
CancelTask cancelTask)
Open an existing file (read only), with option of cancelling. |
static NetcdfFile |
open(java.lang.String location,
int buffer_size,
CancelTask cancelTask)
Open an existing file (read only), with option of cancelling, setting the RandomAccessFile buffer size for efficiency. |
static NetcdfFile |
open(java.lang.String location,
int buffer_size,
CancelTask cancelTask,
java.lang.Object spiObject)
Open an existing file (read only), with option of cancelling, setting the RandomAccessFile buffer size for efficiency, with an optional special object for the iosp. |
static NetcdfFile |
open(java.lang.String location,
java.lang.String className,
int bufferSize,
CancelTask cancelTask,
java.lang.String iospParam)
|
static NetcdfFile |
openInMemory(java.lang.String location)
Read a netcdf file into memory. |
static NetcdfFile |
openInMemory(java.lang.String location,
byte[] data)
Open an in-memory netcdf file. |
Array |
read(java.lang.String variableSection,
boolean flatten)
Read a variable using the given section specification, equivilent to readAllStructures() if its a member of a Structure, or read() otherwise. |
java.util.List<Array> |
readArrays(java.util.List<Variable> variables)
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. |
Array |
readData(Variable v,
java.util.List section)
do not call this directly, use Variable.read() !! |
Array |
readMemberData(Variable v,
java.util.List section,
boolean flatten)
do not call this directly, use Variable.readSection() !! |
static void |
registerIOProvider(java.lang.Class iospClass)
Register an IOServiceProvider. |
static void |
registerIOProvider(java.lang.String className)
Register an IOServiceProvider, using its class string name. |
boolean |
removeDimension(Group g,
java.lang.String dimName)
Remove a shared Dimension from a Group by name. |
boolean |
removeVariable(Group g,
java.lang.String varName)
Remove a Variable from the given group by name. |
static void |
setDebugFlags(DebugFlags debugFlag)
debugging |
static void |
setDebugOutputStream(java.io.PrintStream printStream)
debugging |
void |
setId(java.lang.String id)
Set the globally unique dataset identifier. |
void |
setLocation(java.lang.String location)
Set the location, a URL or local filename. |
static void |
setProperty(java.lang.String name,
java.lang.String value)
Set properties. |
void |
setTitle(java.lang.String title)
Set the dataset "human readable" title. |
boolean |
sync()
Check if file has changed, and reread metadata if needed. |
boolean |
syncExtend()
Extend 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. |
java.lang.String |
toString()
CDL representation of Netcdf header info. |
void |
writeCDL(java.io.OutputStream os,
boolean strict)
Write CDL representation to OutputStream. |
void |
writeNcML(java.io.OutputStream os,
java.lang.String uri)
Write the NcML representation: dont show coodinate values |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public NetcdfFile(java.lang.String filename)
throws java.io.IOException
filename - location
java.io.IOException - if error
public NetcdfFile(java.net.URL url)
throws java.io.IOException
url - HTTP URL location
java.io.IOException - if error| Method Detail |
|---|
public static void registerIOProvider(java.lang.String className)
throws java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.ClassNotFoundException
className - Class that implements IOServiceProvider.
java.lang.IllegalAccessException - if class is not accessible.
java.lang.InstantiationException - if class doesnt have a no-arg constructor.
java.lang.ClassNotFoundException - if class not found.
public static void registerIOProvider(java.lang.Class iospClass)
throws java.lang.IllegalAccessException,
java.lang.InstantiationException
iospClass - Class that implements IOServiceProvider.
java.lang.IllegalAccessException - if class is not accessible.
java.lang.InstantiationException - if class doesnt have a no-arg constructor.
java.lang.ClassCastException - if class doesnt implement IOServiceProvider interface.public static void setDebugFlags(DebugFlags debugFlag)
debugFlag - debug flagspublic static void setDebugOutputStream(java.io.PrintStream printStream)
printStream - write to this stream.
public static void setProperty(java.lang.String name,
java.lang.String value)
name - name of propertyvalue - value of property
public static NetcdfFile open(java.lang.String location)
throws java.io.IOException
location - location of file.
java.io.IOException - if error
public static NetcdfFile open(java.lang.String location,
CancelTask cancelTask)
throws java.io.IOException
location - location of the file.cancelTask - allow task to be cancelled; may be null.
java.io.IOException - if error
public static NetcdfFile open(java.lang.String location,
int buffer_size,
CancelTask cancelTask)
throws java.io.IOException
location - location of file.buffer_size - RandomAccessFile buffer size, if <= 0, use default sizecancelTask - allow task to be cancelled; may be null.
java.io.IOException - if error
public static NetcdfFile open(java.lang.String location,
int buffer_size,
CancelTask cancelTask,
java.lang.Object spiObject)
throws java.io.IOException
location - location of file. This may be a
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
java.io.IOException - if error
public static NetcdfFile openInMemory(java.lang.String location,
byte[] data)
throws java.io.IOException
location - location of file, used as the name.data - in-memory netcdf file
java.io.IOException - if error
public static NetcdfFile openInMemory(java.lang.String location)
throws java.io.IOException
location - location of CDM file, used as the name.
java.io.IOException - if error reading file
public static NetcdfFile open(java.lang.String location,
java.lang.String className,
int bufferSize,
CancelTask cancelTask,
java.lang.String iospParam)
throws java.lang.ClassNotFoundException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.io.IOException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.io.IOExceptionpublic static boolean isValidNetcdfObjectName(java.lang.String name)
name - test this.
public static java.lang.String getValidNetcdfObjectNamePattern()
public static java.lang.String createValidNetcdfObjectName(java.lang.String name)
name - convert this name
public boolean isClosed()
public void close()
throws java.io.IOException
java.io.IOException - if error closingpublic int getCacheState()
public java.lang.String getCacheName()
public java.lang.String getLocation()
public java.lang.String getId()
public java.lang.String getTitle()
public Group getRootGroup()
public java.util.List<Variable> getVariables()
public Variable findTopVariable(java.lang.String name)
name - full name, starting from root group.
public Variable findVariable(java.lang.String fullName)
fullName - eg "group/subgroup/name1.name2.name".
public java.util.List<Dimension> getDimensions()
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 generally better to get the shared Dimensions from the Groups.
public Dimension findDimension(java.lang.String name)
name - dimension full name, (using parent group names if not in the root group)
public boolean hasUnlimitedDimension()
public Dimension getUnlimitedDimension()
public java.util.List<Attribute> getGlobalAttributes()
public Attribute findGlobalAttribute(java.lang.String name)
name - the name of the attribute
public Attribute findGlobalAttributeIgnoreCase(java.lang.String name)
name - the name of the attribute
public java.lang.String findAttValueIgnoreCase(Variable v,
java.lang.String attName,
java.lang.String defaultValue)
v - the variable or null for global attributeattName - the (full) name of the attribute, case insensitivedefaultValue - return this if attribute not found
public java.util.List<Array> readArrays(java.util.List<Variable> variables)
throws java.io.IOException
variables - List of type Variable
java.io.IOException - if read error
public Array read(java.lang.String variableSection,
boolean flatten)
throws java.io.IOException,
InvalidRangeException
variableSection - the constraint expression. This must start with a top variable.flatten - if true and its a member of a Structure, remove the surrounding StructureData.
java.io.IOException - if error
InvalidRangeException - if variableSection is invalidfor syntax of constraint expression
public void writeCDL(java.io.OutputStream os,
boolean strict)
os - write to this OutputStreamstrict - if true, make it stricly CDL, otherwise, add a little extra infopublic 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 Output Stream.uri - use this for the uri attribute; if null use getLocation(). // ??
java.io.IOException - if errorNCdump.writeNcML(ucar.nc2.NetcdfFile, java.io.OutputStream, boolean, java.lang.String)
public boolean syncExtend()
throws java.io.IOException
java.io.IOException - if error
public boolean sync()
throws java.io.IOException
java.io.IOException - if error
public void addAttribute(Group parent,
Attribute att)
parent - add to this group. If group is null, use root groupatt - add this attribute
public void addGroup(Group parent,
Group g)
parent - add to this group. If group is null, use root groupg - add this group
public void addDimension(Group parent,
Dimension d)
parent - add to this group. If group is null, use root groupd - add this Dimension
public boolean removeDimension(Group g,
java.lang.String dimName)
g - remove from this group. If group is null, use root groupdimName - name of Dimension to remove.
public void addVariable(Group g,
Variable v)
g - add to this group. If group is null, use root groupv - add this Variable
public boolean removeVariable(Group g,
java.lang.String varName)
g - remove from this group. If group is null, use root groupvarName - name of variable to remove.
public void addVariableAttribute(Variable v,
Attribute att)
v - add to this Variable.att - add this attribute
public void addMemberVariable(Structure s,
Variable v)
s - add to this Structurev - add this Variable.public boolean addRecordStructure()
public boolean hasRecordStructure()
public void setId(java.lang.String id)
id - the idpublic void setTitle(java.lang.String title)
title - the titlepublic void setLocation(java.lang.String location)
location - the locationpublic void finish()
public void empty()
public Array readData(Variable v,
java.util.List section)
throws java.io.IOException,
InvalidRangeException
java.io.IOException
InvalidRangeException
public Array readMemberData(Variable v,
java.util.List section,
boolean flatten)
throws java.io.IOException,
InvalidRangeException
java.io.IOException
InvalidRangeExceptionpublic java.lang.String getDetailInfo()
public IOServiceProvider getIosp()
public static void main(java.lang.String[] arg)
throws java.lang.Exception
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||