srcires.cc 3.8 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file srcires.cc
 * \brief source wavelet impulse response (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id$
thomas.forbriger's avatar
thomas.forbriger committed
7
8
9
10
11
12
 * \author Thomas Forbriger
 * \date 04/01/2003
 * 
 * source wavelet impulse response (implementation)
 * 
 * Copyright (c) 2003 by Thomas Forbriger (IMG Frankfurt) 
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 *
 * ----
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * ----
thomas.forbriger's avatar
thomas.forbriger committed
29
30
31
32
33
34
35
36
37
 * 
 * REVISIONS and CHANGES 
 *  - 04/01/2003   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define TF_SRCIRES_CC_VERSION \
  "TF_SRCIRES_CC   V1.0   "
#define TF_SRCIRES_CC_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
38
  "$Id$"
thomas.forbriger's avatar
thomas.forbriger committed
39
40
41
42
43
44
45
46
47
48
49
50

#include <cmath>
#include <stdio.h>
#include <gremlin1/srcires.h>
#include <tfxx/error.h>
#include <aff/array.h>
#include <aff/subarray.h>

namespace gremlin1 {

  std::istream& operator>>(std::istream& is, GremlinIres& ires)
  {
thomas.forbriger's avatar
thomas.forbriger committed
51
    const double pi2=2.*3.141592653589793115997;
thomas.forbriger's avatar
thomas.forbriger committed
52
53
54
55
56
57
58
59
    const int maxskip=500;
    is.ignore(maxskip,'\n');
    is.ignore(maxskip,'\n');
    is.ignore(maxskip,'\n');
    is.ignore(maxskip,'\n');
    is.ignore(maxskip,'\n');
    double df;
    is >> df;
thomas.forbriger's avatar
thomas.forbriger committed
60
    df /= pi2;
thomas.forbriger's avatar
thomas.forbriger committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    is.ignore(maxskip,'\n');
    int nf;
    is >> nf;
    is.ignore(maxskip,'\n');

    GremlinIres::Tcarray inarray(nf);
    aff::Array<double> inomega(nf);

    for (int i=inarray.f(0); i<=inarray.l(0); ++i)
    {
      double omega, realpart, imagpart;
      is >> omega >> realpart >> imagpart;
      inomega(i)=omega;
      inarray(i)=GremlinIres::Tcvalue(realpart,imagpart);
    }

    int n1=static_cast<int>(inomega(1)/(df*pi2))+1;
    int n2=n1+nf-1;

    GremlinIres inires(df,n1,n2);
    GremlinIres::Tcarray iresarray=inires.ires();
    iresarray.copyin(inarray);

    TFXX_assert((std::abs(1.-pi2*inires.f(n1)/inomega(1))<1.e-4),
                "ERROR: frequency range mismatch in gremlin ires");

    ires=inires;
    return(is);
  }

  /*----------------------------------------------------------------------*/

  std::ostream& operator<<(std::ostream& os, const GremlinIres& ires)
  {
thomas.forbriger's avatar
thomas.forbriger committed
95
    const double pi2=2.*3.141592653589793115997;
thomas.forbriger's avatar
thomas.forbriger committed
96
97
98
99
100
101
102
103
104
105
106
    // get copy including frequency zero
    GremlinIres::Tcarray outires(ires.n2());
    GremlinIres::Tcarray
      subires(aff::subarray(outires)(ires.n1(),ires.n2()));

    subires.copyin(ires.ires());
    os << "C++ version of gremlin ires" << std::endl;
    os << "columns below row number 7:" << std::endl;
    os << "  1: angular frequency (1/s)" << std::endl;
    os << "  2: real part" << std::endl;
    os << "  3: imaginary part" << std::endl;
thomas.forbriger's avatar
thomas.forbriger committed
107
    os << pi2*ires.df() << " angular frequency step width" << std::endl;
thomas.forbriger's avatar
thomas.forbriger committed
108
109
    os << outires.size() << " number of frequency samples" << std::endl;

thomas.forbriger's avatar
thomas.forbriger committed
110
    const int bufsize=60;
thomas.forbriger's avatar
thomas.forbriger committed
111
112
113
114
    char buffer[bufsize];

    for (int i=outires.f(0); i<=outires.l(0); ++i) 
    {
thomas.forbriger's avatar
thomas.forbriger committed
115
116
117
118
      double angfreq=static_cast<double>(pi2*ires.f(i));
      double realpart=static_cast<double>(real(outires(i)));
      double imagpart=static_cast<double>(imag(outires(i)));
      std::snprintf(buffer, bufsize, "%15.5f %15.7e %15.7e", 
thomas.forbriger's avatar
thomas.forbriger committed
119
120
121
122
123
124
125
126
127
128
                    angfreq, realpart, imagpart);
      os << buffer << std::endl;
    }

    return(os);
  }

}

/* ----- END OF srcires.cc ----- */