LCOV - code coverage report
Current view: top level - alma/ASDM - ComplexWrapper.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 4 81 4.9 %
Date: 2024-12-11 20:54:31 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      269184 : Complex Complex::getComplex(StringTokenizer &t) {
      36      269184 :         double r = Double::parseDouble(t.nextToken());
      37      269184 :         double i = Double::parseDouble(t.nextToken());
      38      269184 :         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 :     double re = eis.readDouble();
      91           0 :     double im = eis.readDouble();
      92           0 :     return Complex(re, im);
      93             : }
      94             : 
      95           0 : vector<Complex> Complex::from1DBin(EndianIStream & eis) {
      96           0 :         int dim1 = eis.readInt();
      97           0 :         vector<Complex> result;
      98           0 :         for (int i = 0; i < dim1; i++)
      99           0 :             result.push_back(Complex::fromBin(eis));
     100           0 :         return result;  
     101           0 : }
     102             : 
     103           0 : vector<vector<Complex > > Complex::from2DBin(EndianIStream & eis) {
     104           0 :         int dim1 = eis.readInt();
     105           0 :         int dim2 = eis.readInt();
     106           0 :         vector< vector<Complex> >result;
     107           0 :         vector <Complex> aux;
     108           0 :         for (int i = 0; i < dim1; i++) {
     109           0 :                 aux.clear();
     110           0 :                 for (int j = 0; j < dim2; j++)
     111           0 :                     aux.push_back(Complex::fromBin(eis))                                 ;
     112           0 :                 result.push_back(aux);
     113             :         }
     114           0 :         return result;  
     115           0 : }
     116             : 
     117           0 : vector<vector<vector<Complex > > > Complex::from3DBin(EndianIStream & eis) {
     118           0 :         int dim1 = eis.readInt();
     119           0 :         int dim2 = eis.readInt();
     120           0 :         int dim3 = eis.readInt();
     121           0 :         vector<vector< vector<Complex> > >result;
     122           0 :         vector < vector<Complex> >aux1;
     123           0 :         vector <Complex> aux2;
     124           0 :         for (int i = 0; i < dim1; i++) {
     125           0 :                 aux1.clear();
     126           0 :                 for (int j = 0; j < dim2; j++) {
     127           0 :                         aux2.clear();
     128           0 :                         for (int k = 0; k < dim3; k++)
     129           0 :                             aux2.push_back(Complex::fromBin(eis));
     130           0 :                         aux1.push_back(aux2);
     131             :                 }
     132           0 :                 result.push_back(aux1);
     133             :         }
     134           0 :         return result;  
     135           0 : }
     136             : 
     137             : } // End namespace asdm

Generated by: LCOV version 1.16