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

grestf 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: 1280
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 5e078929
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: greenspec.h,v 1.2 2003-01-04 21:49:37 forbrig Exp $
* $Id: greenspec.h,v 1.3 2003-01-05 20:37:18 forbrig Exp $
* \author Thomas Forbriger
* \date 04/01/2003
*
......@@ -23,7 +23,7 @@
#define TF_GREENSPEC_H_VERSION \
"TF_GREENSPEC_H V1.0 "
#define TF_GREENSPEC_H_CVSID \
"$Id: greenspec.h,v 1.2 2003-01-04 21:49:37 forbrig Exp $"
"$Id: greenspec.h,v 1.3 2003-01-05 20:37:18 forbrig Exp $"
#include<aff/array.h>
#include<iostream>
......@@ -46,7 +46,9 @@ namespace gremlin1 {
int nf() const { return(Mgreen.size(1)); }
int np() const { return(Mgreen.size(0)); }
const double& fmin() const { return(Mfmin); }
double fmax() const { return(f(nf())); }
const double& pmin() const { return(Mpmin); }
double pmax() const { return(p(np())); }
const double& df() const { return(Mdf); }
const double& dp() const { return(Mdp); }
double f(const int& i) const { return((i-1)*Mdf+Mfmin); }
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: srcires.cc,v 1.1 2003-01-04 21:49:37 forbrig Exp $
* $Id: srcires.cc,v 1.2 2003-01-05 20:37:19 forbrig Exp $
* \author Thomas Forbriger
* \date 04/01/2003
*
......@@ -19,7 +19,7 @@
#define TF_SRCIRES_CC_VERSION \
"TF_SRCIRES_CC V1.0 "
#define TF_SRCIRES_CC_CVSID \
"$Id: srcires.cc,v 1.1 2003-01-04 21:49:37 forbrig Exp $"
"$Id: srcires.cc,v 1.2 2003-01-05 20:37:19 forbrig Exp $"
#include <cmath>
#include <stdio.h>
......@@ -32,6 +32,7 @@ namespace gremlin1 {
std::istream& operator>>(std::istream& is, GremlinIres& ires)
{
const double pi2=2.*3.141592653589793115997;
const int maxskip=500;
is.ignore(maxskip,'\n');
is.ignore(maxskip,'\n');
......@@ -47,7 +48,6 @@ namespace gremlin1 {
GremlinIres::Tcarray inarray(nf);
aff::Array<double> inomega(nf);
const double pi2=2.*3.141592653589793115997;
for (int i=inarray.f(0); i<=inarray.l(0); ++i)
{
......@@ -75,6 +75,7 @@ namespace gremlin1 {
std::ostream& operator<<(std::ostream& os, const GremlinIres& ires)
{
const double pi2=2.*3.141592653589793115997;
// get copy including frequency zero
GremlinIres::Tcarray outires(ires.n2());
GremlinIres::Tcarray
......@@ -89,7 +90,6 @@ namespace gremlin1 {
os << ires.df() << " angular frequency step width" << std::endl;
os << outires.size() << " number of frequency samples" << std::endl;
const double pi2=2.*3.141592653589793115997;
const int bufsize=20;
char buffer[bufsize];
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: srcires.h,v 1.1 2003-01-04 21:49:38 forbrig Exp $
* $Id: srcires.h,v 1.2 2003-01-05 20:37:19 forbrig Exp $
* \author Thomas Forbriger
* \date 04/01/2003
*
......@@ -23,7 +23,7 @@
#define TF_SRCIRES_H_VERSION \
"TF_SRCIRES_H V1.0 "
#define TF_SRCIRES_H_CVSID \
"$Id: srcires.h,v 1.1 2003-01-04 21:49:38 forbrig Exp $"
"$Id: srcires.h,v 1.2 2003-01-05 20:37:19 forbrig Exp $"
#include<complex>
#include<iostream>
......@@ -39,11 +39,15 @@ namespace gremlin1 {
GremlinIres(): Mdf(0.), Mires(1) { Mires=Tcvalue(0.); }
GremlinIres(const double& df, const int& n1, const int& n2):
Mdf(df), Mires(aff::Shaper(n1,n2)) { Mires=Tcvalue(0.); }
GremlinIres(const double& df, const double& f1, const double& f2):
Mdf(df), Mires(aff::Shaper(findex(f1),findex(f2)))
{ Mires=Tcvalue(0.); }
int nf() const { return(Mires.size(0)); }
int n1() const { return(Mires.f(0)); }
int n2() const { return(Mires.l(0)); }
const double& df() const { return(Mdf); }
double f(const int& i) const { return((i-1)*Mdf); }
int findex(const double& fr) const { return(static_cast<int>(fr/Mdf)+1); }
Tcarray ires() { return(Mires); }
Tcarray::Tcoc ires() const { return(Mires); }
......
#
# Makefile for src/green/gremlin1/tools
#
# $Id: Makefile,v 1.13 2003-01-04 21:49:38 forbrig Exp $
# $Id: Makefile,v 1.14 2003-01-05 20:37:19 forbrig Exp $
#
# 26/05/2000 - thof - new dependency generator (fdep.sh)
# 19/01/2001 reactivated them all
......@@ -98,7 +98,7 @@ pmotra: %: %.o
newprog $@
$(CXXSRC:.cc=): %: %.o
$(CXX) -o $@ $< $(LDFLAGS) -lgremlin1xx -ltfxx -laff
$(CXX) -o $@ $< $(LDFLAGS) -lgremlin1xx -lfourierxx -ltfxx -laff
newprog $@
%77: %.f
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: grestf.cc,v 1.1 2003-01-04 21:49:38 forbrig Exp $
* $Id: grestf.cc,v 1.2 2003-01-05 20:37:19 forbrig Exp $
* \author Thomas Forbriger
* \date 04/01/2003
*
......@@ -19,7 +19,7 @@
#define GRESTF_VERSION \
"GRESTF V1.0 source time function from Green"
#define GRESTF_CVSID \
"$Id: grestf.cc,v 1.1 2003-01-04 21:49:38 forbrig Exp $"
"$Id: grestf.cc,v 1.2 2003-01-05 20:37:19 forbrig Exp $"
#include <iostream>
#include <fstream>
......@@ -28,12 +28,16 @@
#include <tfxx/error.h>
#include <aff/slice.h>
#include <gremlin1/greenspec.h>
#include <gremlin1/srcires.h>
#include <fourier/fcommand.h>
using std::cout;
using std::cerr;
using std::endl;
typedef gremlin1::GreenSpectrum::Tcarray Tcarray;
typedef gremlin1::GreenSpectrum::Tcvalue Tcvalue;
typedef std::complex<double> Tzvalue;
/*======================================================================*/
// functions
......@@ -68,10 +72,25 @@ int main(int iargc, char* argv[])
char help_text[]=
{
"-v verbose" "\n"
"-datafil f instrument response inherent to data" "\n"
"-filter f filter to be applied to result" "\n"
"-restifi do not apply datafil to synthetics" "\n"
" use this as inverse filter" "\n"
"-damp v set damping factor to v" "\n"
"-slraw f write raw stf from linear regression to f" "\n"
"-slfil f write filtered stf from linear regression to f" "\n"
"\n"
"ires impulse response Green" "\n"
"data Green from data" "\n"
"\n"
"concept:" "\n"
"If -restifi is not set, we will apply -datafil to the synthetics" "\n"
"\"ires\". then the force time-function is derived and finally the" "\n"
"-filter will be applied to the force time-function" "\n"
"If -restifi is set, force time-function will be derived first and" "\n"
"-datafile will be applied as an inverse filter to it before" "\n"
"-filter is applied" "\n"
"\n"
GRESTF_CVSID
};
......@@ -83,6 +102,18 @@ int main(int iargc, char* argv[])
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: instrument response inherent to data
{"datafil",arg_yes,"-"},
// 3: filter to be applied to result
{"filter",arg_yes,"-"},
// 4: use datafil for restitution
{"restifi",arg_no,"-"},
// 5: damping factor
{"damp",arg_yes,"-"},
// 6: output of raw stf from linear regresseion
{"slraw",arg_yes,"-"},
// 7: output of filtered stf from linear regresseion
{"slfil",arg_yes,"-"},
{NULL}
};
......@@ -101,10 +132,23 @@ int main(int iargc, char* argv[])
{
cerr << usage_text << endl;
cerr << help_text << endl;
fourier::FilterCommands::help(cerr);
exit(0);
}
bool opt_verbose=cmdline.optset(1);
bool opt_verbose =cmdline.optset(1);
bool opt_datafil =cmdline.optset(2);
std::string arg_datafil=cmdline.string_arg(2);
bool opt_filter =cmdline.optset(3);
std::string arg_filter=cmdline.string_arg(3);
bool opt_restifi =cmdline.optset(4);
double arg_damp =cmdline.double_arg(5);
bool opt_slraw =cmdline.optset(6);
std::string arg_slraw =cmdline.string_arg(6);
bool opt_slfil =cmdline.optset(7);
std::string arg_slfil =cmdline.string_arg(7);
bool act_stflinreg= opt_slfil || opt_slraw;
const char missing_argument[]="ERROR: missing command line argument!";
TFXX_assert(cmdline.extra(), missing_argument);
......@@ -175,11 +219,118 @@ int main(int iargc, char* argv[])
TFXX_assert((std::abs(1.-iresgreen.dp()/datagreen.dp())<1.e-5),
inconsistent_data);
// global ranges
const double fmin=datagreen.fmin();
const double fmax=datagreen.fmax();
const int nf=datagreen.nf();
const int np=datagreen.np();
const double df=datagreen.df();
/*----------------------------------------------------------------------*/
// read filter files
fourier::FilterCommands fil_dataresp;
fourier::FilterCommands fil_filter;
if (opt_datafil)
{
if (opt_verbose) cout << "reading filter from " << arg_datafil << endl;
fil_dataresp.read(arg_datafil.c_str());
fil_dataresp.setfreqmod();
}
if (opt_filter)
{
if (opt_verbose) cout << "reading filter from " << arg_filter << endl;
fil_filter.read(arg_filter.c_str());
fil_filter.setfreqmod();
}
/*----------------------------------------------------------------------*/
// create resorted arrays (rows are frequencies then)
Tcarray rsrtires=resortarray(iresgreen.green());
Tcarray rsrtdata=resortarray(datagreen.green());
//Tcarray rsrtires=resortarray(iresgreen.green());
//Tcarray rsrtdata=resortarray(datagreen.green());
/*----------------------------------------------------------------------*/
// start linear regression part
gremlin1::GremlinIres lr_iresraw(df,fmin,fmax);
gremlin1::GremlinIres lr_iresfil(df,fmin,fmax);
if (act_stflinreg)
{
/*----------------------------------------------------------------------*/
// prepare dataset for linear regression
Tcarray lr_data=datagreen.green().copyout();
Tcarray lr_synt=iresgreen.green().copyout();
if (!opt_restifi)
{
if (opt_verbose) cout << "apply data response to synthetics" << endl;
Tcarray lr_synt=iresgreen.green();
for (int i=lr_synt.f(0); i<=lr_synt.l(0); ++i)
{
for (int j=lr_synt.f(1); j<=lr_synt.l(1); ++j)
{
lr_synt(i,j) *= fil_dataresp.eval(iresgreen.f(j));
}
}
}
/*----------------------------------------------------------------------*/
// calculate linear regression
if (opt_verbose)
{
cout << "calculate linear regression" << endl
<< " and apply filter" << endl;
if (opt_restifi) cout << " and apply inverse data response" << endl;
}
for (int i=lr_synt.f(1); i<=lr_synt.l(1); ++i)
{
double f=datagreen.f(i);
int iires=lr_iresraw.findex(f);
Tzvalue numerator(0.,0.);
Tzvalue denominator(0.,0.);
for (int j=lr_synt.f(0); j<=lr_synt.l(0); ++j)
{
numerator += std::conj(lr_synt(j,i))*lr_data(j,i);
denominator += std::norm(lr_synt(j,i));
}
denominator += arg_damp*arg_damp;
Tcvalue stf= static_cast<Tcvalue>(numerator/denominator);
lr_iresraw.ires()(iires)=stf;
stf *= fil_filter.eval(f);
if (opt_restifi) stf /= fil_dataresp.eval(f);
lr_iresfil.ires()(iires)=stf;
}
if (opt_slraw)
{
if (opt_verbose) cout << "write raw stf to " << arg_slraw << endl;
std::ofstream os(arg_slraw.c_str());
os << lr_iresraw;
}
if (opt_slfil)
{
if (opt_verbose) cout << "write filtered stf to " << arg_slfil << endl;
std::ofstream os(arg_slfil.c_str());
os << lr_iresfil;
}
} // if (act_stflinreg)
/*----------------------------------------------------------------------*/
}
/* ----- END OF grestf.cc ----- */
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.4 2003-01-05 17:36:51 forbrig Exp $
# $Id: Makefile,v 1.5 2003-01-05 20:37:19 forbrig Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -10,6 +10,10 @@
#
# REVISIONS and CHANGES
# 07/11/2002 V1.0 Thomas Forbriger
# 05/01/2003 V1.1 uuuhhhhhh
# had to resolve a specific problem: my library
# procuded object files for Fortran code with the same
# name of the object files of C++ code
#
# ============================================================================
#
......@@ -47,9 +51,9 @@ DOCS=libfourier.doc
docs: $(DOCS)
.f.o:
%.of2c: %.f
f2c $(F2CFLAGS) $<
$(CC) $(CFLAGS) $(<:.f=.c) -c
$(CC) $(CFLAGS) $(<:.f=.c) -c -o $@
@rm $(<:.f=.c)
%.o77: %.f
......@@ -57,20 +61,19 @@ docs: $(DOCS)
.PHONY: clean
clean:
-/bin/rm -fv *.o *.bak *.doc *.o77 flist
-/bin/rm -fv *.o *.bak *.doc *.o77 flist *.of2c
-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.o | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.d | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.h.strip | xargs --no-run-if-empty /bin/rm -v
-/bin/rm -vf flist *.o install-include *.xxx junk*
cd tests; $(MAKE) clean
libfourier.doc: $(LIBSRC) $(wildcard *.inc)
makefdoc.pl $@ $^
libfourier77.a: $(patsubst %.o,%.o77,$(LIBOBS))
libfourier.a: $(LIBOBS)
libfourier.a: $(patsubst %.o,%.of2c,$(LIBOBS))
%.a:
$(AR) rcv $@ $^
......@@ -160,9 +163,9 @@ CPPFLAGS=-I$(LOCINCLUDEDIR) $(FLAGS)
LIBOBSXX=$(patsubst %.cc,%.o,$(SRC))
libfourierxx.a: install-include $(LIBOBSXX)
ar rcv $@ $(LIBOBS)
ar rcv $@ $(LIBOBSXX)
ranlib $@
cp -vpf $@ $(LIBINSTALLPATH)
newlib $@
#======================================================================
# dependencies
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: fcommand.cc,v 1.1 2003-01-05 17:36:51 forbrig Exp $
* $Id: fcommand.cc,v 1.2 2003-01-05 20:37:19 forbrig Exp $
* \author Thomas Forbriger
* \date 05/01/2003
*
......@@ -19,7 +19,7 @@
#define TF_FCOMMAND_CC_VERSION \
"TF_FCOMMAND_CC V1.0 "
#define TF_FCOMMAND_CC_CVSID \
"$Id: fcommand.cc,v 1.1 2003-01-05 17:36:51 forbrig Exp $"
"$Id: fcommand.cc,v 1.2 2003-01-05 20:37:19 forbrig Exp $"
#include <fourier/fcommand.h>
#include <fstream>
......@@ -32,34 +32,34 @@ using std::endl;
namespace fourier {
void FilterCommands::FilterCommands::help() const
void FilterCommands::FilterCommands::help(std::ostream& os)
{
cout << "filter library commands:" << endl;
cout << "rem any comment (ignored)" << endl;
cout << "# any comment (ignored)" << endl;
cout << "dif differentiate" << endl;
cout << "int integrate" << endl;
cout << "lp2 in,h second order low-pass (see foufil_lp2)" << endl;
cout << "hp2 in,h second order high-pass (see foufil_hp2)" << endl;
cout << "lpb in,ord "
os << "filter library commands:" << endl;
os << "rem any comment (ignored)" << endl;
os << "# any comment (ignored)" << endl;
os << "dif differentiate" << endl;
os << "int integrate" << endl;
os << "lp2 in,h second order low-pass (see foufil_lp2)" << endl;
os << "hp2 in,h second order high-pass (see foufil_hp2)" << endl;
os << "lpb in,ord "
<< "Butterworth low-pass of order ord (see foufil_lpb)" << endl;
cout << "hpb in,ord "
os << "hpb in,ord "
<< "Butterworth high-pass of order ord (see foufil_hpb)" << endl;
cout << "fac factor mutiply by factor" << endl;
cout << "mod normal "
os << "fac factor mutiply by factor" << endl;
os << "mod normal "
<< "switch back to normal filters (default)" << endl;
cout << "mod inverse switch to inverse filters" << endl;
cout << "mod period "
os << "mod inverse switch to inverse filters" << endl;
os << "mod period "
<< "switch to specification by period (default)" << endl;
cout << "mod frequency switch to specification by frequency " << endl;
cout << "end terminate file reading" << endl;
cout << endl;
cout << TF_FCOMMAND_H_VERSION << endl;
cout << TF_FCOMMAND_H_CVSID << endl;
cout << TF_FILTERS_H_VERSION << endl;
cout << TF_FILTERS_H_CVSID << endl;
cout << TF_POLESNZEROES_H_VERSION << endl;
cout << TF_POLESNZEROES_H_CVSID << endl;
os << "mod frequency switch to specification by frequency " << endl;
os << "end terminate file reading" << endl;
os << endl;
os << TF_FCOMMAND_H_VERSION << endl;
os << TF_FCOMMAND_H_CVSID << endl;
os << TF_FILTERS_H_VERSION << endl;
os << TF_FILTERS_H_CVSID << endl;
os << TF_POLESNZEROES_H_VERSION << endl;
os << TF_POLESNZEROES_H_CVSID << endl;
}
/*----------------------------------------------------------------------*/
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: fcommand.h,v 1.1 2003-01-05 17:36:51 forbrig Exp $
* $Id: fcommand.h,v 1.2 2003-01-05 20:37:19 forbrig Exp $
* \author Thomas Forbriger
* \date 05/01/2003
*
......@@ -23,7 +23,7 @@
#define TF_FCOMMAND_H_VERSION \
"TF_FCOMMAND_H V1.0 "
#define TF_FCOMMAND_H_CVSID \
"$Id: fcommand.h,v 1.1 2003-01-05 17:36:51 forbrig Exp $"
"$Id: fcommand.h,v 1.2 2003-01-05 20:37:19 forbrig Exp $"
#include<iostream>
#include<fourier/filters.h>
......@@ -39,7 +39,7 @@ namespace fourier {
FilterCommands(const char* filename): Tbase() { read(filename); }
FilterCommands(std::istream& is): Tbase() { read(is); }
void help() const;
static void help(std::ostream& os);
void read(std::istream& is);
void read(const char* filename);
bool command(const char* command);
......
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