Class OpusSpectrumReader

  • All Implemented Interfaces:
    adams.core.AdditionalInformationHandler, adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.io.FileFormatHandler, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.ShallowCopySupporter<adams.data.io.input.AbstractDataContainerReader>, adams.core.SizeOfHandler, adams.core.Stoppable, Serializable, Comparable

    public class OpusSpectrumReader
    extends AbstractSpectrumReader
    Reads spectra in OPUS format.

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -input <adams.core.io.PlaceholderFile> (property: input)
        The file to read and turn into a container.
        default: ${CWD}
     
    -create-dummy-report <boolean> (property: createDummyReport)
        If true, then a dummy report is created if none present.
        default: false
     
    -instrument <java.lang.String> (property: instrument)
        The name of the instrument that generated the spectra (if not already present 
        in data).
        default: unknown
     
    -format <java.lang.String> (property: format)
        The data format string.
        default: NIR
     
    -keep-format <boolean> (property: keepFormat)
        If enabled the format obtained from the file is not replaced by the format 
        defined here.
        default: false
     
    -use-absolute-source <boolean> (property: useAbsoluteSource)
        If enabled the source report field stores the absolute file name rather 
        than just the name.
        default: false
     
    -sample-id <java.lang.String> (property: sampleID)
        ID|Field1|Field2|Field3|[prefix]
        default: SNM
     
    -start <int> (property: start)
        Spectrum number to start loading from.
        default: 1
     
    -max <int> (property: max)
        Maximum spectra to load.
        default: -1
     
    -add-trace-to-report <boolean> (property: addTraceToReport)
        If enabled the trace of identified blocks etc gets added to the report,
        using prefix Trace..
        default: false
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • BLOCKS_OFFSET

        public static int BLOCKS_OFFSET
      • PREFIX_TRACE

        public static String PREFIX_TRACE
        the prefix for the trace values in the report.
      • m_SampleID

        protected String m_SampleID
        where to get sample id from. see param defs
      • m_Start

        protected int m_Start
        starting spectrum.
      • m_Max

        protected int m_Max
        maximum to load.
      • m_Trace

        protected HashMap<String,​Object> m_Trace
        trace of data that was retrieved from byte array.
      • m_AddTraceToReport

        protected boolean m_AddTraceToReport
        whether to add the trace to the report.
    • Constructor Detail

      • OpusSpectrumReader

        public OpusSpectrumReader()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        Returns:
        a description suitable for displaying in the gui
      • getFormatDescription

        public String getFormatDescription()
        Returns a string describing the format (used in the file chooser).
        Specified by:
        getFormatDescription in interface adams.core.io.FileFormatHandler
        Specified by:
        getFormatDescription in class adams.data.io.input.AbstractDataContainerReader<Spectrum>
        Returns:
        a description suitable for displaying in the file chooser
      • getFormatExtensions

        public String[] getFormatExtensions()
        Returns the extension(s) of the format.
        Specified by:
        getFormatExtensions in interface adams.core.io.FileFormatHandler
        Specified by:
        getFormatExtensions in class adams.data.io.input.AbstractDataContainerReader<Spectrum>
        Returns:
        the extension(s) (without the dot!)
      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class AbstractSpectrumReader
      • setMax

        public void setMax​(int value)
        Sets the nth point setting.
        Parameters:
        value - the nth point to use
      • getMax

        public int getMax()
        Returns the nth point setting.
        Returns:
        the nth point
      • maxTipText

        public String maxTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setStart

        public void setStart​(int value)
        Sets the start point setting.
        Parameters:
        value - the nth point to use
      • getStart

        public int getStart()
        Returns the start point setting.
        Returns:
        the nth point
      • startTipText

        public String startTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getSampleID

        public String getSampleID()
        Get id field.
        Returns:
        id field
      • setSampleID

        public void setSampleID​(String value)
        Set id field.
        Parameters:
        value -
      • sampleIDTipText

        public String sampleIDTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getAddTraceToReport

        public boolean getAddTraceToReport()
        Returns whether to add the trace to the report.
        Returns:
        true if to add the trace
      • setAddTraceToReport

        public void setAddTraceToReport​(boolean value)
        Sets whether to add the trace to the report.
        Parameters:
        value - true if to add the trace
      • addTraceToReportTipText

        public String addTraceToReportTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getInt

        protected int getInt​(byte[] b,
                             int offset)
        Get int from 4bytes, LSByte first
        Parameters:
        b - byte array
        offset - grab from
        Returns:
        integer
      • getNirArray

        protected double[] getNirArray​(byte[] file_image)
        Get array of nir data from byte array of bruker file image
        Parameters:
        file_image - byte array
        Returns:
        nir data array
      • getBlockOffset

        protected int getBlockOffset​(byte[] buf,
                                     byte byte1,
                                     byte byte2,
                                     byte byte3,
                                     byte byte4)
        Starting from blocks_offset, find sequence of bytes Return position of sequence, or -1 if not found
        Parameters:
        buf - byte array
        byte1 - the first byte
        byte2 - the second byte
        byte3 - the third byte
        byte4 - the fourth byte
        Returns:
        position of sequence, or -1 if not found
      • getBlockOffsetReverse

        protected int getBlockOffsetReverse​(byte[] buf,
                                            int start,
                                            byte byte1,
                                            byte byte2,
                                            byte byte3,
                                            byte byte4)
        Starting from blocks_offset, find sequence of bytes Return position of sequence, or -1 if not found
        Parameters:
        buf - byte array
        byte1 - the first byte
        byte2 - the second byte
        byte3 - the third byte
        byte4 - the fourth byte
        Returns:
        position of sequence, or -1 if not found
      • getABOffset

        protected int getABOffset​(byte[] buf)
        Find position of AB Block offset
        Parameters:
        buf - byte array
        Returns:
        AB Block offset
      • getTextOffset

        protected int getTextOffset​(byte[] buf)
        Find position of Text Block offset
        Parameters:
        buf - byte array
        Returns:
        Text Block offset
      • getABCount

        protected int getABCount​(byte[] buf)
        Get number of spectral values
        Parameters:
        buf - byte array
        Returns:
        number of spectral values
      • getWaveNumbers

        protected double[] getWaveNumbers​(byte[] buf)
      • getTextBlockOffset

        protected int getTextBlockOffset​(byte[] buf)
        Get position of Text Data.
        Parameters:
        buf - byte array
        Returns:
        the text data pos
      • getTextBlockSize

        protected int getTextBlockSize​(byte[] buf)
        Size of Text Block (in 4-byte words).
        Parameters:
        buf - byte array of bruker file image
        Returns:
        the text block size (in 4-byte words)
      • getABDataOffset

        protected int getABDataOffset​(byte[] buf)
        Get position of nir data.
        Parameters:
        buf - byte array of file image
        Returns:
        nir data pos
      • find

        protected boolean find​(String find,
                               byte[] buf,
                               int start)
        Find a given string in byte array, from a starting pos.
        Parameters:
        find - the string to find
        buf - the byte array
        start - the starting offset
        Returns:
        found?
      • split

        public static String[] split​(String s)
        Attempts to split a string, using the specified delimiter character. A delimiter gets ignored if inside double quotes.
        Parameters:
        s - the string to split
        Returns:
        the parts (single array element if no range)
      • getMetaData

        protected HashMap<String,​Object> getMetaData​(byte[] buf)
        Returns the meta-data from the buffer.
        Parameters:
        buf - the buffer to read from
        Returns:
        the meta data
      • getValueFor

        protected String getValueFor​(String key,
                                     byte[] buf)
        Get value for key, from Text Block. Or null if not found.
        Parameters:
        key - the key to look up
        buf - byte array
        Returns:
        the value
      • byte2UByte

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

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

        protected double convert8ToDouble​(byte[] buf,
                                          int offset)
        Convert 8 bytes to long. LSByte first.
        Parameters:
        buf - byte array
        offset - starting pos
        Returns:
        the double value
      • readData

        protected void readData()
        Performs the actual reading.
        Specified by:
        readData in class adams.data.io.input.AbstractDataContainerReader<Spectrum>
      • main

        public static void main​(String[] args)
        Runs the reader from the command-line. If the option AbstractSpectrumReader.OPTION_OUTPUTDIR is specified then the read spectra get output as .spec files in that directory.
        Parameters:
        args - the command-line options to use