Code:
#include<stdio.h>
#include<math.h>
main()
{
FILE *infp;
infp=fopen("Cu3-_140520_RAES_5_binned_WOBG.Asc", "r");
FILE *outfp;
outfp=fopen("Cu3-_140520_RAES_5b.log", "w");
int r;
double truet, bint;
double truects, bincts;
double tmax;
double first, second, step;
fscanf(infp, "%lf %lf", &first, &truects);
fprintf(outfp, "%lf\t%lf\n", first, truects);
fscanf(infp, "%lf %lf", &second, &truects);
step = second - first;
fprintf(outfp, "%lf\t%lf\n", second, truects);
int nbin=1;
step = step * .5;
r = fscanf(infp, "%lf %lf", &truet, &truects);
while (r != EOF)
{
bint=truet;
bincts=truects;
tmax= truet + truet * step;
r = fscanf(infp, "%lf %lf", &truet, &truects);
while (r != EOF && truet < tmax)
{
bincts = bincts + truects;
bint = bint + truet;
r = fscanf(infp, "%lf %lf", &truet, &truects);
nbin++;
}
bincts= bincts / nbin;
bint= bint / nbin;
fprintf(outfp, "%lf\t%lf\n", bint, bincts);
nbin=1;
}
fclose(infp);
fclose(outfp);
return(0);
}