You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
247 lines
9.6 KiB
C++
247 lines
9.6 KiB
C++
/***************************************************************************
|
|
* Copyright (C) 2016 by gempa GmbH *
|
|
* *
|
|
* All Rights Reserved. *
|
|
* *
|
|
* NOTICE: All information contained herein is, and remains *
|
|
* the property of gempa GmbH and its suppliers, if any. The intellectual *
|
|
* and technical concepts contained herein are proprietary to gempa GmbH *
|
|
* and its suppliers. *
|
|
* Dissemination of this information or reproduction of this material *
|
|
* is strictly forbidden unless prior written permission is obtained *
|
|
* from gempa GmbH. *
|
|
***************************************************************************/
|
|
|
|
|
|
#include "encoderfactory.h"
|
|
|
|
#include "mseed/mseed.h"
|
|
#include "mseed/steim1.h"
|
|
#include "mseed/steim2.h"
|
|
#include "mseed/uncompressed.h"
|
|
|
|
|
|
#include <gempa/caps/packet.h>
|
|
|
|
using namespace std;
|
|
|
|
namespace Gempa {
|
|
namespace CAPS {
|
|
|
|
EncoderFactory::EncoderFactory() {}
|
|
|
|
EncoderFactory::~EncoderFactory() {}
|
|
|
|
const string& EncoderFactory::errorString() const {
|
|
return _errorString;
|
|
}
|
|
|
|
MSEEDEncoderFactory::MSEEDEncoderFactory()
|
|
: _recordLength(9) {}
|
|
|
|
bool MSEEDEncoderFactory::setRecordLength(uint recordLength) {
|
|
if ( recordLength < 7 || recordLength > 32) {
|
|
_errorString = "MSEED record length out of range [7, 32]";
|
|
return false;
|
|
}
|
|
|
|
_recordLength = uint8_t(recordLength);
|
|
return true;
|
|
}
|
|
|
|
bool SteimEncoderFactory::supportsRecord(DataRecord *rec) {
|
|
/*
|
|
DataType dt = rec->header()->dataType;
|
|
if ( (dt == DT_INT64) || (dt == DT_FLOAT) ||
|
|
(dt == DT_DOUBLE) ) {
|
|
return false;
|
|
}
|
|
*/
|
|
|
|
PacketType type = rec->packetType();
|
|
if ( type == RawDataPacket || type == FixedRawDataPacket ) {
|
|
return true;
|
|
}
|
|
else if ( type == MSEEDPacket ) {
|
|
return false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool IdentityEncoderFactory::supportsRecord(DataRecord *rec) {
|
|
PacketType type = rec->packetType();
|
|
return type == RawDataPacket || type == FixedRawDataPacket;
|
|
}
|
|
|
|
Encoder* IdentityEncoderFactory::create(const std::string &networkCode,
|
|
const std::string &stationCode,
|
|
const std::string &locationCode,
|
|
const std::string &channelCode,
|
|
int dt,
|
|
int samplingFrequencyNumerator,
|
|
int samplingFrequencyDenominator) {
|
|
if ( dt == DT_INT8 ) {
|
|
MSEEDFormat *format = new MSEEDFormat(networkCode, stationCode,
|
|
locationCode, channelCode,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator,
|
|
DE_ASCII,
|
|
_recordLength);
|
|
if ( format == NULL ) return NULL;
|
|
|
|
return new UncompressedMSEED<int8_t>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_INT16 ) {
|
|
MSEEDFormat *format = new MSEEDFormat(networkCode, stationCode,
|
|
locationCode, channelCode,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator,
|
|
DE_INT16,
|
|
_recordLength);
|
|
if ( format == NULL ) return NULL;
|
|
|
|
return new UncompressedMSEED<int16_t>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_INT32 ) {
|
|
MSEEDFormat *format = new MSEEDFormat(networkCode, stationCode,
|
|
locationCode, channelCode,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator,
|
|
DE_INT32,
|
|
_recordLength);
|
|
if ( format == NULL ) return NULL;
|
|
|
|
return new UncompressedMSEED<int32_t>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_FLOAT ) {
|
|
MSEEDFormat *format = new MSEEDFormat(networkCode, stationCode,
|
|
locationCode, channelCode,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator,
|
|
DE_FLOAT32,
|
|
_recordLength);
|
|
if ( format == NULL ) return NULL;
|
|
|
|
return new UncompressedMSEED<float>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_DOUBLE ) {
|
|
MSEEDFormat *format = new MSEEDFormat(networkCode, stationCode,
|
|
locationCode, channelCode,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator,
|
|
DE_FLOAT64,
|
|
_recordLength);
|
|
if ( format == NULL ) return NULL;
|
|
|
|
return new UncompressedMSEED<double>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
Encoder* Steim1EncoderFactory::create(const std::string &networkCode,
|
|
const std::string &stationCode,
|
|
const std::string &locationCode,
|
|
const std::string &channelCode,
|
|
int dt,
|
|
int samplingFrequencyNumerator,
|
|
int samplingFrequencyDenominator) {
|
|
MSEEDFormat *format = new MSEEDFormat(networkCode, stationCode,
|
|
locationCode, channelCode,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator,
|
|
DE_STEIM1,
|
|
_recordLength);
|
|
if ( format == NULL ) return NULL;
|
|
|
|
if ( dt == DT_INT8 ) {
|
|
return new Steim1Encoder<int8_t>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_INT16 ) {
|
|
return new Steim1Encoder<int16_t>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_INT32 ) {
|
|
return new Steim1Encoder<int32_t>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_FLOAT ) {
|
|
return new Steim1Encoder<float>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_DOUBLE ) {
|
|
return new Steim1Encoder<double>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
|
|
delete format;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
Encoder* Steim2EncoderFactory::create(const std::string &networkCode,
|
|
const std::string &stationCode,
|
|
const std::string &locationCode,
|
|
const std::string &channelCode,
|
|
int dt,
|
|
int samplingFrequencyNumerator,
|
|
int samplingFrequencyDenominator) {
|
|
MSEEDFormat *format = new MSEEDFormat(networkCode, stationCode,
|
|
locationCode, channelCode,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator,
|
|
DE_STEIM2,
|
|
_recordLength);
|
|
if ( format == NULL ) return NULL;
|
|
|
|
if ( dt == DT_INT8 ) {
|
|
return new Steim2Encoder<int8_t>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_INT16 ) {
|
|
return new Steim2Encoder<int16_t>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_INT32 ) {
|
|
return new Steim2Encoder<int32_t>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_FLOAT ) {
|
|
return new Steim2Encoder<float>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
else if ( dt == DT_DOUBLE ) {
|
|
return new Steim2Encoder<double>(format,
|
|
samplingFrequencyNumerator,
|
|
samplingFrequencyDenominator);
|
|
}
|
|
|
|
delete format;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
}
|
|
}
|