00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _OCS_TOOLS_HH_
00019 #define _OCS_TOOLS_HH_
00020
00021
00022 #include <unistd.h>
00023
00024 #include "cfftw.hh"
00025
00026 #ifndef _OCS_SYSTEM_HDRS_
00027 #define _OCS_SYSTEM_HDRS_
00028
00029 #include <iostream.h>
00030 #include <string.h>
00031 #include <math.h>
00032 #include <fstream.h>
00033 #include <complex.h>
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <strstream>
00037
00038 #include <string>
00039 using namespace std;
00040
00041
00042 #endif
00043
00044 #include "ocsConst.hh"
00045
00046 #define NEAR_ZERO 2.2e-13
00047
00048 typedef complex<double> cplx;
00049
00050
00051 template<class T> inline T sq(T);
00052 template<class T> inline T sq(T in)
00053 {
00054 return (in*in);
00055 }
00056
00057
00058 template<class T> inline T cube(T);
00059 template<class T> inline T cube(T in)
00060 {
00061 return (in*in*in);
00062 }
00063
00064
00065 inline int sgn(double x);
00066 inline int sgn(double x)
00067 {
00068 if (x >= 0)
00069 return(1);
00070 else
00071 return(-1);
00072 }
00073
00074 inline double min(double a, double b);
00075 inline double min(double a, double b)
00076 {
00077 if(a<b)
00078 return a;
00079 else
00080 return b;
00081 }
00082
00083 void MinAndArgMin(double * Vec, int Length, double & MinValue, int & ArgMin);
00084 void MaxAndArgMax(double * Vec, int Length, double & MaxValue, int & ArgMax);
00085
00086
00087
00088
00089
00090 double GetRadiusCircle(double *PointA, double *PointB, double *PointC);
00091 double GetDistance2Points(double *PointA, double *PointB, int FirstCoord);
00092 int Periodicity(int ii, int Periodicity);
00093 void TransRzRyV3toXhat( double *Vector, double *thetaZthetaY);
00094 void TransRzRxV3toXhat( double *Vector, double *thetaZthetaY);
00095
00096 void TransRzRyV3to_Xhat( double *Vector, double *thetaZthetaY);
00097
00098 void TransRyV3to_YZ( double *Vector, double *thetaY);
00099 void TransRzRxV3to_Xhat( double *Vector, double *thetaZthetaX);
00100 void TransRzRxV3to_Xhat( double *Vector, double *thetaZ, double *thetaX);
00101
00102
00103 void Multiply(cplx Left[][2], cplx Right[][2]);
00104 void URotatesAboutZ(double angle, cplx UMatrix[][2]);
00105 void URotatesAboutY(double angle, cplx UMatrix[][2]);
00106 void URotatesAboutX(double angle, cplx UMatrix[][2]);
00107 void MRotatesAboutZ(double angle, double MMatrix[][3]);
00108 void MRotatesAboutY(double angle, double MMatrix[][3]);
00109 void MRotatesAboutX(double angle, double MMatrix[][3]);
00110 void MGeneralRotation(double angle, double *r_vec, double MMatrix[][3]);
00111
00112 void RotatesAboutZ(double angle, double *Vector);
00113 void RotatesAboutX(double angle, double *Vector);
00114 void RotatesAboutY(double angle, double *Vector);
00115
00116 void RotatesAboutX(double angle, cplx *JonesVector);
00117 void RotatesAboutY(double angle, cplx *JonesVector);
00118 void RotatesAboutZ(double angle, cplx *JonesVector);
00119
00120 void Multiply( double Left[][3], double Right[][3]);
00121 void Multiply(double Left[][3],double Right[3]);
00122 double ScalarProduct(double *VectorA, double *VectorB);
00123 void CrossProduct(double Left[4], double Right[4], int FirstCoord);
00124 void CrossProduct(double *Left, double *Right, double *Product);
00125 double GetVectorLength(double *Vector, int Dimension);
00126
00127 double dB2Linear(double dBvalue);
00128 double dBm2Linear(double dBmPower);
00129 double Linear2dB(double LinearValue);
00130 double Linear2dBm(double LinearPower);
00131 double Linear2dB_Limited(double LinearValue, double MaxValue_dB);
00132
00133 double GetDegreeOfPolarization(double *StokesVector);
00134 double GetPhase(const cplx Phasor);
00135 void Stokes2Jones(const double *Stokes, cplx *Jones);
00136 void Jones2Stokes(const cplx *Jones, double *Stokes);
00137 void Stokes2JonesKeepPower(const double *Stokes, cplx *Jones);
00138 void Jones2StokesKeepPower(const cplx *Jones, double *Stokes);
00139
00140
00141
00142
00143
00147
00148 void JonesPair2MixedStokes(const cplx *Jones1, const cplx * Jones2,
00149 cplx *MixedStokes);
00150
00151
00152 double Frequency2Wavelength(double Frequency);
00153 double Wavelength2Frequency(double Wavelength);
00154
00155
00157
00158 double MaxOfArray(double * Array, int Length);
00159
00161
00162 double MinOfArray(double * Array, int Length);
00163
00167
00188 double Quadrature(double * Data, int NumPts,
00189 double LeftEndPt, double RightEndPt);
00190
00194
00195 inline cplx exp_jc_real(double __x)
00196 {
00197 #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__ && defined __GNUC__
00198 register long double __cosr;
00199 register long double __sinr;
00200 __asm __volatile__
00201 ("fsincos\n\t"
00202 : "=t" (__cosr), "=u" (__sinr) : "0" (__x));
00203
00204
00205
00206
00207
00208 return cplx(double(__cosr), double(__sinr));
00209 #else
00210 return cplx(cos(__x), sin(__x));
00211 #endif
00212 }
00213
00214
00215
00216
00217
00218 inline double lin_map(double x, double a1, double diff_a, double b1, double diff_b);
00219 inline int lin_map(double x, double a1, double diff_a, int b1, int num_b);
00220 inline double lin_map(int x, int a1, int num_a, double b1, double diff_b);
00221 inline double lin_map(int x, int a1, int num_a, int b1, int num_b);
00222 inline double lin_interpolate(double x, double a1, double diff_a, int b1, int num_b, double *data);
00223 inline cplx lin_interpolate(double x, double a1, double diff_a, int b1, int num_b, cplx *data);
00224
00225 enum{MOSIX_UNLOCK, MOSIX_LOCK};
00226 int lock_or_unlock_mosix(int what);
00227 int cpujob_mosix(void);
00228 int slow_mosix(void);
00229 inline double dB_to_factor(double G_dB);
00230 inline double factor_to_dB(double factor);
00231
00232 double gaussian(double t, double t0, double FWHM_norm);
00233 void gaussian_pdf(int N, double stan_dev, double *vec);
00234
00235 inline double soliton(double t, double t0, double eta);
00236 cplx bessel5(double omega, double omega_0, double FWHM);
00237 void electrical_filter(cplx *my_power_time, cfftw *fft, double fwhm);
00238 void optical_filter(cplx *my_field_time, cplx *my_field_freq, cfftw *fft, double fwhm);
00239 void my_error(char *spruch);
00240
00241 double peak_power(cplx *in, int N);
00242 double pulse_energy(cplx *in, int N, double width);
00243
00244 void fftshift (cplx *v, int datlen_l);
00245 void ifftshift (cplx *v, int datlen_l);
00246
00247
00248
00249
00250 float ranG(long *);
00251 float Gaussian_pdf(long *idum);
00252 void frprmn(float p[], int n, float ftol, int *iter, float *fret,
00253 float (*func)(float []), void (*dfunc)(float [], float []));
00254 void frprmnd(double p[], int n, double ftol, int *iter, double *fret,
00255 double (*func)(double []), void (*dfunc)(double [], double []));
00256 void powell(float p[], float xi[][4], int n, float ftol, int *iter, float *fret,
00257 float (*func)(float []));
00258
00259
00260
00261 double **dmatrix(long nrl, long nrh, long ncl, long nch);
00262 cplx **cmatrix(long nrl, long nrh, long ncl, long nch);
00263 void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch);
00264 void free_cmatrix(cplx **m, long nrl, long nrh, long ncl, long nch);
00265 void gaussj(double **a, int n, double **b, int m);
00266 void gaussj_complex(cplx **a, int n, cplx **b, int m);
00267 float erffc(float x);
00268 float gammp(float a, float x);
00269 void gcf(float *gammcf, float a, float x, float *gln);
00270 void gser(float *gamser, float a, float x, float *gln);
00271 float gammln(float xx);
00272 float gammq(float a, float x);
00273 double erfccExtendedRange(double x);
00274 float erfcc(float x);
00275 float zbrent(float (*func)(float), float x1, float x2, float tol);
00276 float brent(float ax, float bx, float cx, float (*f)(float), float tol,
00277 float *xmin);
00278 double brentd(double ax, double bx, double cx, double (*f)(double),
00279 double tol, double *xmin);
00280
00281 double splint( double *xa, double *ya, double *y2a, int n, double x);
00282 void spline(double *x, double *y, int n, double yp1, double ypn, double *y2);
00283
00284
00285
00286 #endif
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302