//==================================================== file = smooth1.c ===== //= Program to implement exponential smooth for a series X of size N = //= - Implements f_t+1 = f_t + alpha*(y_t - f_t) for current sample y_t = //=========================================================================== //= Notes: = //= 1) Input from input file "in.dat" to stdin (see example below) = //= * Comments are bounded by "&" characters at the beginning and = //= end of the comment block = //= 2) Output is to stdout = //= 3) Must manually set #define ALPHA = //=-------------------------------------------------------------------------= //= Example "in.dat" file: = //= = //= & Sample series of data which can be integers or reals. = //= There are 11 values in this file. & = //= 50 = //= 42 = //= 48 = //= 61 = //= 60 = //= 53 = //= 39 = //= 54 = //= 42 = //= 59 = //= 53 = //=-------------------------------------------------------------------------= //= Example output (for above "in.dat"): = //= = //= ----------------------------------------------- smooth1.c ----- = //= Input and smoothed values for alpha = 0.500000 (N = 11) = //= 50.000000 50.000000 = //= 42.000000 50.000000 = //= 48.000000 46.000000 = //= 61.000000 47.000000 = //= 60.000000 54.000000 = //= 53.000000 57.000000 = //= 39.000000 55.000000 = //= 54.000000 47.000000 = //= 42.000000 50.500000 = //= 59.000000 46.250000 = //= 53.000000 52.625000 = //= Forecast next value is 52.812500 = //= --------------------------------------------------------------- = //=-------------------------------------------------------------------------= //= Build: gcc smooth1.c, bcc32 smooth1.c, cl smooth1.c = //=-------------------------------------------------------------------------= //= Execute: smooth1 < in.dat = //=-------------------------------------------------------------------------= //= Author: Kenneth J. Christensen = //= University of South Florida = //= WWW: http://www.csee.usf.edu/~christen = //= Email: christen@csee.usf.edu = //=-------------------------------------------------------------------------= //= History: KJC (05/23/00) - Genesis = //=========================================================================== //----- Include files ------------------------------------------------------- #include // Needed for printf() and feof() #include // Needed for exit() and atof() #include // Needed for strcmp() //----- Defines ------------------------------------------------------------- #define MAX_SIZE 1000000L // Maximum size of time series data array #define ALPHA 0.50 // Alpha value (between 0 and 1) //----- Globals ------------------------------------------------------------- double X[MAX_SIZE]; // Time series read from "in.dat" long int N; // Number of values in "in.dat" //----- Function prototypes ------------------------------------------------- void load_X_array(void); // Load X array //=========================================================================== //= Main program = //=========================================================================== void main(void) { double f_current; // Current smoothed value double f_next; // Next smoothed value long int i; // Loop counter // Load the series X printf("----------------------------------------------- smooth1.c -----\n"); load_X_array(); // Ouput run information printf(" Input and smoothed values for alpha = %f (N = %d) \n", ALPHA, N); // Initialize f_current to X[0] and then do smoothing f_current = X[0]; for (i=0; i= MAX_SIZE) { printf("*** ERROR - greater than %ld data values \n", MAX_SIZE); exit(1); } } // End-of-file escape end: return; }