casa  5.7.0-16
SakuraArrayConverter.h
Go to the documentation of this file.
1 #ifndef _CASA_SAKURA_ARRAY_CONVERTER_H_
2 #define _CASA_SAKURA_ARRAY_CONVERTER_H_
3
4 #include <iostream>
5 #include <string>
6 #include <stdexcept>
7 //#include <libsakura/sakura.h>
8 #include <casa/aipstype.h>
9
10 // AIPS++
11 #include <casa/aips.h>
13 #include <casa/Arrays/Vector.h>
14 #include <casa/Arrays/Matrix.h>
15 #include <casa/Arrays/Cube.h>
16
17 using namespace std;
18
19 namespace casa { //# NAMESPACE CASA - BEGIN
20
22 protected:
23
24 public:
25  template<class T, class S> static void ConvertCASAToSakura(
26  casacore::uInt const pol_index, casacore::uInt const num_data,
27  const casacore::Matrix<T> &input_matrix, S *output_data) {
28  casacore::uInt const max_pol = input_matrix.nrow();
29  if (!(pol_index < max_pol)) {
30  throw std::invalid_argument(
31  "pol_index must less than input_matrix.nrow()");
32  }
33  if (!(num_data == input_matrix.ncolumn())) {
34  throw std::invalid_argument(
35  "num_data must equal to input_matrix.ncolumn()");
36  }
37  casacore::Bool deleteIn;
38  const T* pin = input_matrix.getStorage(deleteIn);
39  for (casacore::uInt i = 0; i < num_data; ++i) {
40  CASAToSakura(max_pol * i + pol_index, i, pin, output_data);
41  }
42  input_matrix.freeStorage(pin, deleteIn);
43  }
44  template<class S, class T> static void ConvertSakuraToCASA(
45  casacore::uInt const pol_index, casacore::uInt const num_data, S const *input_data,
46  casacore::Matrix<T> &output_matrix) {
47  casacore::uInt const max_pol = output_matrix.nrow();
48  if (!(pol_index < max_pol)) {
49  throw std::invalid_argument(
50  "pol_index must less than input_matrix.nrow()");
51  }
52  if (!(num_data == output_matrix.ncolumn())) {
53  throw std::invalid_argument(
54  "num_data must equal to output_matrix.ncolumn()");
55  }
56  casacore::Bool deleteOut;
57  T* pout = output_matrix.getStorage(deleteOut);
58  for (casacore::uInt i = 0; i < num_data; ++i) {
59  SakuraToCASA(i, max_pol * i + pol_index, input_data, pout);
60  }
61  output_matrix.putStorage(pout, deleteOut);
62  }
63
64 private:
65  template<class T, class S> static void CASAToSakura(casacore::uInt const index_in,
66  casacore::uInt const index_out, const T* pin, S *output_data) {
67  output_data[index_out] = pin[index_in];
68  }
69  template<class S, class T> static void SakuraToCASA(casacore::uInt const index_in,
70  casacore::uInt const index_out, S const *input_data, T* pout) {
71  pout[index_out] = input_data[index_in];
72  }
73 };
74
75 template<> void SakuraArrayConverter::CASAToSakura<casacore::Complex, float>(
76  casacore::uInt const index_in, casacore::uInt const index_out, const casacore::Complex* pin,
77  float *output_data);
78 template<> void SakuraArrayConverter::SakuraToCASA<float, casacore::Complex>(
79  casacore::uInt const index_in, casacore::uInt const index_out, float const *input_data,
80  casacore::Complex* pout);
81 template<> void SakuraArrayConverter::CASAToSakura<casacore::Bool, bool>(
82  casacore::uInt const index_in, casacore::uInt const index_out, const casacore::Bool* pin,
83  bool *output_data);
84 template<> void SakuraArrayConverter::SakuraToCASA<bool, casacore::Bool>(
85  casacore::uInt const index_in, casacore::uInt const index_out, bool const *input_data,
86  casacore::Bool* pout);
87 } //# NAMESPACE CASA - END
88
89 #endif /* _CASA_SINGLEDISH_DUMMY_H_ */
void putStorage(T *&storage, Bool deleteAndCopy)
putStorage() is normally called after a call to getStorage() (cf).
size_t nrow() const
The number of rows in the Matrix, i.e.
Definition: Matrix.h:301
static void ConvertSakuraToCASA(casacore::uInt const pol_index, casacore::uInt const num_data, S const *input_data, casacore::Matrix< T > &output_matrix)
A 2-D Specialization of the Array class.
static void CASAToSakura(casacore::uInt const index_in, casacore::uInt const index_out, const T *pin, S *output_data)
T * getStorage(Bool &deleteIt)
Generally use of this should be shunned, except to use a FORTRAN routine or something similar...
static void SakuraToCASA(casacore::uInt const index_in, casacore::uInt const index_out, S const *input_data, T *pout)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
size_t ncolumn() const
The number of columns in the Matrix, i.e.
Definition: Matrix.h:305
void freeStorage(const T *&storage, Bool deleteIt) const
If deleteIt is set, delete &quot;storage&quot;.
static void ConvertCASAToSakura(casacore::uInt const pol_index, casacore::uInt const num_data, const casacore::Matrix< T > &input_matrix, S *output_data)
unsigned int uInt
Definition: aipstype.h:51