00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <assert.h>
00004 #include <string.h>
00005 #include <complex.h>
00006 #include <math.h>
00007 #include <assert.h>
00008 #include "ctypes.h"
00009 #include "detrend_C99.h"
00010 #include "xmem.h"
00011
00012 #ifdef FLOAT
00013 #define TYPE FLOAT
00014 #include "detrend_code_C99.h"
00015 #undef TYPE
00016 #endif
00017
00018 #ifdef DOUBLE
00019 #define TYPE DOUBLE
00020 #include "detrend_code_C99.h"
00021 #undef TYPE
00022 #endif
00023
00024 #ifdef COMPLEXFLOAT
00025
00026
00027
00028 static int count2=0;
00029
00030 void cdetrend_discontig( int n, _Complex float *data, int *isgood,
00031 int degree, int length, int skip,
00032 int m, int *sect)
00033 {
00034 int i,first,last;
00035
00036
00037
00038
00039
00040
00041 if (m==0)
00042 cdetrend(n,data,isgood,degree,length,skip);
00043 else
00044 {
00045 for (i=0; i<m; i++)
00046 {
00047 first = sect[2*i];
00048 last = sect[2*i+1];
00049 printf("Detrending [%d:%d]\n",first,last);
00050 cdetrend(last-first+1,&data[first],&isgood[first],degree,length,skip);
00051 }
00052 }
00053 }
00054
00055
00056
00057
00058 void cdetrend( int n, _Complex float *data, int *isgood, int degree,
00059 int length, int skip)
00060 {
00061 int i;
00062
00063 float *real, *imag;
00064 real = (float *) malloc(n*sizeof(float));
00065 for (i=0;i<n;i++)
00066 real[i] = crealf(data[i]);
00067 sdetrend( n, real, isgood, degree, length, skip);
00068
00069 imag = (float *) malloc(n*sizeof(float));
00070 for (i=0;i<n;i++)
00071 imag[i] = cimagf(data[i]);
00072 sdetrend( n, imag, isgood, degree, length, skip);
00073 for (i=0;i<n;i++)
00074 data[i] = real[i] + _Complex_I*imag[i];
00075
00076 #ifdef DEBUG
00077 {
00078 FILE *fh;
00079 char name[1024];
00080 printf("writing debug2 file #%d\n",count2);
00081 sprintf(name,"detrend_debug2_%d.out",count2++);
00082 fh = fopen(name,"w");
00083 assert(fh);
00084 for (i=0; i<n; i++)
00085 fprintf(fh,"%e %e\n",crealf(data[i]),cimagf(data[i]));
00086 fclose(fh);
00087 }
00088 #endif
00089
00090 free(real);
00091 free(imag);
00092 }
00093 #endif
00094
00095 #ifdef COMPLEXDOUBLE
00096 void zdetrend_discontig( int n, _Complex double *data, int *isgood,
00097 int degree, int length, int skip,
00098 int m, int *sect)
00099 {
00100 int i,first,last;
00101
00102
00103
00104
00105
00106
00107 if (m==0)
00108 zdetrend(n,data,isgood,degree,length,skip);
00109 else
00110 {
00111 first = 0;
00112 for (i=0; i<m; i++)
00113 {
00114 first = sect[2*i];
00115 last = sect[2*i+1];
00116 zdetrend(last-first+1,&data[first],&isgood[first],degree,length,skip);
00117 }
00118 }
00119 }
00120
00121
00122 void zdetrend( int n, _Complex double *data, int *isgood, int degree,
00123 int length, int skip)
00124 {
00125 int i;
00126 double *real, *imag;
00127
00128 real = (double *) malloc(n*sizeof(double));
00129 for (i=0;i<n;i++)
00130 real[i] = creal(data[i]);
00131 ddetrend( n, real, isgood, degree, length, skip);
00132
00133 imag = (double *) malloc(n*sizeof(double));
00134 for (i=0;i<n;i++)
00135 imag[i] = cimag(data[i]);
00136 ddetrend( n, imag, isgood, degree, length, skip);
00137 for (i=0;i<n;i++)
00138 data[i] = real[i] + _Complex_I*imag[i];
00139
00140 free(real);
00141 free(imag);
00142 }
00143 #endif