version  0.0.1
Defines the C++ API for MsPASS
Public Member Functions | List of all members
mspass::algorithms::deconvolution::ComplexArray Class Reference

Public Member Functions

 ComplexArray ()
 
 ComplexArray (std::vector< Complex64 > &d)
 
 ComplexArray (std::vector< Complex32 > &d)
 
 ComplexArray (int nsamp, FortranComplex32 *d)
 
 ComplexArray (int nsamp, FortranComplex64 *d)
 
 ComplexArray (int nsamp, float *d)
 
 ComplexArray (int nsamp, double *d)
 
 ComplexArray (int nsamp)
 
template<class T >
 ComplexArray (int nsamp, std::vector< T > d)
 
template<class T >
 ComplexArray (int nsamp, T d)
 
 ComplexArray (std::vector< double > mag, std::vector< double > phase)
 
 ComplexArray (const ComplexArray &parent)
 
ComplexArrayoperator= (const ComplexArray &parent)
 
template<class T >
T * FortranData ()
 
template<class T >
std::vector< std::complex< T > > CPPData ()
 
Complex64 operator[] (int sample)
 
double * ptr ()
 
double * ptr (int sample)
 
ComplexArrayoperator+= (const ComplexArray &other) noexcept(false)
 
ComplexArrayoperator-= (const ComplexArray &other) noexcept(false)
 
ComplexArrayoperator*= (const ComplexArray &other) noexcept(false)
 
ComplexArrayoperator/= (const ComplexArray &other) noexcept(false)
 
const ComplexArray operator+ (const ComplexArray &other) const noexcept(false)
 
const ComplexArray operator- (const ComplexArray &other) const noexcept(false)
 
const ComplexArray operator* (const ComplexArray &other) const noexcept(false)
 
const ComplexArray operator/ (const ComplexArray &other) const noexcept(false)
 
void conj ()
 
std::vector< double > abs () const
 
double rms () const
 
double norm2 () const
 
std::vector< double > phase () const
 
int size () const
 

Constructor & Destructor Documentation

◆ ComplexArray() [1/6]

mspass::algorithms::deconvolution::ComplexArray::ComplexArray ( )

Empty constructor.

10 {
11  nsamp=0;
12  data=NULL;
13 }

◆ ComplexArray() [2/6]

mspass::algorithms::deconvolution::ComplexArray::ComplexArray ( std::vector< Complex64 > &  d)

Construct from stl vector container of complex.

◆ ComplexArray() [3/6]

mspass::algorithms::deconvolution::ComplexArray::ComplexArray ( std::vector< Complex32 > &  d)

Similar for 32 bit version

◆ ComplexArray() [4/6]

mspass::algorithms::deconvolution::ComplexArray::ComplexArray ( int  nsamp,
FortranComplex32 d 
)

Construct from a FORTRAN data array.

Fortran stores complex numbers in a mulitplexed array structure (real(1), imag(1), real(2), imag(2), etc.). The constructors below provide a mechanism for building this object from various permutations of this.

Parameters
nsampis the number of elements in the C vector
dis the pointer to the first compoment of the fortran vector.
35 {
36  nsamp=n;
37  data=new FortranComplex64[nsamp];
38  for(int i=0; i<nsamp; i++)
39  {
40  data[i].real=d[i].real;
41  data[i].imag=d[i].imag;
42  }
43 }

◆ ComplexArray() [5/6]

template<class T >
mspass::algorithms::deconvolution::ComplexArray::ComplexArray ( int  nsamp,
std::vector< T >  d 
)

Construct from different length of vector, adds zoeros to it And construct a constant arrays

175 {
176  nsamp=n;
177  if(nsamp>d.size())
178  {
179  data=new FortranComplex64[nsamp];
180  for(int i=0; i<d.size(); i++)
181  {
182  data[i].real=d[i];
183  data[i].imag=0.0;
184  }
185  for(int i=d.size(); i<nsamp; i++)
186  {
187  data[i].real=0.0;
188  data[i].imag=0.0;
189  }
190  }
191  else
192  {
193  data=new FortranComplex64[nsamp];
194  for(int i=0; i<nsamp; i++)
195  {
196  data[i].real=d[i];
197  data[i].imag=0.0;
198  }
199  }
200 }

◆ ComplexArray() [6/6]

mspass::algorithms::deconvolution::ComplexArray::ComplexArray ( std::vector< double >  mag,
std::vector< double >  phase 
)

Construct from magnitude and phase arrays.

Member Function Documentation

◆ conj()

void mspass::algorithms::deconvolution::ComplexArray::conj ( )

product of complex and real vectors

product of complex and a number

Change vector to complex conjugates.

274 {
275  for(int i=0; i<nsamp; i++)
276  data[i].imag=-data[i].imag;
277 }

◆ FortranData()

template<class T >
T * mspass::algorithms::deconvolution::ComplexArray::FortranData

Return a pointer to a fortran array containing the data vector.

The array linked to the returned pointer should be created with the new operator and the caller should be sure to use delete [] to free this memory when finished.

167 {
168  T* result=new T[nsamp];
169  for(int i=0; i<nsamp; i++)
170  result[i]=data[i];
171  return result;
172 }

◆ operator[]()

Complex64 mspass::algorithms::deconvolution::ComplexArray::operator[] ( int  sample)

Index operator. Cannot make it work by getting the address from reference. Have to call the ptr() function to get the address.

Parameters
sampleis the sample number to return.
Returns
contents of vector at position sample.
143 {
144  return *reinterpret_cast<Complex64*>(&data[sample].real);
145 }

The documentation for this class was generated from the following files: