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

independent of libtfxx

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: 2333
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 5e584c87
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.32 2007-06-29 12:33:32 tforb Exp $
# $Id: Makefile,v 1.33 2007-06-29 13:20:52 tforb Exp $
#
# Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
#
......@@ -36,7 +36,8 @@ HEADERS=$(wildcard *.h */*.h)
HEADERS=datread.h bonjer.h bonjer/readbonjer.h readany.h error.h \
pdas.h pdas/pdasread.h pdas/pdasflags.h mseed/seedstructdump.h \
sff.h mseed.h mseed/mseedread.h mseed/seedstructs.h \
hpmo.h hpmo/readhpmo.h hpmo/hpmodata.h util.h sac.h sac/sacread.h
hpmo.h hpmo/readhpmo.h hpmo/hpmodata.h util.h sac.h sac/sacread.h \
bytesex.h debug.h
#SRC=misc/fortranio.cc misc/commandline.cc misc/ioswap.cc misc/error.cc \
# misc/blitzfortranio.cc hacks/hack_blitztogrepg.cc
......@@ -45,7 +46,7 @@ LIBSRC=datread.cc bonjer/bonjer.cc bonjer/readbonjer.cc readany.cc error.cc \
pdas/pdas.cc pdas/pdasread.cc mseed/seedstructdump.cc \
sff/sff.cc mseed/mseedread.cc mseed/mseed.cc mseed/seedstructs.cc \
hpmo/hpmo.cc hpmo/readhpmo.cc hpmo/hpmodata.cc \
util.cc sac/sac.cc sac/sacread.cc
util.cc sac/sac.cc sac/sacread.cc bytesex.cc
TESTSRC=tests/hpmotest.cc tests/pdastest.cc tests/mseedtest.cc \
tests/sfftest.cc tests/sactest.cc
......
/*! \file bytesex.cc
* \brief a copy of libtfxx ioswap.cc (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: bytesex.cc,v 1.1 2007-06-29 13:20:52 tforb Exp $
* \author Thomas Forbriger
* \date 29/06/2007
*
* a copy of libtfxx ioswap.cc (implementation)
* just to make libdatread more independent
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
* Copyright (c) 2007 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 29/06/2007 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_DATREAD_BYTESEX_CC_VERSION \
"TF_DATREAD_BYTESEX_CC V1.3"
#define TF_DATREAD_BYTESEX_CC_CVSID \
"$Id: bytesex.cc,v 1.1 2007-06-29 13:20:52 tforb Exp $"
#include <datread/bytesex.h>
#include <datread/error.h>
#include <iostream>
using std::cout;
using std::endl;
namespace datread {
namespace util {
//----------------------------------------------------------------------
//! function to create the magic number
int magic(const char* const cmagic)
{
union {
unsigned int uival;
int ival;
} out;
union {
char chr[sizeof(int)];
unsigned char uchr[sizeof(int)];
} in;
const int& intsize=sizeof(int);
for (int i=0; i<intsize; i++)
{ in.chr[i]=cmagic[i]; }
out.uival=0;
for (int i=0; i<intsize; i++)
{ out.uival=out.uival*256+in.uchr[i]; }
return(out.ival);
} // magic()
/*----------------------------------------------------------------------*/
//! check for my CPU model
Ecpu_type cpu()
{
Ecpu_type result=cpu_unknown;
IOUnion<int> u1,u2;
DATREAD_assert((sizeof(int) == 4),
"The integer memory size on this CPU differs from the"
"required value of 4");
const int& intsize=sizeof(int);
char test_seq[]="ABCD";
// prepare sequence and reverse sequence
for (int i=0; i<intsize; i++)
{
u1.bytes[i]=test_seq[i];
u2.bytes[i]=test_seq[intsize-i-1];
}
// request magic number for sequence
int magnum=magic(u1.bytes);
// test against byte representation of sequence and reverse sequence
if (magnum == u1.value)
{
result=cpu_Motorola;
}
else if (magnum == u2.value)
{
result=cpu_Intel;
}
return(result);
} // cpu()
} // namespace util
} // namespace datread
/* ----- END OF bytesex.cc ----- */
/*! \file bytesex.h
* \brief A copy of bytesex.h from libtfxx (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: bytesex.h,v 1.1 2007-06-29 13:20:52 tforb Exp $
* \author Thomas Forbriger
* \date 29/06/2007
*
* A copy of bytesex.h from libtfxx (prototypes)
*
* just to make libdatread a bit more independent
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
* Copyright (c) 2007 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 29/06/2007 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_DATREAD_BYTESEX_H_VERSION
#define TF_DATREAD_BYTESEX_H_VERSION \
"TF_DATREAD_BYTESEX_H V1.0"
#define TF_DATREAD_BYTESEX_H_CVSID \
"$Id: bytesex.h,v 1.1 2007-06-29 13:20:52 tforb Exp $"
// we include fstream, because all function are closely related to file I/O
// and file_magic definitely requires fstream
#include<fstream>
namespace datread {
namespace util {
/*! \defgroup group_bytesex I/O byte swapping facility.
* \brief Provides function to check bytesex and swap input bytes.
*
* When working in a multi-CPU-model environment, data written on one host
* (with Intel CPU e.g.) can not easily be read on a different host (with
* Motorola CPU e.g.) when using binary data. In this group we provide
* facilities to check bytesex of datafiles and perform byte-swapping if
* necessary.
*
* \ref anchor_fortranio_firsttest "Tests on this module" were performed
* within tests of the \ref group_fortranio.
*
* \sa example_fortraniotest
* \sa group_fortranio
* \sa bytesex_h
*
* The components are collected in namespace datread::util.
* @{
*/
//----------------------------------------------------------------------
//
// we start with a set of useful types and enums
/*! A union to support raw I/O.
*
* \arg \c value the numerical value
* \arg \c bytes the raw byte representation
*/
template<typename T>
union IOUnion {
T value;
char bytes[sizeof(T)];
};
//! Define different CPU type that are recognized
enum Ecpu_type {
//! Intel CPU
cpu_Intel = 1,
//! Motorola CPU
cpu_Motorola = 2,
//! unknown CPU
cpu_unknown = 3
};
//! Define bytesex indicator for magic number test
enum Emagic_type {
//! The bytesex of the file matches this machine
magic_match = 1,
//! The bytesex of the file must be swapped to match this machine
magic_swap = 2,
//! The magic number does match the file
magic_nomatch = 3
};
/*!
* @} end of group_bytesex
*/
//----------------------------------------------------------------------
//
// some function templates
/*! \brief How to swap any generic type
*/
template<class T>
T swap(const T& value)
{
IOUnion<T> in, out;
in.value=value;
out=swap(in);
return(out.value);
}
/*! \brief Specialization in case we use use an IOUnion.
* i.e. overloading the function
*/
template<class T>
IOUnion<T> swap(const IOUnion<T>& value)
{
IOUnion<T> result;
for (unsigned int i=0; i<sizeof(T); i++)
{ result.bytes[i]=value.bytes[sizeof(T)-i-1]; }
return(result);
}
//----------------------------------------------------------------------
//
// some binary function
/*! \brief Create a magic number from a character string.
* \ingroup group_ioswap, bytesex_h
*
* If \f$x_{i}=(\vec{x})_{i}\f$ represents the input character sequence \c
* cmagic and \f$N=4\f$ is the value of \c sizeof(int), then the return
* value will be
* \f[
* \textrm{magic}(\vec{x})
* =\sum\limits_{i=0}^{N-1} x_{i}\; 2^{8\; (N-1-i)}
* =x_{3}+256\; (x_{2}+256\; (x_{1}+256\; x_{0})).
* \f]
*
* \param cmagic 4-byte character sequence representing magic number (most
* restrictive: pass a const pointer to a const char)
* is pointer to character array of size sizeof(int)
* \return The magic number representing the 4-byte character sequence on
* your system
*/
int magic(const char* const cmagic);
/*! \brief Check CPU model.
* \ingroup group_ioswap, bytesex_h
* \return return value indicates the CPU model found
*/
Ecpu_type cpu();
} // namespace util
} // namespace datread
#endif // TF_DATREAD_BYTESEX_H_VERSION (includeguard)
/* ----- END OF bytesex.h ----- */
/*! \file debug.h
* \brief macro function for debugging output (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: debug.h,v 1.1 2007-06-29 13:20:52 tforb Exp $
* \author Thomas Forbriger
* \date 29/06/2007
*
* macro function for debugging output (prototypes)
*
* Copyright (c) 2007 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 29/06/2007 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_DEBUG_H_VERSION
#define TF_DEBUG_H_VERSION \
"TF_DEBUG_H V1.0 "
#define TF_DEBUG_H_CVSID \
"$Id: debug.h,v 1.1 2007-06-29 13:20:52 tforb Exp $"
/*! \brief produce debug output
* \ingroup misc_h
*
* \param C output will be generated if C == true
* \param N name of function
* \param M message to print
*/
#define DATREAD_debug(C,N,M) \
if (C) { \
std::cerr << "DEBUG (" << N << ", " \
<< __FILE__ << " line #" << __LINE__ << "):" << std::endl \
<< " " << M << std::endl; \
std::cerr.flush(); \
}
#endif // TF_DEBUG_H_VERSION (includeguard)
/* ----- END OF debug.h ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mseed.cc,v 1.11 2006-07-24 13:52:27 tforb Exp $
* $Id: mseed.cc,v 1.12 2007-06-29 13:20:53 tforb Exp $
* \author Thomas Forbriger
* \date 15/07/2004
*
......@@ -31,19 +31,20 @@
* - 15/07/2004 V1.0 Thomas Forbriger
* - 24/07/2006 V1.1 reading function was not comparing record start
* time against expected record start time
* - 29/06/2007 V1.2 prefer to use our own functions
*
* ============================================================================
*/
#define TF_MSEED_CC_VERSION \
"TF_MSEED_CC V1.1"
"TF_MSEED_CC V1.2"
#define TF_MSEED_CC_CVSID \
"$Id: mseed.cc,v 1.11 2006-07-24 13:52:27 tforb Exp $"
"$Id: mseed.cc,v 1.12 2007-06-29 13:20:53 tforb Exp $"
#include <datreadxx/util.h>
#include <datreadxx/mseed.h>
#include <datreadxx/mseedread.h>
#include <aff/subarray.h>
#include <tfxx/misc.h>
#include <datreadxx/debug.h>
#include <vector>
#include <string>
......@@ -80,7 +81,7 @@ namespace datread {
* ahead.
*/
Mis >> this->Mrecord;
TFXX_debug(Mdebug, "Mrecord read", Mrecord.wid2.line());
DATREAD_debug(Mdebug, "Mrecord read", Mrecord.wid2.line());
} // imseedstream::imseedstream(std::istream& is, const bool& debug)
/*----------------------------------------------------------------------*/
......@@ -118,7 +119,7 @@ namespace datread {
*/
Tiseries imseedstream::read(const bool& skipdata)
{
TFXX_debug(Mdebug, "imseedstream::read", "entered reading function");
DATREAD_debug(Mdebug, "imseedstream::read", "entered reading function");
typedef std::vector<Tiseries> Tvecofrecorddata;
Tvecofrecorddata vecofrecorddata;
DATREAD_assert(Mrecord.valid,
......@@ -138,39 +139,39 @@ namespace datread {
| sff::Fvang);
// collect data
TFXX_debug(Mdebug, "imseedstream::read", "collect data");
DATREAD_debug(Mdebug, "imseedstream::read", "collect data");
sff::WID2 nextwid2=wid2line;
nextwid2.date=sff::wid2nextdate(wid2line);
int nsamples=0;
bool contiguous=true;
while(Mrecord.valid && Mis.good() && contiguous)
{
TFXX_debug(Mdebug, "imseedstream::read",
DATREAD_debug(Mdebug, "imseedstream::read",
"save data from record ("
<< Mrecord.data.size() << " samples)");
Tiseries data=Mrecord.data;
if (!skipdata) { vecofrecorddata.push_back(data.copyout()); }
TFXX_debug(Mdebug, "imseedstream::read", "last data index " <<
DATREAD_debug(Mdebug, "imseedstream::read", "last data index " <<
data.last());
int xm1=data(data.last());
nsamples += Mrecord.wid2.nsamples;
TFXX_debug(Mdebug, "imseedstream::read", "read next");
DATREAD_debug(Mdebug, "imseedstream::read", "read next");
Mis >> Mrecord;
TFXX_debug(Mdebug, "imseedstream::read", "compare next");
TFXX_debug(Mdebug, "imseedstream::read", "expected wid2: " <<
DATREAD_debug(Mdebug, "imseedstream::read", "compare next");
DATREAD_debug(Mdebug, "imseedstream::read", "expected wid2: " <<
nextwid2.line());
TFXX_debug(Mdebug, "imseedstream::read", " this wid2: " <<
DATREAD_debug(Mdebug, "imseedstream::read", " this wid2: " <<
Mrecord.wid2.line());
if (Mrecord.valid)
{
if (! (wid2areequal(Mrecord.wid2, nextwid2) && (xm1 == Mrecord.xm1)))
{
contiguous=false;
TFXX_debug(Mdebug, "imseedstream::read", "non-contiguous data");
DATREAD_debug(Mdebug, "imseedstream::read", "non-contiguous data");
}
else
{
TFXX_debug(Mdebug, "imseedstream::read", "data is still contiguous");
DATREAD_debug(Mdebug, "imseedstream::read", "data is still contiguous");
}
nextwid2.date=sff::wid2nextdate(Mrecord.wid2);
}
......@@ -183,23 +184,23 @@ namespace datread {
wid2line.nsamples=nsamples;
// extract data samples
TFXX_debug(Mdebug, "imseedstream::read", "extract data");
DATREAD_debug(Mdebug, "imseedstream::read", "extract data");
Tiseries series;
if (!skipdata)
{
TFXX_debug(Mdebug, "imseedstream::read", "do not skip");
DATREAD_debug(Mdebug, "imseedstream::read", "do not skip");
Tvecofrecorddata::const_iterator I(vecofrecorddata.begin());
TFXX_debug(Mdebug, "imseedstream::read", "create buffer");
DATREAD_debug(Mdebug, "imseedstream::read", "create buffer");
series=Tiseries(0,nsamples-1);
nsamples=0;
TFXX_debug(Mdebug, "imseedstream::read", "cycle vector");
DATREAD_debug(Mdebug, "imseedstream::read", "cycle vector");
while (I != vecofrecorddata.end())
{
TFXX_debug(Mdebug, "imseedstream::read", "create dest");
DATREAD_debug(Mdebug, "imseedstream::read", "create dest");
Tiseries dest=aff::subarray(series)(nsamples,nsamples+I->size()-1);
TFXX_debug(Mdebug, "imseedstream::read", "copy to dest");
DATREAD_debug(Mdebug, "imseedstream::read", "copy to dest");
dest.copyin(*I);
TFXX_debug(Mdebug, "imseedstream::read", "step nsamples");
DATREAD_debug(Mdebug, "imseedstream::read", "step nsamples");
nsamples += I->size();
++I;
}
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mseedread.cc,v 1.23 2006-07-10 08:29:02 tforb Exp $
* $Id: mseedread.cc,v 1.24 2007-06-29 13:20:53 tforb Exp $
* \author Thomas Forbriger
* \date 15/07/2004
*
......@@ -37,19 +37,20 @@
* - 09/05/2006 V1.3 use general Steim 1 and 2 code
* - 07/07/2006 V1.4 provide debug function when reading MiniSEED record
* - 10/07/2006 V1.5 skip special words within data stream
* - 29/06/2007 V1.6 no longer use libtfxx
*
* ============================================================================
*/
#define TF_MSEEDREAD_CC_VERSION \
"TF_MSEEDREAD_CC V1.4"
"TF_MSEEDREAD_CC V1.6"
#define TF_MSEEDREAD_CC_CVSID \
"$Id: mseedread.cc,v 1.23 2006-07-10 08:29:02 tforb Exp $"
"$Id: mseedread.cc,v 1.24 2007-06-29 13:20:53 tforb Exp $"
#include <string>
#include <string.h>
#include <datreadxx/mseedread.h>
#include <datreadxx/mseed.h>
#include<tfxx/bytesex.h>
#include<datread/bytesex.h>
#include<aff/subarray.h>
namespace datread {
......@@ -179,11 +180,11 @@ namespace datread {
// SEED defines Motorola (big-endian) to be the standard byte order
// for all headers
// check our CPU type
tfxx::ioswap::Ecpu_type mysex=tfxx::ioswap::cpu();
DATREAD_assert((mysex != tfxx::ioswap::cpu_unknown),
datread::util::Ecpu_type mysex=datread::util::cpu();
DATREAD_assert((mysex != datread::util::cpu_unknown),
"ERROR (reading MiniSEED record): "
"cannot identify CPU type");
bool doswap = (mysex == tfxx::ioswap::cpu_Intel);
bool doswap = (mysex == datread::util::cpu_Intel);
Mrecordheader=SEED::FixedDataRecordHeader(block.block(), doswap);
// extract essential header fields
// Blockette1000 is essential to determine bytesex
......@@ -474,15 +475,15 @@ namespace datread {
bool needswap(const unsigned char& bytesex)
{
// my CPU type
tfxx::ioswap::Ecpu_type mysex=tfxx::ioswap::cpu();
datread::util::Ecpu_type mysex=datread::util::cpu();
// file type
tfxx::ioswap::Ecpu_type filesex=tfxx::ioswap::cpu_unknown;
datread::util::Ecpu_type filesex=datread::util::cpu_unknown;
// file type
SEED::EByteOrder byteorder=SEED::EByteOrder(int(bytesex));
if (byteorder == SEED::vax8086)
{ filesex=tfxx::ioswap::cpu_Intel; }
{ filesex=datread::util::cpu_Intel; }
else if (byteorder == SEED::sparc68000)
{ filesex=tfxx::ioswap::cpu_Motorola; }
{ filesex=datread::util::cpu_Motorola; }
bool retval=(filesex != mysex);
return(retval);
} // needswap(const unsigned char& bytesex)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: seedstructs.cc,v 1.8 2006-05-11 14:02:39 tforb Exp $
* $Id: seedstructs.cc,v 1.9 2007-06-29 13:20:53 tforb Exp $
* \author Thomas Forbriger
* \date 10/03/2006
*
......@@ -25,25 +25,24 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
* 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
* - 09/05/2006 V1.1 introduced Steim 2 code
* - 11/05/2006 V1.2 correction for reading bytes in Steim 2 Word
* - 29/06/2007 V1.3 no longer use libtfxx
*
* ============================================================================
*/
#define TF_SEEDSTRUCTS_CC_VERSION \
"TF_SEEDSTRUCTS_CC V1.2"
"TF_SEEDSTRUCTS_CC V1.3"
#define TF_SEEDSTRUCTS_CC_CVSID \
"$Id: seedstructs.cc,v 1.8 2006-05-11 14:02:39 tforb Exp $"
"$Id: seedstructs.cc,v 1.9 2007-06-29 13:20:53 tforb Exp $"
#include<datreadxx/seedstructs.h>
#include<datreadxx/error.h>
#include<tfxx/bytesex.h>
#include<datread/bytesex.h>
#include<iostream>
#include<iomanip>
......@@ -54,7 +53,7 @@ namespace datread {
namespace SEED {
#define SWAPIT( A ) A=tfxx::ioswap::swap(A)
#define SWAPIT( A ) A=datread::util::swap(A)
void BTIME::swap()
{
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sac.cc,v 1.5 2007-06-29 12:33:33 tforb Exp $
* $Id: sac.cc,v 1.6 2007-06-29 13:20:54 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2004
*
......@@ -35,7 +35,7 @@
#define TF_SAC_CC_VERSION \
"TF_SAC_CC V1.0 "
#define TF_SAC_CC_CVSID \
"$Id: sac.cc,v 1.5 2007-06-29 12:33:33 tforb Exp $"
"$Id: sac.cc,v 1.6 2007-06-29 13:20:54 tforb Exp $"
#include <string>
#include <sstream>
......@@ -53,7 +53,6 @@ namespace datread {
Tdseries isacstream::dseries()