//=================================================== file = interval.c ===== //= Program to compute the interval means of a time series X = //=========================================================================== //= 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) The number of intervals for N values is M in the #define section = //= 3) If mod(N,M) is not zero, then the last remainder values are not = //= included in the last interval mean = //= 4) Output is to stdout = //=-------------------------------------------------------------------------= //= Example "in.dat" file: = //= = //= & Here is a series of 7 values to be intervaled with M = 2 & = //= 21 = //= 3 = //= 55 = //= 45 = //= 12 = //= 5 = //= 19 = //=-------------------------------------------------------------------------= //= Example output (for above "in.dat" and M = 2): = //= = //= & ------------------------------------------ interval.c ----- & = //= 26.333333 = //= 20.666667 = //= & Output 2 means for an interval size of 3 and 7 values = //= ---------------------------------------------------------- & = //=-------------------------------------------------------------------------= //= Build: gcc interval.c, bcc32 interval.c, cl interval.c = //=-------------------------------------------------------------------------= //= Execute: interval < in.dat = //=-------------------------------------------------------------------------= //= Author: Zane Reynolds = //= University of South Florida = //= WWW: http://www.csee.usf.edu/~zreynold = //= Email: zreynold@csee.usf.edu = //=-------------------------------------------------------------------------= //= History: ZR (9/20/00) - Genesis (from block.c) = //=========================================================================== //----- Include files ------------------------------------------------------- #include // Needed for printf() and feof() #include // Needed for exit() and atof() #include // Needed for strcmp() //----- Defines ------------------------------------------------------------- #define MAX_SIZE 1000000L // Max size of time series data array #define M 2L // Number of intervals //----- Globals ------------------------------------------------------------- double X[MAX_SIZE]; // Time series read from "in.dat" long int N; // Number of values in X[] //----- Prototypes ---------------------------------------------------------- void load_X_array(void); // Load X array //=========================================================================== //= Main program = //=========================================================================== void main(void) { long int int_size; // Number of values in each interval double int_mean; // Compute block mean double sum; // Temporary sum variable long int i, j; // Loop counters // Load the series X printf("& ------------------------------------------ interval.c ----- & \n"); load_X_array(); // Compute and output M interval means int_size = (long int) N / M; for (i=0; i= MAX_SIZE) { printf("*** ERROR - greater than %ld data values \n", MAX_SIZE); exit(1); } } // End-of-file escape end: return; }