/* C Program example to compute mean and std. deviation for */ /* precipitation data in homework #3 */ /* ASCII file version */ /* External libraries */ /* These are need by the program to do things like IO */ /* and math functions */ #include #include #include /* Define array limits */ /* For the HW #3 data these correspond to the data dimensions */ /* in space and time */ #define XPOINTS 81 #define YPOINTS 51 #define MONTHS 12 #define YEARS 55 /* Main program */ /* Note: you would put any function declarations to be called within the main program before this */ main(){ /* Variable declarations: each variable must be specified as a certain */ /* data type (i.e. int, float, double, etc.) */ /* Counting dimensions for space and time (integers) */ int i,j,p,q; /* Other variable declarations */ int xmaxpoints, ymaxpoints; float missingval; /* Precipitation declared as three dimensional array */ float precip[XPOINTS][YPOINTS][MONTHS][YEARS]; float missingarray[XPOINTS][YPOINTS][MONTHS]; float sumprecip[XPOINTS][YPOINTS][MONTHS]; float sumprecipsq[XPOINTS][YPOINTS][MONTHS]; float meanprecip[XPOINTS][YPOINTS][MONTHS]; float stdevprecip[XPOINTS][YPOINTS][MONTHS]; float years; /* Input and output files */ FILE *inPtr, *outPtr1, *outPtr2; /* Open input and output files */ /* Format: fopen statement, file name, read/write */ inPtr=fopen("precipmonthly_usmx.asci", "r"); outPtr1=fopen("Mon_means.asci", "w"); outPtr2=fopen("Mon_std.asci", "w"); /* Declare missing value */ missingval=-999.9; years=55; /* Initialize missing array */ for(p=0;p