/* smooth.c functions that perform smoothing on vectors *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Biome-BGC version 4.1.2 Copyright 2002, Peter E. Thornton *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* */ #include #include #include #include #include #include "misc_func.h" int run_avg(const double *input, double *output, int n, int w, int w_flag) { /* calculates running averages n = length of input and output arrays w = width of averaging window w_flag : 1=linearly weighted window, 0=constant weighted window */ register int i,j; int ok = 1; int *wt; double total, sum; if (w>n) { printf("Error: averaging window longer than input array\n"); ok=0; } if (ok && (!(wt = (int*) malloc(w * sizeof(int))))) { printf("Allocation error in boxcar_smooth... Exiting\n"); ok=0; } if (ok) { if (w_flag) for (i=0 ; i n/2)) { printf("Boxcar window longer than 1/2 array length...\n"); printf("Resize window and try again\n"); ok=0; } /* establish the lengths of the boxcar tails */ if (ok) { if (!(w % 2)) w += 1; tail = w/2; } if (ok && (!(wt = (int*) malloc(w * sizeof(int))))) { printf("Allocation error in boxcar_smooth... Exiting\n"); ok=0; } /* when w_flag != 0, use linear ramp to weight tails, otherwise use constant weight */ if (ok) { if (w_flag) { for (i=0 ; i= tail) && (i < n-tail)) { for (j=0 ; j= n-tail) { for (j=0 ; j