#!/usr/bin/perl
#
# Program za izracun Jupitrovih lun
# pozenem: lune.pl k*
#
open( L1 , ">luna1.dat" );
open( L2 , ">luna2.dat" );
open( L3 , ">luna3.dat" );
open( L4 , ">luna4.dat" );

for $a (@ARGV) {   #  Berem, vse parametre
    printf "Obdelujem $a\n";
	open( KD,  $a) ;
	$i=0;
	while (<KD>){

		if(/^#/)
			{next}

		if(/^z/)
			{next}

		($x[$i],$y[$i]) = split ;
		$i++;
	}
	# racunamo razdaljo
	for($j=0;$j<4;$j++){
		$d[$j] = sqrt (($x[4]-$x[$j])*($x[4]-$x[$j]) +
					   ($y[4]-$y[$j])*($y[4]-$y[$j]));

		print "j=$j   d=$d[$j]  \n";
	}
	close KD;
	$slika = "j" . substr($a,1,3) . "x.fts";
	$ura =  substr(`buffers $slika fits=UT-START`,12,8);
	print $slika,"  ",$ura,"\n";
	printf (L1 "%s  %7.3f\n",$ura,$d[0]);
	printf (L2 "%s  %7.3f\n",$ura,$d[1]);
	printf (L3 "%s  %7.3f\n",$ura,$d[2]);
	printf (L4 "%s  %7.3f\n",$ura,$d[3]);
}
close L1;
close L2;
close L3;
close L4;


