/* c1_Initialize.c
 * Called by the widget create_grid_1 of oneDay.c
 */

#include <stdlib.h>
#include "gddcalc.h"

float getDescriptor(char *);                                      // prototype

void c1_Initialize() {

	size_t lth = 128;
	char *bfr = malloc(lth);
	FILE *fp;

	fp = fopen("locale.txt", "r");

/* If a locale has been set, read its contents into active variables */

	if (fp == NULL) {haveprefs = 0;}
	else
	{
		haveprefs = 1;
		while (fgets(bfr, lth, fp))
		{
			if (bfr[0] == 'l' && bfr[1] == 'a' && bfr[2] == 't')
				active_latitude = getDescriptor(bfr);
			else if (bfr[0] == 'l' && bfr[1] == 'o' && bfr[2] == 'n')
				active_longitude = getDescriptor(bfr);
			else if (bfr[0] == 'e' && bfr[1] == 'l' && bfr[2] == 'e')
				active_elev = getDescriptor(bfr);
			else if (bfr[0] == 'a' && bfr[1] == 's' && bfr[2] == 'p')
				active_aspect = getDescriptor(bfr);
			else if (bfr[0] == 't' && bfr[1] == 'i' && bfr[2] == 'l')
				active_tilt = getDescriptor(bfr);
		}
		fclose(fp);
		free(bfr);
	}
	
/* Intialize the remaining active variables, which are defined and
 * stored in gddcalc.h. Put in values for noon at Eugene.
 */
	active_timezone = -8;
	active_hour = 12;
	active_minute = 0;
	active_second = 0;
	active_dt = 1;
	active_temp = 15;
	active_press = 1013;
}
