public class NetcdfFileWriter extends Object implements AutoCloseable
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,
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,
String dimName,
int length)
Add a shared Dimension to the file.
|
Dimension |
addDimension(Group g,
String dimName,
int length,
boolean isShared,
boolean isUnlimited,
boolean isVariableLength)
Add a Dimension to the file.
|
Group |
addGroup(Group parent,
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,
String shortName,
List<Dimension> dims,
int max_strlen)
Add a variable with DataType = String to the file.
|
Variable |
addStringVariable(Group g,
Variable stringVar,
List<Dimension> dims)
Add a variable with DataType = String to a netCDF-3 file.
|
Structure |
addStructure(Group g,
Structure org,
String shortName,
List<Dimension> dims)
Add a structure to the file (netcdf4 only).
|
Variable |
addStructureMember(Structure s,
String shortName,
DataType dtype,
String dims) |
EnumTypedef |
addTypedef(Group g,
EnumTypedef td)
Add a EnumTypedef to the file.
|
Dimension |
addUnlimitedDimension(String dimName)
Add single unlimited dimension (classic model)
|
Variable |
addVariable(Group g,
String shortName,
DataType dataType,
List<Dimension> dims)
Add a variable to the file.
|
Variable |
addVariable(Group g,
String shortName,
DataType dataType,
String dimString)
Add a variable to the file.
|
Variable |
addVariable(Group g,
Structure parent,
String shortName,
DataType dataType,
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,
String location) |
static NetcdfFileWriter |
createNew(NetcdfFileWriter.Version version,
String location,
Nc4Chunking chunker)
Create a new Netcdf file, with fill mode true.
|
Attribute |
deleteGroupAttribute(Group g,
String attName)
Delete a group Attribute.
|
Attribute |
deleteVariableAttribute(Variable v,
String attName)
Delete a variable Attribute.
|
Attribute |
findGlobalAttribute(String attName) |
Variable |
findVariable(String fullNameEscaped) |
void |
flush()
Flush anything written to disk.
|
NetcdfFile |
getNetcdfFile() |
NetcdfFileWriter.Version |
getVersion() |
boolean |
hasDimension(Group g,
String dimName) |
boolean |
isDefineMode()
Is the file in define mode, which allows objects to be added and changed?
|
static NetcdfFileWriter |
openExisting(String location)
Open an existing Netcdf file for writing data.
|
Dimension |
renameDimension(Group g,
String oldName,
String newName)
Rename a Dimension.
|
Attribute |
renameGlobalAttribute(Group g,
String oldName,
String newName)
Rename a group Attribute.
|
Variable |
renameVariable(String oldName,
String newName)
Rename a Variable.
|
Attribute |
renameVariableAttribute(Variable v,
String attName,
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, String location, boolean isExisting, Nc4Chunking chunker) throws 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 algorithmIOException
- on I/O errorpublic 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(NetcdfFileWriter.Version version, String location, 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(Group g, 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 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(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(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(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 addStructure(Group g, Structure org, String shortName, 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, 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(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(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(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 AutoCloseable
IOException
- if I/O errorpublic void abort() throws IOException
IOException
Copyright © 1999–2015 UCAR/Unidata. All rights reserved.