#include "gps.h"

stack::stack()
{
////cout<<"constructing"<<endl;
tos=1;
}

void stack::push(double bod_north,double bod_east)
{
	if(tos==(POCET_BODU))
	{
	////cout<<"stack is full"<<endl;
	}
	
	buffer[tos]=bod_north;
	////cout<<"bod_north:"<<buffer[tos]<<endl;
	////cout<<"tos N:"<<tos<<endl;
	tos++;
	buffer[tos]=bod_east;
	//cout<<"bod_east:"<<buffer[tos]<<endl;
	//cout<<"tos E:"<<tos<<endl;
	tos++;
	//cout<<"celk tos"<<tos<<endl;

}

double stack::popNorth()
{	
	
	if(tos<1)
	{
		//cout<<"stack is empty"<<endl;
		return 1;
	}	
	tos--;
	//cout<<"popnorth"<<buffer[tos]<<endl;
	//cout<<"tos_popnorth:"<<tos<<endl;
	return(buffer[tos]);

}


double stack::popEast()
{	
	
	if(tos<0)
	{
		//cout<<"stack is empty"<<endl;
		return 2;
	}
	tos--;
//cout<<"popeast"<<buffer[tos]<<endl;
//cout<<"tos_popeast:"<<tos<<endl;
	return(buffer[tos]);

}


//float degree_to_rad(float);
float degree_to_rad(float souradnice)
{
	float radian;
	return  radian=(souradnice*PI)/180;
}


float degree_to_sec(string s)//prevod ze stupnu minut vterin na vteriny
	{
		string stupne_s("");
		string minuty_s("");
		string vteriny_s("");
		stupne_s=s.substr(0,2);
		minuty_s=s.substr(2,2);
		vteriny_s=s.substr(4,5);
		int stupne=atoi(stupne_s.c_str());
		int minuty=atoi(minuty_s.c_str());
		float vteriny=(atof(vteriny_s.c_str()))*60;
		float d_to_s=(stupne*60*60+minuty*60+vteriny);
////cout<<"souradnice ve formatu:"<<s<<"odpovida:"<<prevod<<"vterin"<<endl;
		
		return d_to_s;
	}


	float sec_to_degree(double vteriny)
	{
		float s_to_d=vteriny/3600;//prevod na stupne do floatu
		return s_to_d;
	}	

	int random(float cislo)
	{
		return cislo;
	}


	float correction(string gps_ref,string ref_poloha)//vypocet korekce ve vterinach,vystup vteriny
	{
		float gpsref=degree_to_sec(gps_ref);
		float gpspoloha=degree_to_sec(ref_poloha);
		float korekce=gpspoloha-gpsref;

		return korekce;	
	}


	float gps2_correction(string s,float corr)//funkce pro zpresneni polohy mobilni gps pomoci korekcí,vystup ve vterinach,parametr-poloha mobilni GPS
	{
		float gps2_vteriny=degree_to_sec(s);//souradnice gps2-severni sirka,zapadni delka-prevedena na vteriny
		float gps_korig=gps2_vteriny+corr; 
		
		return gps_korig;
	}
