Commit 34a321cc 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: 2980
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent b69b51f9
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README,v 1.3 2010-02-17 21:58:26 tforb Exp $
* $Id: README,v 1.4 2010-02-17 22:13:29 tforb Exp $
* \author Thomas Forbriger
* \date 11/04/2006
*
......@@ -38,7 +38,7 @@ namespace datwrite {
\since April 2006
\date February 2010 2006
\version V1.0
$Id: README,v 1.3 2010-02-17 21:58:26 tforb Exp $
$Id: README,v 1.4 2010-02-17 22:13:29 tforb Exp $
Contents of this page:
- \ref sec_concept
......@@ -62,6 +62,10 @@ $Id: README,v 1.3 2010-02-17 21:58:26 tforb Exp $
to the series is stored.
Until the series is flushed by writing the next trace, the data still can be
modified through other handles.
\note
There is not decision yet regarding this concept.
See datwrite.h for more...
*/
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: bytesex.cc,v 1.2 2010-02-17 22:00:26 tforb Exp $
* $Id: bytesex.cc,v 1.3 2010-02-17 22:13:29 tforb Exp $
* \author Thomas Forbriger
* \date 17/02/2010
*
......@@ -36,12 +36,73 @@
#define DATWRITE_BYTESEX_CC_VERSION \
"TF_BYTESEX_CC V1.0 "
#define DATWRITE_BYTESEX_CC_CVSID \
"$Id: bytesex.cc,v 1.2 2010-02-17 22:00:26 tforb Exp $"
"$Id: bytesex.cc,v 1.3 2010-02-17 22:13:29 tforb Exp $"
#include <datwritexx/bytesex.h>
#include <datwritexx/error.h>
#include <iostream>
using std::cout;
using std::endl;
namespace datwrite {
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 datwrite
/* ----- END OF bytesex.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: bytesex.h,v 1.2 2010-02-17 22:00:26 tforb Exp $
* $Id: bytesex.h,v 1.3 2010-02-17 22:13:29 tforb Exp $
* \author Thomas Forbriger
* \date 17/02/2010
*
......@@ -40,10 +40,134 @@
#define DATWRITE_BYTESEX_H_VERSION \
"TF_BYTESEX_H V1.0 "
#define DATWRITE_BYTESEX_H_CVSID \
"$Id: bytesex.h,v 1.2 2010-02-17 22:00:26 tforb Exp $"
"$Id: bytesex.h,v 1.3 2010-02-17 22:13:29 tforb Exp $"
// we include fstream, because all function are closely related to file I/O
// and file_magic definitely requires fstream
#include<fstream>
namespace datwrite {
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 datwrite
#endif // DATWRITE_BYTESEX_H_VERSION (includeguard)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: datwrite.cc,v 1.3 2010-02-17 22:00:26 tforb Exp $
* $Id: datwrite.cc,v 1.4 2010-02-17 22:13:29 tforb Exp $
* \author Thomas Forbriger
* \date 11/04/2006
*
......@@ -36,12 +36,99 @@
#define DATWRITE_DATWRITE_CC_VERSION \
"TF_DATWRITE_CC V1.0 "
#define DATWRITE_DATWRITE_CC_CVSID \
"$Id: datwrite.cc,v 1.3 2010-02-17 22:00:26 tforb Exp $"
"$Id: datwrite.cc,v 1.4 2010-02-17 22:13:29 tforb Exp $"
#include <datwritexx/datwrite.h>
namespace datwrite {
odatstream::odatstream(std::ostream& os);
Mis(is), Mwid2set(false), Msrceset(false), Minfoset(false),
Mtracefreeset(false), Mfilefreeset(false), Mlast(false),
Mprovidesd(providesd), Mprovidesf(providesf), Mprovidesi(providesi)
{
DATWRITE(is.good(), "input stream is not good!");
}
/*----------------------------------------------------------------------*/
bool odatstream::hasfree() const
{
if (Mwid2set) { return(Mtracefreeset); } else { return(Mfilefreeset); }
}
/*----------------------------------------------------------------------*/
sff::FREE odatstream::free() const
{
if (Mwid2set) { return(Mtracefree); } else { return(Mfilefree); }
}
/*----------------------------------------------------------------------*/
void odatstream::setfilefree(const sff::FREE& free)
{
Mfilefreeset=true;
Mfilefree=free;
}
/*----------------------------------------------------------------------*/
void odatstream::settracefree(const sff::FREE& free)
{
Mtracefreeset=true;
Mtracefree=free;
}
/*----------------------------------------------------------------------*/
void odatstream::setwid2(const sff::WID2& wid2)
{
Mwid2set=true;
Mwid2=wid2;
}
/*----------------------------------------------------------------------*/
void odatstream::setinfo(const sff::INFO& info)
{
Minfoset=true;
Minfo=info;
}
/*----------------------------------------------------------------------*/
void odatstream::setsrce(const sff::SRCE& srce)
{
Msrceset=true;
Msrce=srce;
}
/*----------------------------------------------------------------------*/
void odatstream::setlast()
{
Mlast=true;
}
/*----------------------------------------------------------------------*/
void odatstream::newtrace()
{
Mtracefreeset=false;
Mwid2set=false;
Minfoset=false;
Msrceset=false;
}
/*----------------------------------------------------------------------*/
void odatstream::help(std::ostream& os, char* name)
{
os << "Class " << name << " provides no help text." << std::endl;
}
} // namespace datwrite
/* ----- END OF datwrite.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: datwrite.h,v 1.4 2010-02-17 22:00:26 tforb Exp $
* $Id: datwrite.h,v 1.5 2010-02-17 22:13:29 tforb Exp $
* \author Thomas Forbriger
* \date 11/04/2006
*
......@@ -40,10 +40,79 @@
#define DATWRITE_DATWRITE_H_VERSION \
"TF_DATWRITE_H V1.0 "
#define DATWRITE_DATWRITE_H_CVSID \
"$Id: datwrite.h,v 1.4 2010-02-17 22:00:26 tforb Exp $"
"$Id: datwrite.h,v 1.5 2010-02-17 22:13:29 tforb Exp $"
namespace datwrite {
typedef aff::Series<double> Tdseries;
typedef aff::Series<float> Tfseries;
typedef aff::Series<int> Tiseries;
/*! output stream to write seismic data (abstract base)
*
* The concept is based on SFF data contents and we will make use of SFF
* structures.
*
* \note
* It would be reasonable to use the functions dseries(), fseries(), and
* iseries() to flush a trace to file.
* Then we have, however, to define a separate mechanism to flush the file
* header.
* Let's think about that.
*/
class odatstream {
public:
virtual ~odatstream() { }
virtual Tdseries dseries() { DATWRITE_illegal; }
virtual Tfseries fseries() { DATWRITE_illegal; }
virtual Tiseries iseries() { DATWRITE_illegal; }
//! print some info about data conversion.
static void help(std::ostream& os=std::cout,
char* name="idatsream");
protected:
idatstream(std::ostream& os);
std::ostream& Mos;
void setfilefree(const sff::FREE& free);
void settracefree(const sff::FREE& free);
void setwid2(const sff::WID2& wid2);
void setsrce(const sff::SRCE& srce);
void setinfo(const sff::INFO& info);
void setlast();
void newtrace();
private:
sff::WID2 Mwid2;
sff::SRCE Msrce;
sff::INFO Minfo;
sff::FREE Mtracefree;
sff::FREE Mfilefree;
bool Mwid2set, Msrceset, Minfoset, Mtracefreeset, Mfilefreeset;
bool Mlast;
bool Mprovidesd, Mprovidesf, Mprovidesi;
}; // class idatstream
/*----------------------------------------------------------------------*/
inline idatstream& operator>>(idatstream& is, sff::WID2& wid2)
{ wid2=is.wid2(); return(is); }
inline idatstream& operator>>(idatstream& is, sff::SRCE& srce)
{ srce=is.srce(); return(is); }
inline idatstream& operator>>(idatstream& is, sff::INFO& info)
{ info=is.info(); return(is); }
inline idatstream& operator>>(idatstream& is, sff::FREE& free)
{ free=is.free(); return(is); }
inline idatstream& operator>>(idatstream& is, Tdseries& series)
{ series=is.dseries(); return(is); }
inline idatstream& operator>>(idatstream& is, Tfseries& series)
{ series=is.fseries(); return(is); }
inline idatstream& operator>>(idatstream& is, Tiseries& series)
{ series=is.iseries(); return(is); }
} // namespace datwrite
#endif // DATWRITE_DATWRITE_H_VERSION (includeguard)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: util.h,v 1.2 2010-02-17 22:00:26 tforb Exp $
* $Id: util.h,v 1.3 2010-02-17 22:13:29 tforb Exp $
* \author Thomas Forbriger
* \date 17/02/2010
*
......@@ -40,10 +40,34 @@
#define DATWRITE_UTIL_H_VERSION \
"TF_UTIL_H V1.0 "
#define DATWRITE_UTIL_H_CVSID \
"$Id: util.h,v 1.2 2010-02-17 22:00:26 tforb Exp $"
"$Id: util.h,v 1.3 2010-02-17 22:13:29 tforb Exp $"
namespace datwrite {
namespace util {
/*----------------------------------------------------------------------*/
//! function template to convert a whole series
template<class Cin, class Cout>
Cout convert(const typename Cin::Tcoc& data)
{
int nsamples=data.size();
Cout retval(nsamples);
typedef typename Cin::Tvalue Tinvalue;
typedef typename Cout::Tvalue Toutvalue;
for (int i=0; i<nsamples; ++i)
{
Tinvalue sample=data(i);
retval(i)=Toutvalue(sample);
}
return(retval);
}
/*----------------------------------------------------------------------*/
} // namespace util
} // namespace datwrite
#endif // DATWRITE_UTIL_H_VERSION (includeguard)
......
Markdown is supported
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