framefast/fftype.hh

00001 /*----------------------------------------------------------------------*/
00002 /*                                                                      */
00003 /* Module Name: fftype                                                  */
00004 /*                                                                      */
00005 /* Module Description: Basic data types for framefast and fantom        */
00006 /*                                                                      */
00007 /* Revision History:                                                    */
00008 /* Rel   Date     Programmer    Comments                                */
00009 /* 0.1   26Sep00  D. Sigg       First release                           */
00010 /*                                                                      */
00011 /* Documentation References:                                            */
00012 /*      Man Pages: fftype.html                                          */
00013 /*      References: none                                                */
00014 /*                                                                      */
00015 /* Author Information:                                                  */
00016 /* Name          Telephone       Fax             e-mail                 */
00017 /* Daniel Sigg   (509) 372-8132  (509) 372-8137  sigg_d@ligo.mit.edu    */
00018 /*                                                                      */
00019 /*                                                                      */
00020 /*                      -------------------                             */
00021 /*                                                                      */
00022 /*                             LIGO                                     */
00023 /*                                                                      */
00024 /*        THE LASER INTERFEROMETER GRAVITATIONAL WAVE OBSERVATORY.      */
00025 /*                                                                      */
00026 /*                     (C) The LIGO Project, 1999.                      */
00027 /*                                                                      */
00028 /*                                                                      */
00029 /* Caltech                              MIT                             */
00030 /* LIGO Project MS 51-33                LIGO Project NW-17 161          */
00031 /* Pasadena CA 91125                    Cambridge MA 01239              */
00032 /*                                                                      */
00033 /* LIGO Hanford Observatory             LIGO Livingston Observatory     */
00034 /* P.O. Box 1970 S9-02                  19100 LIGO Lane Rd.             */
00035 /* Richland WA 99352                    Livingston, LA 70754            */
00036 /*                                                                      */
00037 /*----------------------------------------------------------------------*/
00038 
00039 #ifndef _LIGO_FFTYPE_H
00040 #define _LIGO_FFTYPE_H
00041 
00042 #include "PConfig.h"
00043 #include <complex>
00044 #ifdef HAVE_INT_TYPES
00045 #include <inttypes.h>
00046 #endif
00047 
00058 
00059 namespace framefast {
00060 
00061    const int kDefaultFrameVersion = 6;
00062 
00063 #ifdef HAVE_INT_TYPES
00065    typedef int8_t int_1s_t;
00067    typedef uint8_t int_1u_t;
00069    typedef int16_t int_2s_t;
00071    typedef uint16_t int_2u_t;
00073    typedef int32_t int_4s_t;
00075    typedef uint32_t int_4u_t;
00077    typedef int64_t int_8s_t;
00079    typedef uint64_t int_8u_t;
00080 #else // take a guess
00081    // CHAR
00082    typedef char int_1s_t;
00083    // CHAR_U
00084    typedef unsigned char int_1u_t;
00085    // INT_2S
00086    typedef short int_2s_t;
00087    // INT_2U
00088    typedef unsigned short int_2u_t;
00089    // INT_4S
00090    typedef int int_4s_t;
00091    // INT_4U
00092    typedef unsigned int int_4u_t;
00093    // INT_8S
00094    typedef long long int_8s_t;
00095    // INT_8U
00096    typedef unsigned long long int_8u_t;
00097 #endif
00098 
00100    typedef float real_4_t;
00102    typedef double real_8_t;
00104    typedef std::complex<float> complex_8_t;
00106    typedef std::complex<double> complex_16_t;
00107 
00112    enum frametype {
00114    NONE = 0,
00116    FF = 1,
00118    STF = 2,
00120    MTF = 3
00121    };
00122 
00124 
00125 
00135 
00136 #ifndef __CINT__
00138    inline void swap (int_8u_t* ww);
00140    inline void swap (int_8s_t* ww);
00141 #endif
00143    inline void swap (int_4u_t* w);
00145    inline void swap (int_4s_t* ww);
00147    inline void swap (int_2u_t* w);
00149    inline void swap (int_2s_t* ww);
00151    inline void swap (int_1s_t* ww);
00153    inline void swap (int_1u_t* ww);
00155    inline void swap (real_8_t* ww);
00157    inline void swap (real_4_t* w);
00159    inline void swap (complex_8_t* ww);
00161    inline void swap (complex_16_t* ww);
00163    inline bool littleendian ();
00164 
00165 }
00167 
00168 
00169 
00171 //                                                                      //
00172 // inlines                                                              //
00173 //                                                                      //
00175 namespace framefast {
00176 #define byteswap2(a,b) ((char *)&(a))[0] = ((char *)&(b))[1]; ((char *)&(a))[1] = ((char *)&(b))[0];
00177 #define byteswap4(a,b) ((char *)&(a))[0] = ((char *)&(b))[3]; ((char *)&(a))[1] = ((char *)&(b))[2];((char *)&(a))[2] = ((char *)&(b))[1];((char *)&(a))[3] = ((char *)&(b))[0];
00178 #define byteswap8(a,b) ((char *)&(a))[0] = ((char *)&(b))[7]; ((char *)&(a))[1] = ((char *)&(b))[6];((char *)&(a))[2] = ((char *)&(b))[5];((char *)&(a))[3] = ((char *)&(b))[4];((char *)&(a))[4] = ((char *)&(b))[3]; ((char *)&(a))[5] = ((char *)&(b))[2]; ((char *)&(a))[6] = ((char *)&(b))[1]; ((char *)&(a))[7] = ((char *)&(b))[0];
00179 
00180 #ifndef __CINT__
00181    inline void swap (int_8u_t* ww)
00182    {
00183       int_8u_t tmp;
00184       byteswap8(tmp, *ww);
00185       *ww = tmp;
00186    }
00187 
00188 //______________________________________________________________________________
00189    inline void swap (int_8s_t* ww) 
00190    {
00191       swap ((int_8u_t*)ww);
00192    }
00193 #endif
00194 
00195 //______________________________________________________________________________
00196    inline void swap (int_4u_t* w)
00197    {
00198       int_4u_t tmp;
00199       byteswap4(tmp, *w);
00200       *w = tmp;
00201    }
00202 
00203 //______________________________________________________________________________
00204    inline void swap (int_4s_t* ww) 
00205    {
00206       swap ((int_4u_t*)ww);
00207    }
00208 
00209 //______________________________________________________________________________
00210    inline void swap (int_2u_t* w)
00211    {
00212       int_2u_t tmp;
00213       byteswap2(tmp, *w);
00214       *w = tmp;
00215    }
00216 
00217 //______________________________________________________________________________
00218    inline void swap (int_2s_t* ww) 
00219    {
00220       swap ((int_2u_t*)ww);
00221    }
00222 
00223 //______________________________________________________________________________
00224    inline void swap (int_1s_t* ww)
00225    {
00226    }
00227 
00228 //______________________________________________________________________________
00229    inline void swap (int_1u_t* ww)
00230    {
00231    }
00232 
00233 //______________________________________________________________________________
00234    inline void swap (real_8_t* ww)
00235    {
00236       real_8_t tmp;
00237       byteswap8(tmp, *ww);
00238       *ww = tmp;
00239    }
00240 
00241 //______________________________________________________________________________
00242    inline void swap (real_4_t* w)
00243    {
00244       real_4_t tmp;
00245       byteswap4(tmp, *w);
00246       *w = tmp;
00247    }
00248 
00249 //______________________________________________________________________________
00250    inline void swap (complex_8_t* ww)
00251    {
00252       struct complex {
00253          real_4_t re;
00254          real_4_t im;
00255       };
00256       swap (&((complex*)ww)->re);
00257       swap (&((complex*)ww)->im);
00258    }
00259 
00260 //______________________________________________________________________________
00261    inline void swap (complex_16_t* ww)
00262    { 
00263       struct complex {
00264          real_8_t re;
00265          real_8_t im;
00266       } ;
00267       swap (&((complex*)ww)->re);
00268       swap (&((complex*)ww)->im);
00269    }
00270 
00271    inline bool littleendian () {
00272       int_4u_t test = 0; *(int_1u_t*) &test = 1;
00273       return (test == 1);
00274    }
00275 
00276 #undef byteswap2
00277 #undef byteswap4
00278 #undef byteswap8
00279 }
00280 
00281 #endif // _LIGO_FFTYPE_H

Generated on Sun Mar 8 19:20:45 2009 for dmt by  doxygen 1.5.4