Package edu.sc.seis.seisFile.mseed3
Class MSeed3Record
- java.lang.Object
-
- edu.sc.seis.seisFile.mseed3.MSeed3Record
-
public class MSeed3Record extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static intCHANNEL_CODE_LENGTHstatic intCRC_OFFSETprotected intdataByteLengthstatic longDAY_NANOSprotected intdayOfYearprotected static byteDEFAULT_MINISEED_VERSIONprotected static java.lang.StringDEFAULT_RECORD_INDICATORstatic intDEFAULT_START_DAY_OF_YEARstatic intDEFAULT_START_HOURstatic intDEFAULT_START_MINUTEstatic intDEFAULT_START_NANOSECONDstatic intDEFAULT_START_SECONDstatic intDEFAULT_START_YEARprotected org.json.JSONObjectextraHeadersprotected intextraHeadersByteLengthprotected java.lang.StringextraHeadersStrstatic java.lang.StringFDSN_PREFIXstatic intFIXED_HEADER_SIZEprotected byteflagsprotected byteformatVersionprotected inthourstatic longLAST_SEC_NANOSstatic intLOCATION_CODE_LENGTHstatic longMAX_DATA_SIZEstatic java.lang.StringMINISEED_THREE_MIMEprotected intminuteprotected intnanosecondstatic intNETWORK_CODE_LENGTHprotected intnumSamplesprotected bytepublicationVersionprotected intrecordCRCprotected java.lang.StringrecordIndicatorprotected doublesampleRatePeriodstatic longSEC_NANOSprotected intsecondprotected FDSNSourceIdsourceIdprotected bytesourceIdByteLengthprotected java.lang.StringsourceIdStrstatic intSTATION_CODE_LENGTHstatic java.lang.StringTIME_LEAP_SECONDprotected byte[]timeseriesBytesprotected bytetimeseriesEncodingFormatstatic java.time.ZoneIdTZ_UTCstatic intUNKNOWN_DATA_VERSIONconst for unknown data version, 0protected intyearstatic java.lang.StringZULU
-
Constructor Summary
Constructors Constructor Description MSeed3Record()creates a DataHeader object with nothing set (ie nulls and zeros)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.ByteBufferasByteBuffer()write DataHeader contents as a ByteBufferintcalcExtraHeadersByteLength()edu.iris.dmc.seedcodec.DecompressedDatadecompress()Decompress the data in this record according to the compression type in the header.static MSeed3RecordfromByteBuffer(java.nio.ByteBuffer buf)read record contents from a ByteBufferintgetDataByteLength()intgetDayOfYear()static java.time.ZonedDateTimegetDefaultStartTime()org.json.JSONObjectgetExtraHeaders()java.lang.StringgetExtraHeadersAsString(int indent)intgetExtraHeadersByteLength()bytegetFlags()bytegetFormatVersion()intgetHour()java.time.ZonedDateTimegetLastSampleTime()the derived last sample time for this record adjusted for leap seconds.java.lang.StringgetLastSampleTimeString()get the time of the last sample of the record, derived from Start time, sample rate, and number of samples -1.intgetLeapSecInRecord()intgetMinute()intgetNanosecond()intgetNumSamples()java.time.ZonedDateTimegetPredictedNextRecordStartTime()the predicted start time for the record following this one adjusted for leap seconds.bytegetPublicationVersion()intgetRecordCRC()java.lang.StringgetRecordIndicator()longgetSamplePeriodAsNanos()doublegetSampleRatePeriod()Gets sample rate/period value from header.intgetSecond()intgetSize()Gets the number of bytes for this record.FDSNSourceIdgetSourceId()Gets the sourceId parsed as a FDSN source id.bytegetSourceIdByteLength()java.lang.StringgetSourceIdStr()Gets the raw sourceid header field as a String.java.time.ZonedDateTimegetStartDateTime()Start time as a Date.java.time.InstantgetStartInstant()java.lang.StringgetStartTimeString()Get the value of startTime.byte[]getTimeseriesBytes()bytegetTimeseriesEncodingFormat()java.lang.StringgetTimeseriesEncodingFormatName()intgetYear()booleanisClockLocked()booleanisEndTimeInLeapSecond()booleanisStartTimeInLeapSecond()booleanisTimeTagQuestionable()static java.lang.StringnanosToString(int nanos)Converts nanoseconds to string to append to time, removing trailing zeros to be 3, 6 or 9 digits.booleanpossibleLeapSecond()Checks if the record covers a time range that might contain a leap second, effectively if it crosses midnight on Dec 31 or June 30.voidprintASCII(java.io.PrintWriter out)Writes an ASCII version of the record header.voidprintASCII(java.io.PrintWriter out, java.lang.String indent)voidprintASCII(java.io.PrintWriter out, java.lang.String indent, boolean withData)static voidprintData(java.io.PrintWriter out, java.lang.String indent, double[] data)static voidprintData(java.io.PrintWriter out, java.lang.String indent, float[] data)static voidprintData(java.io.PrintWriter out, java.lang.String indent, int[] data)static voidprintData(java.io.PrintWriter out, java.lang.String indent, short[] data)voidprintDataASCII(java.io.PrintWriter out)voidprintDataASCII(java.io.PrintWriter out, java.lang.String indent)voidprintDataRawBytes(java.io.PrintWriter out, java.lang.String indent)protected intread(byte[] buf, int offset)populates this object with Fixed Section Data Header info.static MSeed3Recordread(java.io.DataInput in)Instantiate an object of this class and read an FSDH byte stream into it, parsing the contents into the instance variables of this object, which represent the individual FSDH fields.doublesamplingAsPeriod()Calculate sample period value from header.doublesamplingAsRate()Calculate sample rate value from header.voidsetClockLocked(boolean b)voidsetDayOfYear(int dayOfYear)voidsetExtraHeaders(java.lang.String extraHeaders)voidsetExtraHeaders(org.json.JSONObject extraHeaders)voidsetFlags(byte flags)voidsetFormatVersion(byte formatVersion)voidsetHour(int hour)voidsetLeapSecInRecord(int value)voidsetMinute(int minute)voidsetNanosecond(int nanosecond)voidsetNumSamples(int numSamples)voidsetPublicationVersion(byte publicationVersion)voidsetRecordCRC(int recordCRC)voidsetRecordIndicator(java.lang.String recordIndicator)voidsetSampleRatePeriod(double sampleRatePeriod)Sets sample rate/period value in header.voidsetSecond(int second)voidsetSourceId(FDSNSourceId sourceId)voidsetSourceId(java.lang.String sourceId)voidsetStartDateTime(java.time.Instant start)voidsetStartDateTime(java.time.ZonedDateTime start)voidsetTimeseries(double[] data)voidsetTimeseries(float[] data)voidsetTimeseries(int[] data)voidsetTimeseries(short[] data)voidsetTimeseriesBytes(byte[] timeseriesBytes)voidsetTimeseriesEncodingFormat(byte timeseriesEncodingFormat)voidsetTimeTagQuestionable(boolean b)voidsetYear(int year)java.lang.StringstartFieldsInUtilFormat()intsteim1Timeseries(int[] data)intsteim1Timeseries(int[] data, int maxFrames)Encodes data via Steim1, up to maxFrames number of 64 byte frames.intsteim2Timeseries(int[] data)intsteim2Timeseries(int[] data, int maxFrames)Encodes data via Steim2, up to maxFrames number of 64 byte frames.byte[]toByteArray()java.lang.StringtoString()Present a default string representation of the contents of this objectvoidwrite(java.io.OutputStream dos)write DataHeader contents to a DataOutput stream
-
-
-
Field Detail
-
MINISEED_THREE_MIME
public static final java.lang.String MINISEED_THREE_MIME
- See Also:
- Constant Field Values
-
TIME_LEAP_SECOND
public static final java.lang.String TIME_LEAP_SECOND
- See Also:
- Constant Field Values
-
UNKNOWN_DATA_VERSION
public static final int UNKNOWN_DATA_VERSION
const for unknown data version, 0- See Also:
- Constant Field Values
-
recordIndicator
protected java.lang.String recordIndicator
-
formatVersion
protected byte formatVersion
-
flags
protected byte flags
-
year
protected int year
-
dayOfYear
protected int dayOfYear
-
hour
protected int hour
-
minute
protected int minute
-
second
protected int second
-
nanosecond
protected int nanosecond
-
sampleRatePeriod
protected double sampleRatePeriod
-
timeseriesEncodingFormat
protected byte timeseriesEncodingFormat
-
publicationVersion
protected byte publicationVersion
-
numSamples
protected int numSamples
-
recordCRC
protected int recordCRC
-
sourceIdByteLength
protected byte sourceIdByteLength
-
extraHeadersByteLength
protected int extraHeadersByteLength
-
dataByteLength
protected int dataByteLength
-
sourceIdStr
protected java.lang.String sourceIdStr
-
sourceId
protected FDSNSourceId sourceId
-
extraHeadersStr
protected java.lang.String extraHeadersStr
-
extraHeaders
protected org.json.JSONObject extraHeaders
-
timeseriesBytes
protected byte[] timeseriesBytes
-
CRC_OFFSET
public static final int CRC_OFFSET
- See Also:
- Constant Field Values
-
MAX_DATA_SIZE
public static long MAX_DATA_SIZE
-
TZ_UTC
public static final java.time.ZoneId TZ_UTC
-
ZULU
public static final java.lang.String ZULU
- See Also:
- Constant Field Values
-
FDSN_PREFIX
public static final java.lang.String FDSN_PREFIX
- See Also:
- Constant Field Values
-
NETWORK_CODE_LENGTH
public static final int NETWORK_CODE_LENGTH
- See Also:
- Constant Field Values
-
STATION_CODE_LENGTH
public static final int STATION_CODE_LENGTH
- See Also:
- Constant Field Values
-
LOCATION_CODE_LENGTH
public static final int LOCATION_CODE_LENGTH
- See Also:
- Constant Field Values
-
CHANNEL_CODE_LENGTH
public static final int CHANNEL_CODE_LENGTH
- See Also:
- Constant Field Values
-
FIXED_HEADER_SIZE
public static final int FIXED_HEADER_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_RECORD_INDICATOR
protected static final java.lang.String DEFAULT_RECORD_INDICATOR
- See Also:
- Constant Field Values
-
DEFAULT_MINISEED_VERSION
protected static final byte DEFAULT_MINISEED_VERSION
- See Also:
- Constant Field Values
-
SEC_NANOS
public static final long SEC_NANOS
- See Also:
- Constant Field Values
-
DAY_NANOS
public static final long DAY_NANOS
- See Also:
- Constant Field Values
-
LAST_SEC_NANOS
public static final long LAST_SEC_NANOS
- See Also:
- Constant Field Values
-
DEFAULT_START_YEAR
public static final int DEFAULT_START_YEAR
- See Also:
- Constant Field Values
-
DEFAULT_START_DAY_OF_YEAR
public static final int DEFAULT_START_DAY_OF_YEAR
- See Also:
- Constant Field Values
-
DEFAULT_START_HOUR
public static final int DEFAULT_START_HOUR
- See Also:
- Constant Field Values
-
DEFAULT_START_MINUTE
public static final int DEFAULT_START_MINUTE
- See Also:
- Constant Field Values
-
DEFAULT_START_SECOND
public static final int DEFAULT_START_SECOND
- See Also:
- Constant Field Values
-
DEFAULT_START_NANOSECOND
public static final int DEFAULT_START_NANOSECOND
- See Also:
- Constant Field Values
-
-
Method Detail
-
printASCII
public void printASCII(java.io.PrintWriter out) throws java.io.IOExceptionWrites an ASCII version of the record header. This is not meant to be a definitive ascii representation, merely to give something to print for debugging purposes. Ideally each field of the header should be printed in the order is appears in the header in a visually appealing way.- Parameters:
out- a Writer- Throws:
java.io.IOException
-
printASCII
public void printASCII(java.io.PrintWriter out, java.lang.String indent) throws java.io.IOException- Throws:
java.io.IOException
-
printASCII
public void printASCII(java.io.PrintWriter out, java.lang.String indent, boolean withData) throws java.io.IOException- Throws:
java.io.IOException
-
printDataASCII
public void printDataASCII(java.io.PrintWriter out)
-
printDataASCII
public void printDataASCII(java.io.PrintWriter out, java.lang.String indent)
-
printData
public static void printData(java.io.PrintWriter out, java.lang.String indent, int[] data)
-
printData
public static void printData(java.io.PrintWriter out, java.lang.String indent, short[] data)
-
printData
public static void printData(java.io.PrintWriter out, java.lang.String indent, float[] data)
-
printData
public static void printData(java.io.PrintWriter out, java.lang.String indent, double[] data)
-
printDataRawBytes
public void printDataRawBytes(java.io.PrintWriter out, java.lang.String indent)
-
read
public static MSeed3Record read(java.io.DataInput in) throws java.io.IOException, SeedFormatException, FDSNSourceIdException
Instantiate an object of this class and read an FSDH byte stream into it, parsing the contents into the instance variables of this object, which represent the individual FSDH fields.- Parameters:
in- miniSEED3 data stream .- Returns:
- an object of this class with fields filled from 'in' parameter
- Throws:
java.io.IOExceptionSeedFormatExceptionFDSNSourceIdException
-
read
protected int read(byte[] buf, int offset)populates this object with Fixed Section Data Header info.- Parameters:
buf- data buffer containing FSDH informationoffset- byte offset to begin reading buf
-
write
public void write(java.io.OutputStream dos) throws java.io.IOExceptionwrite DataHeader contents to a DataOutput stream- Parameters:
dos- DataOutput stream to write to- Throws:
java.io.IOException
-
fromByteBuffer
public static MSeed3Record fromByteBuffer(java.nio.ByteBuffer buf) throws java.io.IOException, SeedFormatException
read record contents from a ByteBuffer- Throws:
java.io.IOExceptionSeedFormatException
-
asByteBuffer
public java.nio.ByteBuffer asByteBuffer() throws java.io.IOExceptionwrite DataHeader contents as a ByteBuffer- Throws:
java.io.IOException
-
toByteArray
public byte[] toByteArray()
-
getLeapSecInRecord
public int getLeapSecInRecord()
-
setLeapSecInRecord
public void setLeapSecInRecord(int value)
-
setStartDateTime
public void setStartDateTime(java.time.ZonedDateTime start)
-
setStartDateTime
public void setStartDateTime(java.time.Instant start)
-
getStartDateTime
public java.time.ZonedDateTime getStartDateTime()
Start time as a Date. This adjusts for possible leap seconds, but will be wrong during a leap second. In particular, the returned value is the same if the seconds field is 59 or 60, as if the 59th second repeats.
-
getStartInstant
public java.time.Instant getStartInstant()
-
possibleLeapSecond
public boolean possibleLeapSecond()
Checks if the record covers a time range that might contain a leap second, effectively if it crosses midnight on Dec 31 or June 30. This does not imply that the date actually has a leap second, just that it could.- Returns:
-
getStartTimeString
public java.lang.String getStartTimeString()
Get the value of startTime.- Returns:
- Value of startTime.
-
nanosToString
public static java.lang.String nanosToString(int nanos)
Converts nanoseconds to string to append to time, removing trailing zeros to be 3, 6 or 9 digits. Includes decimal separator if needed.- Parameters:
nanos-- Returns:
-
getLastSampleTime
public java.time.ZonedDateTime getLastSampleTime()
the derived last sample time for this record adjusted for leap seconds. In the case of a leap second in a record, getLastSampleTime() minus getStartDateTime() is NOT equal to (numSamples-1) * samplePeriod. Also, in case of a record ending in a leap second, the seconds field in the date will be 59, ie it is as if the 59th second repeats.
-
getPredictedNextRecordStartTime
public java.time.ZonedDateTime getPredictedNextRecordStartTime()
the predicted start time for the record following this one adjusted for leap seconds. In the case of a leap second in a record, getPredictedNextRecordStartTime() minus getStartDateTime() is NOT equal to (numSamples) * samplePeriod. Also, in case of a record starting in a leap second, the seconds field in the date will be 59, ie it is as if the 59th second repeats.
-
getLastSampleTimeString
public java.lang.String getLastSampleTimeString()
get the time of the last sample of the record, derived from Start time, sample rate, and number of samples -1.- Returns:
- the value of end time
-
getSamplePeriodAsNanos
public long getSamplePeriodAsNanos()
-
isStartTimeInLeapSecond
public boolean isStartTimeInLeapSecond()
-
isEndTimeInLeapSecond
public boolean isEndTimeInLeapSecond()
-
isTimeTagQuestionable
public boolean isTimeTagQuestionable()
-
setTimeTagQuestionable
public void setTimeTagQuestionable(boolean b)
-
isClockLocked
public boolean isClockLocked()
-
setClockLocked
public void setClockLocked(boolean b)
-
toString
public java.lang.String toString()
Present a default string representation of the contents of this object- Overrides:
toStringin classjava.lang.Object- Returns:
- formatted string of object contents
-
getExtraHeaders
public org.json.JSONObject getExtraHeaders()
-
getRecordIndicator
public java.lang.String getRecordIndicator()
-
setRecordIndicator
public void setRecordIndicator(java.lang.String recordIndicator)
-
getFormatVersion
public byte getFormatVersion()
-
setFormatVersion
public void setFormatVersion(byte formatVersion)
-
getFlags
public byte getFlags()
-
setFlags
public void setFlags(byte flags)
-
startFieldsInUtilFormat
public java.lang.String startFieldsInUtilFormat()
-
getYear
public int getYear()
-
setYear
public void setYear(int year)
-
getDayOfYear
public int getDayOfYear()
-
setDayOfYear
public void setDayOfYear(int dayOfYear)
-
getHour
public int getHour()
-
setHour
public void setHour(int hour)
-
getMinute
public int getMinute()
-
setMinute
public void setMinute(int minute)
-
getSecond
public int getSecond()
-
setSecond
public void setSecond(int second)
-
getNanosecond
public int getNanosecond()
-
setNanosecond
public void setNanosecond(int nanosecond)
-
getSampleRatePeriod
public double getSampleRatePeriod()
Gets sample rate/period value from header. Is rate if positive, period if negative.- Returns:
-
setSampleRatePeriod
public void setSampleRatePeriod(double sampleRatePeriod)
Sets sample rate/period value in header. Is rate if positive, period if negative.
-
samplingAsRate
public double samplingAsRate()
Calculate sample rate value from header. This is always positive, even if value is negative, indicating a period in the header.- Returns:
- sample rate as a non-negative number (Hz)
-
samplingAsPeriod
public double samplingAsPeriod()
Calculate sample period value from header. This is always positive, even if value is negative, indicating a period in the header.- Returns:
- sample period as a non-negative number (seconds)
-
getTimeseriesEncodingFormat
public byte getTimeseriesEncodingFormat()
-
getTimeseriesEncodingFormatName
public java.lang.String getTimeseriesEncodingFormatName()
-
setTimeseriesEncodingFormat
public void setTimeseriesEncodingFormat(byte timeseriesEncodingFormat)
-
getPublicationVersion
public byte getPublicationVersion()
-
setPublicationVersion
public void setPublicationVersion(byte publicationVersion)
-
getNumSamples
public int getNumSamples()
-
setNumSamples
public void setNumSamples(int numSamples)
-
getRecordCRC
public int getRecordCRC()
-
setRecordCRC
public void setRecordCRC(int recordCRC)
-
getExtraHeadersAsString
public java.lang.String getExtraHeadersAsString(int indent)
-
setExtraHeaders
public void setExtraHeaders(java.lang.String extraHeaders)
-
setExtraHeaders
public void setExtraHeaders(org.json.JSONObject extraHeaders)
-
getSourceId
public FDSNSourceId getSourceId()
Gets the sourceId parsed as a FDSN source id. If the source is is not parsable as an FDSN source id, returns null- Returns:
-
getSourceIdStr
public java.lang.String getSourceIdStr()
Gets the raw sourceid header field as a String.- Returns:
-
setSourceId
public void setSourceId(java.lang.String sourceId)
-
setSourceId
public void setSourceId(FDSNSourceId sourceId)
-
getSourceIdByteLength
public byte getSourceIdByteLength()
-
calcExtraHeadersByteLength
public int calcExtraHeadersByteLength()
-
getExtraHeadersByteLength
public int getExtraHeadersByteLength()
-
getDataByteLength
public int getDataByteLength()
-
getTimeseriesBytes
public byte[] getTimeseriesBytes()
-
setTimeseriesBytes
public void setTimeseriesBytes(byte[] timeseriesBytes)
-
setTimeseries
public void setTimeseries(short[] data)
-
setTimeseries
public void setTimeseries(int[] data)
-
steim1Timeseries
public int steim1Timeseries(int[] data) throws edu.iris.dmc.seedcodec.SteimException, java.io.IOException- Throws:
edu.iris.dmc.seedcodec.SteimExceptionjava.io.IOException
-
steim1Timeseries
public int steim1Timeseries(int[] data, int maxFrames) throws edu.iris.dmc.seedcodec.SteimException, java.io.IOExceptionEncodes data via Steim1, up to maxFrames number of 64 byte frames. If maxFrames is zero, encodes all samples.- Parameters:
data-maxFrames-- Returns:
- Throws:
edu.iris.dmc.seedcodec.SteimExceptionjava.io.IOException
-
steim2Timeseries
public int steim2Timeseries(int[] data) throws edu.iris.dmc.seedcodec.SteimException, java.io.IOException- Throws:
edu.iris.dmc.seedcodec.SteimExceptionjava.io.IOException
-
steim2Timeseries
public int steim2Timeseries(int[] data, int maxFrames) throws edu.iris.dmc.seedcodec.SteimException, java.io.IOExceptionEncodes data via Steim2, up to maxFrames number of 64 byte frames. If maxFrames is zero, encodes all samples.- Parameters:
data-maxFrames-- Returns:
- Throws:
edu.iris.dmc.seedcodec.SteimExceptionjava.io.IOException
-
setTimeseries
public void setTimeseries(float[] data)
-
setTimeseries
public void setTimeseries(double[] data)
-
decompress
public edu.iris.dmc.seedcodec.DecompressedData decompress() throws SeedFormatException, edu.iris.dmc.seedcodec.UnsupportedCompressionType, edu.iris.dmc.seedcodec.CodecExceptionDecompress the data in this record according to the compression type in the header.- Returns:
- Throws:
SeedFormatException- if no blockette 1000 presentedu.iris.dmc.seedcodec.UnsupportedCompressionTypeedu.iris.dmc.seedcodec.CodecException
-
getSize
public int getSize()
Gets the number of bytes for this record.- Returns:
-
getDefaultStartTime
public static final java.time.ZonedDateTime getDefaultStartTime()
-
-