00001
00002
00003
00004
00005
00006
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifdef HAVE_CONFIG_H
00055 #include <config.h>
00056 #endif
00057
00059 #define _GNU_SOURCE
00060
00061
00062 #ifdef HAVE_SYS_TYPES_H
00063 #include <sys/types.h>
00064 #endif
00065 #ifdef HAVE_SYS_STAT_H
00066 #include <sys/stat.h>
00067 #endif
00068 #ifdef HAVE_FCNTL_H
00069 #include <fcntl.h>
00070 #endif
00071 #ifdef HAVE_UNSTD_H
00072 #include <unistd.h>
00073 #endif
00074 #ifdef HAVE_STDIO_H
00075 #include <stdio.h>
00076 #endif
00077 #ifdef HAVE_STRING_H
00078 #include <string.h>
00079 #endif
00080 #ifdef HAVE_STDLIB_H
00081 #include <stdlib.h>
00082 #endif
00083 #ifdef HAVE_MATH_H
00084 #include <math.h>
00085 #endif
00086 #ifdef HAVE_TIME_H
00087 #include <time.h>
00088 #endif
00089 #ifdef HAVE_LIBGEN_H
00090 #include <libgen.h>
00091 #endif
00092
00093 #include <utils.h>
00094 #include <regress.h>
00095
00097 void show_usage(char *pgm);
00098
00100 int main(int argc, char **argv)
00101 {
00109 int npts;
00110 int nterm;
00111 int pts;
00112 #if DEBUG >= 6
00113 int term;
00114 #endif
00115
00116 int i;
00117 int istat;
00118
00119 double *x = NULL;
00120 double *y = NULL;
00121 double *yreg = NULL;
00122 double *coef = NULL;
00123 double *yerr = NULL;
00124 double *vif = NULL;
00125 double cte;
00126 double chisq;
00127 double rsq;
00128 double autocor;
00129
00130
00131 (void) banner(basename(argv[0]), "1.0", "BEGIN");
00132
00133
00134 for (i=1; i<argc; i++) {
00135 if ( !strcmp(argv[i], "-h") ) {
00136 (void) show_usage(basename(argv[0]));
00137 (void) banner(basename(argv[0]), "OK", "END");
00138 return 0;
00139 }
00140 else {
00141 (void) fprintf(stderr, "%s:: Wrong arg %s.\n\n", basename(argv[0]), argv[i]);
00142 (void) show_usage(basename(argv[0]));
00143 (void) banner(basename(argv[0]), "ABORT", "END");
00144 (void) abort();
00145 }
00146 }
00147
00148 npts = 6;
00149 nterm = 2;
00150
00151 x = (double *) calloc(npts*nterm, sizeof(double));
00152 if (x == NULL) alloc_error(__FILE__, __LINE__);
00153
00154 x[0+0*npts] = 1.0;
00155 x[1+0*npts] = 2.0;
00156 x[2+0*npts] = 4.0;
00157 x[3+0*npts] = 8.0;
00158 x[4+0*npts] = 16.0;
00159 x[5+0*npts] = 32.0;
00160
00161 x[0+1*npts] = 0.0;
00162 x[1+1*npts] = 1.0;
00163 x[2+1*npts] = 2.0;
00164 x[3+1*npts] = 3.0;
00165 x[4+1*npts] = 4.0;
00166 x[5+1*npts] = 5.0;
00167
00168 y = (double *) calloc(npts, sizeof(double));
00169 if (y == NULL) alloc_error(__FILE__, __LINE__);
00170 yreg = (double *) calloc(npts, sizeof(double));
00171 if (yreg == NULL) alloc_error(__FILE__, __LINE__);
00172 yerr = (double *) calloc(npts, sizeof(double));
00173 if (yerr == NULL) alloc_error(__FILE__, __LINE__);
00174 coef = (double *) calloc(nterm, sizeof(double));
00175 if (coef == NULL) alloc_error(__FILE__, __LINE__);
00176 vif = (double *) calloc(nterm, sizeof(double));
00177 if (vif == NULL) alloc_error(__FILE__, __LINE__);
00178
00179 for (pts=0; pts<npts; pts++)
00180 y[pts] = 5.0 + 3.0 * x[pts+0*npts] - 4.0 * x[pts+1*npts];
00181
00182 istat = regress(coef, x, y, &cte, yreg, yerr, &chisq, &rsq, vif, &autocor, nterm, npts);
00183
00184 #if DEBUG >= 6
00185 for (term=0; term<nterm; term++)
00186 for (pts=0; pts<npts; pts++)
00187 (void) fprintf(stdout, "%s: term=%d pts=%d x=%lf\n", __FILE__, term, pts, x[pts+term*npts]);
00188
00189 for (term=0; term<nterm; term++)
00190 (void) fprintf(stdout, "%s: term=%d coef=%lf\n", __FILE__, term, coef[term]);
00191
00192 (void) fprintf(stdout, "%s: cte=%lf chisq=%lf\n", __FILE__, cte, chisq);
00193
00194 for (pts=0; pts<npts; pts++)
00195 (void) fprintf(stdout, "%s: pts=%d y=%lf yreg=%lf yerr=%lf\n", __FILE__, pts, y[pts], yreg[pts], yerr[pts]);
00196 #endif
00197
00198 (void) free(coef);
00199 (void) free(yreg);
00200 (void) free(yerr);
00201 (void) free(vif);
00202 (void) free(y);
00203 (void) free(x);
00204
00205
00206 (void) banner(basename(argv[0]), "OK", "END");
00207
00208 return 0;
00209 }
00210
00211
00215 void show_usage(char *pgm) {
00220 (void) fprintf(stderr, "%s: usage:\n", pgm);
00221 (void) fprintf(stderr, "-h: help\n");
00222
00223 }