/* # correggi_tc.c # # (C) Luca Barion 2010 # Last modified: 2012-09-12 15:01 # */ #include #include #include #include #include // 0-76 K (CLTS) #define P0 -7920.91 #define P1 481.92 #define P2 -11.7329 #define P3 0.142982 #define P4 -0.000869082 #define P5 2.10627E-06 // 76-110 K (CLTS) #define Q0 -478.932 #define Q1 15.8473 #define Q2 -0.197846 #define Q3 0.0012728 #define Q4 -3.21378e-06 // 110-280 K (CLTS) #define R0 -111.300 #define R1 2.56908 #define R2 -0.00839146 #define R3 1.93376e-05 #define R4 -1.58789e-08 // Functions prototypes void print_help(void); float correggi(float tc); /*** Main ***/ int main(int argc, char *argv[]) { FILE *fp; char buf[32]; int i; float tc; fprintf(stderr, "correggi_tc - (C) 2010 Luca Barion\n"); if (argc == 2) { if (strcmp(argv[1],"-h")==0) print_help(); } else { print_help(); return 0; } fp=fopen(argv[1],"r"); if (fp==NULL) {perror("fopen"); return -1;} fprintf(stderr, "Reading from %s...\n", argv[1]); sleep(2); fgets(buf, 32,fp); printf("%s",buf); i=1; while (i>0) { i=fscanf(fp, "%f\n", &tc); if (i<=0) continue; printf("%3.2f\n", correggi(tc) ); fprintf(stderr, " \\=> tc_raw: %3.2f\n", tc); } return 0; } /* /////////|\\\\\\\\\ <**** Functions ****> \\\\\\\\\|///////// */ float correggi(float tc) { float tc_corrected; if (tc<98) tc_corrected= P0 + P1*tc + P2*pow(tc,2) + P3*pow(tc,3) + P4*pow(tc,4) + P5*pow(tc,5); else { if (tc<121.7) tc_corrected= Q0 + Q1*tc + Q2*pow(tc,2) + Q3*pow(tc,3) + Q4*pow(tc,4); else tc_corrected= R0 + R1*tc + R2*pow(tc,2) + R3*pow(tc,3) + R4*pow(tc,4); } return (tc_corrected); } void print_help(void) { printf("usage: correggi_tc [ > ]\n" "(eg. correggi_tc input.txt > output.txt)\n" "\n"); exit(0); }