00001
00002
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <complex.h>
00007 #include <float.h>
00008 #include <math.h>
00009 #include <assert.h>
00010 #include <time.h>
00011
00012 #include "ctypes.h"
00013 #include "fahlman_ulrych_C99.h"
00014 #include "multi_burg_C99.h"
00015 #include "pcg_C99.h"
00016 #include "levinson_C99.h"
00017
00018
00019
00020 static inline int max(int a, int b) { return (a>b? a : b); }
00021 static inline int min(int a, int b) { return (a<b? a : b); }
00022
00023 typedef struct interval_struct
00024 { int first;
00025 int last;
00026 } interval;
00027
00028 typedef struct gapped_timeseries_struct
00029 {
00030 int first_is_good;
00031 int n_data, m_data;
00032 int n_gap, m_gap;
00033 interval *gap_int, *data_int;
00034 } gapped_timeseries;
00035
00036
00037 static int maxorder(gapped_timeseries *ts, int *data_length,
00038 int minpercentage)
00039 {
00040 int i,j;
00041 int *len,idx,tmp,order;
00042
00043
00044
00045 len = malloc(ts->m_data*sizeof(int));
00046 memcpy(len, data_length, ts->m_data*sizeof(int));
00047
00048
00049
00050 for (i=0; i<ts->m_data; i++)
00051 {
00052 idx = i;
00053 for (j=i+1; j<ts->m_data; j++)
00054 if (len[j]>len[idx])
00055 idx = j;
00056 tmp = len[idx];
00057 len[idx] = len[i];
00058 len[i] = tmp;
00059 }
00060 #ifdef DEBUGOUT
00061 {
00062 for (i=0; i<ts->m_data; i++)
00063 printf("%5d ",len[i]);
00064 printf("\n");
00065 }
00066 #endif
00067 tmp = 0; i = 0;
00068 while(i<ts->n_data && tmp<(minpercentage*ts->n_data)/100)
00069 {
00070 tmp += len[i++];
00071 }
00072 order = len[i-1]-1;
00073 #ifdef DEBUGOUT
00074 {
00075 printf("maximal initial order chosen = %d\n",order);
00076 printf("using %d out of %d data points\n",tmp,ts->n_data);
00077 }
00078 #endif
00079 free(len);
00080 return order;
00081 }
00082
00083
00084
00085
00086 #ifdef FLOAT
00087 #define TYPE FLOAT
00088 #include "fahlman_ulrych_code_C99.h"
00089 #undef TYPE
00090 #endif
00091
00092 #ifdef DOUBLE
00093 #define TYPE DOUBLE
00094 #include "fahlman_ulrych_code_C99.h"
00095 #undef TYPE
00096 #endif
00097
00098 #ifdef COMPLEXFLOAT
00099 #define TYPE COMPLEXFLOAT
00100 #include "fahlman_ulrych_code_C99.h"
00101 #undef TYPE
00102 #endif
00103
00104 #ifdef COMPLEXDOUBLE
00105 #define TYPE COMPLEXDOUBLE
00106 #include "fahlman_ulrych_code_C99.h"
00107 #undef TYPE
00108 #endif
00109
00110