Package de.labathome
Class BinaryTimeseries
java.lang.Object
de.labathome.BinaryTimeseries
public class BinaryTimeseries
extends java.lang.Object
This is a class to save evenly-sampled time series data in a very simple and
easy-to-read format. The key idea is to simply dump a header and then the raw
data values one after another into a ByteBuffer. When you want to read only a
small subset of the data, you can specify a time or an index range. A scaling
and an offset can be defined for the data values (e.g. from an ADC). Examples
of how to use this class can be found in Examples.java.
- Author:
- Jonathan Schilling (jonathan.schilling@mail.de)
-
Field Summary
Fields Modifier and Type Field Description static byteDTYPE_BYTEIdentifier value forbytedatatype.static byteDTYPE_DOUBLEIdentifier value fordoubledatatype.static byteDTYPE_FLOATIdentifier value forfloatdatatype.static byteDTYPE_INTIdentifier value forintdatatype.static byteDTYPE_LONGIdentifier value forlongdatatype.static byteDTYPE_NONEIdentifier value used to indicate that no raw data scaling is used.static byteDTYPE_SHORTIdentifier value forshortdatatype. -
Constructor Summary
Constructors Constructor Description BinaryTimeseries() -
Method Summary
Modifier and Type Method Description static voidbuildTimebase(double[] target, double t0, double dt)Compute the timebase values for a given t_0 and Delta_t.static voidbuildTimebase(int sourceOffset, double[] target, int targetOffset, int numSamples, double t0, double dt)Compute the timebase values for a given t_0 and Delta_t.static voidbuildTimebase(int sourceOffset, long[] target, int targetOffset, int numSamples, long t0, long dt)Compute the timebase values for a given t_0 and Delta_t.static voidbuildTimebase(long[] target, long t0, long dt)Compute the timebase values for a given t_0 and Delta_t.static java.lang.StringdtypeStr(byte dtype)Get a human-readable identification string for a given data type.static java.lang.StringexplainHeader(byte[] header)Given 64 header bytes, generate a human-readable explanation similar to Tab.static intfileOffset(int dataSize, int index)Compute the file offset (and buffer size when reading the file) in bytes given the size of the contained raw data type and the number of samples/index.static intfirstIndexInside(double t0, double dt, double t_l)Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l,t_u].static intfirstIndexInside(long t0, long dt, long t_l)Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l,t_u].static booleanhasScaling(byte scaling_dtype)Check the given dtype byte to see if the given file has a value scaling or not.static intlastIndexInside(double t0, double dt, double t_u)Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l,t_u].static intlastIndexInside(long t0, long dt, long t_u)Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l,t_u].static byte[]readData_byte(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into abyte[]array.static byte[]readData_byte(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into abyte[]array.static double[]readData_double(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into adouble[]array.static double[]readData_double(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into adouble[]array.static float[]readData_float(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into afloat[]array.static float[]readData_float(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into afloat[]array.static int[]readData_int(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into aint[]array.static int[]readData_int(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into aint[]array.static long[]readData_long(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into along[]array.static long[]readData_long(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into along[]array.static short[]readData_short(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into ashort[]array.static short[]readData_short(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into ashort[]array.static bytereadDataType(java.nio.ByteBuffer source)Read the raw data type from the givensourcebuffer.static booleanreadEndianessOk(java.nio.ByteBuffer source)Read the firstshortvalue from thesourcebuffer and check if it was correctly read as 1.static byte[]readHeader(java.nio.ByteBuffer source)Read the 64 byte header from the given source buffer.static intreadNumSamples(java.nio.ByteBuffer source)Read the number of samples from the givensourcebuffer.static voidreadRawData(java.nio.ByteBuffer source, byte[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.static voidreadRawData(java.nio.ByteBuffer source, double[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.static voidreadRawData(java.nio.ByteBuffer source, float[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.static voidreadRawData(java.nio.ByteBuffer source, int[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.static voidreadRawData(java.nio.ByteBuffer source, long[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.static voidreadRawData(java.nio.ByteBuffer source, short[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.static voidreadReservedDummy(java.nio.ByteBuffer source)Proceed with reading from the givensourcebuffer over the bytes reserved in the header.static voidreadScalingDisabled(java.nio.ByteBuffer source)Proceed with reading from the givensourcebuffer over the bytes reserved in the header for optional scaling parameters.static bytereadScalingFactor_byte(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer asbyteand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.static doublereadScalingFactor_double(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer asdouble.static floatreadScalingFactor_float(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer asfloatand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.static intreadScalingFactor_int(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer asintand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.static longreadScalingFactor_long(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer aslong.static shortreadScalingFactor_short(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer asshortand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.static bytereadScalingOffset_byte(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer asbyteand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.static doublereadScalingOffset_double(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer asdouble.static floatreadScalingOffset_float(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer asfloatand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.static intreadScalingOffset_int(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer asintand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.static longreadScalingOffset_long(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer aslong.static shortreadScalingOffset_short(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer asshortand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.static bytereadScalingType(java.nio.ByteBuffer source)Read the scaling data type from the givensourcebuffer.static doublereadTimeDt_double(java.nio.ByteBuffer source)Read the time interval between two consecutive samples Delta_t from the givensourcebuffer.static longreadTimeDt_long(java.nio.ByteBuffer source)Read the time interval between two consecutive samples Delta_t from the givensourcebuffer.static doublereadTimeT0_double(java.nio.ByteBuffer source)Read the reference timestamp t_0 from the givensourcebuffer.static longreadTimeT0_long(java.nio.ByteBuffer source)Read the reference timestamp t_0 from the givensourcebuffer.static bytereadTimeType(java.nio.ByteBuffer source)Read the timestamp data type from thesourcebuffer.static voidwrite(java.nio.ByteBuffer target, java.lang.Object t0, java.lang.Object dt, java.lang.Object rawData)Create a BinaryTimeseries with the timebase parameterst0anddtand the unscaledrawData.static voidwrite(java.nio.ByteBuffer target, java.lang.Object t0, java.lang.Object dt, java.lang.Object rawData, java.lang.Object scalingOffset, java.lang.Object scalingFactor)Create a BinaryTimeseries with the timebase parameterst0anddtand the unscaledrawDataand the scaling parametersscalingOffsetandscalingFactor.static voidwriteData(java.nio.ByteBuffer target, byte[] values)Write the raw data values into thetargetbuffer.static voidwriteData(java.nio.ByteBuffer target, double[] values)Write the raw data values into thetargetbuffer.static voidwriteData(java.nio.ByteBuffer target, float[] values)Write the raw data values into thetargetbuffer.static voidwriteData(java.nio.ByteBuffer target, int[] values)Write the raw data values into thetargetbuffer.static voidwriteData(java.nio.ByteBuffer target, long[] values)Write the raw data values into thetargetbuffer.static voidwriteData(java.nio.ByteBuffer target, short[] values)Write the raw data values into thetargetbuffer.static voidwriteEndianessCheckValue(java.nio.ByteBuffer target)Write a 1 asshortto thetargetfile.static voidwriteReservedDummy(java.nio.ByteBuffer target)Write zeros for the reserved area in the header.static voidwriteScaling(java.nio.ByteBuffer target, byte o, byte s)Write the scaling parameters o and s into thetargetbuffer.static voidwriteScaling(java.nio.ByteBuffer target, double o, double s)Write the scaling parameters o and s into thetargetbuffer.static voidwriteScaling(java.nio.ByteBuffer target, float o, float s)Write the scaling parameters o and s into thetargetbuffer.static voidwriteScaling(java.nio.ByteBuffer target, int o, int s)Write the scaling parameters o and s into thetargetbuffer.static voidwriteScaling(java.nio.ByteBuffer target, long o, long s)Write the scaling parameters o and s into thetargetbuffer.static voidwriteScaling(java.nio.ByteBuffer target, short o, short s)Write the scaling parameters o and s into thetargetbuffer.static voidwriteScalingDisabled(java.nio.ByteBuffer target)Write the identifier value into thetargetbuffer that tells the reader that no scaling is available.static voidwriteTimebase(java.nio.ByteBuffer target, double t0, double dt)Write the timebase parameters t0 and dt to thetargetbuffer.static voidwriteTimebase(java.nio.ByteBuffer target, long t0, long dt)Write the timebase parameters t0 and dt to thetargetbuffer.
-
Field Details
-
DTYPE_NONE
public static final byte DTYPE_NONEIdentifier value used to indicate that no raw data scaling is used.- See Also:
- Constant Field Values
-
DTYPE_BYTE
public static final byte DTYPE_BYTEIdentifier value forbytedatatype.
Length: 1 Byte
Range: -128 ... 127- See Also:
- Constant Field Values
-
DTYPE_SHORT
public static final byte DTYPE_SHORTIdentifier value forshortdatatype.
Length: 2 Bytes
Range: -32768 ... 32767- See Also:
- Constant Field Values
-
DTYPE_INT
public static final byte DTYPE_INTIdentifier value forintdatatype.
Length: 4 Bytes
Range: -2147483648 ... 2147483647- See Also:
- Constant Field Values
-
DTYPE_LONG
public static final byte DTYPE_LONGIdentifier value forlongdatatype.
Length: 8 Bytes
Range: -9223372036854775808 ... 9223372036854775807- See Also:
- Constant Field Values
-
DTYPE_FLOAT
public static final byte DTYPE_FLOATIdentifier value forfloatdatatype.
Length: 4 Bytes
7 decimal digits- See Also:
- Constant Field Values
-
DTYPE_DOUBLE
public static final byte DTYPE_DOUBLEIdentifier value fordoubledatatype.
Length: 8 Bytes
16 decimal digits- See Also:
- Constant Field Values
-
-
Constructor Details
-
BinaryTimeseries
public BinaryTimeseries()
-
-
Method Details
-
dtypeStr
public static final java.lang.String dtypeStr(byte dtype)Get a human-readable identification string for a given data type.- Parameters:
dtype- one of [DTYPE_NONE, DTYPE_BYTE, DTYPE_SHORT, DTYPE_INT, DTYPE_LONG, DTYPE_FLOAT, DTYPE_DOUBLE]- Returns:
- one of ["N", "B", "S", "I", "L", "F", "D"] or "?" if it could not be identified
-
buildTimebase
public static final void buildTimebase(long[] target, long t0, long dt)Compute the timebase values for a given t_0 and Delta_t. The number of values is given by the length of thetargetarray, into which the values are put.- Parameters:
target- [N] array into which to put the timebase values t_i.t0- reference timestamp; will go intotarget[0]dt- time interval between two samples
-
buildTimebase
public static final void buildTimebase(int sourceOffset, long[] target, int targetOffset, int numSamples, long t0, long dt)Compute the timebase values for a given t_0 and Delta_t. All entries intargetfromsourceOffsetup to and includingsourceOffset+numSamples-1are filled with appropriate values of the timebase.- Parameters:
sourceOffset- offset in the time series indicestarget- [numSamples] array into which to put the timebase values t_itargetOffset- index at which to put t_0 in thetargetarraynumSamples- number of time stamps to generate; has to greater than or equal totarget.lengtht0- reference timestamp; will go intotarget[targetOffset]dt- time interval between two consecutive samples
-
buildTimebase
public static final void buildTimebase(double[] target, double t0, double dt)Compute the timebase values for a given t_0 and Delta_t. The number of values is given by the length of thetargetarray, into which the values are put.- Parameters:
target- [N] array into which to put the timebase values t_i.t0- reference timestamp; will go intotarget[0]dt- time interval between two samples
-
buildTimebase
public static final void buildTimebase(int sourceOffset, double[] target, int targetOffset, int numSamples, double t0, double dt)Compute the timebase values for a given t_0 and Delta_t. All entries intargetfromsourceOffsetup to and includingsourceOffset+numSamples-1are filled with appropriate values of the timebase.- Parameters:
sourceOffset- offset in the time series indicestarget- [numSamples] array into which to put the timebase values t_itargetOffset- index at which to put t_0 in thetargetarraynumSamples- number of time stamps to generate; has to greater than or equal totarget.lengtht0- reference timestamp; will go intotarget[targetOffset]dt- time interval between two consecutive samples
-
firstIndexInside
public static final int firstIndexInside(long t0, long dt, long t_l)Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l,t_u]. See also Eqn. (7) in the documentation.- Parameters:
t0- reference timestamp from the filedt- time interval between two consecutive samples from the filet_l- lower boundary of the time interval to read data from- Returns:
- first index inside the time interval [
t_l,t_u] - See Also:
- https://stackoverflow.com/questions/7139382/java-rounding-up-to-an-int-using-math-ceil
-
lastIndexInside
public static final int lastIndexInside(long t0, long dt, long t_u)Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l,t_u]. See also Eqn. (8) in the documentation.- Parameters:
t0- reference timestamp from the filedt- time interval between two consecutive samples from the filet_u- upper boundary of the time interval to read data from- Returns:
- last index inside the time interval [
t_l,t_u]
-
firstIndexInside
public static final int firstIndexInside(double t0, double dt, double t_l)Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l,t_u]. See also Eqn. (5) in the documentation.- Parameters:
t0- reference timestamp from the filedt- time interval between two consecutive samples from the filet_l- lower boundary of the time interval to read data from- Returns:
- first index inside the time interval [
t_l,t_u]
-
lastIndexInside
public static final int lastIndexInside(double t0, double dt, double t_u)Given a timebase (t0, dt), compute the first index of timestamps inside the given time interval [t_l,t_u]. See also Eqn. (6) in the documentation.- Parameters:
t0- reference timestamp from the filedt- time interval between two consecutive samples from the filet_u- upper boundary of the time interval to read data from- Returns:
- last index inside the time interval [
t_l,t_u]
-
fileOffset
public static final int fileOffset(int dataSize, int index)Compute the file offset (and buffer size when reading the file) in bytes given the size of the contained raw data type and the number of samples/index. These values can be obtained from first just reading the header and then continuing with reading the whole file.- Parameters:
dataSize- size of the raw data values in bytesindex- sample index or number of samples in the file- Returns:
- byte index or file size to hold the given amount of data using a BinaryTimeseries
-
explainHeader
public static final java.lang.String explainHeader(byte[] header)Given 64 header bytes, generate a human-readable explanation similar to Tab. 2 of the documentation which lists the header contents. This routine stops explaning at the first occurrence of an invalid entry.- Parameters:
header- [64] binary header bytes- Returns:
- a multi-line text (\n as line separator) which tells the user about the contents of the given header info
-
writeEndianessCheckValue
public static final void writeEndianessCheckValue(java.nio.ByteBuffer target)Write a 1 asshortto thetargetfile. This is used to check if correct endianess is used in reading; wrong endianess would lead to reading this as 256.- Parameters:
target- buffer into which to write the time series data
-
writeTimebase
public static final void writeTimebase(java.nio.ByteBuffer target, long t0, long dt)Write the timebase parameters t0 and dt to thetargetbuffer.- Parameters:
target- buffer into which to write the time series datat0- reference timestampdt- time interval between two consecutive samples
-
writeTimebase
public static final void writeTimebase(java.nio.ByteBuffer target, double t0, double dt)Write the timebase parameters t0 and dt to thetargetbuffer.- Parameters:
target- buffer into which to write the time series datat0- reference timestampdt- time interval between two consecutive samples
-
writeScalingDisabled
public static final void writeScalingDisabled(java.nio.ByteBuffer target)Write the identifier value into thetargetbuffer that tells the reader that no scaling is available.- Parameters:
target- buffer into which to write the time series data
-
writeScaling
public static final void writeScaling(java.nio.ByteBuffer target, byte o, byte s)Write the scaling parameters o and s into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datao- offset of the raw data valuess- scaling factor of the raw data values
-
writeScaling
public static final void writeScaling(java.nio.ByteBuffer target, short o, short s)Write the scaling parameters o and s into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datao- offset of the raw data valuess- scaling factor of the raw data values
-
writeScaling
public static final void writeScaling(java.nio.ByteBuffer target, int o, int s)Write the scaling parameters o and s into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datao- offset of the raw data valuess- scaling factor of the raw data values
-
writeScaling
public static final void writeScaling(java.nio.ByteBuffer target, long o, long s)Write the scaling parameters o and s into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datao- offset of the raw data valuess- scaling factor of the raw data values
-
writeScaling
public static final void writeScaling(java.nio.ByteBuffer target, float o, float s)Write the scaling parameters o and s into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datao- offset of the raw data valuess- scaling factor of the raw data values
-
writeScaling
public static final void writeScaling(java.nio.ByteBuffer target, double o, double s)Write the scaling parameters o and s into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datao- offset of the raw data valuess- scaling factor of the raw data values
-
writeReservedDummy
public static final void writeReservedDummy(java.nio.ByteBuffer target)Write zeros for the reserved area in the header.- Parameters:
target- buffer into which to write the time series data
-
writeData
public static final void writeData(java.nio.ByteBuffer target, byte[] values)Write the raw data values into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datavalues- raw data values; all of them will be dumped into the target buffer
-
writeData
public static final void writeData(java.nio.ByteBuffer target, short[] values)Write the raw data values into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datavalues- raw data values; all of them will be dumped into the target buffer
-
writeData
public static final void writeData(java.nio.ByteBuffer target, int[] values)Write the raw data values into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datavalues- raw data values; all of them will be dumped into the target buffer
-
writeData
public static final void writeData(java.nio.ByteBuffer target, long[] values)Write the raw data values into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datavalues- raw data values; all of them will be dumped into the target buffer
-
writeData
public static final void writeData(java.nio.ByteBuffer target, float[] values)Write the raw data values into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datavalues- raw data values; all of them will be dumped into the target buffer
-
writeData
public static final void writeData(java.nio.ByteBuffer target, double[] values)Write the raw data values into thetargetbuffer.- Parameters:
target- buffer into which to write the time series datavalues- raw data values; all of them will be dumped into the target buffer
-
write
public static final void write(java.nio.ByteBuffer target, java.lang.Object t0, java.lang.Object dt, java.lang.Object rawData)Create a BinaryTimeseries with the timebase parameterst0anddtand the unscaledrawData.- Parameters:
target- buffer into which to write the time series datat0- reference timestamp; can bedoubleorlongdt- reference timestamp; can bedoubleorlongrawData- raw data array; can bebyte[],short[],int[],long[],float[]ordouble[]
-
write
public static final void write(java.nio.ByteBuffer target, java.lang.Object t0, java.lang.Object dt, java.lang.Object rawData, java.lang.Object scalingOffset, java.lang.Object scalingFactor)Create a BinaryTimeseries with the timebase parameterst0anddtand the unscaledrawDataand the scaling parametersscalingOffsetandscalingFactor.- Parameters:
target- buffer into which to write the time series datat0- reference timestamp; can bedoubleorlongdt- reference timestamp; can bedoubleorlongrawData- raw data array; can bebyte[],short[],int[],long[],float[]ordouble[]scalingOffset- scaling offset of the raw data to be saved into the file; can benull,byte,short,int,long,floatordoublescalingFactor- scaling factor of the raw data to be saved into the file; can benull,byte,short,int,long,floatordouble
-
readHeader
public static final byte[] readHeader(java.nio.ByteBuffer source)Read the 64 byte header from the given source buffer.- Parameters:
source- buffer from which to read the first 64 bytes- Returns:
- the first 64 bytes as read from
source
-
readEndianessOk
public static final boolean readEndianessOk(java.nio.ByteBuffer source)Read the firstshortvalue from thesourcebuffer and check if it was correctly read as 1.- Parameters:
source- buffer from which to read- Returns:
- true if the read value was 1, false if if was 256 (indicating wrong
endianess of
source - Throws:
java.lang.RuntimeException- in any case something else than 1 or 256 was read
-
readTimeType
public static final byte readTimeType(java.nio.ByteBuffer source)Read the timestamp data type from thesourcebuffer.- Parameters:
source- buffer from which to read- Returns:
- timestamp dtype; should either be
DTYPE_LONGorDTYPE_DOUBLE
-
readTimeT0_long
public static final long readTimeT0_long(java.nio.ByteBuffer source)Read the reference timestamp t_0 from the givensourcebuffer.- Parameters:
source- buffer from which to read- Returns:
- reference timestamp read as
long
-
readTimeDt_long
public static final long readTimeDt_long(java.nio.ByteBuffer source)Read the time interval between two consecutive samples Delta_t from the givensourcebuffer.- Parameters:
source- buffer from which to read- Returns:
- time interval between two consecutive samples Delta_t read as
long
-
readTimeT0_double
public static final double readTimeT0_double(java.nio.ByteBuffer source)Read the reference timestamp t_0 from the givensourcebuffer.- Parameters:
source- buffer from which to read- Returns:
- reference timestamp read as
double
-
readTimeDt_double
public static final double readTimeDt_double(java.nio.ByteBuffer source)Read the time interval between two consecutive samples Delta_t from the givensourcebuffer.- Parameters:
source- buffer from which to read- Returns:
- time interval between two consecutive samples Delta_t read as
double
-
hasScaling
public static final boolean hasScaling(byte scaling_dtype)Check the given dtype byte to see if the given file has a value scaling or not.- Parameters:
scaling_dtype- dtype byte as read from input buffer- Returns:
- false if the data has no scaling; true if it has scaling
-
readScalingType
public static final byte readScalingType(java.nio.ByteBuffer source)Read the scaling data type from the givensourcebuffer.- Parameters:
source- buffer from which to read- Returns:
- one of
DTYPE_NONE,DTYPE_BYTE,DTYPE_SHORT,DTYPE_INT,DTYPE_LONG,DTYPE_FLOATorDTYPE_DOUBLE
-
readScalingDisabled
public static final void readScalingDisabled(java.nio.ByteBuffer source)Proceed with reading from the givensourcebuffer over the bytes reserved in the header for optional scaling parameters. Currently, this simply reads 16 bytes from the buffer.- Parameters:
source- buffer from which to read
-
readScalingOffset_byte
public static final byte readScalingOffset_byte(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer asbyteand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.- Parameters:
source- buffer from which to read- Returns:
- scaling offset read as
byte
-
readScalingFactor_byte
public static final byte readScalingFactor_byte(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer asbyteand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.- Parameters:
source- buffer from which to read- Returns:
- scaling factor read as
byte
-
readScalingOffset_short
public static final short readScalingOffset_short(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer asshortand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.- Parameters:
source- buffer from which to read- Returns:
- scaling offset read as
short
-
readScalingFactor_short
public static final short readScalingFactor_short(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer asshortand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.- Parameters:
source- buffer from which to read- Returns:
- scaling factor read as
short
-
readScalingOffset_int
public static final int readScalingOffset_int(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer asintand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.- Parameters:
source- buffer from which to read- Returns:
- scaling offset read as
int
-
readScalingFactor_int
public static final int readScalingFactor_int(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer asintand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.- Parameters:
source- buffer from which to read- Returns:
- scaling factor read as
int
-
readScalingOffset_long
public static final long readScalingOffset_long(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer aslong.- Parameters:
source- buffer from which to read- Returns:
- scaling offset read as
long
-
readScalingFactor_long
public static final long readScalingFactor_long(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer aslong.- Parameters:
source- buffer from which to read- Returns:
- scaling factor read as
long
-
readScalingOffset_float
public static final float readScalingOffset_float(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer asfloatand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.- Parameters:
source- buffer from which to read- Returns:
- scaling offset read as
float
-
readScalingFactor_float
public static final float readScalingFactor_float(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer asfloatand proceed reading until a total of 8 bytes has been read to stay aligned with the defined file structure.- Parameters:
source- buffer from which to read- Returns:
- scaling factor read as
float
-
readScalingOffset_double
public static final double readScalingOffset_double(java.nio.ByteBuffer source)Read the scaling offset from the givensourcebuffer asdouble.- Parameters:
source- buffer from which to read- Returns:
- scaling offset read as
double
-
readScalingFactor_double
public static final double readScalingFactor_double(java.nio.ByteBuffer source)Read the scaling factor from the givensourcebuffer asdouble.- Parameters:
source- buffer from which to read- Returns:
- scaling factor read as
double
-
readReservedDummy
public static final void readReservedDummy(java.nio.ByteBuffer source)Proceed with reading from the givensourcebuffer over the bytes reserved in the header. Currently, this simply reads 23 bytes from the buffer.- Parameters:
source- buffer from which to read
-
readDataType
public static final byte readDataType(java.nio.ByteBuffer source)Read the raw data type from the givensourcebuffer.- Parameters:
source- buffer from which to read- Returns:
- one of
DTYPE_BYTE,DTYPE_SHORT,DTYPE_INT,DTYPE_LONG,DTYPE_FLOATorDTYPE_DOUBLE
-
readNumSamples
public static final int readNumSamples(java.nio.ByteBuffer source)Read the number of samples from the givensourcebuffer.- Parameters:
source- buffer from which to read- Returns:
- number of samples; should be > 0
-
readRawData
public static final void readRawData(java.nio.ByteBuffer source, byte[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.- Parameters:
source- buffer from which to readtarget- array into which to read the given samplestargetOffset- offset intargetat which to put the first sample read from thesourcebuffernumSamples- number of samples to be read from thesourcebuffer
-
readRawData
public static final void readRawData(java.nio.ByteBuffer source, short[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.- Parameters:
source- buffer from which to readtarget- array into which to read the given samplestargetOffset- offset intargetat which to put the first sample read from thesourcebuffernumSamples- number of samples to be read from thesourcebuffer
-
readRawData
public static final void readRawData(java.nio.ByteBuffer source, int[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.- Parameters:
source- buffer from which to readtarget- array into which to read the given samplestargetOffset- offset intargetat which to put the first sample read from thesourcebuffernumSamples- number of samples to be read from thesourcebuffer
-
readRawData
public static final void readRawData(java.nio.ByteBuffer source, long[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.- Parameters:
source- buffer from which to readtarget- array into which to read the given samplestargetOffset- offset intargetat which to put the first sample read from thesourcebuffernumSamples- number of samples to be read from thesourcebuffer
-
readRawData
public static final void readRawData(java.nio.ByteBuffer source, float[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.- Parameters:
source- buffer from which to readtarget- array into which to read the given samplestargetOffset- offset intargetat which to put the first sample read from thesourcebuffernumSamples- number of samples to be read from thesourcebuffer
-
readRawData
public static final void readRawData(java.nio.ByteBuffer source, double[] target, int targetOffset, int numSamples)Read the raw data from the givensourcebuffer and put them into a giventargetarray at an offset specified bytargetOffset.- Parameters:
source- buffer from which to readtarget- array into which to read the given samplestargetOffset- offset intargetat which to put the first sample read from thesourcebuffernumSamples- number of samples to be read from thesourcebuffer
-
readData_byte
public static final byte[] readData_byte(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into abyte[]array.- Parameters:
source- buffer from which to read- Returns:
- an array containing the (scaled) data from the
sourcebuffer - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_byte
public static final byte[] readData_byte(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into abyte[]array.- Parameters:
source- buffer from which to readfirstDataIndex- the index of the first sample to read from the givenbufferlastDataIndex- the index of the last sample to read from the givenbuffer; -1 means read all available samples- Returns:
- an array containing the (scaled) data from the
sourcebuffer in the rangefirstDataIndexup to and includinglastDataIndex - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_short
public static final short[] readData_short(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into ashort[]array.- Parameters:
source- buffer from which to read- Returns:
- an array containing the (scaled) data from the
sourcebuffer - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_short
public static final short[] readData_short(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into ashort[]array.- Parameters:
source- buffer from which to readfirstDataIndex- the index of the first sample to read from the givenbufferlastDataIndex- the index of the last sample to read from the givenbuffer; -1 means read all available samples- Returns:
- an array containing the (scaled) data from the
sourcebuffer in the rangefirstDataIndexup to and includinglastDataIndex - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_int
public static final int[] readData_int(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into aint[]array.- Parameters:
source- buffer from which to read- Returns:
- an array containing the (scaled) data from the
sourcebuffer - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_int
public static final int[] readData_int(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into aint[]array.- Parameters:
source- buffer from which to readfirstDataIndex- the index of the first sample to read from the givenbufferlastDataIndex- the index of the last sample to read from the givenbuffer; -1 means read all available samples- Returns:
- an array containing the (scaled) data from the
sourcebuffer in the rangefirstDataIndexup to and includinglastDataIndex - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_long
public static final long[] readData_long(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into along[]array.- Parameters:
source- buffer from which to read- Returns:
- an array containing the (scaled) data from the
sourcebuffer - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_long
public static final long[] readData_long(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into along[]array.- Parameters:
source- buffer from which to readfirstDataIndex- the index of the first sample to read from the givenbufferlastDataIndex- the index of the last sample to read from the givenbuffer; -1 means read all available samples- Returns:
- an array containing the (scaled) data from the
sourcebuffer in the rangefirstDataIndexup to and includinglastDataIndex - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_float
public static final float[] readData_float(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into afloat[]array.- Parameters:
source- buffer from which to read- Returns:
- an array containing the (scaled) data from the
sourcebuffer - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_float
public static final float[] readData_float(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into afloat[]array.- Parameters:
source- buffer from which to readfirstDataIndex- the index of the first sample to read from the givenbufferlastDataIndex- the index of the last sample to read from the givenbuffer; -1 means read all available samples- Returns:
- an array containing the (scaled) data from the
sourcebuffer in the rangefirstDataIndexup to and includinglastDataIndex - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_double
public static final double[] readData_double(java.nio.ByteBuffer source)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into adouble[]array.- Parameters:
source- buffer from which to read- Returns:
- an array containing the (scaled) data from the
sourcebuffer - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-
readData_double
public static final double[] readData_double(java.nio.ByteBuffer source, int firstDataIndex, int lastDataIndex)Read the scaling parameters, the reserved (dummy) area, the raw data type and number of samples and the raw data; scale the raw data according to the (possibly present) scaling parameters and put the resulting samples into adouble[]array.- Parameters:
source- buffer from which to readfirstDataIndex- the index of the first sample to read from the givenbufferlastDataIndex- the index of the last sample to read from the givenbuffer; -1 means read all available samples- Returns:
- an array containing the (scaled) data from the
sourcebuffer in the rangefirstDataIndexup to and includinglastDataIndex - Throws:
java.lang.RuntimeException- if an unknown scaling type or data type was encountered
-