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

compiles

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: 2330
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent d82a8db3
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.31 2007-06-29 11:09:13 tforb Exp $
# $Id: Makefile,v 1.32 2007-06-29 12:33:32 tforb Exp $
#
# Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
#
......@@ -27,6 +27,7 @@
#
# REVISIONS and CHANGES
# 30/03/2004 V1.0 Thomas Forbriger
# 29/06/2007 V1.1 included SAC binary reading
#
# ============================================================================
#
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sac.h,v 1.3 2006-03-28 16:07:43 tforb Exp $
* $Id: sac.h,v 1.4 2007-06-29 12:33:32 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2004
*
......@@ -39,10 +39,32 @@
#define TF_SAC_H_VERSION \
"TF_SAC_H V1.0 "
#define TF_SAC_H_CVSID \
"$Id: sac.h,v 1.3 2006-03-28 16:07:43 tforb Exp $"
"$Id: sac.h,v 1.4 2007-06-29 12:33:32 tforb Exp $"
#include<datreadxx/datread.h>
namespace datread {
/*! \brief class to read SAC binary data
*
* \ingroup sac
*/
class isacstream: public idatstream {
public:
typedef idatstream Tbase;
isacstream(std::istream& is);
virtual ~isacstream() { }
virtual Tdseries dseries();
virtual Tfseries fseries();
virtual Tiseries iseries();
virtual void skipseries();
static void help(std::ostream& os=std::cout);
private:
void readheader();
// expected value of initial and final sample
float Minitial, Mfinal;
}; // class isacstream
} // namespace datread
#endif // TF_SAC_H_VERSION (includeguard)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sac.cc,v 1.4 2007-06-29 10:33:22 tforb Exp $
* $Id: sac.cc,v 1.5 2007-06-29 12:33:33 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2004
*
......@@ -35,12 +35,97 @@
#define TF_SAC_CC_VERSION \
"TF_SAC_CC V1.0 "
#define TF_SAC_CC_CVSID \
"$Id: sac.cc,v 1.4 2007-06-29 10:33:22 tforb Exp $"
"$Id: sac.cc,v 1.5 2007-06-29 12:33:33 tforb Exp $"
#include <string>
#include <sstream>
#include <datreadxx/sac.h>
#include <datreadxx/sacread.h>
#include <datreadxx/error.h>
#include <datreadxx/util.h>
namespace datread {
isacstream::isacstream(std::istream& is): Tbase(is, true, true, true)
{ }
/*----------------------------------------------------------------------*/
Tdseries isacstream::dseries()
{
this->readheader();
return(datread::util::convert<Tfseries, Tdseries>(this->fseries()));
}
/*----------------------------------------------------------------------*/
Tfseries isacstream::fseries()
{
this->readheader();
return(datread::sac::read_sac_data(this->Mis, this->wid2().nsamples,
this->Minitial,
this->Mfinal));
}
/*----------------------------------------------------------------------*/
Tiseries isacstream::iseries()
{
this->readheader();
return(datread::util::convert<Tfseries, Tiseries>(this->fseries()));
}
/*----------------------------------------------------------------------*/
void isacstream::skipseries()
{
this->readheader();
}
/*----------------------------------------------------------------------*/
void isacstream::readheader()
{
this->newtrace();
sff::FREE free;
sff::WID2 wid2;
sff::INFO info;
std::ostringstream oss;
free.append("values from SAC binary header"
"that do not fit into SFF trace header");
datread::sac::SACheader hd=datread::sac::read_sac_header(this->Mis);
wid2.dt=hd.delta;
this->Minitial=hd.b;
this->Mfinal=hd.e;
info.cs=sff::CS_spherical;
info.cx=hd.stla;
info.cy=hd.stlo;
info.cz=hd.stel;
oss << hd.stdp;
free.append("station depth: " + oss.str() + " m");
wid2.hang=hd.cmpaz;
wid2.vang=hd.cmpinc;
wid2.date=libtime::TAbsoluteTime(hd.nzyear, 1, hd.nzhour,
hd.nzmin, hd.nzsec, hd.nzmsec);
wid2.date.setdoy(hd.nzjday);
wid2.nsamples=hd.npts;
wid2.station=std::string(hd.kstnm,8);
wid2.channel=std::string(hd.kcmpnm,8);
wid2.auxid=std::string(hd.khole,8);
free.append("network name: " + std::string(hd.knetwk, 8));
DATREAD_assert(hd.iftype==1, "unexpected file type");
DATREAD_assert(hd.leven==1, "uneven sampling");
this->setwid2(wid2);
this->setinfo(info);
this->settracefree(free);
this->setlast();
}
/*----------------------------------------------------------------------*/
void isacstream::help(std::ostream& os)
{ datread::sac::help(os); }
} // namespace datread
/* ----- END OF sac.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sacread.cc,v 1.5 2007-06-29 11:09:13 tforb Exp $
* $Id: sacread.cc,v 1.6 2007-06-29 12:33:33 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2004
*
......@@ -35,19 +35,57 @@
#define TF_SACREAD_CC_VERSION \
"TF_SACREAD_CC V1.0 "
#define TF_SACREAD_CC_CVSID \
"$Id: sacread.cc,v 1.5 2007-06-29 11:09:13 tforb Exp $"
"$Id: sacread.cc,v 1.6 2007-06-29 12:33:33 tforb Exp $"
#include <datreadxx/sacread.h>
#include <datreadxx/error.h>
namespace datread {
namespace sac {
// read SAC header from stream
void read_sac_header(std::istream& is, SACheader* sh)
SACheader read_sac_header(std::istream& is)
{
SACheader retval;
typedef char* Pchar;
is.read(Pchar(sh), sizeof(SACheader));
is.read(Pchar(&retval), sizeof(SACheader));
return(retval);
} // SACheader read_sac_header(std::istream& is)
/*----------------------------------------------------------------------*/
// print info about SAC reading
void help(std::ostream& os)
{
os <<
"SAC reading functions" "\n"
"---------------------" "\n"
TF_SACREAD_CC_VERSION "\n"
TF_SACREAD_CC_CVSID "\n"
"\n"
"These functions are tuned to read binary SAC files as produced by" "\n"
"rdseed from IRIS SEED volumes." "\n";
} // void help(std::ostream& os)
/*----------------------------------------------------------------------*/
//! read samples from file
Tseries read_sac_data(std::istream& is, const long int& nsamples,
const Tvalue& initial, const Tvalue& final)
{
Tseries series(nsamples);
DATREAD_assert(is.good(),
"read_sac_data: input stream is not good before reading");
typedef char* Pchar;
is.read(Pchar(series.pointer()), nsamples*sizeof(Tvalue));
DATREAD_assert(is.good(),
"read_sac_data: input stream is not good after reading");
DATREAD_assert(initial==series(series.first()),
"read_sac_data: unexpected value of initial sample");
DATREAD_assert(final==series(series.last()),
"read_sac_data: unexpected value of final sample");
return(series);
}
} // namespace sac
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sacread.h,v 1.4 2007-06-29 11:09:13 tforb Exp $
* $Id: sacread.h,v 1.5 2007-06-29 12:33:33 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2004
*
......@@ -39,9 +39,10 @@
#define TF_SACREAD_H_VERSION \
"TF_SACREAD_H V1.0 "
#define TF_SACREAD_H_CVSID \
"$Id: sacread.h,v 1.4 2007-06-29 11:09:13 tforb Exp $"
"$Id: sacread.h,v 1.5 2007-06-29 12:33:33 tforb Exp $"
#include<istream>
#include<aff/series.h>
namespace datread {
......@@ -231,11 +232,26 @@ namespace datread {
char kinst[8]; /* instrument name */
}; // struct SACheader
/*======================================================================*/
//! binary SAC sample type
typedef float Tvalue;
//! binary SAC sample array type
typedef aff::Series<Tvalue> Tseries;
/*======================================================================*/
// functions
//! read SAC header from stream
void read_sac_header(std::istream& is, SACheader* sh);
SACheader read_sac_header(std::istream& is);
//! print information about file decoding
void help(std::ostream& os);
//! read samples from file
Tseries read_sac_data(std::istream& is, const int& nsamples,
const Tvalue& initial, const Tvalue& final);
} // namespace sac
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sactest.cc,v 1.4 2007-06-29 11:09:14 tforb Exp $
* $Id: sactest.cc,v 1.5 2007-06-29 12:33:33 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2004
*
......@@ -35,7 +35,7 @@
#define SACTEST_VERSION \
"SACTEST V1.0 test SAC reading functions"
#define SACTEST_CVSID \
"$Id: sactest.cc,v 1.4 2007-06-29 11:09:14 tforb Exp $"
"$Id: sactest.cc,v 1.5 2007-06-29 12:33:33 tforb Exp $"
#include <iostream>
#include <string>
......@@ -146,31 +146,30 @@ int main(int iargc, char* argv[])
cout << "dump header" << endl;
cout << "-----------" << endl;
}
datread::sac::SACheader hd;
std::ifstream ifs(filename.c_str());
datread::sac::read_sac_header(ifs, &hd);
cout << "sampling interval: " << hd.delta << " s" << endl;
cout << "initial value: " << hd.b << endl;
cout << "final value: " << hd.e << endl;
cout << "station latitude: " << hd.stla << " N" << endl;
cout << "station longitude: " << hd.stlo << " E" << endl;
cout << "station elevation: " << hd.stel << " m" << endl;
cout << "station depth: " << hd.stdp << " m" << endl;
cout << "component azimuth: " << hd.cmpaz << " " << endl;
cout << "component inclination: " << hd.cmpinc << " " << endl;
cout << "zero time of file, year: " << hd.nzyear << endl;
cout << "zero time of file, doy: " << hd.nzjday << endl;
cout << "zero time of file, hour: " << hd.nzhour << endl;
cout << "zero time of file, minute: " << hd.nzmin << endl;
cout << "zero time of file, second: " << hd.nzsec << endl;
cout << "zero time of file, millisecond: " << hd.nzmsec << endl;
cout << "number of samples: " << hd.npts << endl;
cout << "station name: " << std::string(hd.kstnm,8) << endl;
cout << "component name: " << std::string(hd.kcmpnm,8) << endl;
cout << "network name: " << std::string(hd.knetwk,8) << endl;
cout << "man-made event name: " << std::string(hd.khole,8) << endl;
cout << "type of file: " << hd.iftype << endl;
cout << "even sampling flag: " << hd.leven << endl;
datread::sac::SACheader hd=datread::sac::read_sac_header(ifs);
cout << " sampling interval: " << hd.delta << " s" << endl;
cout << " initial value: " << hd.b << endl;
cout << " final value: " << hd.e << endl;
cout << " station latitude: " << hd.stla << " N" << endl;
cout << " station longitude: " << hd.stlo << " E" << endl;
cout << " station elevation: " << hd.stel << " m" << endl;
cout << " station depth: " << hd.stdp << " m" << endl;
cout << " component azimuth: " << hd.cmpaz << " " << endl;
cout << " component inclination: " << hd.cmpinc << " " << endl;
cout << " zero time of file, year: " << hd.nzyear << endl;
cout << " zero time of file, doy: " << hd.nzjday << endl;
cout << " zero time of file, hour: " << hd.nzhour << endl;
cout << " zero time of file, minute: " << hd.nzmin << endl;
cout << " zero time of file, second: " << hd.nzsec << endl;
cout << " zero time of file, millisecond: " << hd.nzmsec << endl;
cout << " number of samples: " << hd.npts << endl;
cout << " station name: " << std::string(hd.kstnm,8) << endl;
cout << " component name: " << std::string(hd.kcmpnm,8) << endl;
cout << " network name: " << std::string(hd.knetwk,8) << endl;
cout << " man-made event name: " << std::string(hd.khole,8) << endl;
cout << " type of file: " << hd.iftype << endl;
cout << " even sampling flag: " << hd.leven << endl;
}
}
......
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