public class NetcdfFormatWriter extends Object implements Closeable
NetcdfFormatWriter.Builder writerb = NetcdfFormatWriter.createNewNetcdf3(testFile.getPath());
writerb.addDimension(Dimension.builder().setName("vdim").setIsUnlimited(true).build());
writerb.addVariable("v", DataType.BYTE, "vdim");
try (NetcdfFormatWriter writer = writerb.build()) {
writer.config().forVariable("v").withArray(dataArray).write();
}
| Modifier and Type | Class and Description |
|---|---|
static class |
NetcdfFormatWriter.Builder<T extends NetcdfFormatWriter.Builder<T>> |
class |
NetcdfFormatWriter.WriteConfig
Fluid API for writing.
|
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Abort writing to this file.
|
int |
appendStructureData(Structure s,
StructureData sdata)
Write StructureData along the unlimited dimension.
|
int |
appendStructureData(Structure s,
StructureData sdata)
Deprecated.
|
static NetcdfFormatWriter.Builder<?> |
builder()
Obtain a mutable Builder to create or modify the file metadata.
|
long |
calcSize()
An estimate of the size of the file when written to disk.
|
void |
close()
Close the file.
|
NetcdfFormatWriter.WriteConfig |
config()
Obtain a WriteConfig to configure data writing.
|
static NetcdfFormatWriter.Builder<?> |
createNewNetcdf3(String location)
Create a new Netcdf3 file.
|
static NetcdfFormatWriter.Builder<?> |
createNewNetcdf4(NetcdfFileFormat format,
String location,
Nc4Chunking chunker)
Create a new Netcdf4 file.
|
static NetcdfFormatWriter.Builder<?> |
createNewNetcdf4(String location)
Create a new NetcdfFileFormat.NETCDF4 file, with default chunker.
|
Dimension |
findDimension(String dimName)
Find the named Dimension in the output file.
|
Attribute |
findGlobalAttribute(String attName)
Find the named global attribute in the output file.
|
Variable |
findVariable(String fullNameEscaped)
Find the named Variable in the output file.
|
NetcdfFileFormat |
getFormat()
The output file's format.
|
Group |
getRootGroup()
The output file's root group.
|
static NetcdfFormatWriter.Builder<?> |
openExisting(String location)
Open an existing Netcdf format file for writing data.
|
void |
updateAttribute(Variable v2,
Attribute att)
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.
|
void |
write(Variable v,
Index origin,
Array<?> values)
Write to Variable with an ucar.array.Array.
|
void |
write(Variable v,
int[] origin,
Array values)
Deprecated.
|
void |
writeStringData(Variable v,
Index origin,
String data)
Write String value to a CHAR Variable.
|
void |
writeStringDataToChar(Variable v,
Array values)
Deprecated.
|
void |
writeStringDataToChar(Variable v,
int[] origin,
Array values)
Deprecated.
|
public static NetcdfFormatWriter.Builder<?> createNewNetcdf3(String location)
location - name of new file to open; if it exists, will overwrite it.public static NetcdfFormatWriter.Builder<?> createNewNetcdf4(String location)
location - name of new file to open; if it exists, will overwrite it.public static NetcdfFormatWriter.Builder<?> createNewNetcdf4(NetcdfFileFormat format, String location, @Nullable Nc4Chunking chunker)
format - One of the netcdf-4 NetcdfFileFormat.location - name of new file to open; if it exists, will overwrite it.chunker - used only for netcdf4, or null for default chunking algorithmpublic static NetcdfFormatWriter.Builder<?> openExisting(String location) throws IOException
location - name of existing NetCDF file to open.IOExceptionpublic Group getRootGroup()
public NetcdfFileFormat getFormat()
@Nullable public Variable findVariable(String fullNameEscaped)
@Nullable public Dimension findDimension(String dimName)
@Nullable public Attribute findGlobalAttribute(String attName)
public long calcSize()
public void write(Variable v, Index origin, Array<?> values) throws IOException, InvalidRangeException
v - variable to write toorigin - offset within the variable to start writing.values - write this array; must have compatible type and shape with VariableIOExceptionInvalidRangeExceptionpublic void writeStringData(Variable v, Index origin, String data) throws IOException, InvalidRangeException
Index index = Index.ofRank(v.getRank()); writer.writeStringData(v, index, "This is the first string."); writer.writeStringData(v, index, "Shorty"); writer.writeStringData(v, index, "This is too long so it will get truncated");
v - write to this variable, must be of type CHAR.origin - offset within the variable to start writing.data - The String to write.IOExceptionInvalidRangeExceptionpublic int appendStructureData(Structure s, StructureData sdata) throws IOException, InvalidRangeException
IOExceptionInvalidRangeException@Deprecated public void write(Variable v, Array values) throws IOException, InvalidRangeException
write(Variable, ucar.array.Index, ucar.array.Array)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 shape@Deprecated public void write(String varName, Array values) throws IOException, InvalidRangeException
write(Variable, ucar.array.Index, ucar.array.Array)IOExceptionInvalidRangeException@Deprecated public void write(Variable v, int[] origin, Array values) throws IOException, InvalidRangeException
write(Variable, Index, ucar.array.Array)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 shape@Deprecated public void write(String varName, int[] origin, Array values) throws IOException, InvalidRangeException
write(Variable, ucar.array.Index, ucar.array.Array)varName - name of 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 shape@Deprecated public void writeStringDataToChar(Variable v, Array values) throws IOException, InvalidRangeException
writeStringData(Variable, Index, String)v - variable to write tovalues - write this array; must be ArrayObject of StringIOException - if I/O errorInvalidRangeException - if values Array has illegal shape@Deprecated public void writeStringDataToChar(Variable v, int[] origin, Array values) throws IOException, InvalidRangeException
writeStringData(Variable, Index, String)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 shape@Deprecated public int appendStructureData(Structure s, StructureData sdata) throws IOException, InvalidRangeException
appendStructureData(Structure, ucar.array.StructureData)IOExceptionInvalidRangeExceptionpublic void updateAttribute(Variable v2, Attribute att) throws IOException
v2 - variable, or null for global attributeatt - replace with this valueIOException - if I/O errorpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic void abort()
throws IOException
IOExceptionpublic static NetcdfFormatWriter.Builder<?> builder()
public NetcdfFormatWriter.WriteConfig config()