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

WIDX writing works

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: 3034
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 10255cd9
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sfftest.cc,v 1.10 2010-04-13 16:14:20 tforb Exp $
* $Id: sfftest.cc,v 1.11 2010-04-13 20:33:42 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -36,7 +36,7 @@
#define SFFTEST_VERSION \
"SFFTEST V1.0 test library modules"
#define SFFTEST_CVSID \
"$Id: sfftest.cc,v 1.10 2010-04-13 16:14:20 tforb Exp $"
"$Id: sfftest.cc,v 1.11 2010-04-13 20:33:42 tforb Exp $"
#include <fstream>
#include <iostream>
......@@ -56,11 +56,14 @@ void test_extended_functions()
sff::WID2 mywid2;
sff::verbose(cout, mywid2);
mywid2.date += libtime::TRelativeTime(0,0,0,0,432,567);
mywid2.station="BFO";
mywid2.channel="UGZ";
mywid2.instype="ET-19";
mywid2.nsamples=2048;
mywid2.dt=10.;
mywid2.dt=0.01;
mywid2.hang=98.3342;
mywid2.vang=-15.3;
sff::verbose(cout, mywid2);
std::string Xline=sff::WIDXline(mywid2);
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffxx.h,v 1.35 2010-04-13 16:14:20 tforb Exp $
* $Id: sffxx.h,v 1.36 2010-04-13 20:33:42 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -51,7 +51,7 @@
#define TF_SFFXX_H_VERSION \
"TF_SFFXX_H V1.8"
#define TF_SFFXX_H_CVSID \
"$Id: sffxx.h,v 1.35 2010-04-13 16:14:20 tforb Exp $"
"$Id: sffxx.h,v 1.36 2010-04-13 20:33:42 tforb Exp $"
#include<string>
#include<cmath>
......@@ -109,7 +109,7 @@ namespace sff {
* \sa WIDXline(std::istream& is)
* \sa WIDXline(const sff::WID2& wid2)
*/
const char *const WIDX = "WIDX";
const char *const WIDXID = "WIDX";
/*======================================================================*/
// SFF structs
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: widXio.cc,v 1.1 2010-04-13 16:14:20 tforb Exp $
* $Id: widXio.cc,v 1.2 2010-04-13 20:33:42 tforb Exp $
* \author Thomas Forbriger
* \date 13/04/2010
*
......@@ -35,12 +35,37 @@
#define TF_WIDXIO_CC_VERSION \
"TF_WIDXIO_CC V1.0"
#define TF_WIDXIO_CC_CVSID \
"$Id: widXio.cc,v 1.1 2010-04-13 16:14:20 tforb Exp $"
"$Id: widXio.cc,v 1.2 2010-04-13 20:33:42 tforb Exp $"
#include <sffxx.h>
#include <sstream>
namespace sff {
namespace helper {
//! return number of significant digits
int nsignificantdigits(double v)
{
if (v<0) { v = -v; }
int n=0;
double basefactor=pow(10.,-floor(log10(v)));
double v1,v2;
do
{
double factor=basefactor*pow(10.,n);
v1=floor(v*factor);
v2=floor(v*factor*10.)/10.;
n++;
}
while (v1 != v2);
return (n);
} // int nsignificantdigits(const double& v)
} // namespace helper
/*----------------------------------------------------------------------*/
/*! \brief write WID information in extended format.
*
* This function breaks the SFF format definition.
......@@ -65,8 +90,55 @@ namespace sff {
*/
std::string WIDXline(const sff::WID2& wid2)
{
std::string retval;
return(retval);
std::ostringstream os;
os << sff::WIDXID;
os << " " << wid2.date.hierarchicalstring();
os << " ";
os.width(5);
os.setf(std::ios_base::left, std::ios_base::adjustfield);
os << wid2.station.substr(0,5);
os << " ";
os.width(3);
os.setf(std::ios_base::left, std::ios_base::adjustfield);
os << wid2.channel.substr(0,3);
os << " ";
os.width(4);
os.setf(std::ios_base::left, std::ios_base::adjustfield);
os << wid2.auxid.substr(0,4);
os << " ";
os.width(6);
os.setf(std::ios_base::left, std::ios_base::adjustfield);
os << wid2.instype.substr(0,6);
os << " " << wid2.nsamples;
double rate=1./wid2.dt;
double value=wid2.dt;
if (sff::helper::nsignificantdigits(rate) < 4)
{
os << " r ";
value=rate;
}
else
{
os << " i ";
}
os.setf(std::ios_base::scientific, std::ios_base::floatfield);
int ndigits=sff::helper::nsignificantdigits(value);
os.precision(ndigits);
os.width(ndigits+6);
os << value;
os << " ";
os.precision(sff::helper::nsignificantdigits(wid2.calib));
os << wid2.calib;
os << " ";
os.precision(sff::helper::nsignificantdigits(wid2.calper));
os << wid2.calper;
os << " ";
os.precision(sff::helper::nsignificantdigits(wid2.hang));
os << wid2.hang;
os << " ";
os.precision(sff::helper::nsignificantdigits(wid2.vang));
os << wid2.vang;
return(os.str());
} // std::string WIDXline(const sff::WID2& wid2)
/*----------------------------------------------------------------------*/
......
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