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