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
00084
00085
00086
00087
00088 double GetRadiusCircle(double *PointA, double *PointB, double *PointC);
00089 double GetDistance2Points(double *PointA, double *PointB, int FirstCoord);
00090 int Periodicity(int ii, int Periodicity);
00091 void TransRzRyV3to_Xhat( double *Vector, double *thetaZthetaY);
00092
00093 void TransRyV3to_YZ( double *Vector, double *thetaY);
00094 void TransRzRxV3to_Xhat( double *Vector, double *thetaZthetaX);
00095 void TransRzRxV3to_Xhat( double *Vector, double *thetaZ, double *thetaX);
00096
00097
00098 void RotatesAboutZ(double angle, double *Vector);
00099 void RotatesAboutX(double angle, double *Vector);
00100 void RotatesAboutY(double angle, double *Vector);
00101
00102 void RotatesAboutX(double angle, cplx *JonesVector);
00103 void RotatesAboutY(double angle, cplx *JonesVector);
00104 void RotatesAboutZ(double angle, cplx *JonesVector);
00105
00106 void Multiply( double Left[][3], double Right[][3]);
00107 void Multiply(double Left[][3],double Right[3]);
00108 double ScalarProduct(double *VectorA, double *VectorB);
00109 void CrossProduct(double Left[4], double Right[4], int FirstCoord);
00110 double GetVectorLength(double *Vector, int Dimension);
00111
00112 double dB2Linear(double dBvalue);
00113 double dBm2Linear(double dBmPower);
00114 double Linear2dB(double LinearValue);
00115 double Linear2dBm(double LinearPower);
00116 double Linear2dB_Limited(double LinearValue, double MaxValue_dB);
00117
00118 double GetDegreeOfPolarization(double *StokesVector);
00119 double GetPhase(const cplx Phasor);
00120 void Stokes2Jones(const double *Stokes, cplx *Jones);
00121 void Jones2Stokes(const cplx *Jones, double *Stokes);
00122 void Stokes2JonesKeepPower(const double *Stokes, cplx *Jones);
00123 void Jones2StokesKeepPower(const cplx *Jones, double *Stokes);
00124
00125
00126
00127
00128
00129 double Frequency2Wavelength(double Frequency);
00130 double Wavelength2Frequency(double Wavelength);
00131
00132
00133
00134
00135
00136 inline double lin_map(double x, double a1, double diff_a, double b1, double diff_b);
00137 inline int lin_map(double x, double a1, double diff_a, int b1, int num_b);
00138 inline double lin_map(int x, int a1, int num_a, double b1, double diff_b);
00139 inline double lin_map(int x, int a1, int num_a, int b1, int num_b);
00140 inline double lin_interpolate(double x, double a1, double diff_a, int b1, int num_b, double *data);
00141 inline cplx lin_interpolate(double x, double a1, double diff_a, int b1, int num_b, cplx *data);
00142
00143 enum{MOSIX_UNLOCK, MOSIX_LOCK};
00144 int lock_or_unlock_mosix(int what);
00145 int cpujob_mosix(void);
00146 int slow_mosix(void);
00147 inline double dB_to_factor(double G_dB);
00148 inline double factor_to_dB(double factor);
00149
00150 double gaussian(double t, double t0, double FWHM_norm);
00151 void gaussian_pdf(int N, double stan_dev, double *vec);
00152
00153 inline double soliton(double t, double t0, double eta);
00154 cplx bessel5(double omega, double omega_0, double FWHM);
00155 void electrical_filter(cplx *my_power_time, cfftw *fft, double fwhm);
00156 void optical_filter(cplx *my_field_time, cplx *my_field_freq, cfftw *fft, double fwhm);
00157 void my_error(char *spruch);
00158
00159 double peak_power(cplx *in, int N);
00160 double pulse_energy(cplx *in, int N, double width);
00161
00162 void fftshift (cplx *v, int datlen_l);
00163 void ifftshift (cplx *v, int datlen_l);
00164
00165
00166
00167
00168 float ranG(long *);
00169 float Gaussian_pdf(long *idum);
00170 void frprmn(float p[], int n, float ftol, int *iter, float *fret,
00171 float (*func)(float []), void (*dfunc)(float [], float []));
00172 void frprmnd(double p[], int n, double ftol, int *iter, double *fret,
00173 double (*func)(double []), void (*dfunc)(double [], double []));
00174 void powell(float p[], float xi[][4], int n, float ftol, int *iter, float *fret,
00175 float (*func)(float []));
00176
00177
00178
00179 double **dmatrix(long nrl, long nrh, long ncl, long nch);
00180 cplx **cmatrix(long nrl, long nrh, long ncl, long nch);
00181 void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch);
00182 void free_cmatrix(cplx **m, long nrl, long nrh, long ncl, long nch);
00183 void gaussj(double **a, int n, double **b, int m);
00184 void gaussj_complex(cplx **a, int n, cplx **b, int m);
00185 float erffc(float x);
00186 float gammp(float a, float x);
00187 void gcf(float *gammcf, float a, float x, float *gln);
00188 void gser(float *gamser, float a, float x, float *gln);
00189 float gammln(float xx);
00190 float gammq(float a, float x);
00191
00192
00193 #endif
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209