/** @license 2023 Neil Edelman, distributed under the terms of the [MIT License](https://opensource.org/licenses/MIT). Date _vs_ hours flown. */ #include "journal.h" #include "flight.h" #include "source.h" #include #include #include #include #include int main(void) { int success = EXIT_SUCCESS; errno = 0; struct journal j = journal(); struct sources s = sources(&j); struct flights f = flights(&j); if(errno) goto catch; fprintf(stderr, "Journal: %s.\n" "Flights: %s.\n", journal_to_string(&j), flights_to_string(&f)); printf("set term postscript eps enhanced\n" "set output \"flighthours.eps\"\n" "$Data <name.a) { errno = EDOM; goto catch; } printf("%s\t%.*s\t", datestr, (int)(src->name.b - src->name.a), src->name.a); assert(flight); switch(flight->type) { case GLIDER: total += flight->glider.dual_min + flight->glider.pilot_min + flight->glider.instr_min; printf("%.*s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\n", (int)(flight->glider.reg.b - flight->glider.reg.a), flight->glider.reg.a, flight->glider.dual_min, flight->glider.pilot_min + flight->glider.instr_min, total); break; case POWER: total += flight->power.dual_min + flight->power.pilot_min; printf("%.*s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\n", (int)(flight->power.reg.b - flight->power.reg.a), flight->power.reg.a, flight->power.dual_min, flight->power.pilot_min, total); break; } } printf("EOD\n" "set monochrome\n" "set xdata time\n" "set timefmt \"%%Y-%%m-%%d\"\n" "set xtics format \"%%Y-%%m-%%d\" rotate by -30\n" "set ylabel \"hours\"\n" "set grid\n" "unset key\n" "unset border\n" "set xrange [*:'2001-09-11']\n" "#set style fill solid 0.1 #pattern 5 (better, but restarts)\n" "plot $Data using 1:($6/60) with fillsteps lw 2\n"); goto finally; catch: success = EXIT_FAILURE; perror("flights"); finally: flights_(&f); sources_(&s); journal_(&j); return success; }