Commit 129859a4 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

proceeding

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1998
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent d046869b
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.21 2005-07-22 11:02:02 tforb Exp $
# $Id: Makefile,v 1.22 2006-03-13 10:09:03 tforb Exp $
#
# Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
#
......@@ -22,11 +22,13 @@ HEADERS=datread.h bonjer.h bonjer/readbonjer.h readany.h error.h \
# misc/blitzfortranio.cc hacks/hack_blitztogrepg.cc
LIBSRC=$(wildcard *.cc */*.cc)
LIBSRC=datread.cc bonjer/bonjer.cc bonjer/readbonjer.cc readany.cc error.cc \
pdas/pdas.cc pdas/pdasread.cc tests/pdastest.cc \
sff/sff.cc mseed/mseedread.cc mseed/mseed.cc tests/mseedtest.cc \
hpmo/hpmo.cc hpmo/readhpmo.cc tests/hpmotest.cc hpmo/hpmodata.cc \
pdas/pdas.cc pdas/pdasread.cc \
sff/sff.cc mseed/mseedread.cc mseed/mseed.cc mseed/seedstructs.cc \
hpmo/hpmo.cc hpmo/readhpmo.cc hpmo/hpmodata.cc \
util.cc
TESTSRC=tests/hpmotest.cc tests/pdastest.cc tests/mseedtest.cc
INCINSTALLPATH=$(LOCINCLUDEDIR)/datreadxx
LIBINSTALLPATH=$(LOCLIBDIR)
......@@ -59,7 +61,7 @@ all: install doxybrief doxyfull
install: install-include libdatreadxx.a
flist: Makefile $(wildcard *.cfg contrib/*.h) $(HEADERS) $(LIBSRC) \
README
$(TESTSRC) README
echo $^ | tr ' ' '\n' | sort > $@
.PHONY: edit
......@@ -68,7 +70,9 @@ edit: flist; vim $<
.PHONY: clean
clean: ;
-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
-/bin/rm -vf flist *.d *.o tsxx_tests
-find . -name \*.o | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.d | xargs --no-run-if-empty /bin/rm -v
-/bin/rm -vf flist
#======================================================================
# pattern rules
......@@ -84,7 +88,7 @@ clean: ;
# library part
# ------------
-include $(patsubst %.cc,%.d,$(LIBSRC))
-include $(patsubst %.cc,%.d,$(LIBSRC) $(TESTSRC))
libdatreadxx.a: $(patsubst %.cc,%.o,$(LIBSRC))
ar rcv $@ $^
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mseedread.cc,v 1.4 2006-01-13 10:36:39 tforb Exp $
* $Id: mseedread.cc,v 1.5 2006-03-13 10:09:04 tforb Exp $
* \author Thomas Forbriger
* \date 15/07/2004
*
......@@ -19,7 +19,7 @@
#define TF_MSEEDREAD_CC_VERSION \
"TF_MSEEDREAD_CC V1.0 "
#define TF_MSEEDREAD_CC_CVSID \
"$Id: mseedread.cc,v 1.4 2006-01-13 10:36:39 tforb Exp $"
"$Id: mseedread.cc,v 1.5 2006-03-13 10:09:04 tforb Exp $"
#include <string>
#include <datreadxx/mseedread.h>
......@@ -32,9 +32,11 @@ namespace datread {
/*! Concept of reading MiniSEED files
*
* This module is designed to read data from SeisComP an there from the
* old version used in the GRSN, where MiniSEED data files containe
* telemetry volume headers and the recent version that only contains data
* blocks.
* old version used in the GRSN (with comserv client datalog) as well as
* the new version (using seedlink). Further it will read EDL (Earth Data
* Logger) MiniSEED files. Their formats differ in block size and MiniSEED
* data files that are written by comserv contain telemetry volume headers
* additionally.
*
* If we provide a stream like class, that is constructed from an istream
* object and returns a full data block at once (containing fixed data
......@@ -52,7 +54,7 @@ namespace datread {
* assumptions about the blockette structure used in the file.
*
* We will use the basic structures defined in namespace SEED to hold the
* data. However, it will be nacessary to put some envelope around these
* data. However, it will be necessary to put some envelope around these
* structure in particular to indicate if a blockette was actually read
* from a dataset or not (because it will be present in the returned data
* block structure in any case).
......@@ -61,6 +63,19 @@ namespace datread {
/*----------------------------------------------------------------------*/
/*! contructor of MiniSEEDblock allocates memory of requested block size.
* In case this fails, an exception is thrown.
*/
MiniSEEDblock::MiniSEEDblock(const unsigned int& blocksize):
Mblocksize(blocksize)
{
try { Mblock=new Tvalue[blocksize]; }
catch (std::bad_alloc) {
DATREAD_abort("MiniSEEDblock: could not allocate memory!");
}
} // MiniSEEDblock::MiniSEEDblock
std::string char2string(char* in,int len)
{
return(std::string("not yet coded"));
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mseedread.h,v 1.3 2005-07-06 11:49:10 tforb Exp $
* $Id: mseedread.h,v 1.4 2006-03-13 10:09:04 tforb Exp $
* \author Thomas Forbriger
* \date 15/07/2004
*
......@@ -23,8 +23,10 @@
#define TF_MSEEDREAD_H_VERSION \
"TF_MSEEDREAD_H V1.0 "
#define TF_MSEEDREAD_H_CVSID \
"$Id: mseedread.h,v 1.3 2005-07-06 11:49:10 tforb Exp $"
"$Id: mseedread.h,v 1.4 2006-03-13 10:09:04 tforb Exp $"
#include<new>
#include<iostream>
#include<datreadxx/seedstructs.h>
namespace datread {
......@@ -43,28 +45,61 @@ namespace datread {
*/
namespace mseed {
//! standard block size for mini-SEED files (in SeisComP)
const int block_size=0x200;
//! number of data bytes in one block
const int data_size=block_size-
sizeof(SEED::FixedDataRecordHeader)-
sizeof(SEED::DataOnlySEEDBlockette)-
sizeof(SEED::DataExtensionBlockette);
struct DataBlock {
SEED::FixedDataRecordHeader header;
SEED::DataOnlySEEDBlockette blockette1000;
SEED::DataExtensionBlockette blockette1001;
char data[data_size];
}; // DataBlock
union AnyBlock {
char buffer;
DataBlock db;
SEED::TelemetryVolumeIdentifierBlockette tvib;
};
/*======================================================================*/
// reading classes
/*! MiniSEED input block
*
* This class just encapsulates memory handling for data blocks of
* different size.
*/
class MiniSEEDblock {
public:
// type of data block value
typedef char Tvalue;
//! standard block size for mini-SEED files (in SeisComP)
const static int standard_block_size=0x200;
// constructor allocates new memory
MiniSEEDblock(const unsigned int& blocksize=standard_block_size);
// free memory
~MiniSEEDblock() { delete[] Mblock; }
// return size of block
unsigned int blocksize() const { return(Mblocksize); }
// return byte size of block
unsigned int bytesize() const
{ return(this->blocksize()*sizeof(Tvalue)); }
// return pointer to first data value
Tvalue* block() const { return(Mblock); }
// return pointer to any data value
Tvalue operator[](const unsigned int& i) { return(Mblock[i]); }
private:
// pointer to block
Tvalue* Mblock;
// size of block
unsigned int Mblocksize;
}; // MiniSEEDblock
/*! The input operator for MiniSEEDblock allows to read data into a
* MiniSEEdblock instance from any istream.
*/
inline std::istream& operator >> (std::istream& is, MiniSEEDblock& mb)
{ is.read(mb.block(), mb.bytesize()); return(is); }
/*----------------------------------------------------------------------*/
/*! MiniSEED reading class
*
* Create an instance of this class by passing an input stream to its
* constructor. It will handle MiniSEED reading from thif stream.
*/
class MiniSEEDReader {
public:
MiniSEEDReader(std::istream& is): Mis(is) { }
private:
// reference to input stream
std::istream& Mis;
}; // MiniSEEDReader
/*======================================================================*/
// functions
......
/*! \file seedstructs.cc
* \brief provide memeber functions for SEED structs (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: seedstructs.cc,v 1.1 2006-03-13 10:09:04 tforb Exp $
* \author Thomas Forbriger
* \date 10/03/2006
*
* provide memeber functions for SEED structs (implementation)
*
* notice: we use the byte swapping facilities in libtfxx
*
* Copyright (c) 2006 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 10/03/2006 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_SEEDSTRUCTS_CC_VERSION \
"TF_SEEDSTRUCTS_CC V1.0 "
#define TF_SEEDSTRUCTS_CC_CVSID \
"$Id: seedstructs.cc,v 1.1 2006-03-13 10:09:04 tforb Exp $"
#include<datreadxx/seedstructs.h>
#include<tfxx/bytesex.h>
namespace datread {
namespace mseed {
namespace SEED {
#define SWAPIT( A ) A=tfxx::ioswap::swap(A)
void BTIME::swap()
{
SWAPIT(year);
SWAPIT(doy);
SWAPIT(hour);
SWAPIT(min);
SWAPIT(sec);
SWAPIT(zero);
SWAPIT(tmilsec);
} // void BTIME::swap() const
void FixedDataRecordHeader::swap()
{
stime.swap();
SWAPIT(nsamp);
SWAPIT(srate);
SWAPIT(srmult);
SWAPIT(tcorr);
SWAPIT(dbeg);
SWAPIT(fblock);
} // void FixedDataRecordHeader::swap() const
void DataRecordBlocketteHeader::swap()
{
SWAPIT(type);
SWAPIT(next);
} // void DataRecordBlocketteHeader::swap() const
void DataOnlySEEDBlockette::swap()
{
blocketteheader.swap();
} // void DataOnlySEEDBlockette::swap() const
void DataExtensionBlockette::swap()
{
blocketteheader.swap();
} // void DataExtensionBlockette::swap() const
} // namespace SEED
} // namespace mseed
} // namespace datread
#undef SWAPIT
/* ----- END OF seedstructs.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: seedstructs.h,v 1.3 2006-01-13 10:36:39 tforb Exp $
* $Id: seedstructs.h,v 1.4 2006-03-13 10:09:05 tforb Exp $
* \author Thomas Forbriger
* \date 16/07/2004
*
......@@ -23,7 +23,7 @@
#define TF_SEEDSTRUCTS_H_VERSION \
"TF_SEEDSTRUCTS_H V1.0 "
#define TF_SEEDSTRUCTS_H_CVSID \
"$Id: seedstructs.h,v 1.3 2006-01-13 10:36:39 tforb Exp $"
"$Id: seedstructs.h,v 1.4 2006-03-13 10:09:05 tforb Exp $"
namespace datread {
......@@ -55,11 +55,17 @@ namespace datread {
*/
namespace SEED {
template<class C>
void copy_from_pointer(C* target, const char* p)
{ *target = *((C*)(p)); }
/*! a structure to hold any control header
*
* see chapter 3, page 34 on "How to Assemble Control Headers"
*/
struct ControlHeader {
ControlHeader() { }
ControlHeader(const char* p) { copy_from_pointer(this, p); }
char seqno[6];
char type;
char cont;
......@@ -73,6 +79,8 @@ namespace datread {
* See DataRecordBlocketteHeader below.
*/
struct BlocketteHeader {
BlocketteHeader() { }
BlocketteHeader(const char* p) { copy_from_pointer(this, p); }
char type[3];
char len[4];
}; // BlocketteHeader
......@@ -117,6 +125,13 @@ namespace datread {
* see chapter 3, page 35.
*/
struct BTIME {
BTIME() { }
BTIME(const char* p, const bool& swap=false)
{
copy_from_pointer(this, p);
if (swap) { this->swap(); }
}
void swap();
unsigned short int year;
unsigned short int doy;
unsigned char hour;
......@@ -131,6 +146,13 @@ namespace datread {
* see chapter 8, page 92.
*/
struct FixedDataRecordHeader {
FixedDataRecordHeader() { }
FixedDataRecordHeader(const char* p, const bool& doswap=false)
{
copy_from_pointer(this, p);
if (doswap) { this->swap(); }
}
void swap();
ControlHeader controlheader; //!< control header with sequence number
char stat[5]; //!< station identifier code
char loc[2]; //!< location identifier
......@@ -152,6 +174,13 @@ namespace datread {
/*! s structure to hold a data record blockette header
*/
struct DataRecordBlocketteHeader {
DataRecordBlocketteHeader() { }
DataRecordBlocketteHeader(const char* p, const bool& swap=false)
{
copy_from_pointer(this, p);
if (swap) { this->swap(); }
}
void swap();
unsigned short int type; //!< Blockette type
unsigned short int next; //!< Next blockette's byte number
}; // DataRecordBlocketteHeader
......@@ -161,6 +190,13 @@ namespace datread {
* [1000] Data Only SEED Blockette
*/
struct DataOnlySEEDBlockette {
DataOnlySEEDBlockette() { }
DataOnlySEEDBlockette(const char* p, const bool& swap=false)
{
copy_from_pointer(this, p);
if (swap) { this->swap(); }
}
void swap();
DataRecordBlocketteHeader blocketteheader;
unsigned char format; //!< Encoding Format
unsigned char bytesex; //!< Word order
......@@ -173,6 +209,13 @@ namespace datread {
* [1001] Data Extension Blockette
*/
struct DataExtensionBlockette {
DataExtensionBlockette() { }
DataExtensionBlockette(const char* p, const bool& swap=false)
{
copy_from_pointer(this, p);
if (swap) { this->swap(); }
}
void swap();
DataRecordBlocketteHeader blocketteheader;
unsigned char tquality; //!< Timing quality
unsigned char usec; //!< microseconds
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mseedtest.cc,v 1.2 2004-07-19 07:22:02 tforb Exp $
* $Id: mseedtest.cc,v 1.3 2006-03-13 10:09:05 tforb Exp $
* \author Thomas Forbriger
* \date 15/07/2004
*
......@@ -19,7 +19,7 @@
#define MSEEDTEST_VERSION \
"MSEEDTEST V1.0 test mini-SEED reading"
#define MSEEDTEST_CVSID \
"$Id: mseedtest.cc,v 1.2 2004-07-19 07:22:02 tforb Exp $"
"$Id: mseedtest.cc,v 1.3 2006-03-13 10:09:05 tforb Exp $"
#include <fstream>
#include <iostream>
......@@ -105,34 +105,30 @@ int main(int iargc, char* argv[])
std::cout << "file: " << filename << std::endl;
std::ifstream ifs(filename.c_str());
datread::mseed::AnyBlock datablock;
cout << "sizeof(datread::mseed::DataBlock): "
<< sizeof(datread::mseed::DataBlock) << endl;
cout << "sizeof(datread::mseed::AnyBlock): "
<< sizeof(datread::mseed::AnyBlock) << endl;
cout << "datread::mseed::block_size: "
<< datread::mseed::block_size << endl;
int iblock=0;
ifs.read(&datablock.buffer, sizeof(datablock));
datread::mseed::MiniSEEDblock block;
ifs >> block;
while (ifs.good())
{
iblock++;
cout << endl << "block #" << iblock << endl;
std::string seqnum(datablock.db.header.header.seqno, 6);
datread::mseed::SEED::ControlHeader controlheader(block.block());
std::string seqnum(controlheader.seqno, 6);
cout << "seqno: #" << seqnum << "#"
<< datablock.db.header.header.type
<< controlheader.type
<< "-"
<< datablock.db.header.header.cont
<< controlheader.cont
<< endl;
cout << "blockette1000: "
<< datablock.db.blockette1000.type
<< datablock.db.blockette1000.next
<< endl;
cout << "blockette1001: "
<< datablock.db.blockette1001.type
<< datablock.db.blockette1001.next
<< endl;
ifs.read(&datablock.buffer, sizeof(datablock));
if (controlheader.type == 'D')
{
datread::mseed::SEED::FixedDataRecordHeader
dataheader(block.block(),true);
cout << "data header!" << endl;
cout << "contains " << int(dataheader.numblock)
<< " blockette(s)" << endl;
cout << "data starts at offset " << int(dataheader.fblock) << endl;
}
ifs >> block;
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment