Christensen C Programming Style Guidelines |
//=================================================== file = summary1.c ===== //= Program to compute summary statistics for a series X of size N = //= - Computes min, max, sum, mean, var, std dev, and cov = //=========================================================================== //= 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 = //=-------------------------------------------------------------------------= //= 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"): = //= = //= ---------------------------------------------- summary1.c ----- = //= Total of 11 values = //= Minimum = 39.000000 (position = 6) = //= Maximum = 61.000000 (position = 3) = //= Sum = 561.000000 = //= Mean = 51.000000 = //= Variance = 52.545455 = //= Std Dev = 7.248824 = //= CoV = 0.142134 = //= --------------------------------------------------------------- = //=-------------------------------------------------------------------------= //= Build: bcc32 summary1.c = //=-------------------------------------------------------------------------= //= Execute: summary1 < 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 = //= KJC (06/06/02) - Changed MAX_SIZE to 2 million = //=========================================================================== //----- Include files ------------------------------------------------------- //----- Defines ------------------------------------------------------------- //----- Global variables ---------------------------------------------------- //----- Function prototypes ------------------------------------------------- //===== Main program ========================================================
//=========================================================================== //= Function to load X array from stdin and determine N = //=-------------------------------------------------------------------------= //=- Inputs: None -= //=- Returns: X and N -= //=========================================================================== void load_X_array(void)
// Compute mean, variance, standard deviation, and cov from mom1 and mom2 mean = mom1; var = mom2 - pow(mom1, 2.0); stddev = sqrt(var); cov = sqrt(var) / mom1; // Output the computed summary statistics printf(" Total of %ld values \n", N); printf(" Minimum = %f (position = %ld) \n", min, minpos); printf(" Maximum = %f (position = %ld) \n", max, maxpos); printf(" Sum = %f \n", sum); printf(" Mean = %f \n", mean); printf(" Variance = %f \n", var); printf(" Std Dev = %f \n", stddev); printf(" CoV = %f \n", cov); printf("---------------------------------------------------------------\n");
#define MAX_FILES 100 // Maximum number of files int Error_count; // Global count of errors int error_count; // Count of errors
// Compute the sum and product of MAX values in X[] for (i=0; i<MAX; i++) { sum = sum + X[i]; product = product * X[i]; }
|