LCOV - code coverage report
Current view: top level - synthesis/MeasurementComponents - CExp.new3.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 2 2 100.0 %
Date: 2024-12-11 20:54:31 Functions: 2 2 100.0 %

          Line data    Source code
       1             : //# CExp.cc: Implementation of CExp (tabulated complex exponential) class
       2             : //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //# $Id$
      27             : #if !defined(CEXP3_H)
      28             : #define CEXP3_H
      29             : 
      30             : #include <stdlib.h>
      31             : #include <math.h>
      32             : #include <iostream>
      33             : #include <sstream>
      34             : #include <complex>
      35             : #include <vector>
      36             : #include <ctime>
      37             : 
      38             : namespace casa{
      39             : # define PI2 6.28318530717958623
      40             : # define CE_TYPE float
      41             : 
      42             : using namespace std;
      43             : 
      44             : template <class T> class CExp3
      45             : {
      46             : public:
      47         180 :   CExp3() { Size = 0; ITable=RTable=NULL; };
      48             :   CExp3(int n) { Size = n; build(Size); };
      49         180 :   ~CExp3(){if (ITable) {free(ITable);free(RTable);}}
      50             :   inline void build(int n)
      51             :   {
      52             :     Size = n;
      53             :     //    ITable.resize(Size); RTable.resize(Size);
      54             :     ITable = (T*)malloc(sizeof(T)*Size);
      55             :     RTable = (T*)malloc(sizeof(T)*Size);
      56             :     Step = PI2/Size;
      57             :     for (int i=0; i<Size; i++) {
      58             :       ITable[i] = sin(i*Step);
      59             :       RTable[i] = cos(i*Step);
      60             :     }
      61             :   }
      62             :   inline int f(T arg)
      63             :   {
      64             :     return (int)((arg<0)?((arg+1-(int)arg)*Size):((arg-(int)arg)*Size));
      65             :     //    if (arg < 0) return (int)((arg+1-(int)arg)*Size); return (int)((arg-(int)arg)*Size);
      66             :   }
      67             : 
      68             :   inline int hashFunction(T arg)
      69             :   {
      70             :     return f(arg/PI2);
      71             :     // return (int)(fmodf(fabsf(arg+PI2),PI2)/Step);
      72             :   }
      73             : 
      74             :   inline std::complex<T> operator()(T& arg)
      75             :   {
      76             :     int N=hashFunction(arg);
      77             :     return std::complex<T>(RTable[N],ITable[N]);
      78             :   }
      79             : 
      80             :   inline T imag(T arg) { return ITable[hashFunction(arg)]; }
      81             :   inline T real(T arg) { return RTable[hashFunction(arg)]; }
      82             :   inline void reim(T& arg,T& re, T&im)
      83             :   { int N = hashFunction(arg);
      84             :     re = RTable[N]; im = ITable[N];
      85             :   }
      86             : private:
      87             :   //  vector<T> RTable, ITable;
      88             :   T *RTable, *ITable;
      89             :   T Step;
      90             :   int Size;
      91             : };
      92             : };  
      93             : #endif

Generated by: LCOV version 1.16