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
00063 #include <sys/types.h>
00064 #endif
00065 #ifdef HAVE_STAT_H
00066 #include <sys/stat.h>
00067 #endif
00068 #ifdef HAVE_FCNTL_H
00069 #include <fcntl.h>
00070 #endif
00071 #ifdef HAVE_UNISTD_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_LIBGEN_H
00087 #include <libgen.h>
00088 #endif
00089
00090
00091 #include <utils.h>
00092 #include <filter.h>
00093
00095 void show_usage(char *pgm);
00096
00098 int main(int argc, char **argv)
00099 {
00107 int i;
00108
00109
00110 char filein[500];
00111 char fileout[500];
00112 FILE *inptr;
00113 FILE *outptr;
00114
00115 int end;
00116 int numval;
00117 int istat;
00118
00119 double *invect;
00120 double *outvect;
00121 double value;
00122 int width = 60;
00123
00124
00125 (void) banner(basename(argv[0]), "1.0", "BEGIN");
00126
00127
00128 if (argc <= 1) {
00129 (void) show_usage(basename(argv[0]));
00130 (void) banner(basename(argv[0]), "ABORT", "END");
00131 (void) abort();
00132 }
00133 else
00134 for (i=1; i<argc; i++) {
00135 if ( !strcmp(argv[i], "-i") )
00136 (void) strcpy(filein, argv[++i]);
00137 else if ( !strcmp(argv[i], "-o") )
00138 (void) strcpy(fileout, argv[++i]);
00139 else if ( !strcmp(argv[i], "-w") )
00140 (void) sscanf(argv[++i], "%d", &width);
00141 else {
00142 (void) fprintf(stderr, "%s:: Wrong arg %s.\n\n", basename(argv[0]), argv[i]);
00143 (void) show_usage(basename(argv[0]));
00144 (void) banner(basename(argv[0]), "ABORT", "END");
00145 (void) abort();
00146 }
00147 }
00148
00149 inptr = fopen(filein, "r");
00150 if (inptr == NULL) {
00151 (void) fprintf(stderr, "Cannot open input file : %s.\n", filein);
00152 (void) abort();
00153 }
00154 outptr = fopen(fileout, "w");
00155 if (outptr == NULL) {
00156 (void) fprintf(stderr, "Cannot open output file : %s.\n", fileout);
00157 (void) abort();
00158 }
00159 (void) fprintf(stdout, "Filter width=%d\n", width);
00160
00161 end = FALSE;
00162 numval = 0;
00163 invect = NULL;
00164 while (end == FALSE) {
00165 istat = fscanf(inptr, "%lf", &value);
00166 if ( istat != 1 )
00167
00168 end = TRUE;
00169 else {
00170 numval++;
00171 invect = (double *) realloc(invect, numval * sizeof(double));
00172 if (invect == NULL) alloc_error(__FILE__, __LINE__);
00173 invect[numval-1] = value;
00174 }
00175 }
00176
00177 outvect = (double *) calloc(numval, sizeof(double));
00178 if (outvect == NULL) alloc_error(__FILE__, __LINE__);
00179
00180 filter(outvect, invect, "hanning", width, 1, 1, numval);
00181
00182 for (i=0; i<numval; i++)
00183 (void) fprintf(outptr, "%d %lf %lf\n", i, invect[i], outvect[i]);
00184
00185 (void) fclose(inptr);
00186 (void) fclose(outptr);
00187
00188 (void) free(invect);
00189 (void) free(outvect);
00190
00191
00192 (void) banner(basename(argv[0]), "OK", "END");
00193
00194 return 0;
00195 }
00196
00197
00201 void show_usage(char *pgm) {
00206 (void) fprintf(stderr, "%s: usage:\n", pgm);
00207 (void) fprintf(stderr, "-i: input file\n");
00208 (void) fprintf(stderr, "-o: output file\n");
00209 (void) fprintf(stderr, "-w: filter width\n");
00210
00211 }