1#ifndef __COMPLEX_ARRAY_H__
2#define __COMPLEX_ARRAY_H__
4#include <boost/archive/text_iarchive.hpp>
5#include <boost/archive/text_oarchive.hpp>
6#include <boost/serialization/shared_ptr.hpp>
8#include <gsl/gsl_errno.h>
9#include <gsl/gsl_fft_complex.h>
10#include "mspass/utility/MsPASSError.h"
16#define REAL(z, i) ((z)[2 * (i)])
17#define IMAG(z, i) ((z)[2 * (i) + 1])
18namespace mspass::algorithms::deconvolution {
19typedef std::complex<double> Complex64;
20typedef std::complex<float> Complex32;
33template <
class Archive>
34void serialize(Archive &ar,
FortranComplex64 &z,
const unsigned int version) {
74 template <
class T>
ComplexArray(
int nsamp, std::vector<T> d);
89 data.swap(other.data);
90 std::swap(nsamp, other.nsamp);
126 double *
ptr(
int sample);
161 std::vector<double>
abs()
const;
165 double norm2()
const;
167 std::vector<double>
phase()
const;
190 std::shared_ptr<FortranComplex64[]> data;
192 friend boost::serialization::access;
193 template <
class Archive>
194 void save(Archive &ar,
const unsigned int version)
const {
195 std::vector<FortranComplex64> dv;
196 dv.reserve(this->nsamp);
197 for (
auto i = 0; i < nsamp; ++i)
198 dv.push_back(this->data[i]);
202 template <
class Archive>
void load(Archive &ar,
const unsigned int version) {
204 std::vector<FortranComplex64> dv;
207 const std::string caller(
"ComplexArray serialization load");
208 if (loaded_nsamp < 0)
210 caller +
": archived sample count cannot be negative",
211 mspass::utility::ErrorSeverity::Invalid);
212 if (dv.size() !=
static_cast<size_t>(loaded_nsamp))
214 caller +
": archived sample count does not match data vector",
215 mspass::utility::ErrorSeverity::Invalid);
217 std::shared_ptr<FortranComplex64[]> loaded_data;
218 if (loaded_nsamp > 0) {
219 loaded_data = std::shared_ptr<FortranComplex64[]>(
221 for (
int i = 0; i < loaded_nsamp; ++i)
222 loaded_data[i] = dv[i];
224 data.swap(loaded_data);
225 nsamp = loaded_nsamp;
227 BOOST_SERIALIZATION_SPLIT_MEMBER()
258 if (nsamp > d.size()) {
260 for (std::size_t i = 0; i < d.size(); i++) {
261 this->data[i].real = d[i];
262 this->data[i].imag = 0.0;
264 for (std::size_t i = d.size(); i < nsamp; i++) {
265 this->data[i].real = 0.0;
266 this->data[i].imag = 0.0;
270 for (std::size_t i = 0; i < nsamp; i++) {
271 this->data[i].real = d[i];
272 this->data[i].imag = 0.0;
279 for (std::size_t i = 0; i < nsamp; i++) {
280 this->data[i].real = d;
281 this->data[i].imag = 0.0;
Interfacing object to ease conversion between FORTRAN and C++ complex.
Definition ComplexArray.h:44
const ComplexArray operator*(const ComplexArray &other) const noexcept(false)
Definition ComplexArray.cc:221
ComplexArray()
Definition ComplexArray.cc:8
double rms() const
Definition ComplexArray.cc:253
double norm2() const
Definition ComplexArray.cc:261
int size() const
Definition ComplexArray.cc:275
const ComplexArray operator/(const ComplexArray &other) const noexcept(false)
Definition ComplexArray.cc:231
ComplexArray & operator=(const ComplexArray &parent)
Definition ComplexArray.cc:94
std::vector< double > abs() const
Definition ComplexArray.cc:245
ComplexArray & operator-=(const ComplexArray &other) noexcept(false)
Definition ComplexArray.cc:135
void conj()
Definition ComplexArray.cc:241
Complex64 operator[](int sample)
Definition ComplexArray.cc:117
void swap(ComplexArray &other) noexcept
Definition ComplexArray.h:88
double * ptr()
Definition ComplexArray.cc:111
ComplexArray & operator+=(const ComplexArray &other) noexcept(false)
Definition ComplexArray.cc:120
const ComplexArray operator+(const ComplexArray &other) const noexcept(false)
Definition ComplexArray.cc:201
ComplexArray & operator/=(const ComplexArray &other) noexcept(false)
Definition ComplexArray.cc:168
std::vector< double > phase() const
Definition ComplexArray.cc:268
const ComplexArray operator-(const ComplexArray &other) const noexcept(false)
Definition ComplexArray.cc:211
~ComplexArray()
Definition ComplexArray.cc:106
ComplexArray & operator*=(const ComplexArray &other) noexcept(false)
Definition ComplexArray.cc:150
Base class for error object thrown by MsPASS library routines.
Definition MsPASSError.h:38
FORTRAN-compatible single-precision complex value.
Definition ComplexArray.h:23
float imag
Definition ComplexArray.h:25
float real
Definition ComplexArray.h:24
FORTRAN-compatible double-precision complex value.
Definition ComplexArray.h:28
double imag
Definition ComplexArray.h:30
double real
Definition ComplexArray.h:29