Package adams.data.io.input
Class OpusSpectrumReader
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.input.AbstractDataContainerReader<Spectrum>
-
- adams.data.io.input.AbstractSpectrumReader
-
- adams.data.io.input.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 Summary
Fields Modifier and Type Field Description static int
BLOCKS_OFFSET
protected boolean
m_AddTraceToReport
whether to add the trace to the report.protected int
m_Max
maximum to load.protected String
m_SampleID
where to get sample id from. see param defsprotected int
m_Start
starting spectrum.protected HashMap<String,Object>
m_Trace
trace of data that was retrieved from byte array.static String
PREFIX_TRACE
the prefix for the trace values in the report.-
Fields inherited from class adams.data.io.input.AbstractSpectrumReader
m_Format, m_Instrument, m_KeepFormat, m_Stopped, m_UseAbsoluteSource, OPTION_OUTPUTDIR
-
-
Constructor Summary
Constructors Constructor Description OpusSpectrumReader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
addTraceToReportTipText()
Returns the tip text for this property.protected int
byte2UByte(byte b)
Convert byte to unsigned byte.protected double
convert8ToDouble(byte[] buf, int offset)
Convert 8 bytes to long.protected long
convertToLong(byte[] buf, int offset)
Convert 4 bytes to long.void
defineOptions()
Adds options to the internal list of options.protected boolean
find(String find, byte[] buf, int start)
Find a given string in byte array, from a starting pos.protected int
getABCount(byte[] buf)
Get number of spectral valuesprotected int
getABDataOffset(byte[] buf)
Get position of nir data.protected int
getABOffset(byte[] buf)
Find position of AB Block offsetboolean
getAddTraceToReport()
Returns whether to add the trace to the report.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 foundprotected 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 foundString
getFormatDescription()
Returns a string describing the format (used in the file chooser).String[]
getFormatExtensions()
Returns the extension(s) of the format.protected int
getInt(byte[] b, int offset)
Get int from 4bytes, LSByte firstint
getMax()
Returns the nth point setting.protected HashMap<String,Object>
getMetaData(byte[] buf)
Returns the meta-data from the buffer.protected double[]
getNirArray(byte[] file_image)
Get array of nir data from byte array of bruker file imageString
getSampleID()
Get id field.int
getStart()
Returns the start point setting.protected int
getTextBlockOffset(byte[] buf)
Get position of Text Data.protected int
getTextBlockSize(byte[] buf)
Size of Text Block (in 4-byte words).protected int
getTextOffset(byte[] buf)
Find position of Text Block offsetprotected String
getValueFor(String key, byte[] buf)
Get value for key, from Text Block.protected double[]
getWaveNumbers(byte[] buf)
String
globalInfo()
Returns a string describing the object.static void
main(String[] args)
Runs the reader from the command-line.String
maxTipText()
Returns the tip text for this property.protected void
readData()
Performs the actual reading.String
sampleIDTipText()
Returns the tip text for this property.void
setAddTraceToReport(boolean value)
Sets whether to add the trace to the report.void
setMax(int value)
Sets the nth point setting.void
setSampleID(String value)
Set id field.void
setStart(int value)
Sets the start point setting.static String[]
split(String s)
Attempts to split a string, using the specified delimiter character.String
startTipText()
Returns the tip text for this property.-
Methods inherited from class adams.data.io.input.AbstractSpectrumReader
checkData, createDummyReport, formatTipText, getDefaultFormat, getDefaultInstrument, getDefaultKeepFormat, getDefaultUseAbsoluteSource, getFormat, getInstrument, getKeepFormat, getReaders, getUseAbsoluteSource, instrumentTipText, keepFormatTipText, postProcessData, runReader, setFormat, setInstrument, setKeepFormat, setUseAbsoluteSource, stopExecution, useAbsoluteSourceTipText
-
Methods inherited from class adams.data.io.input.AbstractDataContainerReader
cleanUp, compareTo, createDummyReportTipText, destroy, doRead, equals, getAdditionalInformation, getCreateDummyReport, getDefaultFormatExtension, getInput, initialize, inputTipText, isInputFile, read, reset, setCreateDummyReport, setInput, shallowCopy, shallowCopy
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
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_AddTraceToReport
protected boolean m_AddTraceToReport
whether to add the trace to the report.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceadams.core.GlobalInfoSupporter
- Specified by:
globalInfo
in classadams.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 interfaceadams.core.io.FileFormatHandler
- Specified by:
getFormatDescription
in classadams.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 interfaceadams.core.io.FileFormatHandler
- Specified by:
getFormatExtensions
in classadams.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 interfaceadams.core.option.OptionHandler
- Overrides:
defineOptions
in classAbstractSpectrumReader
-
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 arrayoffset
- 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 arraybyte1
- the first bytebyte2
- the second bytebyte3
- the third bytebyte4
- 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 arraybyte1
- the first bytebyte2
- the second bytebyte3
- the third bytebyte4
- 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 findbuf
- the byte arraystart
- 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 upbuf
- 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 arrayoffset
- starting pos- Returns:
- the long value
-
convert8ToDouble
protected double convert8ToDouble(byte[] buf, int offset)
Convert 8 bytes to long. LSByte first.- Parameters:
buf
- byte arrayoffset
- starting pos- Returns:
- the double value
-
readData
protected void readData()
Performs the actual reading.- Specified by:
readData
in classadams.data.io.input.AbstractDataContainerReader<Spectrum>
-
main
public static void main(String[] args)
Runs the reader from the command-line. If the optionAbstractSpectrumReader.OPTION_OUTPUTDIR
is specified then the read spectra get output as .spec files in that directory.- Parameters:
args
- the command-line options to use
-
-