#include <gtk/gtk.h>
#include <stdlib.h>
#include "gddcalc.h"
#include "solpos.h"

float getMonthsIrr(int);              // prototype
float getMonthsGDD(float, int);       // prototype
void setMonthLengths(int);            // prototype

void t3_Populate() {
	size_t lth = 64;
	char *bfr = malloc(lth);
	int month;
	float monthsIrr, monthsGDD, cumulativeGDD;
	
	active_year = 2007;                // initialize Willamette Valley
	active_latitude = 44.133;
	active_longitude = -123.214;
	active_elev = 114.0;
	active_aspect = 180.0;
	active_tilt = 10.0;
	active_timezone = -8;
	active_dt = 1;
	active_temp = 15;
	active_press = 1006;
	northsouth = 1;
	
/* Make the calculations */

	setMonthLengths(active_year);
	cumulativeGDD = 0.0;
	for (month = 4; month <= 10; month++) {
		monthsIrr = getMonthsIrr(month);
		monthsGDD = getMonthsGDD(monthsIrr, month);
		sprintf(bfr, "%.2f degree days", monthsGDD);
		switch(month) {
			case 4:
				gtk_entry_set_text (GTK_ENTRY (t3_entry1), (gchar*) bfr);
				break;
			case 5:
				gtk_entry_set_text (GTK_ENTRY (t3_entry2), (gchar*) bfr);
				break;
			case 6:
				gtk_entry_set_text (GTK_ENTRY (t3_entry3), (gchar*) bfr);
				break;
			case 7:
				gtk_entry_set_text (GTK_ENTRY (t3_entry4), (gchar*) bfr);
				break;
			case 8:
				gtk_entry_set_text (GTK_ENTRY (t3_entry5), (gchar*) bfr);
				break;
			case 9:
				gtk_entry_set_text (GTK_ENTRY (t3_entry6), (gchar*) bfr);
				break;
			case 10:
				gtk_entry_set_text (GTK_ENTRY (t3_entry7), (gchar*) bfr);
				break;
		}
		cumulativeGDD = cumulativeGDD + monthsGDD;
	}
	sprintf(bfr, "%.2f degree days", cumulativeGDD);
	gtk_entry_set_text (GTK_ENTRY (t3_entry8), (gchar*) bfr);
	free(bfr);
}
