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

added example

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: 1974
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 00c919f4
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.7 2005-07-05 08:21:14 tforb Exp $
# $Id: Makefile,v 1.8 2006-01-25 09:44:12 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -94,7 +94,7 @@ doxyview: doxyfullview doxybrief
# test code
# ---------
gsexx_tests: gsexx_tests.cc
gsexx_write_example gsexx_tests: %: %.cc
$(CXX) -o $@ $< -I$(LOCINCLUDEDIR) -lgsexx -L$(LOCLIBDIR)
tests: gsexx_tests; $<; rm -fv $<
......
/*! \file gsexx_write_example.cc
* \brief Example for writing GSE data
*
* ----------------------------------------------------------------------------
*
* $Id: gsexx_write_example.cc,v 1.1 2006-01-25 09:44:12 tforb Exp $
* \author Thomas Forbriger
* \date 25/01/2006
*
* Example for writing GSE data
*
* Copyright (c) 2006 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 25/01/2006 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define GSEXX_WRITE_EXAMPLE_VERSION \
"GSEXX_WRITE_EXAMPLE V1.0 Example for writing GSE data"
#define GSEXX_WRITE_EXAMPLE_CVSID \
"$Id: gsexx_write_example.cc,v 1.1 2006-01-25 09:44:12 tforb Exp $"
#include<string>
#include<fstream>
#include<iostream>
#include<gsexx.h>
using std::cout;
using std::cerr;
using std::endl;
// name of example data file
const char* examplefile="example.gse";
int main(int iargc, char* argv[])
{
cout << GSEXX_WRITE_EXAMPLE_VERSION << endl;
cout << GSEXX_WRITE_EXAMPLE_CVSID << endl;
cout << endl;
cout << "This program provides an example of basic writing to" << endl
<< "GSE data files. The program will write two traces" << endl
<< "of CM6 encoded data to a file called '"
<< examplefile << "'." << endl;
cout << endl;
// open output file
std::ofstream os(examplefile);
// write first time series
{
// number of samples to be written
const int nsamples=2000;
// prepare WID2 line
GSE2::waveform::TWID2 wid2line;
wid2line.Fyear=2006;
wid2line.Fmonth=1;
wid2line.Fday=25;
wid2line.Fhour=10;
wid2line.Fminute=30;
wid2line.Fseconds=12.456789;
wid2line.Fsamps=nsamples;
wid2line.Fsamprate=20.;
wid2line.Fstation="BFO";
wid2line.Finstype="STS2";
wid2line.Fchannel="BHZ";
wid2line.Fauxid="any";
wid2line.Fvang=0.;
wid2line.Fhang=90.;
wid2line.Fcalib=1.e5;
wid2line.Fcalper=10.;
wid2line.Fsubformat=GSE2::waveform::SF_CM6;
// report WID2 line
std::cout << wid2line.line();
// write WID2 line to data file
os << wid2line.line();
// create CM6 encoding data writer for appropriate number of samples
GSE2::waveform::TDAT2writeCM6 writer(nsamples);
// write data
int i=0;
while (writer.hot())
{
// calculate synthetic sample
int sample=int(1.e5*std::sin(i*2.*3.141592653*5./(nsamples-35)));
// output sample to data file
os << writer(sample);
i++;
}
}
// write second time series
{
// number of samples to be written
const int nsamples=2300;
// prepare WID2 line with the bare minimum of information required
GSE2::waveform::TWID2 wid2line;
wid2line.Fsamps=nsamples;
wid2line.Fsamprate=1.;
wid2line.Fsubformat=GSE2::waveform::SF_CM6;
// report WID2 line
std::cout << wid2line.line();
// write WID2 line to data file
os << wid2line.line();
// create CM6 encoding data writer for appropriate number of samples
GSE2::waveform::TDAT2writeCM6 writer(nsamples);
// write data
int i=0;
while (writer.hot())
{
// calculate synthetic sample
int sample=int(1.2e5*(std::sin(i*2.*3.141592653*5./(nsamples-35))
+std::cos(i*2.*3.141592653*5.5/(nsamples-35))));
// output sample to data file
os << writer(sample);
i++;
}
}
// that's it!
cout << "data file is written..." << endl;
} // main
/* ----- END OF gsexx_write_example.cc ----- */
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