LCOV - code coverage report
Current view: top level - alma/ASDM - ComplexWrapper.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 4 76 5.3 %
Date: 2023-10-25 08:47:59 Functions: 1 11 9.1 %

          Line data    Source code
       1             : /*
       2             :  * ALMA - Atacama Large Millimeter Array
       3             :  * (c) European Southern Observatory, 2002
       4             :  * (c) Associated Universities Inc., 2002
       5             :  * Copyright by ESO (in the framework of the ALMA collaboration),
       6             :  * Copyright by AUI (in the framework of the ALMA collaboration),
       7             :  * All rights reserved.
       8             :  * 
       9             :  * This library is free software; you can redistribute it and/or
      10             :  * modify it under the terms of the GNU Lesser General Public
      11             :  * License as published by the Free software Foundation; either
      12             :  * version 2.1 of the License, or (at your option) any later version.
      13             :  * 
      14             :  * This library is distributed in the hope that it will be useful,
      15             :  * but WITHOUT ANY WARRANTY, without even the implied warranty of
      16             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :  * Lesser General Public License for more details.
      18             :  * 
      19             :  * You should have received a copy of the GNU Lesser General Public
      20             :  * License along with this library; if not, write to the Free Software
      21             :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      22             :  * MA 02111-1307  USA
      23             :  *
      24             :  * File Complex.cpp
      25             :  */
      26             : 
      27             : #include <alma/ASDM/ComplexWrapper.h>
      28             : #include <alma/ASDM/DoubleWrapper.h>
      29             : #include <alma/ASDM/NumberFormatException.h>
      30             : 
      31             : using namespace std;
      32             : 
      33             : namespace asdm {
      34             : 
      35      223040 : Complex Complex::getComplex(StringTokenizer &t) {
      36      223040 :         double r = Double::parseDouble(t.nextToken());
      37      223040 :         double i = Double::parseDouble(t.nextToken());
      38      223040 :         return Complex (r,i);
      39             : }
      40             : 
      41           0 : Complex Complex::fromString(const string& s) {
      42           0 :         string::size_type n = s.find(' ');
      43           0 :         if (n == string::npos)
      44           0 :                 throw NumberFormatException("Not a complex number.");
      45           0 :         double r = Double::parseDouble(s.substr(0,n));
      46           0 :         double i = Double::parseDouble(s.substr(n+1, s.length() - (n + 1)));
      47           0 :         return Complex(r,i);
      48             : }
      49             : 
      50           0 : string Complex::toString(const Complex &x) {
      51           0 :         return Double::toString(x.getReal()) + " " + Double::toString(x.getImg());
      52             : }
      53             : 
      54           0 : void Complex::toBin(EndianOSStream& eoss) {
      55           0 :         eoss.writeDouble(       real());
      56           0 :         eoss.writeDouble(       imag());
      57           0 : }
      58             : 
      59           0 : void Complex::toBin(const vector<Complex>& cmplx,  EndianOSStream& eoss) {
      60           0 :         eoss.writeInt((int) cmplx.size());
      61           0 :         for (unsigned int i = 0; i < cmplx.size(); i++) {
      62           0 :                 eoss.writeDouble(cmplx.at(i).real());
      63           0 :                 eoss.writeDouble(cmplx.at(i).imag());
      64             :         }
      65           0 : }
      66             : 
      67           0 : void Complex::toBin(const vector<vector<Complex> >& cmplx,  EndianOSStream& eoss) {
      68           0 :         eoss.writeInt((int) cmplx.size());
      69           0 :         eoss.writeInt((int) cmplx.at(0).size());
      70           0 :         for (unsigned int i = 0; i < cmplx.size(); i++)
      71           0 :                 for (unsigned int j = 0; j < cmplx.at(0).size(); j++) {
      72           0 :                         eoss.writeDouble(cmplx.at(i).at(j).real());
      73           0 :                         eoss.writeDouble(cmplx.at(i).at(j).imag());
      74             :                 }
      75           0 : }
      76             : 
      77           0 : void Complex::toBin(const vector< vector<vector<Complex> > >& cmplx,  EndianOSStream& eoss) {
      78           0 :         eoss.writeInt((int) cmplx.size());
      79           0 :         eoss.writeInt((int) cmplx.at(0).size());
      80           0 :         eoss.writeInt((int) cmplx.at(0).at(0).size());  
      81           0 :         for (unsigned int i = 0; i < cmplx.size(); i++)
      82           0 :                 for (unsigned int j = 0; j < cmplx.at(0).size(); j++)
      83           0 :                                 for (unsigned int k = 0; k < cmplx.at(0).at(0).size(); j++) {
      84           0 :                                         eoss.writeDouble(cmplx.at(i).at(j).at(k).real());
      85           0 :                                         eoss.writeDouble(cmplx.at(i).at(j).at(k).imag());
      86             :                                 }
      87           0 : }
      88             : 
      89           0 : Complex Complex::fromBin(EndianIStream & eis) {
      90           0 :         return Complex(eis.readDouble(), eis.readDouble());
      91             : }
      92             : 
      93           0 : vector<Complex> Complex::from1DBin(EndianIStream & eis) {
      94           0 :         int dim1 = eis.readInt();
      95           0 :         vector<Complex> result;
      96           0 :         for (int i = 0; i < dim1; i++)
      97           0 :                 result.push_back(Complex(eis.readDouble(),  eis.readDouble()));
      98           0 :         return result;  
      99             : }
     100             : 
     101           0 : vector<vector<Complex > > Complex::from2DBin(EndianIStream & eis) {
     102           0 :         int dim1 = eis.readInt();
     103           0 :         int dim2 = eis.readInt();
     104           0 :         vector< vector<Complex> >result;
     105           0 :         vector <Complex> aux;
     106           0 :         for (int i = 0; i < dim1; i++) {
     107           0 :                 aux.clear();
     108           0 :                 for (int j = 0; j < dim2; j++)
     109           0 :                         aux.push_back(Complex(eis.readDouble(), eis.readDouble()));
     110           0 :                 result.push_back(aux);
     111             :         }
     112           0 :         return result;  
     113             : }
     114             : 
     115           0 : vector<vector<vector<Complex > > > Complex::from3DBin(EndianIStream & eis) {
     116           0 :         int dim1 = eis.readInt();
     117           0 :         int dim2 = eis.readInt();
     118           0 :         int dim3 = eis.readInt();
     119           0 :         vector<vector< vector<Complex> > >result;
     120           0 :         vector < vector<Complex> >aux1;
     121           0 :         vector <Complex> aux2;
     122           0 :         for (int i = 0; i < dim1; i++) {
     123           0 :                 aux1.clear();
     124           0 :                 for (int j = 0; j < dim2; j++) {
     125           0 :                         aux2.clear();
     126           0 :                         for (int k = 0; k < dim3; k++)
     127           0 :                                 aux2.push_back(Complex(eis.readDouble(), eis.readDouble()));
     128           0 :                         aux1.push_back(aux2);
     129             :                 }
     130           0 :                 result.push_back(aux1);
     131             :         }
     132           0 :         return result;  
     133             : }
     134             : 
     135             : } // End namespace asdm

Generated by: LCOV version 1.16