Package ucar.nc2.internal.iosp.netcdf3
Class N3iospWriter
- java.lang.Object
-
- ucar.nc2.iosp.AbstractIOServiceProvider
-
- ucar.nc2.internal.iosp.netcdf3.N3iospNew
-
- ucar.nc2.internal.iosp.netcdf3.N3iospWriter
-
- All Implemented Interfaces:
Comparable<IOServiceProvider>
,IOServiceProvider
,IOServiceProviderWriter
public class N3iospWriter extends N3iospNew implements IOServiceProviderWriter
IOServiceProviderWriter for Netcdf3 files.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ucar.nc2.iosp.IOServiceProvider
IOServiceProvider.SortGroup
-
-
Field Summary
-
Fields inherited from class ucar.nc2.internal.iosp.netcdf3.N3iospNew
header, lastModified, log
-
Fields inherited from class ucar.nc2.iosp.AbstractIOServiceProvider
location, ncfile, raf, rafOrder
-
-
Constructor Summary
Constructors Constructor Description N3iospWriter(IOServiceProvider iosp)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
appendStructureData(Structure s, StructureData sdata)
Append a structureData along the unlimited dimensionvoid
create(String filename, NetcdfFile ncfile, int extra, long preallocateSize, boolean largeFile)
Create new file, populate it from the objects in ncfile.void
flush()
Flush all data buffers to disk.void
openForWriting(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask)
Open existing file and allow writing.boolean
rewriteHeader(boolean largeFile)
if theres room before data, rewrite header without moving the data.void
setFill(boolean fill)
Set the fill flag.boolean
syncExtend()
Extend the NetcdfFile if the underlying dataset has changed in a way that is compatible with the current metadata.void
updateAttribute(Variable v2, Attribute att)
Update the value of an existing attribute on disk, not in memory.void
writeData(Variable v2, Section section, Array values)
Write data into a variable.-
Methods inherited from class ucar.nc2.internal.iosp.netcdf3.N3iospNew
build, close, getDetailInfo, getFileTypeDescription, getFileTypeId, getFileTypeVersion, isBuilder, isValidFile, open, reacquire, readData, readToByteChannel, sendIospMessage, toStringDebug
-
Methods inherited from class ucar.nc2.iosp.AbstractIOServiceProvider
buildFinish, getLastModified, getStructureIterator, readSection, readToOutputStream, release, setNetcdfFile, streamToByteChannel
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ucar.nc2.iosp.IOServiceProvider
build, buildFinish, close, compareTo, getDetailInfo, getFileTypeDescription, getFileTypeId, getFileTypeVersion, getSortGroup, getStructureIterator, isBuilder, isValidFile, open, reacquire, readData, readSection, readToByteChannel, readToOutputStream, release, sendIospMessage, streamToByteChannel, toStringDebug
-
-
-
-
Constructor Detail
-
N3iospWriter
public N3iospWriter(IOServiceProvider iosp)
-
-
Method Detail
-
openForWriting
public void openForWriting(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException
Description copied from interface:IOServiceProviderWriter
Open existing file and allow writing. Netcdf-4 writing is general. Netcdf-3 writing is restricted to writing data into existing variables.- Specified by:
openForWriting
in interfaceIOServiceProviderWriter
- Parameters:
raf
- the file to work on.ncfile
- add objects to this empty NetcdfFilecancelTask
- used to monitor user cancellation; may be null.- Throws:
IOException
- if I/O error
-
setFill
public void setFill(boolean fill)
Description copied from interface:IOServiceProviderWriter
Set the fill flag. For new files, set in the create() method. This method is to set fill for existing files that you want to write. If true, the data is first written with fill values. Set to false if you expect to write all data values, set to true if you want to be sure that unwritten data values have the fill value in it.- Specified by:
setFill
in interfaceIOServiceProviderWriter
- Parameters:
fill
- set fill mode true or false
-
create
public void create(String filename, NetcdfFile ncfile, int extra, long preallocateSize, boolean largeFile) throws IOException
Description copied from interface:IOServiceProviderWriter
Create new file, populate it from the objects in ncfile.- Specified by:
create
in interfaceIOServiceProviderWriter
- Parameters:
filename
- name of file to create.ncfile
- get everything but data from hereextra
- if > 0, pad header with extra bytespreallocateSize
- if > 0, set length of file to this upon creation - this (usually) pre-allocates contiguous storage.largeFile
- if want large file format- Throws:
IOException
- if I/O error
-
rewriteHeader
public boolean rewriteHeader(boolean largeFile) throws IOException
Description copied from interface:IOServiceProviderWriter
if theres room before data, rewrite header without moving the data. netcdf3 only- Specified by:
rewriteHeader
in interfaceIOServiceProviderWriter
- Returns:
- true if it worked
- Throws:
IOException
-
writeData
public void writeData(Variable v2, Section section, Array values) throws IOException, InvalidRangeException
Description copied from interface:IOServiceProviderWriter
Write data into a variable.- Specified by:
writeData
in interfaceIOServiceProviderWriter
- Parameters:
v2
- variable to write; must already exist.section
- the section of data to write. There must be a Range for each Dimension in the variable, in order. The shape must match the shape of values. The origin and stride indicate where the data is placed into the stored Variable array.values
- data to write. The shape must match section.getShape().- Throws:
IOException
- if I/O errorInvalidRangeException
- if invalid section
-
appendStructureData
public int appendStructureData(Structure s, StructureData sdata) throws IOException, InvalidRangeException
Description copied from interface:IOServiceProviderWriter
Append a structureData along the unlimited dimension- Specified by:
appendStructureData
in interfaceIOServiceProviderWriter
- Parameters:
s
- belongs to this structuresdata
- the stuctureData to append- Returns:
- the recnum where it was written
- Throws:
IOException
InvalidRangeException
-
updateAttribute
public void updateAttribute(Variable v2, Attribute att) throws IOException
Update the value of an existing attribute on disk, not in memory. Attribute is found by name, which must match exactly. You cannot make an attribute longer, or change the number of values. For strings: truncate if longer, zero fill if shorter. Strings are padded to 4 byte boundaries, ok to use padding if it exists. For numerics: must have same number of values.- Specified by:
updateAttribute
in interfaceIOServiceProviderWriter
- Parameters:
v2
- variable, or null for global attributeatt
- replace with this value- Throws:
IOException
-
flush
public void flush() throws IOException
Description copied from interface:IOServiceProviderWriter
Flush all data buffers to disk.- Specified by:
flush
in interfaceIOServiceProviderWriter
- Overrides:
flush
in classN3iospNew
- Throws:
IOException
-
syncExtend
public boolean syncExtend() throws IOException
Description copied from interface:IOServiceProvider
Extend the NetcdfFile if the underlying dataset has changed in a way that is compatible with the current metadata. For example, if the unlimited dimension has grown.- Specified by:
syncExtend
in interfaceIOServiceProvider
- Overrides:
syncExtend
in classN3iospNew
- Returns:
- true if the NetcdfFile was extended.
- Throws:
IOException
- if a read error occured when accessing the underlying dataset.
-
-