public class NetcdfFileWriter
extends java.lang.Object
implements java.io.Closeable
NetcdfFileWriter is a low level wrap of IOServiceProviderWriter, if possible better to use:
Modifier and Type | Class and Description |
---|---|
static class |
NetcdfFileWriter.Version
The kinds of netcdf file that can be written.
|
Modifier | Constructor and Description |
---|---|
protected |
NetcdfFileWriter(NetcdfFileWriter.Version version,
java.lang.String location,
boolean isExisting,
Nc4Chunking chunker)
Open an existing or create a new Netcdf file
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Abort writing to this file.
|
Dimension |
addDimension(Group g,
java.lang.String dimName,
int length)
Add a shared Dimension to the file.
|
Dimension |
addDimension(Group g,
java.lang.String dimName,
int length,
boolean isShared,
boolean isUnlimited,
boolean isVariableLength)
Add a Dimension to the file.
|
Group |
addGroup(Group parent,
java.lang.String name)
Add a Group to the file.
|
Attribute |
addGroupAttribute(Group g,
Attribute att)
Add a Global attribute to the file.
|
Structure |
addRecordStructure()
For netcdf3 only, take all unlimited variables and make them into a structure.
|
Variable |
addStringVariable(Group g,
java.lang.String shortName,
java.util.List<Dimension> dims,
int max_strlen)
Add a variable with DataType = String to the file.
|
Variable |
addStringVariable(Group g,
Variable stringVar,
java.util.List<Dimension> dims)
Add a variable with DataType = String to a netCDF-3 file.
|
Structure |
addStructure(Group g,
Structure org,
java.lang.String shortName,
java.util.List<Dimension> dims)
Add a structure to the file (netcdf4 only).
|
Variable |
addStructureMember(Structure s,
java.lang.String shortName,
DataType dtype,
java.lang.String dims) |
EnumTypedef |
addTypedef(Group g,
EnumTypedef td)
Add a EnumTypedef to the file.
|
Dimension |
addUnlimitedDimension(java.lang.String dimName)
Add single unlimited dimension (classic model)
|
Variable |
addVariable(Group g,
java.lang.String shortName,
DataType dataType,
java.util.List<Dimension> dims)
Add a variable to the file.
|
Variable |
addVariable(Group g,
java.lang.String shortName,
DataType dataType,
java.lang.String dimString)
Add a variable to the file.
|
Variable |
addVariable(Group g,
Structure parent,
java.lang.String shortName,
DataType dataType,
java.util.List<Dimension> dims)
Add a variable to the file.
|
boolean |
addVariableAttribute(Variable v,
Attribute att)
Add an attribute to the named Variable.
|
int |
appendStructureData(Structure s,
StructureData sdata) |
void |
close()
close the file.
|
void |
create()
After you have added all of the Dimensions, Variables, and Attributes,
call create() to actually create the file.
|
static NetcdfFileWriter |
createNew(NetcdfFileWriter.Version version,
java.lang.String location) |
static NetcdfFileWriter |
createNew(NetcdfFileWriter.Version version,
java.lang.String location,
Nc4Chunking chunker)
Create a new Netcdf file, with fill mode true.
|
Attribute |
deleteGroupAttribute(Group g,
java.lang.String attName)
Delete a group Attribute.
|
Attribute |
deleteVariableAttribute(Variable v,
java.lang.String attName)
Delete a variable Attribute.
|
Attribute |
findGlobalAttribute(java.lang.String attName) |
Variable |
findVariable(java.lang.String fullNameEscaped) |
void |
flush()
Flush anything written to disk.
|
NetcdfFile |
getNetcdfFile() |
NetcdfFileWriter.Version |
getVersion() |
boolean |
hasDimension(Group g,
java.lang.String dimName) |
boolean |
isDefineMode()
Is the file in define mode, which allows objects to be added and changed?
|
static NetcdfFileWriter |
openExisting(java.lang.String location)
Open an existing Netcdf file for writing data.
|
Dimension |
renameDimension(Group g,
java.lang.String oldName,
java.lang.String newName)
Rename a Dimension.
|
Attribute |
renameGlobalAttribute(Group g,
java.lang.String oldName,
java.lang.String newName)
Rename a group Attribute.
|
Variable |
renameVariable(java.lang.String oldName,
java.lang.String newName)
Rename a Variable.
|
Attribute |
renameVariableAttribute(Variable v,
java.lang.String attName,
java.lang.String newName)
Rename a variable Attribute.
|
void |
setExtraHeaderBytes(int extraHeaderBytes)
Set extra bytes to reserve in the header.
|
void |
setFill(boolean fill)
Set the fill flag: call before calling create() or doing any data writing.
|
void |
setLargeFile(boolean isLargeFile)
Set if this should be a "large file" (64-bit offset) format.
|
void |
setLength(long size)
Preallocate the file size, for efficiency.
|
boolean |
setRedefineMode(boolean redefineMode)
Set the redefine mode.
|
void |
updateAttribute(Variable v2,
Attribute att)
Update the value of an existing attribute.
|
void |
write(Variable v,
Array values)
Write data to the named variable, origin assumed to be 0.
|
void |
write(Variable v,
int[] origin,
Array values)
Write data to the named variable.
|
void |
writeStringData(Variable v,
Array values)
Write String data to a CHAR variable, origin assumed to be 0.
|
void |
writeStringData(Variable v,
int[] origin,
Array values)
Write String data to a CHAR variable.
|
protected NetcdfFileWriter(NetcdfFileWriter.Version version, java.lang.String location, boolean isExisting, Nc4Chunking chunker) throws java.io.IOException
version
- which kind of file to write, if null, use netcdf3 (isExisting= false) else open file and figure out the versionlocation
- open a new file at this locationisExisting
- true if file already existschunker
- used only for netcdf4, or null for used only for netcdf4, or null for default chunking algorithmjava.io.IOException
- on I/O errorpublic static NetcdfFileWriter openExisting(java.lang.String location) throws java.io.IOException
location
- name of existing file to open.java.io.IOException
- on I/O errorpublic static NetcdfFileWriter createNew(NetcdfFileWriter.Version version, java.lang.String location) throws java.io.IOException
java.io.IOException
public static NetcdfFileWriter createNew(NetcdfFileWriter.Version version, java.lang.String location, Nc4Chunking chunker) throws java.io.IOException
version
- netcdf-3 or 4location
- name of new file to open; if it exists, will overwrite it.chunker
- used only for netcdf4, or null for default chunking algorithmjava.io.IOException
- on I/O errorpublic void setFill(boolean fill)
fill
- set fill mode true or falsepublic void setLength(long size)
size
- if set to > 0, set length of file to this upon creation - this (usually) pre-allocates contiguous storage.public void setLargeFile(boolean isLargeFile)
isLargeFile
- true if large filepublic void setExtraHeaderBytes(int extraHeaderBytes)
extraHeaderBytes
- # bytes extra for the headerpublic boolean isDefineMode()
public NetcdfFile getNetcdfFile()
public NetcdfFileWriter.Version getVersion()
public Variable findVariable(java.lang.String fullNameEscaped)
public Attribute findGlobalAttribute(java.lang.String attName)
public Dimension addDimension(Group g, java.lang.String dimName, int length)
dimName
- name of dimensionlength
- size of dimension.public Dimension addUnlimitedDimension(java.lang.String dimName)
dimName
- name of dimensionpublic Dimension addDimension(Group g, java.lang.String dimName, int length, boolean isShared, boolean isUnlimited, boolean isVariableLength)
dimName
- name of dimensionlength
- size of dimension.isShared
- if dimension is shared LOOK what does it mean if false ??isUnlimited
- if dimension is unlimitedisVariableLength
- if dimension is variable lengthpublic boolean hasDimension(Group g, java.lang.String dimName)
public Dimension renameDimension(Group g, java.lang.String oldName, java.lang.String newName)
oldName
- existing dimension has this namenewName
- rename to thispublic Group addGroup(Group parent, java.lang.String name)
parent
- the parent of this group, if null then returns the root group.name
- the name of this group, unique within parentpublic Attribute addGroupAttribute(Group g, Attribute att)
g
- the group to add to. if null, use root groupatt
- the attribute.public EnumTypedef addTypedef(Group g, EnumTypedef td)
g
- the group to add to. if null, use root grouptd
- the EnumTypedef.public Attribute deleteGroupAttribute(Group g, java.lang.String attName)
g
- the group to add to. if null, use root groupattName
- existing Attribute has this namepublic Attribute renameGlobalAttribute(Group g, java.lang.String oldName, java.lang.String newName)
g
- the group to add to. if null, use root groupoldName
- existing Attribute has this namenewName
- rename to thispublic Variable addVariable(Group g, java.lang.String shortName, DataType dataType, java.lang.String dimString)
g
- the group to add to. if null, use root groupshortName
- name of Variable, must be unique with the file.dataType
- type of underlying elementdimString
- names of Dimensions for the variable, blank separated.
Must already have been added. Use an empty string for a scalar variable.public Variable addVariable(Group g, java.lang.String shortName, DataType dataType, java.util.List<Dimension> dims)
g
- add to this group in the new fileshortName
- name of Variable, must be unique with the file.dataType
- type of underlying elementdims
- list of Dimensions for the variable in the new file, must already have been added.
Use a list of length 0 for a scalar variable.public Variable addVariable(Group g, Structure parent, java.lang.String shortName, DataType dataType, java.util.List<Dimension> dims)
g
- add to this group in the new fileparent
- parent Structure (netcdf4 only), or null if not a member of a StructureshortName
- name of Variable, must be unique with the file.dataType
- type of underlying elementdims
- list of Dimensions for the variable in the new file, must already have been added.
Use a list of length 0 for a scalar variable.public Structure addStructure(Group g, Structure org, java.lang.String shortName, java.util.List<Dimension> dims)
g
- add to this group in the new fileorg
- rent Structure (netcdf4 only), or null if not a member of a StructureshortName
- name of Variable, must be unique with the file.dims
- list of Dimensions for the variable in the new file, must already have been added.
Use a list of length 0 for a scalar variable.public Variable addStructureMember(Structure s, java.lang.String shortName, DataType dtype, java.lang.String dims)
public Variable addStringVariable(Group g, Variable stringVar, java.util.List<Dimension> dims)
g
- add to this group in the new filestringVar
- string variable.dims
- list of Dimensions for the string variable.public Variable addStringVariable(Group g, java.lang.String shortName, java.util.List<Dimension> dims, int max_strlen)
shortName
- name of Variable, must be unique within the file.dims
- list of Dimensions for the variable, must already have been added. Use a list of length 0
for a scalar variable. Do not include the string length dimension.max_strlen
- maximum string length.public Variable renameVariable(java.lang.String oldName, java.lang.String newName)
oldName
- existing Variable has this namenewName
- rename to thispublic boolean addVariableAttribute(Variable v, Attribute att)
v
- Variable to add attribute toatt
- Attribute to add.public Attribute deleteVariableAttribute(Variable v, java.lang.String attName)
v
- Variable to delete attribute toattName
- existing Attribute has this namepublic Attribute renameVariableAttribute(Variable v, java.lang.String attName, java.lang.String newName)
v
- Variable to modify attributeattName
- existing Attribute has this namenewName
- rename to thispublic void updateAttribute(Variable v2, Attribute att) throws java.io.IOException
v2
- variable, or null for global attributeatt
- replace with this valuejava.io.IOException
- if I/O errorpublic void create() throws java.io.IOException
java.io.IOException
- if I/O errorpublic boolean setRedefineMode(boolean redefineMode) throws java.io.IOException
redefineMode
- start or end define modejava.io.IOException
- on read/write errorpublic Structure addRecordStructure()
public void write(Variable v, Array values) throws java.io.IOException, InvalidRangeException
v
- variable to write tovalues
- write this array; must be same type and rank as Variablejava.io.IOException
- if I/O errorInvalidRangeException
- if values Array has illegal shapepublic void write(Variable v, int[] origin, Array values) throws java.io.IOException, InvalidRangeException
v
- variable to write toorigin
- offset within the variable to start writing.values
- write this array; must be same type and rank as Variablejava.io.IOException
- if I/O errorInvalidRangeException
- if values Array has illegal shapepublic void writeStringData(Variable v, Array values) throws java.io.IOException, InvalidRangeException
v
- variable to write tovalues
- write this array; must be ArrayObject of Stringjava.io.IOException
- if I/O errorInvalidRangeException
- if values Array has illegal shapepublic void writeStringData(Variable v, int[] origin, Array values) throws java.io.IOException, InvalidRangeException
v
- variable to write toorigin
- offset to start writing, ignore the strlen dimension.values
- write this array; must be ArrayObject of Stringjava.io.IOException
- if I/O errorInvalidRangeException
- if values Array has illegal shapepublic int appendStructureData(Structure s, StructureData sdata) throws java.io.IOException, InvalidRangeException
java.io.IOException
InvalidRangeException
public void flush() throws java.io.IOException
java.io.IOException
- if I/O errorpublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- if I/O errorpublic void abort() throws java.io.IOException
java.io.IOException