#include #include #include #include #define WSYS24HOUR "/u/hans/public_html/watersys/day/wsys_24h.data" #define OUTPUTFILE "/u/hans/public_html/watersys/wsys_24h.html" #define SENSORTABLE "/u/hans/watersys/sensor_table.dat" #define SENSORS 33 char sensor_plot[SENSORS][128]; char sensor_name[SENSORS][128]; char sensor_unit[SENSORS][128]; char sensor_detail[SENSORS][128]; char start_time[40], end_time[40]; FILE *out; float x[SENSORS], x_max[SENSORS], x_min[SENSORS], x_av[SENSORS]; float warn0[SENSORS], warn1[SENSORS], warn2[SENSORS]; void define_sensors(void); void read_sensor_data(void); int print_sensor(int); main(int argc, char **argv) { int l; define_sensors(); read_sensor_data(); if ((out=fopen(OUTPUTFILE,"w"))!=NULL) { if (argc==2 && atoi(argv[1])==1) { printf("writing output file to %s\n", OUTPUTFILE); fprintf(out,"K2K Watersystem 24-hour status\n"); } fprintf(out,"\n", end_time); fprintf(out,""); fprintf(out,"\n"); for (l=0; l\n"); if (argc==2 && atoi(argv[1])==1) { fprintf(out,"\n"); } fclose(out); } } void define_sensors() { FILE *in; float wrn0, wrn1, wrn2; int i; if ((in=fopen(SENSORTABLE,"rb"))!=NULL) { i=0; while (!feof(in) && !ferror(in) && iW"); } warn0[i] = wrn0; warn1[i] = wrn1; warn2[i] = wrn2; fgets(sensor_detail[i],120,in); i++; } } fclose(in); } } void read_sensor_data() { FILE *in; char monthstring[13][10], str[512]; int i, k, year, mon, day, hour, min, sec; sprintf(monthstring[0], "---"); sprintf(monthstring[1], "JAN"); sprintf(monthstring[2], "FEB"); sprintf(monthstring[3], "MAR"); sprintf(monthstring[4], "APR"); sprintf(monthstring[5], "MAY"); sprintf(monthstring[6], "JUN"); sprintf(monthstring[7], "JUL"); sprintf(monthstring[8], "AUG"); sprintf(monthstring[9], "SEP"); sprintf(monthstring[10],"OCT"); sprintf(monthstring[11],"NOV"); sprintf(monthstring[12],"DEC"); if ((in=fopen(WSYS24HOUR,"rb"))!=NULL) { i = 0; while( fgets(str,500,in) && !feof(in) && !ferror(in) ) { /* retrieve data points line-by-line */ /* note: order of sensors in data file different than desired */ /* display order (historical reasons: */ /* */ /* sorted by data file position: */ /* */ /* data file pos. display pos. label */ /* ---------------------------------------------------- */ /* 2 [0] 1 = x[0] SIGNET_FLOW_PRODUCT */ /* 3 [1] 2 = x[1] SIGNET_FLOW_RO_WASTE */ /* 4 [2] 3 = x[2] SIGNET_FLOW_TO_DETEC */ /* 5 [3] 4 = x[3] SIGNET_FLOW_TO_FAST_ */ /* 6 [4] 19 = x[18] PRESSURE_AFTER_ANION */ /* 7 [5] - no longer in use */ /* 8 [6] 21 = x[20] PRESSURE_AFTER_UV */ /* 9 [7] 12 = x[11] PRESSURE_CITY_WATER */ /* 10 [8] 10 = x[9] PRESSURE_DETECTOR_PU */ /* 11 [9] 8 = x[7] PRESSURE_OF_DETECTOR */ /* 12 [10] 9 = x[8] PRESSURE_OF_DETE_009 */ /* 13 [11] 22 = x[21] PSI_AFTER_UF */ /* 14 [12] 14 = x[13] PSI_AFT_DEPTH_FILTER */ /* 15 [13] 20 = x[19] PSI_BEFORE_UF_PREFIL */ /* 16 [14] 23 = x[22] PSI_TO_DETECTOR */ /* 17 [15] 30 = x[29] QUALITY_AFTER_MIXBED */ /* 18 [16] - no longer in use */ /* 19 [17] 25 = x[24] TEMPERATURE_BEFORE_C */ /* 20 [18] 24 = x[23] TEMPERATURE_OF_DETEC */ /* 21 [19] 26 = x[25] TEMPERATURE_TO_DETEC */ /* 22 [20] 28 = x[27] TEMP_TENT */ /* 23 [21] 29 = x[28] QUALITY_FROM_DETECTO */ /* 24 [22] 32 = x[31] QUALITY_OUTOF_UF */ /* 25 [23] 31 = x[30] QUALITY_AFTER_UV */ /* 26 [24] 7 = x[6] SIGNET_FLOW_TOTAL_35 */ /* 27 [25] 33 = x[32] UV_LAMPS */ /* 28 [26] 13 = x[12] PRESSURE_AFTER_REPRE */ /* 29 [27] 11 = x[10] PRESSURE_AFTER_FAST_ */ /* 30 [28] 15 = x[14] PRESSURE_AFT_CARBON */ /* 31 [29] 18 = x[17] PRESSURE_AFT_PRE_UV */ /* 32 [30] 17 = x[16] PRESSURE_AFT_RO_PREF */ /* 33 [31] 16 = x[15] PRESSURE_AFT_SOFTENE */ /* 34 [32] 27 = x[26] TEMPERATURE_CITY_WAT */ /* 35 [33] 5 = x[4] SIGNET_FLOW_UF_WASTE */ /* 36 [34] 6 = x[5] SIGNET_FLOW_UF_BYPAS */ /* ---------------------------------------------------- */ /* */ /* sorted by display position: */ /* */ /* data file pos. display pos. label */ /* ---------------------------------------------------- */ /* 2 [0] 1 = x[0] SIGNET_FLOW_PRODUCT */ /* 3 [1] 2 = x[1] SIGNET_FLOW_RO_WASTE */ /* 4 [2] 3 = x[2] SIGNET_FLOW_TO_DETEC */ /* 5 [3] 4 = x[3] SIGNET_FLOW_TO_FAST_ */ /* 35 [33] 5 = x[4] SIGNET_FLOW_UF_WASTE */ /* 36 [34] 6 = x[5] SIGNET_FLOW_UF_BYPAS */ /* 26 [24] 7 = x[6] SIGNET_FLOW_TOTAL_35 */ /* 11 [9] 8 = x[7] PRESSURE_OF_DETECTOR */ /* 12 [10] 9 = x[8] PRESSURE_OF_DETE_009 */ /* 10 [8] 10 = x[9] PRESSURE_DETECTOR_PU */ /* 29 [27] 11 = x[10] PRESSURE_AFTER_FAST_ */ /* 9 [7] 12 = x[11] PRESSURE_CITY_WATER */ /* 28 [26] 13 = x[12] PRESSURE_AFTER_REPRE */ /* 14 [12] 14 = x[13] PSI_AFT_DEPTH_FILTER */ /* 30 [28] 15 = x[14] PRESSURE_AFT_CARBON */ /* 33 [31] 16 = x[15] PRESSURE_AFT_SOFTENE */ /* 32 [30] 17 = x[16] PRESSURE_AFT_RO_PREF */ /* 31 [29] 18 = x[17] PRESSURE_AFT_PRE_UV */ /* 6 [4] 19 = x[18] PRESSURE_AFTER_ANION */ /* 15 [13] 20 = x[19] PSI_BEFORE_UF_PREFIL */ /* 8 [6] 21 = x[20] PRESSURE_AFTER_UV */ /* 13 [11] 22 = x[21] PSI_AFTER_UF */ /* 16 [14] 23 = x[22] PSI_TO_DETECTOR */ /* 20 [18] 24 = x[23] TEMPERATURE_OF_DETEC */ /* 19 [17] 25 = x[24] TEMPERATURE_BEFORE_C */ /* 21 [19] 26 = x[25] TEMPERATURE_TO_DETEC */ /* 34 [32] 27 = x[26] TEMPERATURE_CITY_WAT */ /* 22 [20] 28 = x[27] TEMP_TENT */ /* 23 [21] 29 = x[28] QUALITY_FROM_DETECTO */ /* 17 [15] 30 = x[29] QUALITY_AFTER_MIXBED */ /* 25 [23] 31 = x[30] QUALITY_AFTER_UV */ /* 24 [22] 32 = x[31] QUALITY_OUTOF_UF */ /* 27 [25] 33 = x[32] UV_LAMPS */ /* 7 [5] - no longer in use */ /* 18 [16] - no longer in use */ /* ---------------------------------------------------- */ if (!strstr(str,"#") && (SENSORS+6)==sscanf(str, \ "%d-%d-%d-%d:%d:%d" \ " %g %g %g %g %g %*g %g %g %g %g %g %g %g %g %g %g %*g" \ " %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g", \ &year, &mon, &day, &hour, &min, &sec, \ &x[0], &x[1], &x[2], &x[3], &x[18], &x[20], &x[11], &x[9], \ &x[7], &x[8], &x[21], &x[13], &x[19], &x[22], &x[29], &x[24], \ &x[23], &x[25], &x[27], &x[28], &x[31], &x[30], &x[6], &x[32], \ &x[12], &x[10], &x[14], &x[17], &x[16], &x[15], &x[26], &x[4], \ &x[5]) ) { if (i==0) /* init min/max values */ { for (k=0; k x_max[k]) x_max[k] = x[k]; if (x[k] < x_min[k]) x_min[k] = x[k]; x_av[k] = (x_av[k] * ((float) i) + x[k]) / ((float) (i+1)); } } } fclose(in); sprintf(end_time,"%2d %s %02d:%02d:%02d (JST) %4d",\ day, monthstring[mon], hour, min, sec, year); } } int print_sensor(int row) { char color_def[128]; fprintf(out, "\n", \ row+1, sensor_plot[row], sensor_detail[row]); fprintf(out, " \n", \ sensor_name[row]); sprintf(color_def,"WHITE"); if (x[row] < warn0[row]) sprintf(color_def,"LIGHTBLUE"); if (x[row] > warn1[row]) sprintf(color_def,"YELLOW"); if (x[row] > warn2[row]) sprintf(color_def,"RED"); fprintf(out, " \n", sensor_unit[row]); sprintf(color_def,"WHITE"); if (x_min[row] < warn0[row]) sprintf(color_def,"LIGHTBLUE"); if (x_min[row] > warn1[row]) sprintf(color_def,"YELLOW"); if (x_min[row] > warn2[row]) sprintf(color_def,"RED"); fprintf(out, " \n"); sprintf(color_def,"WHITE"); if (x_av[row] < warn0[row]) sprintf(color_def,"LIGHTBLUE"); if (x_av[row] > warn1[row]) sprintf(color_def,"YELLOW"); if (x_av[row] > warn2[row]) sprintf(color_def,"RED"); fprintf(out, " \n"); sprintf(color_def,"WHITE"); if (x_max[row] < warn0[row]) sprintf(color_def,"LIGHTBLUE"); if (x_max[row] > warn1[row]) sprintf(color_def,"YELLOW"); if (x_max[row] > warn2[row]) sprintf(color_def,"RED"); fprintf(out, " \n"); fprintf(out, " \n", warn1[row]); }
"); fprintf(out,"K2K Watersystem Status as of %s
sensor namelabel in data filecurrent value"); fprintf(out,"24-hour min. / avg. / max.ok range
"); fprintf(out, "%d. %s:%s
", color_def); if (x[row]>=1000 || x[row]==0) { fprintf(out, "%d", (int)x[row]); } else if (x[row]>=100) { fprintf(out, "%5.1f", x[row]); } else if (x[row]>=10) { fprintf(out, "%5.2f", x[row]); } else { fprintf(out, "%.3f", x[row]); } fprintf(out, " %s
", color_def); if (x_min[row]>=1000 || x_min[row]==0) { fprintf(out, "%d", (int)x_min[row]); } else if (x_min[row]>=100) { fprintf(out, "%5.1f", x_min[row]); } else if (x_min[row]>=10) { fprintf(out, "%5.2f", x_min[row]); } else { fprintf(out, "%.3f", x_min[row]); } fprintf(out, "
", color_def); if (x_av[row]==0) { fprintf(out, "%d", (int)x_av[row]); } else if (x_av[row]>=100) { fprintf(out, "%5.1f", x_av[row]); } else if (x_av[row]>=10) { fprintf(out, "%5.2f", x_av[row]); } else { fprintf(out, "%.3f", x_av[row]); } fprintf(out, "
", color_def); if (x_max[row]>=1000 || x_max[row]==0) { fprintf(out, "%d", (int)x_max[row]); } else if (x_max[row]>=100) { fprintf(out, "%5.1f", x_max[row]); } else if (x_max[row]>=10) { fprintf(out, "%5.2f", x_max[row]); } else { fprintf(out, "%.3f", x_max[row]); } fprintf(out, "
%g ... ", warn0[row]); fprintf(out, "%g