/** @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 <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>

int main(void) {
	int success = EXIT_SUCCESS;
	struct journal j = journal();
	union date32 k;
	struct flights f = flights(&j);
	if(!journal_is_valid(&j)) goto catch;
	fprintf(stderr, "Journal: %s.\n", journal_to_string(&j));
	printf("set term postscript eps enhanced\n"
		"set output \"flighthours.eps\"\n"
		"$Data <<EOD\n"
		"# date\tminutes\tcumulative\n");
	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 format y \"%%g%%%%\"\n"
		"set key top left\n"
		"set grid\n"
		"unset border\n"
		"#set style fill solid 0.1 #pattern 5 (better, but restarts)\n"
		"plot $Data using 1:($3) with fillsteps lw 2\n");
	goto finally;
catch:
	success = EXIT_FAILURE;
	perror("journal");
finally:
	journal_(&j);
	return success;
}
