/* $Id: RdGeCalFile.c,v 1.1 2007/09/18 19:25:00 tl Exp $ */ #include #include #include #include int RdGeCalFile(char *fn, float *offset, float *gain) { /* process cal files */ /* declarations */ FILE *fp; int i1, nn; float f1, f2; char *st, str[128]; /* open file */ fp = fopen(fn, "r"); if (fp == NULL) { printf("could not open \"%s\"\n", fn); exit(1); }; printf("\"%s\" open \n", fn); /* read values */ nn = 0; st = fgets(str, 64, fp); while (st != NULL) { if (str[0] == 35) { /* '#' comment line, do nothing */ } else if (str[0] == 59) { /* ';' comment line, do nothing */ } else if (str[0] == 10) { /* empty line, do nothing */ } else { sscanf(str, "%i %f %f", &i1, &f1, &f2); if (i1>0 && i1<=110) { offset[i1]=f1; gain[i1]=f2; printf("det %3.3i: offset=%9.3f, gain=%9.6f\n", i1, offset[i1], gain[i1]); fflush(stdout); }; nn++; }; /* attempt to read next line */ st = fgets(str, 64, fp); }; printf("read %i gain calibration coefficients\n", nn); /* done */ fclose(fp); return (0); };