public class NetcdfFileWriter extends Object implements Closeable
NetcdfFileWriter is a low level wrap of IOServiceProviderWriter, if possible better to use:
Modifier and Type | Class and Description |
---|---|
static class |
NetcdfFileWriter.Version
Deprecated.
TODO use ucar.nc2.writer.NetcdfFileWriter
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Deprecated.
Abort writing to this file.
|
Structure |
addCopyOfStructure(Group g,
Structure original,
String shortName,
List<Dimension> dims)
Deprecated.
Adds a copy of the specified structure to the file (netcdf4 only).
|
Dimension |
addDimension(Group g,
String dimName,
int length)
Deprecated.
Add a shared Dimension to the file.
|
Dimension |
addDimension(Group g,
String dimName,
int length,
boolean isUnlimited,
boolean isVariableLength)
Deprecated.
Add a shared Dimension to the file.
|
Dimension |
addDimension(String dimName,
int length)
Deprecated.
|
Dimension |
addDimension(String dimName,
int length,
boolean isUnlimited,
boolean isVariableLength)
Deprecated.
|
Attribute |
addGlobalAttribute(Attribute att)
Deprecated.
|
Attribute |
addGlobalAttribute(String name,
Number value)
Deprecated.
|
Attribute |
addGlobalAttribute(String name,
String value)
Deprecated.
|
Group |
addGroup(Group parent,
String name)
Deprecated.
Add a Group to the file.
|
Attribute |
addGroupAttribute(Group g,
Attribute att)
Deprecated.
Add a Global attribute to the file.
|
Structure |
addRecordStructure()
Deprecated.
For netcdf3 only, take all unlimited variables and make them into a structure.
|
Variable |
addStringVariable(Group g,
String shortName,
List<Dimension> dims,
int max_strlen)
Deprecated.
Add a variable with DataType = String to the file.
|
Variable |
addStringVariable(Group g,
Variable stringVar,
List<Dimension> dims)
Deprecated.
Add a variable with DataType = String to a netCDF-3 file.
|
Variable |
addStructureMember(Structure s,
String shortName,
DataType dtype,
String dims)
Deprecated.
|
EnumTypedef |
addTypedef(Group g,
EnumTypedef td)
Deprecated.
Add a EnumTypedef to the file.
|
Dimension |
addUnlimitedDimension(String dimName)
Deprecated.
Add single unlimited, shared dimension (classic model)
|
Variable |
addVariable(Group g,
String shortName,
DataType dataType,
List<Dimension> dims)
Deprecated.
Add a variable to the file.
|
Variable |
addVariable(Group g,
String shortName,
DataType dataType,
String dimString)
Deprecated.
Add a variable to the file.
|
Variable |
addVariable(Group g,
Structure parent,
String shortName,
DataType dataType,
List<Dimension> dims)
Deprecated.
Add a variable to the file.
|
Variable |
addVariable(String shortName,
DataType dataType,
List<Dimension> dims)
Deprecated.
|
Variable |
addVariable(String shortName,
DataType dataType,
String dimString)
Deprecated.
|
boolean |
addVariableAttribute(String varName,
Attribute att)
Deprecated.
|
boolean |
addVariableAttribute(String varName,
String name,
Number value)
Deprecated.
|
boolean |
addVariableAttribute(String varName,
String name,
String value)
Deprecated.
|
boolean |
addVariableAttribute(Variable v,
Attribute att)
Deprecated.
Add an attribute to the named Variable.
|
int |
appendStructureData(Structure s,
StructureData sdata)
Deprecated.
|
void |
close()
Deprecated.
close the file.
|
void |
create()
Deprecated.
After you have added all of the Dimensions, Variables, and Attributes,
call create() to actually create the file.
|
static NetcdfFileWriter |
createNew(NetcdfFileWriter.Version version,
String location)
Deprecated.
|
static NetcdfFileWriter |
createNew(NetcdfFileWriter.Version version,
String location,
ucar.nc2.write.Nc4Chunking chunker)
Deprecated.
Create a new Netcdf file, with fill mode true.
|
static NetcdfFileWriter |
createNew(String location,
boolean fill)
Deprecated.
|
Attribute |
deleteGlobalAttribute(String attName)
Deprecated.
|
Attribute |
deleteGroupAttribute(Group g,
String attName)
Deprecated.
Delete a group Attribute.
|
Variable |
deleteVariable(String fullName)
Deprecated.
|
Attribute |
deleteVariableAttribute(Variable v,
String attName)
Deprecated.
Delete a variable Attribute.
|
Dimension |
findDimension(String dimName)
Deprecated.
|
Attribute |
findGlobalAttribute(String attName)
Deprecated.
|
Variable |
findVariable(String fullNameEscaped)
Deprecated.
|
void |
flush()
Deprecated.
Flush anything written to disk.
|
NetcdfFile |
getNetcdfFile()
Deprecated.
|
NetcdfFileWriter.Version |
getVersion()
Deprecated.
|
boolean |
hasDimension(Group g,
String dimName)
Deprecated.
|
boolean |
isDefineMode()
Deprecated.
Is the file in define mode, which allows objects to be added and changed?
|
static NetcdfFileWriter |
openExisting(String location)
Deprecated.
Open an existing Netcdf file for writing data.
|
Dimension |
renameDimension(Group g,
String oldName,
String newName)
Deprecated.
Rename a Dimension.
|
Attribute |
renameGlobalAttribute(String oldName,
String newName)
Deprecated.
|
Attribute |
renameGroupAttribute(Group g,
String oldName,
String newName)
Deprecated.
Rename a group Attribute.
|
Variable |
renameVariable(String oldName,
String newName)
Deprecated.
Rename a Variable.
|
Attribute |
renameVariableAttribute(Variable v,
String attName,
String newName)
Deprecated.
Rename a variable Attribute.
|
void |
setExtraHeaderBytes(int extraHeaderBytes)
Deprecated.
Set extra bytes to reserve in the header.
|
void |
setFill(boolean fill)
Deprecated.
Set the fill flag: call before calling create() or doing any data writing.
|
void |
setLargeFile(boolean isLargeFile)
Deprecated.
Set if this should be a "large file" (64-bit offset) format.
|
void |
setLength(long size)
Deprecated.
Preallocate the file size, for efficiency.
|
boolean |
setRedefineMode(boolean redefineMode)
Deprecated.
Set the redefine mode.
|
void |
updateAttribute(Variable v2,
Attribute att)
Deprecated.
Update the value of an existing attribute.
|
void |
write(String varname,
Array values)
Deprecated.
|
void |
write(String varName,
int[] origin,
Array values)
Deprecated.
|
void |
write(Variable v,
Array values)
Deprecated.
Write data to the named variable, origin assumed to be 0.
|
void |
write(Variable v,
int[] origin,
Array values)
Deprecated.
Write data to the named variable.
|
void |
writeStringData(Variable v,
Array values)
Deprecated.
Write String data to a CHAR variable, origin assumed to be 0.
|
void |
writeStringData(Variable v,
int[] origin,
Array values)
Deprecated.
Write String data to a CHAR variable.
|
public static NetcdfFileWriter openExisting(String location) throws IOException
location
- name of existing file to open.IOException
- on I/O errorpublic static NetcdfFileWriter createNew(NetcdfFileWriter.Version version, String location) throws IOException
IOException
public static NetcdfFileWriter createNew(String location, boolean fill) throws IOException
IOException
public static NetcdfFileWriter createNew(NetcdfFileWriter.Version version, String location, ucar.nc2.write.Nc4Chunking chunker) throws 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 algorithmIOException
- 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 Dimension addDimension(Group g, String dimName, int length)
dimName
- name of dimensionlength
- size of dimension.public Dimension addUnlimitedDimension(String dimName)
dimName
- name of dimensionpublic Dimension addDimension(String dimName, int length, boolean isUnlimited, boolean isVariableLength)
public Dimension addDimension(Group g, String dimName, int length, boolean isUnlimited, boolean isVariableLength)
dimName
- name of dimensionlength
- size of dimension.isUnlimited
- if dimension is unlimitedisVariableLength
- if dimension is variable lengthpublic Dimension renameDimension(Group g, String oldName, String newName)
oldName
- existing dimension has this namenewName
- rename to thispublic Group addGroup(Group parent, 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, String attName)
g
- the group to add to. if null, use root groupattName
- existing Attribute has this namepublic Attribute renameGlobalAttribute(String oldName, String newName)
public Attribute renameGroupAttribute(Group g, String oldName, String newName)
g
- the group to add to. if null, use root groupoldName
- existing Attribute has this namenewName
- rename to thispublic Variable addVariable(String shortName, DataType dataType, String dimString)
public Variable addVariable(Group g, String shortName, DataType dataType, 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(String shortName, DataType dataType, List<Dimension> dims)
public Variable addVariable(Group g, String shortName, DataType dataType, 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, String shortName, DataType dataType, 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 addCopyOfStructure(Group g, @Nonnull Structure original, String shortName, List<Dimension> dims)
g
- add to this group in the new fileoriginal
- the structure to make a copy of in the new file.shortName
- 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, String shortName, DataType dtype, String dims)
public Variable addStringVariable(Group g, Variable stringVar, 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, String shortName, 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(String oldName, String newName)
oldName
- existing Variable has this namenewName
- rename to thispublic boolean addVariableAttribute(String varName, String name, String value)
public boolean addVariableAttribute(String varName, String name, Number value)
public boolean addVariableAttribute(Variable v, Attribute att)
v
- Variable to add attribute toatt
- Attribute to add.public Attribute deleteVariableAttribute(Variable v, String attName)
v
- Variable to delete attribute toattName
- existing Attribute has this namepublic Attribute renameVariableAttribute(Variable v, String attName, String newName)
v
- Variable to modify attributeattName
- existing Attribute has this namenewName
- rename to thispublic void updateAttribute(Variable v2, Attribute att) throws IOException
v2
- variable, or null for global attributeatt
- replace with this valueIOException
- if I/O errorpublic void create() throws IOException
IOException
- if I/O errorpublic boolean setRedefineMode(boolean redefineMode) throws IOException
redefineMode
- start or end define modeIOException
- on read/write errorpublic Structure addRecordStructure()
public void write(String varname, Array values) throws IOException, InvalidRangeException
IOException
InvalidRangeException
public void write(Variable v, Array values) throws IOException, InvalidRangeException
v
- variable to write tovalues
- write this array; must be same type and rank as VariableIOException
- if I/O errorInvalidRangeException
- if values Array has illegal shapepublic void write(String varName, int[] origin, Array values) throws IOException, InvalidRangeException
IOException
InvalidRangeException
public void write(Variable v, int[] origin, Array values) throws 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 VariableIOException
- if I/O errorInvalidRangeException
- if values Array has illegal shapepublic void writeStringData(Variable v, Array values) throws IOException, InvalidRangeException
v
- variable to write tovalues
- write this array; must be ArrayObject of StringIOException
- if I/O errorInvalidRangeException
- if values Array has illegal shapepublic void writeStringData(Variable v, int[] origin, Array values) throws IOException, InvalidRangeException
v
- variable to write toorigin
- offset to start writing, ignore the strlen dimension.values
- write this array; must be ArrayObject of StringIOException
- if I/O errorInvalidRangeException
- if values Array has illegal shapepublic int appendStructureData(Structure s, StructureData sdata) throws IOException, InvalidRangeException
IOException
InvalidRangeException
public void flush() throws IOException
IOException
- if I/O errorpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
- if I/O errorpublic void abort() throws IOException
IOException