Class TextWriter


public class TextWriter extends EarthDataWriter
A text writer is an earth data writer that writes variable data as a series of lines in an ASCII text file. An optional dimension header may be prepended to each variable.
Since:
3.1.0
Author:
Peter Hollemans, Mark Robinson
  • Field Details

    • DEFAULT_CHUNK_SIZE

      public static final int DEFAULT_CHUNK_SIZE
      Output buffer size in kilobytes.
      See Also:
  • Constructor Details

    • TextWriter

      public TextWriter(EarthDataInfo info, String file) throws IOException
      Creates a new text file from the specified earth data info and file name. By default, each line contains the latitude, longitude, and data value to 6 decimal places, separated by a space with no header line. The double value Double.NaN is used for the missing value.
      Parameters:
      info - the earth data info object.
      file - the new binary file name.
      Throws:
      IOException - if an error occurred opening the file.
  • Method Details

    • setDecimals

      public void setDecimals(int decimals)
      Sets the decimal places.
      Parameters:
      decimals - the number of decimal places to use in coordinate value printing.
    • setCoords

      public void setCoords(boolean coords)
      Sets coordinate printing.
      Parameters:
      coords - the coordinate flag. If true, the earth location coordinates are printed along with each data value in the order latitude, longitude. Otherwise no coordinates are printed.
    • setReverse

      public void setReverse(boolean reverse)
      Sets the reverse flag. If true, the order of latitude and longitude printing is reversed.
      Parameters:
      reverse - the reverse flag.
      See Also:
    • setDelimiter

      public void setDelimiter(String delimiter)
      Sets the field delimiter.
      Parameters:
      delimiter - the field delimiter. The delimiter is used to separate multiple data fields on one line.
    • setHeader

      public void setHeader(boolean header)
      Sets the header flag.
      Parameters:
      header - the header flag. If true, a header line is printed prior to any data values. The header line consists of one integer specifying the number of dimensions followed by a series of integers specifying the dimension lengths. If false, no header line is printed.
    • setMissing

      public void setMissing(Number missing)
      Sets the missing value.
      Parameters:
      missing - the missing value. The missing value is used to represent missing or out of range data values. The missing value is printed when such data is encountered in the variable data. If the missing value is null, the value Double.NaN is used.
    • writeHeader

      protected void writeHeader(DataVariable var) throws IOException
      Writes a dimension header. The header line consists of one integer specifying the number of dimensions followed by a series of integers specifying the dimension lengths.
      Parameters:
      var - the data variable to write a header for.
      Throws:
      IOException - if an error occurred writing the header data to the file.
    • 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.
    • writeVariable

      protected void writeVariable(DataVariable var) throws IOException
      Writes the variable data as a stream of text lines.
      Parameters:
      var - the data variable to write data for.
      Throws:
      IOException - if an error occurred writing the data to the file.
    • 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.