Commit 999678da 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: 2113
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 0140262b
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: seedstructs.cc,v 1.5 2006-03-28 16:07:46 tforb Exp $
* $Id: seedstructs.cc,v 1.6 2006-05-09 16:36:38 tforb Exp $
* \author Thomas Forbriger
* \date 10/03/2006
*
......@@ -31,13 +31,14 @@
*
* REVISIONS and CHANGES
* - 10/03/2006 V1.0 Thomas Forbriger
* - 09/05/2006 V1.1 introduced Steim 2 code
*
* ============================================================================
*/
#define TF_SEEDSTRUCTS_CC_VERSION \
"TF_SEEDSTRUCTS_CC V1.0 "
"TF_SEEDSTRUCTS_CC V1.1 "
#define TF_SEEDSTRUCTS_CC_CVSID \
"$Id: seedstructs.cc,v 1.5 2006-03-28 16:07:46 tforb Exp $"
"$Id: seedstructs.cc,v 1.6 2006-05-09 16:36:38 tforb Exp $"
#include<datreadxx/seedstructs.h>
#include<datreadxx/error.h>
......@@ -92,95 +93,139 @@ namespace datread {
blocketteheader.swap();
} // void DataExtensionBlockette::swap()
void Steim1Frame::swap()
/*======================================================================*/
SteimFrame::ESteimControl SteimFrame::ctrl(const int& i) const
{
unsigned int code = ((control >> ((nwords-i-1)*2)) & 0x03);
return(ESteimControl(code));
} // SteimFrame::ESteimControl SteimFrame::ctrl(const int& i) const
/*======================================================================*/
virtual void Steim1Frame::swap()
{
SWAPIT(this->control);
for (int i=0; i<nelements; ++i)
Steim1Word w;
SWAPIT(this->Mdata.control);
for (int i=0; i<nwords; ++i)
{
w.fw=this->Mdata.word[i];
switch(this->ctrl(i)) {
case Fspecial:
SWAPIT(w[i].fw);
case Ffw:
SWAPIT(w.fw);
break;
case Fbyte:
SWAPIT(w[i].byte[0]);
SWAPIT(w[i].byte[1]);
SWAPIT(w[i].byte[2]);
SWAPIT(w[i].byte[3]);
SWAPIT(w.byte[0]);
SWAPIT(w.byte[1]);
SWAPIT(w.byte[2]);
SWAPIT(w.byte[3]);
break;
case Fhw:
SWAPIT(w[i].hw[0]);
SWAPIT(w[i].hw[1]);
break;
case Ffw:
SWAPIT(w[i].fw);
SWAPIT(w.hw[0]);
SWAPIT(w.hw[1]);
break;
default:
DATREAD_abort("ERROR (Steim1Frame::swap()): illegal code");
}
this->Mdata.word[i]=w.fw;
}
} // void Steim1Frame::swap()
} // virtual void Steim1Frame::swap()
Steim1Frame::ESteim1Control Steim1Frame::ctrl(const int& i) const
/*======================================================================*/
virtual void Steim2Frame::swap()
{
unsigned int code = ((control >> ((nelements-i-1)*2)) & 0x03);
return(ESteim1Control(code));
} // Steim1Frame::ESteim1Control Steim1Frame::ctrl(const int& i) const
Steim1Word w;
SWAPIT(this->Mdata.control);
for (int i=0; i<nwords; ++i)
{
w.fw=this->Mdata.word[i];
switch(this->ctrl(i)) {
case Fspecial:
case Fdnib1:
case Fdnib2:
SWAPIT(w.fw);
break;
case Fbyte:
SWAPIT(w.byte[0]);
SWAPIT(w.byte[1]);
SWAPIT(w.byte[2]);
SWAPIT(w.byte[3]);
break;
default:
DATREAD_abort("ERROR (Steim2Frame::swap()): illegal code");
}
this->Mdata.word[i]=w.fw;
}
} // virtual void Steim2Frame::swap()
/*======================================================================*/
/*----------------------------------------------------------------------*/
void Steim1Reader::reset()
void SteimFrame::reset()
{
Mielement=0;
Minumber=0;
Miword=0;
Midiff=0;
Mvalid=true;
setn();
} // void Steim1Reader::reset()
} // void SteimFrame::reset()
/*----------------------------------------------------------------------*/
void SteimFrame::next()
{
++Midiff;
if (Midiff == Mn) { ++Miword; Midiff=0; }
if (Miword == Steim1Frame::nwords) { Mvalid=false; }
if (Mvalid) { setn(); }
} // void SteimFrame::next()
/*======================================================================*/
/* Steim 1 Reader code
* -------------------
*/
void Steim1Reader::setn()
void Steim1Frame::setn()
{
switch(this->ctrl()) {
case Steim1Frame::Fspecial:
case SteimFrame::Fspecial:
Mn=1;
break;
case Steim1Frame::Fbyte:
case SteimFrame::Fbyte:
Mn=4;
break;
case Steim1Frame::Fhw:
case SteimFrame::Fhw:
Mn=2;
break;
case Steim1Frame::Ffw:
case SteimFrame::Ffw:
Mn=1;
break;
default:
DATREAD_abort("ERROR (Steim1Reader::setn()): illegal code");
DATREAD_abort("ERROR (Steim1Frame::setn()): illegal code");
}
} // void Steim1Reader::setn()
} // void Steim1Frame::setn()
void Steim1Reader::next()
{
++Minumber;
if (Minumber == Mn) { ++Mielement; Minumber=0; }
if (Mielement == Steim1Frame::nelements) { Mvalid=false; }
if (Mvalid) { setn(); }
} // void Steim1Reader::next()
/*----------------------------------------------------------------------*/
int Steim1Reader::diff() const
int Steim1Frame::diff() const
{
int retval=0;
Steim1Word w;
w.fw=this->word();
if (Mvalid)
{
switch(this->ctrl()) {
case Steim1Frame::Fspecial:
retval=Mframe.w[Mielement].fw;
case SteimFrame::Fspecial:
retval=w.fw;
break;
case Steim1Frame::Fbyte:
retval=int(Mframe.w[Mielement].byte[Minumber]);
case SteimFrame::Fbyte:
retval=int(w.byte[Minumber]);
break;
case Steim1Frame::Fhw:
retval=Mframe.w[Mielement].hw[Minumber];
case SteimFrame::Fhw:
retval=w.hw[Minumber];
break;
case Steim1Frame::Ffw:
retval=Mframe.w[Mielement].fw;
case SteimFrame::Ffw:
retval=w.fw;
break;
default:
DATREAD_abort("ERROR (Steim1Reader::diff()): illegal code");
......@@ -188,7 +233,164 @@ namespace datread {
}
// std::cout << " ** diff is " << retval << std::endl;
return(retval);
} // int Steim1Reader::diff()
} // int Steim1Frame::diff()
/*======================================================================*/
/* Steim 2 Reader code
* -------------------
*/
void Steim2Frame::setn()
{
Steim2Word w(this->ctrl(), this->word());
Mn=w.nval();
} // void Steim2Frame::setn()
/*----------------------------------------------------------------------*/
int Steim2Frame::diff() const
{
Steim2Word w(this->ctrl(), this->word());
int retval=w.value(Midiff);
return(retval);
} // int Steim2Frame::diff()
/*======================================================================*/
/* Steim 2 Word code
* -----------------
*/
int Steim2Word::dnib() const
{
return(int((Mword >> 30) & 0x03));
} // int Steim2Word::dnib() const
/*----------------------------------------------------------------------*/
int Steim2Word::nval() const
{
int retval=0;
switch (Mctrl) {
case Steim2Word::Fspecial:
retval=1;
break;
case Steim2Word::Fbyte:
retval=4;
break;
case Steim2Word::Fdnib1:
switch (this->dnib()) {
case Steim2Word::Fdnib01:
retval=1;
break;
case Steim2Word::Fdnib10:
retval=2;
break;
case Steim2Word::Fdnib11:
retval=3;
break;
default:
DATREAD_abort("ERROR (Steim2Word::value): "
"illegal decode nibble");
}
break;
case Steim2Word::Fdnib2:
switch (this->dnib()) {
case Steim2Word::Fdnib00:
retval=5;
break;
case Steim2Word::Fdnib01:
retval=6;
break;
case Steim2Word::Fdnib10:
retval=7;
break;
default:
DATREAD_abort("ERROR (Steim2Word::value): "
"illegal decode nibble");
}
break;
default:
DATREAD_abort("ERROR (Steim2Word::value): illegal ctrl code");
}
return(retval);
} // int Steim2Word::nval() const
/*----------------------------------------------------------------------*/
int Steim2Word::value(const int& i) const
{
int nval=this->nval();
DATREAD_assert((i<nval),
"ERROR (Steim2Word::value): "
"illegal value index");
int retval=0;
--nval;
switch (Mctrl) {
case Steim2Word::Fspecial:
retval=Mword;
break;
case Steim2Word::Fbyte:
retval=this->extract(8,nval-i);
break;
case Steim2Word::Fdnib1:
switch (this->dnib()) {
case Steim2Word::Fdnib01:
retval=this->extract(30,0);
break;
case Steim2Word::Fdnib10:
retval=this->extract(15,nval-i);
break;
case Steim2Word::Fdnib11:
retval=this->extract(10,nval-i);
break;
default:
DATREAD_abort("ERROR (Steim2Word::value): "
"illegal decode nibble");
}
break;
case Steim2Word::Fdnib2:
switch (this->dnib()) {
case Steim2Word::Fdnib00:
retval=this->extract(6,nval-i);
break;
case Steim2Word::Fdnib01:
retval=this->extract(5,nval-i);
break;
case Steim2Word::Fdnib10:
retval=this->extract(4,nval-i);
break;
default:
DATREAD_abort("ERROR (Steim2Word::value): "
"illegal decode nibble");
}
break;
default:
DATREAD_abort("ERROR (Steim2Word::value): illegal ctrl code");
}
return(retval);
} // int Steim2Word::value(const int& p) const
/*----------------------------------------------------------------------*/
int Steim2Word::extract(const int& b, const int& p) const
{
DATREAD_assert((b>0), "ERROR (Steim2Word::extract): "
"use at least 1 byte");
DATREAD_assert((p>=0), "ERROR (Steim2Word::extract): "
"illegal position");
DATREAD_assert((p<int(32/b)), "ERROR (Steim2Word::extract): "
"illegal position");
int signmask=int(1 << (b-1));
int valmask=signmask - 1;
int nshift=b*p;
// extract sign bit
int sign=int((Mword >> nshift) & signmask);
// extract value bit code
int value=int((Mword >> nshift) & valmask);
// construct 32-bit (int size) two's complement value
int retval= sign ? (value | ~valmask) : value;
return(retval);
} // int Steim2Word::extract(const int& p) const
} // namespace SEED
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: seedstructs.h,v 1.12 2006-04-28 08:44:33 tforb Exp $
* $Id: seedstructs.h,v 1.13 2006-05-09 16:36:38 tforb Exp $
* \author Thomas Forbriger
* \date 16/07/2004
*
......@@ -31,6 +31,8 @@
* - 16/07/2004 V1.0 Thomas Forbriger
* - 28/04/2006 V1.1 long int appears to be of
* implementation dependent size
* - 09/05/2006 V1.2 introduced Steim 2 code
* SteimFrame now does all that Steim1Reader did
*
* ============================================================================
*/
......@@ -39,9 +41,9 @@
#ifndef TF_SEEDSTRUCTS_H_VERSION
#define TF_SEEDSTRUCTS_H_VERSION \
"TF_SEEDSTRUCTS_H V1.1"
"TF_SEEDSTRUCTS_H V1.2"
#define TF_SEEDSTRUCTS_H_CVSID \
"$Id: seedstructs.h,v 1.12 2006-04-28 08:44:33 tforb Exp $"
"$Id: seedstructs.h,v 1.13 2006-05-09 16:36:38 tforb Exp $"
namespace datread {
......@@ -381,52 +383,169 @@ namespace datread {
/*----------------------------------------------------------------------*/
/*! a structure holding a Steim 1 frame
/*! a class to hold a four-byte word in a Steim 2 frame
*
* A Steim 2 frame knows eight different types of data encoding:
* - c=00 special (like Steim 1)
* - c=01 four 1 Byte (8 Bit) differences (like Steim 1)
* - c=10 look for dnib (high order two bits) in data word
* - dnib=01 one 30-bit difference
* - dnib=10 two 15-bit differences
* - dnib=11 three 10-bit differences
* - c=11 look for dnib (high order two bits) in data word
* - dnib=00 five 6-bit differences
* - dnib=01 six 5-bit differences
* - dnib=10 seven 4-bit differences
*/
struct Steim1Frame {
Steim1Frame() { }
Steim1Frame(const char* p, const bool& swap=false)
{
//copy_from_pointer(p);
datread::mseed::SEED::copy_from_pointer(this, p);
if (swap) { this->swap(); }
}
void swap();
enum ESteim1Control {
Fspecial=0, //!< contains non-data information, like headers
Fbyte=1, //!< four 8-bit differences (byte)
Fhw=2, //!< two 16-bit differences (halfword)
Ffw=3 //!< one 32-bit difference (fullword)
}; // enum ESteim1Control
static const int nelements=15;
static const int blocksize=16*sizeof(int);
ESteim1Control ctrl(const int& i) const;
unsigned int control; //!< control flags
Steim1Word w[nelements]; //!< compressed data
}; // struct Steim1Frame
class Steim2Word {
public:
enum ESteim2Control {
Fspecial=0, //!< contains non-data information, like headers
Fbyte=1, //!< four 8-bit differences (byte)
Fdnib1=2, //!< check dnib
Fdnib2=3 //!< check dnib
}; // enum ESteim1Control
enum ESteim2dnib {
Fdnib00=0,
Fdnib01=1,
Fdnib10=2,
Fdnib11=3
}; // enum ESteim2dnib
//! store control code and data word
Steim2Word(const ESteim2Control& c, const int& word):
Mctrl(c), Mword(word) { };
//! return dnib
int dnib() const;
/*! return value
*
* \arg \c i index in word
*/
int value(const int& i) const;
//! return number of values in this word
int nval() const;
private:
/*! return masked value
*
* \arg \c b number of bits
* \arg \c p position in word
*/
int extract(const int& b, const int& p) const;
ESteim2Control Mctrl;
int Mword;
}; // class Steim2Word
/*----------------------------------------------------------------------*/
/*! wrapper class to read from Steim 1 Frame
/*! a base class to handle a Steim frame
*
* We explicitely distinguish between Steim 1 and Steim 2 frames,
* since data swapping differs for them.
*/
class Steim1Reader {
class SteimFrame {
public:
Steim1Reader(const Steim1Frame& frame):
Mframe(frame), Mielement(0), Minumber(0), Mvalid(true) { reset(); }
int diff() const;
//! numer of words to process
static const int nwords=15;
//! size of frame in bytes
static const int blocksize=16*sizeof(int);
//! possible control codes
enum ESteimControl {
Fspecial=0, //!< contains non-data information, like headers
Fbyte=1, //!< four 8-bit differences (byte)
Fhw=2, //!< two 16-bit differences (halfword)
Ffw=3, //!< one 32-bit difference (fullword)
Fdnib1=2, //!< check dnib
Fdnib2=3 //!< check dnib
}; // enum ESteimControl
//! struct to hold frame data
struct FrameData {
//! read
FrameData(const char* p)
{ datread::mseed::SEED::copy_from_pointer(this, p); }
//! control flags
unsigned int control;
//! data buffer
int word[nwords];
}; // struct FrameData
virtual ~SteimFrame() { }
//! return control code for word \c i
ESteimControl ctrl(const int& i) const;
//! return data word \c i
int word(const int& i) const { return(Mdata.word[i]); }
//! return current data word
int word() const { return(this->word(this->iword())); }
//! read data from pointer
void read(const char* p, const bool& swap=false)
{
Mdata=FrameData(p);
if (swap) { this->swap(); }
}
//! return current difference value
virtual int diff() const;
//! we are still inside the frame
bool valid() const { return(Mvalid); }
Steim1Frame::ESteim1Control ctrl() const
{ return(Mframe.ctrl(Mielement)); }
//! return control code for current word
SteimFrame::ESteimControl ctrl() const
{ return(Mdata.ctrl(this->iword())); }
//! step to next difference value
void next();
//! step to first difference value
void reset();
protected:
//! swapping must be performed differently for Steim1 and Steim2
virtual void swap();
//! read data to buffer
Steim1Frame(const char* p, const bool& swap=false):
Mdata(p), Mn(0), Miword(0), Midiff(0), Mvalid(true)
{
if (swap) { this->swap(); }
reset();
}
//! return current word index
int iword() const { return(Miword); }
//! return current difference index
int idiff() const { return(Midiff); }
//! frame data (swapped)
FrameData Mdata;
//! number of differences in this word
int Mn;
//! set Mn for current word (compression type specific)
virtual void setn();
private:
void setn();
Steim1Frame Mframe;
int Mielement;
int Minumber;
//! current word in frame
int Miword;
//! current difference value in word
int Midiff;
//! we are still inside the current frame
bool Mvalid;
int Mn;
}; // Steim1Reader
}; // class SteimFrame
/*----------------------------------------------------------------------*/
/*! a structure holding a Steim 1 frame
*/
class Steim1Frame: public SteimFrame {
public:
typedef SteimFrame Tbase;
virtual ~Steim1Frame() { }
Steim1Frame(const char* p, const bool& swap=false):
Tbase(p, swap) { }
virtual void swap();
virtual void setn();
}; // class Steim1Frame
/*----------------------------------------------------------------------*/
/*! a structure holding a Steim 2 frame
*/
class Steim2Frame: public SteimFrame {
public:
typedef SteimFrame Tbase;
virtual ~Steim2Frame() { }
Steim2Frame(const char* p, const bool& swap=false):
Tbase(p, swap) { }