stfinv.cc 6.01 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*! \file stfinv.cc
 * \brief C API to library (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * ----
 * 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
 * ----
 *
 * \author Thomas Forbriger
 * \date 06/05/2011
 * 
 * C API to library (implementation)
 * 
 * Copyright (c) 2011 by Thomas Forbriger (BFO Schiltach) 
 * 
 * REVISIONS and CHANGES 
 *  - 06/05/2011   V1.0   Thomas Forbriger
 *  - 30/09/2011   V1.1   implemented handling of additional time series pairs
 *  - 05/10/2011   V1.2   correction: initstfinvenginewithpairs was named
 *                        incorrectly initstfinvenginepairs
34
 *  - 14/10/2015   V1.3   new end-user usage functions
35
36
37
38
 * 
 * ============================================================================
 */
#define STFINV_STFINV_C_VERSION \
39
  "STFINV_STFINV_C   V1.3"
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

#include <stfinv/stfinv.h>
#include <stfinv/error.h>
#include <stfinv/stfinvany.h>

/*! \brief Internals of C API.
 *
 * The C language API uses some internal data structures to keep engines.
 *
 * \defgroup capiinternal Internals of C API
 * \sa cinterface
 */

namespace stfinv {

  /*! \brief Namespace for internal data structures of the C API.
   * \ingroup capiinternal
   */
  namespace capi {

    /*! \brief Pointer to engine to work with.
     * \ingroup capiinternal
     */
    stfinv::STFEngine* Pengine=0;

  } // namespace capi

} // namespace stfinv

/*======================================================================*/

void initstfinvenginewithpairs(struct CTriples triples,
                               struct CWaveform stf,
                               struct CPairs pairs,
                               char* parameters)
{
  // remove existing engine if has previously been initialized
  freestfinvengine();

  // convert parameter string
  std::string cxxparameters(parameters);

  // convert pointer to source correction filter array
  stfinv::Waveform cxxstf;
  cxxstf.sampling=stf.sampling;
  aff::LinearShape shape(0, cxxstf.sampling.n-1, 0);
  cxxstf.series
    =stfinv::Tseries(shape, 
                     aff::SharedHeap<Tvalue>(stf.series,
                                             cxxstf.sampling.n));

  // convert pointer triples
  // notice: it is not required to check consistency here; all header fields
  // are transferred to the C++ containers; the C++ engine will check
  // consistency during its initialization
  STFINV_assert(triples.n>0, "no triples provided");
  stfinv::Tvectoroftriples cxxtriples(triples.n);
  for (int i=0; i<triples.n; ++i)
  {
    CWaveformTriple ctriple=triples.triples[i];
    cxxtriples[i].header=ctriple.header;
    const int& n=cxxtriples[i].header.sampling.n;
    shape=aff::LinearShape(0, n-1, 0);
    cxxtriples[i].data
      =stfinv::Tseries::Tcoc(shape, 
                       aff::SharedHeap<Tvalue>::Tcoc(ctriple.data, n));
    cxxtriples[i].synthetics
      =stfinv::Tseries::Tcoc(shape, 
                       aff::SharedHeap<Tvalue>::Tcoc(ctriple.synthetics, n));
    cxxtriples[i].convolvedsynthetics
      =stfinv::Tseries(shape, 
                       aff::SharedHeap<Tvalue>(ctriple.convolvedsynthetics, n));
  }

  // convert pointer pairs
  // notice: it is not required to check consistency here; all header fields
  // are transferred to the C++ containers; the C++ engine will check
  // consistency during its initialization
  stfinv::Tvectorofpairs cxxpairs(pairs.n);
  for (int i=0; i<pairs.n; ++i)
  {
    CWaveformPair cpair=pairs.pairs[i];
    cxxpairs[i].sampling=cpair.sampling;
    const int& n=cxxpairs[i].sampling.n;
    shape=aff::LinearShape(0, n-1, 0);
    cxxpairs[i].synthetics
      =stfinv::Tseries::Tcoc(shape, 
                       aff::SharedHeap<Tvalue>::Tcoc(cpair.synthetics, n));
    cxxpairs[i].convolvedsynthetics
      =stfinv::Tseries(shape, 
                       aff::SharedHeap<Tvalue>(cpair.convolvedsynthetics, n));
  }

  // create engine
  stfinv::capi::Pengine=new stfinv::STFEngine(cxxtriples, cxxstf,
                                              cxxpairs,
                                              cxxparameters);
} // void initstfinvenginewithpairs

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

void initstfinvengine(struct CTriples triples,
                      struct CWaveform stf,
                      char* parameters)
{
  struct CPairs pairs;
  pairs.n=0;
  initstfinvenginewithpairs(triples, stf, pairs, parameters);
} // void initstfinvengine

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

void runstfinvengine()
{
  STFINV_assert(stfinv::capi::Pengine != 0,
                "runstfinvengine(): engine is not initialized!");
  stfinv::capi::Pengine->run();
} // void runstfinvengine()

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

void freestfinvengine()
{
  if (stfinv::capi::Pengine != 0) { delete stfinv::capi::Pengine; }
} // void freestfinvengine()

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

168
169
170
171
172
173
174
void printengines()
{
  stfinv::engines();
} // void printengines()

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

175
176
177
178
179
void printhelp()
{
  stfinv::help();
} // void printhelp()

180
181
182
183
184
185
186
187
/*----------------------------------------------------------------------*/

void printusage(char* id)
{
  std::string selectid(id);
  stfinv::usage(selectid);
} // void printhelp(age(char* id)

188
/* ----- END OF stfinv.cc ----- */