Class FossHelper


  • public class FossHelper
    extends Object
    Helper for handling Foss cal files. Info used here is from studying .cal files with hex editor. Has been tested on many .cal files, but no guarantees.
    Author:
    dale
    • Field Detail

      • count_offset

        protected static int count_offset
        number of Rows in this file.
      • deleted_offset

        protected static int deleted_offset
        number of Rows in this file.
      • datapoint_offset

        protected static int datapoint_offset
        number of nir wavelengths.
      • reference_count

        protected static int reference_count
      • reference_offset

        protected static int reference_offset
      • reference_name_width

        protected static int reference_name_width
      • reference_name_num

        protected static int reference_name_num
      • NSeg_offset

        protected static int NSeg_offset
      • Npps_offset

        protected static int Npps_offset
      • WaveType_offset

        protected static int WaveType_offset
      • Wave_offset

        protected static int Wave_offset
      • head_end

        protected static int head_end
        data header end.
      • m_count

        protected int m_count
        number of (non deleted) spectra.
      • m_num_points

        protected int m_num_points
        number of spectral data points.
      • m_ref_names

        protected List<String> m_ref_names
        reference names.
      • m_ref_count

        protected int m_ref_count
        number of reference values per spectra.
      • m_spectra_head_size

        protected int m_spectra_head_size
        size of spectrum header (static).
      • m_spectra_size

        protected int m_spectra_size
        size of spectra data.
      • m_spectra_tail_size

        protected int m_spectra_tail_size
        size of spectrum tail (static).
      • m_deleted

        protected int m_deleted
        number of deleted rows in this file.
    • Constructor Detail

      • FossHelper

        public FossHelper​(byte[] bytes)
        Constructor.
        Parameters:
        bytes - byte array of cal file
    • Method Detail

      • getFields

        public FossHelper.FossFields getFields​(int i)
        Get the non-spectral data for a given row.
        Parameters:
        i - row number
        Returns:
      • getSpectraForRow

        public double[] getSpectraForRow​(int i)
        Get spectrum of row.
        Parameters:
        i - row num
        Returns:
        spectrum as array
      • getRefForRow

        public float[] getRefForRow​(int i)
        Get reference values for a row. Sorted as per getRefNames()
        Parameters:
        i - row num
        Returns:
        array of reference values
      • getBlockSize

        public int getBlockSize()
        Get block size of a row in bytes.
        Returns:
        size of all data for a row
      • getSpectraBlockSize

        protected int getSpectraBlockSize()
        Get size of the spectral data block. (taking account of padding)
        Returns:
        size of the spectral data block
      • getSpectraOffsetForRow

        public int getSpectraOffsetForRow​(int i)
        Get start of spectrum for given row.
        Parameters:
        i - row number
        Returns:
        spectrum start
      • getRefOffsetForRow

        public int getRefOffsetForRow​(int i)
        Get start of reference for given row.
        Parameters:
        i - row number
        Returns:
        ref values start
      • processHeader

        public boolean processHeader()
        Process the data from the cal file header.
        Returns:
        true
      • getTotal

        public int getTotal()
        Total number of rows, including deleted rows.
        Returns:
        total num rows
      • countDeleted

        public int countDeleted()
        How many deleted rows?
        Returns:
        deleted rows?
      • getRefCount

        public int getRefCount()
        number of reference values.
        Returns:
        ref count
      • getSegmentsType

        public int getSegmentsType()
        Get segment type (00=TILFIL, 01=EQLSPC, 02=FILFIL, 03=SINSPA
        Returns:
        type
      • getNumSegments

        public int getNumSegments()
        get number of segments
        Returns:
        num segments
      • getSegmentLengths

        public int[] getSegmentLengths()
      • getSegmentStart

        public double[] getSegmentStart()
      • getSegmentInc

        public double[] getSegmentInc()
      • getSegmentEnd

        public double[] getSegmentEnd()
      • getWavenumbers

        public double[] getWavenumbers()
      • getReferenceNames

        public List<String> getReferenceNames()
        Get names of references.
        Returns:
        reference names
      • getZeroTerminatedString

        protected String getZeroTerminatedString​(int offset)
        Build string until reaching zero termination.
        Parameters:
        offset - pos in file to start
        Returns:
        string
      • getCount

        public int getCount()
        Number of non-deleted rows.
        Returns:
        num rows
      • getNumDatapoints

        public int getNumDatapoints()
        Number of spectral data points.
        Returns:
        num data points
      • byte2UByte

        protected int byte2UByte​(byte by)
        Convert byte to unsigned byte.
        Parameters:
        by - byte
        Returns:
        unsigned byte
      • convertToLong

        protected long convertToLong​(byte[] b,
                                     int offset)
        Convert 4 bytes to long. LSByte first.
        Parameters:
        b - byte array
        offset - starting pos
        Returns:
        long
      • longFrom2Bytes

        protected long longFrom2Bytes​(byte[] b,
                                      int offset)
        Get long from 2 bytes LSByte first.
        Parameters:
        b - byte array
        offset - start in array
        Returns:
        long
      • main

        public static void main​(String[] args)
                         throws Exception
        Test. arg0 cal filename
        Parameters:
        args - commandline arguments
        Throws:
        Exception - if somethin goes wrong