Class NetCDFOutputAdapter

All Implemented Interfaces:
FWSimFieldContainer

public class NetCDFOutputAdapter extends FWSimOutputAdapter
Output adapter writing the output of an FWSimOutput to a NetCDF-3 file (NetCDFInterface). The file has the dimensions time (unlimited, days since 1970-01-01), simulationid (number of simulations from the interface) and stringlength (64); every output variable becomes a NetCDF variable over time and simulation, arrays get an additional dimension count<n>. Missing numbers are written as -999, missing texts, booleans and arrays are not written (fill value).

The adapter needs the first three columns to be project id, current date and simulation id (no clean="true" header, no CAL frequency); otherwise the output is not written. If the file name depends on the project (e.g. ${projectid}), each project gets its own file (see updateFile(FWSimVarMap)).

Author:
Andreas Enders
  • Constructor Details

    • NetCDFOutputAdapter

      public NetCDFOutputAdapter(org.jdom2.Element aResourceElement, int aOrderNumber, FWSimVarMap aVarMap)
      Creates the adapter from an output element.
      Parameters:
      aResourceElement - the output element
      aOrderNumber - order number of the adapter
      aVarMap - template variable map of the solution
    • NetCDFOutputAdapter

      public NetCDFOutputAdapter(String aFile, String aName, String aDivider, int aOrderNumber, FWSimIOAdapter.FREQUENCE aFrequence, String aCacheSize, ProcessTime aProcessTime, FWSimSession aSession)
      Creates the adapter with its own NetCDF interface.
      Parameters:
      aFile - output file
      aName - name of the adapter; the interface is named <name>_INTERFACE
      aDivider - not used
      aOrderNumber - order number of the adapter
      aFrequence - frequency of the output
      aCacheSize - capacity of the queue
      aProcessTime - runtime statistics of the adapter
      aSession - the session
    • NetCDFOutputAdapter

      public NetCDFOutputAdapter(FWSimOutputAdapter aOldAdapter, FILEInterface aInterface)
      Copy constructor used when the interface is replaced.
      Parameters:
      aOldAdapter - the adapter to copy
      aInterface - the new interface
  • Method Details

    • init

      protected void init(FWSimVarMap aVarMap)
      Creates the NetCDF file with its dimensions, one variable per output variable (with units, description and aggregation mode as attributes) and global attributes describing solution, project and output. A file created before is closed first. Errors (also a wrong column layout) are logged and leave the writer null.
      Specified by:
      init in class FWSimOutputAdapter
      Parameters:
      aVarMap - variable map used for replacing tokens
    • writeData

      protected void writeData(FWSimQueueObjectMap aObjectToWrite)
      Writes an output line to the NetCDF file (in the writer thread): a new date or simulation id is added to its dimension first, then each value (from the fourth column on) is written at its time and simulation index. Errors are logged.
      Specified by:
      writeData in class FWSimOutputAdapter
      Parameters:
      aObjectToWrite - the output line
      See Also:
    • finalize

      public void finalize() throws Exception
      Closes the file pool and the NetCDF writer.
      Overrides:
      finalize in class FWSimIOAdapter
      Throws:
      Exception - if closing fails
      See Also:
    • updateFile

      public void updateFile(FWSimVarMap aVarMap)
      Determines the output file for the current project; if it differs from the current file, the current file is closed and a new file is created. Called by the output manager at the start of a project, after the lines of the previous project are written.
      Parameters:
      aVarMap - variable map of the first simulation of the project