#include <iostream>
#include <stdlib.h>
#include <cmath>
#include "radiation.h"

extern const float pi;
const float degtorad = 2*pi/360;
enum c_aspect {N = -4, NE = -3, E = -2, SE = -1, S = 0, SW = 1, W = 2, NW = 3};
int main (int argc, char * const argv[]) {

	float slope = 0; // enter in degrees
	float aspect = 0; // enter in degrees, South = 0, W = 90, E = -90, N = ±180
	float latitude = 52; // northern = positive
	short day = 31+28+31+30+31+21; // day of year
	 
	float rise = 0.0, set = 0.0, riseb = 0.0, setb = 0.0; // prepare for time output
	SOLAR_RADIATION my_earth = SOLAR_RADIATION(latitude); // create an object
	
	// print a few numbers
	std::cout << "slope: " << slope << "°, aspect: " << aspect << "°, latitude: " << latitude << "°, day of year: " << day << std::endl;
		slope*= degtorad; aspect *= degtorad;
		std::cout << std::endl;		
	std::cout << "instantaneous extraterrestrial solar radiation (W/m² = J/(m² s))\n";
	for (int h=6; h<19; h++)
		std::cout << h << ":00\t" << my_earth.get_inst_radiation(slope, aspect, day, h) << std::endl;
	std::cout << std::endl;		

	std::cout << "hourly extraterrestrial solar radiation (MJ/(m² h)) " << std::endl;
	for (int h=4; h<20; h++)
		std::cout << h << ":00-" << h+1 << ":00\t" << my_earth.get_hourly_radiation(slope, aspect, day, h, h+1) << std::endl;
	std::cout << std::endl;		
	std::cout << "daily extraterrestrial solar radiation (MJ/(m² d)): " << my_earth.get_daily_radiation(slope, aspect, day) << std::endl;

	std::cout << std::endl;		
	my_earth.get_hour_sunriseset(slope, aspect, day,rise, set, riseb, setb);
	std::cout << "sun rise: " << floor(rise)<<":"<<floor((rise-floor(rise))*60) <<", sun set: " << floor(set) << ":"<< floor((set-floor(set))*60) << std::endl;
	std::cout << "==========================\n\n" << std::endl;
	
	std::cout << "radiation as a function of aspect and slope throughout the year"<<std::endl;
	std::cout << "day of year, slope (°), aspect(π/4), radiation (MJ/(m² d)), sun rise1 (h), sun set1 (h), sun rise2 (h), sun set2 (h)\n" << std::endl;
	
	float R = 0.0;
	for (day=0; day < 366; day+=60)
		for (short s=0; s<10; s++)
			for(short a=-4; a<5; a+=1) 
			{
			aspect = a * 45 * degtorad;
			slope = s*10 * 2*pi/360.0;
//			for(short h = 0; h<24; h++) {
//				R = my_earth.get_inst_radiation(slope, aspect, day, h);
//				std::cout << day << "\t" << a << "\t" << s*10 << "\t" << h << "\t" << R << std::endl;}
			R = my_earth.get_daily_radiation(slope, aspect, day);
			std::cout << day << "\t" << s*10 << "\t" << a << "\t" << R;
			my_earth.get_hour_sunriseset(slope, aspect, day, rise, set, riseb, setb);
//			std::cout << "\tsun rise: " << floor(rise)<<":"<<floor((rise-floor(rise))*60) <<", sun set: " << floor(set) << ":"<< floor((set-floor(set))*60) << std::endl;
			std::cout << "\t" << rise <<"\t" << setb << "\t" << riseb << "\t" << set << std::endl;
		}
			
    return 0;
}
