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.AbstractByteBasedSpectrumReader
-
- 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.DataContainerReader>,adams.core.SizeOfHandler,adams.core.Stoppable,adams.data.io.input.DataContainerReader<Spectrum>,adams.data.io.input.StreamableBinaryDataContainerReader<Spectrum>,adams.data.io.input.StreamableDataContainerReader<Spectrum>,Serializable,Comparable
public class OpusSpectrumReader extends AbstractByteBasedSpectrumReader
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 intBLOCKS_OFFSETprotected booleanm_AddTraceToReportwhether to add the trace to the report.protected intm_Maxmaximum to load.protected Stringm_SampleIDwhere to get sample id from. see param defsprotected intm_Startstarting spectrum.protected HashMap<String,Object>m_Tracetrace of data that was retrieved from byte array.static StringPREFIX_TRACEthe 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 StringaddTraceToReportTipText()Returns the tip text for this property.protected intbyte2UByte(byte b)Convert byte to unsigned byte.protected doubleconvert8ToDouble(byte[] buf, int offset)Convert 8 bytes to long.protected longconvertToLong(byte[] buf, int offset)Convert 4 bytes to long.voiddefineOptions()Adds options to the internal list of options.protected booleanfind(String find, byte[] buf, int start)Find a given string in byte array, from a starting pos.protected intgetABCount(byte[] buf)Get number of spectral valuesprotected intgetABDataOffset(byte[] buf)Get position of nir data.protected intgetABOffset(byte[] buf)Find position of AB Block offsetbooleangetAddTraceToReport()Returns whether to add the trace to the report.protected intgetBlockOffset(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 intgetBlockOffsetReverse(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 foundStringgetFormatDescription()Returns a string describing the format (used in the file chooser).String[]getFormatExtensions()Returns the extension(s) of the format.protected intgetInt(byte[] b, int offset)Get int from 4bytes, LSByte firstintgetMax()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 imageStringgetSampleID()Get id field.intgetStart()Returns the start point setting.protected intgetTextBlockOffset(byte[] buf)Get position of Text Data.protected intgetTextBlockSize(byte[] buf)Size of Text Block (in 4-byte words).protected intgetTextOffset(byte[] buf)Find position of Text Block offsetprotected StringgetValueFor(String key, byte[] buf)Get value for key, from Text Block.protected double[]getWaveNumbers(byte[] buf)StringglobalInfo()Returns a string describing the object.static voidmain(String[] args)Runs the reader from the command-line.StringmaxTipText()Returns the tip text for this property.protected voidreadData(byte[] data)Performs the actual reading.StringsampleIDTipText()Returns the tip text for this property.voidsetAddTraceToReport(boolean value)Sets whether to add the trace to the report.voidsetMax(int value)Sets the nth point setting.voidsetSampleID(String value)Set id field.voidsetStart(int value)Sets the start point setting.static String[]split(String s)Attempts to split a string, using the specified delimiter character.StringstartTipText()Returns the tip text for this property.-
Methods inherited from class adams.data.io.input.AbstractByteBasedSpectrumReader
read, readData
-
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
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface adams.data.io.input.DataContainerReader
createDummyReportTipText, getCreateDummyReport, getInput, inputTipText, isInputFile, read, setCreateDummyReport, setInput
-
-
-
-
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:
globalInfoin interfaceadams.core.GlobalInfoSupporter- Specified by:
globalInfoin 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:
getFormatDescriptionin interfaceadams.core.io.FileFormatHandler- Specified by:
getFormatDescriptionin 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:
getFormatExtensionsin interfaceadams.core.io.FileFormatHandler- Specified by:
getFormatExtensionsin 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:
defineOptionsin interfaceadams.core.option.OptionHandler- Overrides:
defineOptionsin 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(byte[] data)
Performs the actual reading.- Specified by:
readDatain classAbstractByteBasedSpectrumReader- Parameters:
data- the content to read from
-
main
public static void main(String[] args)
Runs the reader from the command-line. If the optionAbstractSpectrumReader.OPTION_OUTPUTDIRis specified then the read spectra get output as .spec files in that directory.- Parameters:
args- the command-line options to use
-
-