#!/usr/bin/perl

open(NEWDAT, ">LR_gap.dat");

for($n=0; $n<=809; $n++){

#strings are put together with a .
#e.g. $string1="hello", $string2="world", $string3=$string1." ".$string2
#     will give hello world

$file="LR".$n.".dat";
open(IN, $file) or die "Can't read file\n";

#This line converts every line in your file into
#an array where $filearray[0] is the first line
@filearray = <IN>;
#$num=@filearray; returns the size of the array (the number of lines
#in your file, but don't forget that the array index starts at 0
$num=@filearray;

#split(/\s+/) splits everything with spaces into different variables

@data1=split(/\s+/, $filearray[$num-2]);  #Next to last line
@data2=split(/\s+/, $filearray[$num-1]);  #Last line

$diff= sqrt((($data2[1]-$data1[1]) ** 2) + (($data2[2]-$data1[2]) ** 2) + (($data2[3]-$data1[3]) ** 2) + (($data2[4]-$data1[4]) ** 2)); 

$nn=$n*0.01;

#print "$data1[1], $data1[2], $data1[3], $data1[4] \n";
#print "$data2[1], $data2[2], $data2[3], $data2[4] \n";


print NEWDAT "$nn   $diff \n";

}
