casa
$Rev:20696$
|
00001 //# CExp.cc: Implementation of CExp (tabulated complex exponential) class 00002 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 #if !defined(CEXP3_H) 00028 #define CEXP3_H 00029 00030 #include <stdlib.h> 00031 #include <math.h> 00032 #include <iostream> 00033 #include <sstream> 00034 #include <complex> 00035 #include <vector> 00036 #include <ctime> 00037 00038 namespace casa{ 00039 # define PI2 6.28318530717958623 00040 # define CE_TYPE float 00041 00042 using namespace std; 00043 00044 template <class T> class CExp3 00045 { 00046 public: 00047 CExp3() { Size = 0; ITable=RTable=NULL; }; 00048 CExp3(int n) { Size = n; build(Size); }; 00049 ~CExp3(){if (ITable) {free(ITable);free(RTable);}} 00050 inline void build(int n) 00051 { 00052 Size = n; 00053 // ITable.resize(Size); RTable.resize(Size); 00054 ITable = (T*)malloc(sizeof(T)*Size); 00055 RTable = (T*)malloc(sizeof(T)*Size); 00056 Step = PI2/Size; 00057 for (int i=0; i<Size; i++) { 00058 ITable[i] = sin(i*Step); 00059 RTable[i] = cos(i*Step); 00060 } 00061 } 00062 inline int f(register T arg) 00063 { 00064 return (int)((arg<0)?((arg+1-(int)arg)*Size):((arg-(int)arg)*Size)); 00065 // if (arg < 0) return (int)((arg+1-(int)arg)*Size); return (int)((arg-(int)arg)*Size); 00066 } 00067 00068 inline int hashFunction(T arg) 00069 { 00070 return f(arg/PI2); 00071 // return (int)(fmodf(fabsf(arg+PI2),PI2)/Step); 00072 } 00073 00074 inline std::complex<T> operator()(T& arg) 00075 { 00076 int N=hashFunction(arg); 00077 return std::complex<T>(RTable[N],ITable[N]); 00078 } 00079 00080 inline T imag(T arg) { return ITable[hashFunction(arg)]; } 00081 inline T real(T arg) { return RTable[hashFunction(arg)]; } 00082 inline void reim(T& arg,T& re, T&im) 00083 { int N = hashFunction(arg); 00084 re = RTable[N]; im = ITable[N]; 00085 } 00086 private: 00087 // vector<T> RTable, ITable; 00088 T *RTable, *ITable; 00089 T Step; 00090 int Size; 00091 }; 00092 }; 00093 #endif