Class CFNCWriter


public class CFNCWriter extends EarthDataWriter

A CF NetCDF writer creates NetCDF format files with CF metadata using the Unidata Java NetCDF library.

Some implementation notes:

  1. The Java NetCDF library documentation mentions that it can be extremely I/O intensive to put the file back into define mode (via NetcdfFileWriteable.setRedefineMode (true)), because it may require that the entire file be re-written to accommodate the new header information. To avoid this issue, we reserve 64 kb of extra space for header information. **NOTE** Currently, there is a bug in the NetCDF library that makes this option not work correctly. Waiting for it to be fixed. For now, we have to suffer the performance loss.
  2. The NetCDF 3 data model does not allow for unsigned data types. If unsigned variable data is present (as specified by the DataVariable.getUnsigned() flag), it is written as signed data of the next largest NetCDF data type. This rule applies for 16-bit and 32-bit integer data, but for 8-bit bytes, we use the NetCDF byte type and indicated unsignedness using the valid_range attribute as recommended by the CF conventions.
  3. As much as possible, the CF metadata written to the NetCDF file conforms to the examples laid out in the document "Encoding CoastWatch Satellite Data in NetCDF using the CF Metadata Conventions", Peter Hollemans, February 2010. Some of the metadata attributes require that CWHDF style attributes be available in the input stream. This will generally not be the case for non-CW input files. For now, this is how we handle things because the CW data model does not handle all attributes as full properties of the model (such as date and time, these are fully recognized properties of the model) and so must rely on the generic metadata container attributes to populate attributes in the CF output stream. For example, the CF attribute "ancillary_variables" is populated using the CWHDF attributes "quality_mask" and "direction_variable" but the CW data model does not include the concept of ancillary variables explicitly, even though the CWHDF format supports it.
Since:
3.3.0
Author:
Peter Hollemans
  • Constructor Details

    • CFNCWriter

      public CFNCWriter(EarthDataInfo info, String file) throws IOException
      Creates a new NetCDF file from the specified info and file name. The required CF data variables and attributes are written to the file. No extra DCS or CW attributes are written.
      Parameters:
      info - the earth data info object.
      file - the new NetCDF file name.
      Throws:
      IOException - if an error occurred creating the file or writing the initial data.
      Since:
      3.3.1
    • CFNCWriter

      public CFNCWriter(EarthDataInfo info, String file, boolean writeDcs, boolean writeCw) throws IOException
      Creates a new NetCDF file from the specified info and file name. The required CF data variables and attributes are written to the file.
      Parameters:
      info - the earth data info object.
      file - the new NetCDF file name.
      writeDcs - DCS metadata flag, true to write DCS attributes.
      writeCw - CW metadata flag, true to write CW attributes.
      Throws:
      IOException - if an error occurred creating the file or writing the initial data.
      Since:
      3.3.1
  • Method Details

    • flush

      public void flush() throws IOException
      Description copied from class: EarthDataWriter
      Flushes all unwritten data to the destination.
      Specified by:
      flush in class EarthDataWriter
      Throws:
      IOException - if the data destination had I/O errors.
    • close

      public void close() throws IOException
      Description copied from class: EarthDataWriter
      Closes the writer and frees any resources. The flush method is called prior to closing.
      Specified by:
      close in class EarthDataWriter
      Throws:
      IOException - if the data destination had I/O errors.
    • main

      public static void main(String[] argv) throws Exception
      Tests this class.
      Parameters:
      argv - the array of command line parameters.
      Throws:
      Exception