Commit c33be710 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: 2178
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 1c679f65
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.1 2006-11-13 12:19:07 tforb Exp $
# $Id: Makefile,v 1.2 2006-11-17 16:46:50 tforb Exp $
#
# Copyright (c) 2006 by Thomas Forbriger (BFO Schiltach)
#
......@@ -14,7 +14,7 @@
all:
flist: Makefile
flist: Makefile $(wildcard *.cc)
echo $^ | tr ' ' '\n' | sort > $@
.PHONY: edit
......@@ -25,5 +25,17 @@ clean: ;
-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
-/bin/rm -vf flist
FLAGS=
CXXFLAGS=-fhonor-std -Wall $(FLAGS)
CXXFLAGS=-Wall $(FLAGS)
LDFLAGS=-L$(LOCLIBDIR)
CPPFLAGS=-I$(LOCINCLUDEDIR) $(FLAGS)
mgm2sff: %: %.o
$(CXX) -o $@ $^ -I$(LOCINCLUDEDIR) \
-lsffxx -ltime++ -lgsexx -laff \
-ltfxx -L$(LOCLIBDIR) $(CXXFLAGS) $(FLAGS)
/bin/cp -vpd $@ $(LOCBINDIR)
# ----- END OF Makefile -----
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mgm2sff.cc,v 1.1 2006-11-13 12:19:07 tforb Exp $
* $Id: mgm2sff.cc,v 1.2 2006-11-17 16:46:50 tforb Exp $
* \author Thomas Forbriger
* \date 13/11/2006
*
......@@ -19,15 +19,192 @@
#define MGM2SFF_VERSION \
"MGM2SFF V1.0 Convert Monschau data to SFF"
#define MGM2SFF_CVSID \
"$Id: mgm2sff.cc,v 1.1 2006-11-13 12:19:07 tforb Exp $"
"$Id: mgm2sff.cc,v 1.2 2006-11-17 16:46:50 tforb Exp $"
#include <iostream>
#include <fstream>
#include <vector>
#include <aff/series.h>
#include <tfxx/commandline.h>
#include <tfxx/error.h>
#include <libtime++.h>
using std::cout;
using std::cerr;
using std::endl;
/*======================================================================*/
typedef float Tvalue;
typedef aff::Series<Tvalue> Tseries;
/*======================================================================*/
/*
* class declarations
* ==================
*/
/*
* header file (geo.inf)
* ===========
*/
class GeoInfFile {
public:
//! return time and date of first sample
libtime::TAbsoluteTime first() const;
//! return time and date of last sample
libtime::TAbsoluteTime last() const;
private:
//! time and date of first sample
unsigned short int Mshour, Msminute, Mssecond, Msyear, Msmonth, Msday,
Msweekday;
//! time and date of last sample
unsigned short int Mehour, Meminute, Mesecond, Meyear, Memonth, Meday,
Meweekday;
}; // class GeoInfFile
/*----------------------------------------------------------------------*/
/*
* data file (geo.dat)
* =========
*/
class GeoDatFile {
public:
GeoDatFile(std::istream& is);
Tseries series(const int& i) const;
Tseries timemark() const { return(Mtm); }
private:
Tseries Ms1, Ms2, Ms3, Mtm;
}; // class GeoDatFile
/*
* options
* =======
*/
struct Options {
bool verbose, readinf, readdat;
std::string inffile, datfile;
};
/*----------------------------------------------------------------------*/
/*
* Byte Block from data file
* =========================
*/
class ByteBlock {
public:
Tvalue v(const int& i) const;
Tvalue tm() const;
private:
unsigned short int w1, w2, w3;
}; // class ByteBlock
/*======================================================================*/
/*
* class definitions
* =================
*/
libtime::TAbsoluteTime GeoInfFile::first() const
{
libtime::TAbsoluteTime retval(this->Msyear,
this->Msmonth,
this->Msday,
this->Mshour,
this->Msminute,
this->Mssecond);
return(retval);
} // libtime::TAbsoluteTime GeoInfFile::first()
/*----------------------------------------------------------------------*/
libtime::TAbsoluteTime GeoInfFile::last() const
{
libtime::TAbsoluteTime retval(this->Meyear,
this->Memonth,
this->Meday,
this->Mehour,
this->Meminute,
this->Mesecond);
return(retval);
} // libtime::TAbsoluteTime GeoInfFile::last()
/*----------------------------------------------------------------------*/
GeoDatFile::GeoDatFile(std::istream& is)
{
ByteBlock bb;
std::vector<Tvalue> in1, in2, in3, intm;
while (is.good())
{
typedef char* pchar;
is.read(pchar(&bb), sizeof(ByteBlock));
in1.push_back(bb.v(1));
in2.push_back(bb.v(2));
in3.push_back(bb.v(3));
intm.push_back(bb.tm());
}
this->Ms1=Tseries(in1.size());
for (int i=Ms1.f(); i<=Ms1.l(); ++i)
{ Ms1(i)=in1[i-Ms1.f()]; }
this->Ms2=Tseries(in2.size());
for (int i=Ms2.f(); i<=Ms2.l(); ++i)
{ Ms2(i)=in2[i-Ms2.f()]; }
this->Ms3=Tseries(in3.size());
for (int i=Ms3.f(); i<=Ms3.l(); ++i)
{ Ms3(i)=in3[i-Ms3.f()]; }
this->Mtm=Tseries(intm.size());
for (int i=Mtm.f(); i<=Mtm.l(); ++i)
{ Mtm(i)=intm[i-Mtm.f()]; }
} // GeoDatFile::GeoDatFile(std::istream& is)
/*----------------------------------------------------------------------*/
Tseries GeoDatFile::series(const int& i) const
{
Tseries retval;
switch(i) {
case 1: retval=this->Ms1;
break;
case 2: retval=this->Ms2;
break;
case 3: retval=this->Ms3;
break;
default: TFXX_abort("GeoDatFile: illegal index!");
}
return(retval);
} // Tseries GeoDatFile::series(const int& i)
/*----------------------------------------------------------------------*/
Tvalue ByteBlock::v(const int& i) const
{
unsigned short int w;
switch(i) {
case 1: w=this->w1;
break;
case 2: w=this->w2;
break;
case 3: w=this->w3;
break;
default: TFXX_abort("ByteBlock: illegal index!");
}
Tvalue v=float((w << 2)-8192)/8192;
return(v);
} // Tvalue ByteBlock::v(const int& i)
/*----------------------------------------------------------------------*/
Tvalue ByteBlock::tm() const
{
Tvalue v=float(w1 & 0x03);
return(v);
} // Tvalue ByteBlock::tm()
/*======================================================================*/
int main(int iargc, char* argv[])
{
......@@ -35,14 +212,17 @@ int main(int iargc, char* argv[])
char usage_text[]=
{
MGM2SFF_VERSION "\n"
"usage: mgm2sff" "\n"
"usage: mgm2sff [-v] [-inf file] [-dat file] " "\n"
" or: mgm2sff --help|-h" "\n"
};
// define full help text
char help_text[]=
{
MGM2SFF_CVSID
MGM2SFF_CVSID "\n"
"-v be verbose" "\n"
"-inf file read inf file and dump" "\n"
"-dat file read dat file and dump" "\n"
};
// define commandline options
......@@ -53,6 +233,10 @@ int main(int iargc, char* argv[])
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: read inf file and dump
{"inf",arg_yes,"-"},
// 3: read dat file and dump
{"dat",arg_yes,"-"},
{NULL}
};
......@@ -75,6 +259,7 @@ int main(int iargc, char* argv[])
}
// dummy operation: print option settings
/*
for (int iopt=0; iopt<2; iopt++)
{
cout << "option: '" << options[iopt].opt_string << "'" << endl;
......@@ -95,6 +280,54 @@ int main(int iargc, char* argv[])
// dummy operation: print rest of command line
while (cmdline.extra()) { cout << cmdline.next() << endl; }
*/
Options opt;
opt.verbose=cmdline.optset(1);
opt.readinf=cmdline.optset(2);
opt.inffile=cmdline.string_arg(2);
opt.readdat=cmdline.optset(3);
opt.datfile=cmdline.string_arg(3);
if (opt.readinf)
{
if (opt.verbose)
{
cout << "read inf file " << opt.inffile
<< " and dump contents" << endl;
}
std::ifstream ifs(opt.inffile.c_str());
GeoInfFile gif;
typedef char * pchar;
ifs.read(pchar(&gif), sizeof(GeoInfFile));
cout << "first sample at " << gif.first().timestring() << endl;
cout << "last sample at " << gif.last().timestring() << endl;
}
else if (opt.readdat)
{
if (opt.verbose)
{
cout << "read dat file " << opt.datfile
<< " and dump parameters" << endl;
}
std::ifstream ifs(opt.datfile.c_str());
GeoDatFile gdf(ifs);
cout << "index range of series: " << endl;
cout << "ch 1: " << gdf.series(1).f()
<< " - " << gdf.series(1).l() << endl;
cout << "ch 2: " << gdf.series(2).f()
<< " - " << gdf.series(2).l() << endl;
cout << "ch 3: " << gdf.series(3).f()
<< " - " << gdf.series(3).l() << endl;
cout << "marks: " << gdf.timemark().f()
<< " - " << gdf.timemark().l() << endl;
cout << "Assuming 16Hz sampling, " << gdf.timemark().l()+2
<< " intervals span a time of "
<< double(gdf.timemark().l()+2)/16.
<< " seconds."
<< endl;
}
}
/* ----- END OF mgm2sff.cc ----- */
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