#!/usr/bin/php -i 
<?php
set_error_handler("customError");
date_default_timezone_set('Europe/Prague');

/*
Priklad volania skriptu:
php ./geoweight_script.php -l '[{"id":30,"idsite":10,"idmethod":4,"ip":"192.26.179.68","hostname":"plane-lab-pb1.uni-paderborn.de","latitude":"51.708056","longitude":"8.772222","name":"PC2","reliability":98.41,"method":"Planetlab","cost":100,"image":"planetlab.png"},{"id":34,"idsite":12,"idmethod":4,"ip":"147.83.30.164","hostname":"planetlab3.upc.es","latitude":"41.389444","longitude":"2.115833","name":"Universitat_Politecnica_de_Catalunya","reliability":98.01,"method":"Planetlab","cost":100,"image":"planetlab.png"},{"id":61,"idsite":25,"idmethod":4,"ip":"192.43.193.71","hostname":"planetlab-1.cs.unibas.ch","latitude":"47.55858","longitude":"7.5836","name":"University_of_Basel,_Switzerland","reliability":98.72,"method":"Planetlab","cost":100,"image":"planetlab.png"},{"id":108,"idsite":47,"idmethod":4,"ip":"130.73.142.87","hostname":"planet1.zib.de","latitude":"52.455454","longitude":"13.297738","name":"Zuse_Institute_Berlin","reliability":97.44,"method":"Planetlab","cost":100,"image":"planetlab.png"},{"id":127,"idsite":56,"idmethod":4,"ip":"139.91.90.238","hostname":"planetlab1.ics.forth.gr","latitude":"35.304672","longitude":"25.072217","name":"Inst._of_Computer_Science","reliability":25.072217,"method":"Planetlab","cost":100,"image":"planetlab.png"}]' -t '[{"id":199,"idmethod":7,"ip":"81.9.70.62","hostname":"Pln-Pskov.ru","latitude":58.69,"longitude":28.78,"method":"GeoWeight","image":"geoweight.png","comment":"null","duration":"null"}]' 2>&1 
php geoweight_script.php -l '[{"id":0,"idsite":0,"idmethod":4,"ip":"139.19.142.1","hostname":"planetlab01.mpi-sws.mpg.de","latitude":"49.257498","longitude":"7.045423","name":"Max_Planck_Institute_for_Software_Systems","reliability":95.12,"method":"Planetlab","cost":100,"image":"planetlab.png"},{"id":7,"idsite":1,"idmethod":4,"ip":"195.113.161.82","hostname":"planetlab1.cesnet.cz","latitude":"49.22684","longitude":"16.596152","name":"CESNET_-_Czech_Education_and_Research_Network","reliability":88.76,"method":"Planetlab","cost":100,"image":"planetlab.png"},{"id":14,"idsite":4,"idmethod":4,"ip":"88.255.65.220","hostname":"planet2.ku.edu.tr","latitude":"41.204958","longitude":"29.073858","name":"Koc_University","reliability":96.09,"method":"Planetlab","cost":100,"image":"planetlab.png"},{"id":15,"idsite":5,"idmethod":4,"ip":"143.225.229.236","hostname":"planetlab01.dis.unina.it","latitude":"40.828915","longitude":"14.191273","name":"Universita_di_Napoli_Federico_II","reliability":98.17,"method":"Planetlab","cost":100,"image":"planetlab.png"},{"id":17,"idsite":6,"idmethod":4,"ip":"130.104.72.200","hostname":"onelab1.info.ucl.ac.be","latitude":"50.669611","longitude":"4.612264","name":"Universite_Catholique_de_Louvain","reliability":95.95,"method":"Planetlab","cost":100,"image":"planetlab.png"}]' -t '[{"id":42,"idmethod":7,"ip":"147.228.58.47","hostname":"www.zcu.cz","latitude":50.62,"longitude":13.83,"method":"GeoWeight","image":"geoweight.png","comment":"null","duration":"null"}]' 2>&1
*/

//POMOCNY SKRIPT PREBERANIA JSON PARAMETROV LANDMARKOV A CIELOV
function getParam($argv, $options) {
 
  $Pocet=count($argv);
  if ($Pocet>1){
    for ($i=1;$i<$Pocet;$i++){
      switch ($argv[$i]){
        case '-l':
          if ($Pocet>$i+1){
            $options['landmark']=Json_decode($argv[++$i]);
		    //if ($options['debug'])echo "\nDEBUG: -l ".$argv[$i]."\n";
          }else{
            echo "ERROR in parsing argument -l: missing value\n";
            //Manual();
            //exit (STATE_UNKNOWN);
          }
          break;
        case '-t':
          if ($Pocet>$i+1){
            $options['test']=Json_decode($argv[++$i]);
		    
        //if ($options['debug'])echo "\nDEBUG: -t ".$argv[$i]."\n";
          }else{
            echo "ERROR in parsing argument -t: missing value\n";
            //Manual();
            //exit (STATE_UNKNOWN);
          } 
          break;
          
        default:
          echo "ERROR in argument parsing: ".$argv[$i]."\n";
          //Manual();
          //exit(STATE_UNKNOWN);
          break;
      }
    }
  }
  return $options;
}
/**********************Konec nacteni vstupinch parametru**********************/



////////////////////////ZACIATOK_GEOWEIGHT_FUNKCIA////////////////////////////
function aaa($test, $landmarkarray){
  
  $landmarks = $landmarkarray;
  $targets = $test;
//tolerancia pre vypocet kruznic
$tolerance = 100;
$konst_lat = 111.330;
$konst_lng = 94.152;

//zaciatok pocitania behu skriptu
$time_start = getmicrot();

//definovanie poli
$bestlines = array();

//zaciatok cyklu
foreach($landmarks as $key1 => $pole1)
{ 
	//	echo "\nPripojenie na landmark: ".$pole1->hostname."\n";
	$host = $pole1->hostname;
	$host_ip = $pole1->ip;
	$host_id = $pole1->id;
	$host_lat = $pole1->latitude;
	$host_lon = $pole1->longitude;
	   	
	 
	//test ci landmark odpoveda na ping ak ano pokracuje sa dalej
	$testping = control_ping($host_ip);
	if(empty($testping)){
		$date = Date("d/m/Y H:i:s", Time());
		trigger_error("$date   NEODPOVEDA na ping - Landmark ID: $host_id - IP address: $host_ip - Hostname: $host");
	}else{ 
	    $bestline = ssh_func($host,$targets,$key1,$host_lat,$host_lon,$host_id,$host_ip);
	    array_push($bestlines, $bestline);
	}
}   
$bestlines = compute_weight($bestlines);	
$priesecniky = array();
$landmarky = array();
foreach($bestlines as $keys1 => $value1){
//echo "\n\nPRVA: ".$value1["landmark"] ."\n";
$lat1 = $value1["latitude"];
$lon1 = $value1["longitude"];
	
	foreach($bestlines as $keys2 => $value2){
		$lat2 = $value2["latitude"];
		$lon2 = $value2["longitude"];
			if($lat1==$lat2 && $lon1==$lon2){
				  continue;
			}				
	
		$Ax = $bestlines[$keys1]["latitude"]*$konst_lat;
		$Ay = $bestlines[$keys1]["longitude"]*$konst_lng;
		$Ar = $bestlines[$keys1]["distance_from_landmark"]+$tolerance;
		$Bx = $bestlines[$keys2]["latitude"]*$konst_lat;
		$By = $bestlines[$keys2]["longitude"]*$konst_lng;
		$Br = $bestlines[$keys2]["distance_from_landmark"]+$tolerance;
//echo " LAT1: " . $Ax ." LON1: " . $Ay . " DIST1: " . $Ar . " LAT1: " . $Bx ." LON1: " . $By . " DIST1: " .$Br . "\n";
	
                $lat1 = $bestlines[$keys1]["latitude"];
				$lng1 = $bestlines[$keys1]["longitude"];
				$lat2 = $bestlines[$keys2]["latitude"];
				$lng2 = $bestlines[$keys2]["longitude"];
				$d_real = distance($lat1, $lng1, $lat2, $lng2, $miles = false);            
//echo " D real: " .$d . "\n";
                
    //podmienka ak su kruznice: 1. mimo seba || 2. vnutri seba || 3.maju jeden spolocny bod
	if ($d_real > ($Ar + $Br)) continue;
	if($d_real < ($Ar - $Br)) continue;
	if($d_real == ($Ar + $Br)) continue;            
                
	//podmienka ak maju kruznice dva spolocne body
    if ($d_real > ($Ar - $Br) && $d_real < ($Ar + $Br)) {
          
                    //vzorec na vzdialenost stredov
                    $d = sqrt((pow(($Ax - $Bx),2))+(pow(($Ay - $By),2)));                    
//echo " D: " .$d . "\n";

					//vzdialenost stredov rozdelena na dve casti - m, n
                    $m = ((pow($Ar,2)-pow($Br,2))/(2*$d))+($d/2)  ;
//echo " M: " .$m . "\n";

                    //vypocet vysky
                    $v = sqrt(pow($Ar,2)-pow($m,2));
//echo " V: " .$v . "\n";                    
                    
                    //vypocet suradnic stredu S vzdialenosti medzi stredmi kruznic                    
                    $Sx = $Ax + (($m/$d) * ($Bx - $Ax));
                    $Sy = $Ay + (($m/$d) * ($By - $Ay));
//echo " Sx: " .$Sx . " Sy: " .$Sy ."\n";
		
                    //vypocet suradnic priesecnikov
                    $cx = $Sx - ($v / $d)*($Ay - $By);
                    $cy = $Sy + ($v / $d)*($Ax - $Bx);
					
					//podmienka pre vyradenie neplatnych hodnot z pola
					if(is_nan($cx) || is_nan($cy)) continue;
					$cx = $cx/$konst_lat;
					$cy = $cy/$konst_lng;
                    array_push($priesecniky,$cx,$cy);
//echo "1. Prvy secnik cx: " .$cx ."Druhy secnik cy: " .$cy ."\n";
					
					
                    $cx = $Sx + ($v / $d)*($Ay - $By);
                    $cy = $Sy - ($v / $d)*($Ax - $Bx);
                    
                    //podmienka pre vyradenie neplatnych hodnot z pola
                    if(is_nan($cx) || is_nan($cy)) continue;
                    $cx = $cx/$konst_lat;
					$cy = $cy/$konst_lng;                 
                    array_push($priesecniky,$cx,$cy);
// echo "2. Prvy secnik cx: " .$cx ."Druhy secnik cy: " .$cy ."\n"


                    $Ax = $Ax/$konst_lat;
                    $Ay = $Ay/$konst_lng;
                    $Bx = $Bx/$konst_lat;
                    $By = $By/$konst_lng;
                    array_push($landmarky,$Ax,$Ay,$Ar,$Bx,$By,$Br);
}else{continue;}
	}
	unset($bestlines[$keys1]);
}

$landmarky = array_chunk($landmarky, 3);

//odstrani opakujuce sa hodnoty z multipola $landmarky
$landmarky = array_map("unserialize", array_unique(array_map("serialize", $landmarky)));
$landmarky = array_values($landmarky);
//print_r($landmarky);

//vytvori dvojice z pola $priesecniky
$priesecniky = array_chunk($priesecniky, 2);

$poly = array();
$poly_priesec = array();
$poloha_pries = array();
$toler = 100;
foreach($landmarky as $keyz2 => $val2){
		$latitude = $val2[0];
		$longitude = $val2[1];
		$rad = $val2[2]+$toler;
		
		$radius=radius($latitude,$longitude,$rad);
		array_push($poly,$radius);
	}

/////OVERENIE a VYRADENIE PRIESECNIKOV, KTORE NEPATRIA VSETKYM KRUZNICIAM/OBLASTIAM
foreach($priesecniky as $keyz1 => $val1){
	$latitude_priesec = $val1[0];
	$longitude_priesec = $val1[1];
	
foreach($poly as $key => $keyVal){
	$lat_min = $keyVal["lat_min"];
	$lat_max = $keyVal["lat_max"];
	$lng_min = $keyVal["lng_min"];
	$lng_max = $keyVal["lng_max"];		
	
		if($latitude_priesec >= $lat_min && $latitude_priesec <= $lat_max) {
			if($longitude_priesec >= $lng_min && $longitude_priesec <= $lng_max)
				{
				array_push($poloha_pries,$latitude_priesec,$longitude_priesec);
				}		
		 }	
}
	$poloha_pries = array_chunk($poloha_pries,2);
	$kontrol_sucet_pries = count($poloha_pries);
	$pocet_landm = count($poly);
    if ($kontrol_sucet_pries == $pocet_landm)
    {
		array_push($poly_priesec,$latitude_priesec,$longitude_priesec);
    }    
    $poloha_pries = array();
}	

$poly_priesec = array_chunk($poly_priesec,2);
 
$polygon = $poly_priesec;

//vypocet obalky
/*include( '/var/www/html/bachsoft/public/methods/xtropp00/convex_hull.php' );
$hull = new ConvexHull( $polygon );
$polygon = ($hull->getHullPoints());
//print_r($polygon);*/


//vypocet taziska zo spolocnych polov
$n = count($polygon); 
centroid($polygon,$n);    
$x = 0;
$y = 0;

for($i=0;$i<$n;$i++)
   {
    $x+=$polygon[$i][0];
    $y+=$polygon[$i][1];
   }
   
			if ($n != 0){
			$x = round($x/$n,8); $y = round($y/$n,8);
			$time_end = getmicrot();
			
			
//vypocet casu pocitania skriptu			
$time = round(($time_end - $time_start),2);

$targets['duration'] = $time;
$targets['latitude'] = $x;
$targets['longitude'] = $y;
//$targets['radius'] = comment_radius($x,$y,$polygon);
$r = comment_radius($x,$y,$polygon);
$S = round((M_PI * $r * $r),2) ;
$targets['comment'] = $S;
return $targets;
			}else{
				//$target = $targets;
			}	
  
}
////////////////////////KONIEC_HLAVNEJ_GEOWEIGHT_FUNKCIE////////////////////////////



//-------------ZACIATOK DEFINICIE CIASTOCNYCH FUNKCII-------------//
function getmicrot(){
   list($usec, $sec) = explode(" ",microtime());
   return ((float)$usec + (float)$sec);
   } 

//funkcia pre kontrolu ci landmark odpoveda na ping
function control_ping($host_ip) {
		$testping = exec('ping -q -i 0.5 -c 4 '."$host_ip".' | grep rtt | sed -e \'s/.*mdev = \([^\/]*\).*/\1/\'');	
		return $testping;
	}
		
//funkcia pre pripojenie na ssh
function ssh_func($host,$targets,$key1,$host_lat,$host_lon,$host_id,$host_ip){

// Vytvorenie ssh spojenia na landmark 
		$ssh = @ssh2_connect($host, 22, array('hostkey'=>'ssh-rsa'));
		if(!$ssh) {
			//echo "Chyba - Neda sa spojit s ssh serverom.\n";
			$date = Date("d/m/Y H:i:s", Time());
			trigger_error("$date   NEUSPESNE pripojenie s ssh serverom ID: $host_id - IP address: $host_ip - Hostname: $host");		
		}else{
			
		// Prihlasenie na server
		$sshLogin = @ssh2_auth_pubkey_file($ssh, 'cesnet_vutbr2', '/var/www/html/bachsoft/public/methods/xtropp00/keys_rsa/identity.pub', '/var/www/html/bachsoft/public/methods/xtropp00/keys_rsa/identity');
		if(!$sshLogin) {
				//echo "Chyba - Neda sa prihlasit na server.\n";
				$date = Date("d/m/Y H:i:s", Time());
				trigger_error("$date   NEUSPESNE prihlasenie na ssh server ID: $host_id - IP address: $host_ip - Hostname: $host");
		}else{				
				//upravit riesenie v pripade viacerych cielov ?? foreach($targets as $key2 => $pole2)
				$IP = $targets["ip"];
				//echo "$IP ";
				$stream = ssh2_exec($ssh, 'ping -q -i 0.5 -c 10 '."$IP".' | grep rtt | sed -e \'s/.*mdev = \([^\/]*\).*/\1/\'');
				stream_set_blocking($stream, true);
				$ping_result = "";
				while($buffer = fread($stream, 4096)) 
				{
					$ping_result .= $buffer;
				}
											
				//pokial nie je ping bez odozvy tak zapise hodnoty a ping k cielu
				if (!empty($ping_result))
				{
					$soubor = "/var/www/html/bachsoft/public/methods/xtropp00/bestline-".$host.".txt";
					if(file_exists($soubor)){
						$files = file_get_contents($soubor);
						$bestline_landmarks=json_decode($files,true);
						
						$k = $bestline_landmarks["k"];
						$q = $bestline_landmarks["q"];
						$y = $ping_result;
						
						$x = null;					
						$x = (($y - $q)/$k);	
										
						$bestlines = array("landmark" => $host, "latitude" => $host_lat, "longitude" => $host_lon, "k" => $k, "q" => $q, "ping_to_target" => $ping_result, "distance_from_landmark" => $x);
			
					}
				}		
			fclose($stream); 
		//koniec else --- if(ssh2_auth_pubkey_file)
		}	  
	  //koniec else --- if($ssh = ssh2_connect()) 
  }	  
  return $bestlines;	
}


//funkcia prepoctu vah
function compute_weight($bestlines){
//vyhladanie MAX vzdialenosti $max_d
usort($bestlines, "cmp_distance");
$max_d = $bestlines[0]["distance_from_landmark"];

//vyhladanie MAX pingu k cielu $max_t_ping
usort($bestlines, "cmp_ping_to_target");
$max_t_ping = $bestlines[0]["ping_to_target"];

$all_landmarks = count($bestlines);

//scita vsetky hodnoty ping
$total_t = 0;
foreach($bestlines as $item)
{
	$total_t += $item["ping_to_target"];	
}
$average_t = $total_t/$all_landmarks;

//scita vsetky hodnoty distance_from_landmark
$total_d = 0;
foreach($bestlines as $item)
{
	$total_d += $item["distance_from_landmark"];	
}
$average_d = $total_d/$all_landmarks;


//////////////////
$group1=array();
$group2=array();
$groups=array();
$mrd = 0;
$mrt = 0;

//normalizacia oblasti 
for($i = 1; $i <= $all_landmarks; $i++){
	
	//prechadzanie bestlines pre rozdelenie na skupiny vzdialenosti a ping
	foreach($bestlines as $items)
	{
		$max_rozsah_d = $average_d*$i;
		if($items["distance_from_landmark"] <= $max_rozsah_d && $items["distance_from_landmark"] > $mrd ){			
			$group1 = array("max_rozsah_d"=>$max_rozsah_d);
			$newitems1 = array_merge($items,$group1);			
			for($j = 0; $j <= $all_landmarks; $j++){
				$max_rozsah_t = $average_t*$j;
				if($newitems1["ping_to_target"] <= $max_rozsah_t && $newitems1["ping_to_target"] > $mrt ){
					$group2 = array("max_rozsah_t"=>$max_rozsah_t);
					$newitems2 = array_merge($newitems1,$group2);
					$group2 = array();
				}
				$mrt = $max_rozsah_t;
			}			
			array_push($groups,$newitems2);				
		}		
		$group1 = array();				
	}
	$mrd = $max_rozsah_d;
}

//scitanie hodnot vah pre jednotlive vzdialenosti a casy pingov
$over_distance = array();
$sum_all_distance = array();
for($l=1; $l<=count($groups); $l++){
	$max_rozsah_d = $average_d*$l;
	
	foreach($groups as $items){
		if($items["max_rozsah_d"]==$max_rozsah_d){
		array_push($over_distance, $items);	
		}
	}
	if(!empty($over_distance)){
	$sum_d["$max_rozsah_d"] = count($over_distance);
	}
		
	for($m=1; $m<=count($groups); $m++){	
		$sumt = 0;
		$max_rozsah_t = $average_t*$m;
			foreach($over_distance as $item){							
					if($item["max_rozsah_t"]==$max_rozsah_t){
						$sumt++;				
					}				
			}	
			if(!empty($sumt)){
				$sum_t["$max_rozsah_d"]["$max_rozsah_t"] = $sumt;			
			$sum_all["$max_rozsah_d"]["$max_rozsah_t"] = ($sum_t["$max_rozsah_d"]["$max_rozsah_t"])/($sum_d["$max_rozsah_d"]);
			array_push($sum_all_distance,$sum_all["$max_rozsah_d"]["$max_rozsah_t"]);
			}				
	}	
	$over_distance = array();
}


//scitanie vsetkych hodnot ping pre dane rozsahy
$sumArray_t = array();
foreach ($sum_all as $k=>$subArray) {
  foreach ($subArray as $id=>$value) {
    $sumArray_t[$id]+=$value;
  }
}
return $groups;
}

function comment_radius($x,$y,$polygon){
$dist_radius = 0;
	foreach($polygon as $key){
	//echo $key[0]."\n";
	$lat=$key[0];
    $lng=$key[1];    
	$dist_real = distance($x, $y, $lat, $lng, $miles = false);
	//echo $dist_real."\n";
		if($dist_real >= $dist_radius ){		
			$dist_radius = $dist_real;
		}	
	}
return $dist_radius;
}

//funkcia pre prepocet uhlov dvoch bodov na geo vzdialenost
function distance($lat1, $lng1, $lat2, $lng2, $miles = false) {
    $pi80 = M_PI / 180;
    $lat1 *= $pi80;
    $lng1 *= $pi80;
    $lat2 *= $pi80;
    $lng2 *= $pi80;
     
    $r = 6372.797; // mean radius of Earth in km
    $dlat = $lat2 - $lat1;
    $dlng = $lng2 - $lng1;
    $a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2);
    $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
    $km = $r * $c;
     
    return ($miles ? ($km * 0.621371192) : $km);
  }	
  
//funkcia vypoctu oblasti  
function radius($latitude,$longitude,$rad) {
$radius = $rad * 0.621371192; // in miles
$lng_min = $longitude - $radius / abs(cos(deg2rad($latitude)) * 69);
$lng_max = $longitude + $radius / abs(cos(deg2rad($latitude)) * 69);
$lat_min = $latitude - ($radius / 69);
$lat_max = $latitude + ($radius / 69);

return array("lat_min"=>$lat_min,"lat_max"=>$lat_max,"lng_min"=>$lng_min,"lng_max"=>$lng_max);
}

function direction($polygon) {  
   $area = 0;
   $n = count($polygon)-1;
   
   for ($i=0;$i<$n;$i++) {
      $j = ($i + 1);
      $area += $polygon[$i][0] * $polygon[$j][1];
      $area -= $polygon[$i][1] * $polygon[$j][0];
   } 
   $area /= 2;
   
   return ($area);
}
 
function centroid($polygon,$n) {
   $n = count($polygon)-1;
    $a = direction($polygon);
 
    $cx = 0;
    $cy = 0;   
 
    for ($i=0;$i<$n;$i++) {
		$j = ($i + 1);
		//vypocet suradnice Cx,Cy
        $cx += ($polygon[$i][0] + $polygon[$j][0]) * ( ($polygon[$i][0]*$polygon[$j][1]) - ($polygon[$j][0]*$polygon[$i][1]) );
        $cy += ($polygon[$i][1] + $polygon[$j][1]) * ( ($polygon[$i][0]*$polygon[$j][1]) - ($polygon[$j][0]*$polygon[$i][1]) );
    }
 
    return(array( (1/(6*$a))*$cx,(1/(6*$a))*$cy));
   
}

//zoradovacie funkcie//
function cmp_distance($a, $b) {
    if ($a["distance_from_landmark"] == $b["distance_from_landmark"]) {
        return 0;
    }
    return ($a["distance_from_landmark"] > $b["distance_from_landmark"]) ? -1 : 1;
}

function cmp_ping_to_target($a, $b) {
    if ($a["ping_to_target"] == $b["ping_to_target"]) {
        return 0;
    }
    return ($a["ping_to_target"] > $b["ping_to_target"]) ? -1 : 1;
}


//definovanie vlastneho error handleru
function customError($error_num, $error_msg, $error_file, $error_line) {     
   $date = Date("d/m/Y H:i:s", Time());
   $file_name = "/var/www/html/bachsoft/public/methods/xtropp00/error.log";
 switch( $error_num ){   
   case 1024:
	   $error = "\"". $error_msg ."\"\n";         
	   $soubor = fopen($file_name, "a");
	   fwrite($soubor, $error); 
	   break;   
   case 1:
	   $error = "\n" . $date . " ERROR: \"". $error_msg ."\" riadok ". $error_line. " v subore ".$error_file ."\n" ;         
	   $soubor = fopen($file_name, "a");
	   fwrite($soubor, $error); 
	   break;   
   case 2:
	   $error = "\n" . $date . " WARNING: \"". $error_msg ."\" riadok ". $error_line. " v subore ".$error_file ."\n" ;         
	   $soubor = fopen($file_name, "a");
	   fwrite($soubor, $error); 
	   break;
 }
}
//-------------KONIEC DEFINICIE CIASTOCNYCH FUNKCII-------------//




$options = array();
$h = array();
$options = getParam($argv, $options);

//predanie nameranych parametrov do vystupu
foreach ($options['test'] as $key => $test) {
   $test = get_object_vars($test);
   
    $test = aaa($test, $options['landmark']);
    $h[] = $test;
   }
   

echo json_encode($h);
exit(0);




?>
