close all
clear all

km2nm = 1/1.8520;

Start = [36+36.12/60 -(121+53.42/60)];
Finish = [21+12.25/60 -(157+48.6/60)];

TotalDistance = greatcircle(Start(1),Start(2),Finish(1),Finish(2))*km2nm;


TotalDistance

%First index is class{k}, second index is boat{i}, third index is day number{j}

Class_Names{1} = 'Solos';
Class_Names{2} = 'Pairs';
Class_Names{3} = 'Fours';


Team_Names{1}{1} = 'JB'; %Jim Bauer
Team_Names{1}{2} = 'EH'; %Elsa Hammond
Team_Names{1}{3} = 'PFP'; %Project Flight Plan
Team_Names{1}{4} = 'R4R'; %Rowing 4 Reefs

%CL4{1}{}{5} = [];

CL4{1}{1}{1} = Start;  %Jim Bauer
CL4{1}{1}{2} = [036+39.997/60	-(121+57.153/60)];
CL4{1}{1}{3} = [036+47.559/60	-(121+49.795/60)]; 
CL4{1}{1}{4} = [036+48.226/60 	-(121+48.400/60)];
CL4{1}{1}{5} = Start;
CL4{1}{1}{6} = Start;
CL4{1}{1}{7} = Start;
CL4{1}{1}{8} = Start;
CL4{1}{1}{9} = Start;
CL4{1}{1}{10} = Start;
CL4{1}{1}{11} = [36+27.2/60 	-(122+6.6/60)];

CL4{1}{2}{1} = Start;  %Elsa
CL4{1}{2}{2} = [036+44.735/60 	-(121+53.447/60)];  
CL4{1}{2}{3} = [036+44.791/60	-(121+58.728/60)];
CL4{1}{2}{4} = [036+39.883/60   -(122+07.119/60)];
CL4{1}{2}{5} = [36+16.54/60     -(121+58.64/60)];
CL4{1}{2}{6} = [36+1.96/60     -(121+54.29/60)];
CL4{1}{2}{7} = [35+50.4/60 	-(121+58.7/60)];
CL4{1}{2}{8} = [35+39.8/60 	-(121+57.7/60)];
CL4{1}{2}{9} = [35+28.4/60 	-(121+57.7/60)];
CL4{1}{2}{10} = [35+15.9/60 	-(121+58.2/60)];
CL4{1}{2}{11} = [35+3.6/60 	-(121+56.8/60)];

CL4{1}{3}{1} = Start;  %Project Flight Plan
CL4{1}{3}{2} = Start;  
CL4{1}{3}{3} = Start; 
CL4{1}{3}{4} = Start;
CL4{1}{3}{5} = Start;
CL4{1}{3}{6} = Start;
CL4{1}{3}{7} = Start;
CL4{1}{3}{8} = Start;
CL4{1}{3}{9} = Start;
CL4{1}{3}{10} =  Start;
CL4{1}{3}{11} = Start;

CL4{1}{4}{1} = Start;  %Rowing 4 Reefs
CL4{1}{4}{2} = Start;  
CL4{1}{4}{3} = Start;  
CL4{1}{4}{4} = Start;
CL4{1}{4}{5} = Start;
CL4{1}{4}{6} = Start;
CL4{1}{4}{7} = Start;
CL4{1}{4}{8} = Start;
CL4{1}{4}{9} = Start;
CL4{1}{4}{10} =  Start;
CL4{1}{4}{11} = [36+28.5/60 	-(122+8.0/60)];

Team_Names{2}{1} = 'CC4'; %CC4 Pacific
Team_Names{2}{2} = 'FC'; %Fat Chance
%Team_Names{2}{3} = 'CC'; %Clearly Contacts


CL4{2}{1}{1} = Start;  %CC4 Pacific
CL4{2}{1}{2} = [036+45.280/60	-(122+04.459/60)];  
CL4{2}{1}{3} = [036+44.693/60 	-(122+12.194/60)];
CL4{2}{1}{4} = [036+27.671/60   -(122+20.312/60)];
CL4{2}{1}{5} = [35+30.17/60     -(122+33.93/60)];
CL4{2}{1}{6} = [34+43.85/60     -(122+26.09/60)];
CL4{2}{1}{7} = [34+.3/60 	-(122+20.5/60)];
CL4{2}{1}{8} = [33+31.0/60 	-(122+21.6/60)];
CL4{2}{1}{9} = [33+4.1/60 	-(122+25.2/60)];
CL4{2}{1}{10} = [32+34.1/60 	-(122+26.3/60)];
CL4{2}{1}{11} = [32+2.14/60 	-(122+39.1/60)];



CL4{2}{2}{1} = Start;  %Fat Chance
CL4{2}{2}{2} = Start;  
CL4{2}{2}{3} = Start;  
CL4{2}{2}{4} = Start;
CL4{2}{2}{5} = Start;
CL4{2}{2}{6} = Start;
CL4{2}{2}{7} = Start;
CL4{2}{2}{8} = Start;
CL4{2}{2}{9} = Start;
CL4{2}{2}{10} = Start;
CL4{2}{2}{11} = [36+25.9/60 	-(122+26.4/60)];

%CL4{2}{3}{1} = Start;  %Clearly Contacts
%CL4{2}{3}{2} = Start;  



Team_Names{3}{1} = 'UN'; %United Nations
Team_Names{3}{2} = 'PW'; %Pacific Warriors
Team_Names{3}{3} = 'BB'; %Battle Born 
Team_Names{3}{4} = 'NM'; %Noman
Team_Names{3}{5} = 'BL'; %Boaty Liscous
Team_Names{3}{6} = 'PR'; %Pacific Rowers;


CL4{3}{1}{1} = Start;  %United Nations
CL4{3}{1}{2} = [036+37.274/60	-(122+38.825/60)];
CL4{3}{1}{3} = [036+31.861/60	-(123+12.574/60)];
CL4{3}{1}{4} = [036+18.065/60   -(123+25.709/60)];
CL4{3}{1}{5} = [35+47.65/60     -(123+54.83/60)];
CL4{3}{1}{6} = [34+55.24/60     -(124+21.7/60)];
CL4{3}{1}{7} = [33+51.9/60     -(124+44.7/60)];
CL4{3}{1}{8} = [33+11.85/60 	-(125+17.0/60)];
CL4{3}{1}{9} = [32+32.8/60 	-(125+39.8/60)];
CL4{3}{1}{10} = [31+40.7/60 	-(126+13.0/60)];
CL4{3}{1}{11} = [30+43/60 	-(126+33.3/60)];

CL4{3}{2}{1} = Start;  %Pacific Warriors
CL4{3}{2}{2} = [036+51.496/60	-(122+10.414/60)];
CL4{3}{2}{3} = [036+52.097/60 	-(122+30.593/60)];
CL4{3}{2}{4} = [036+39.344/60   -(122+47.382/60)];
CL4{3}{2}{5} = [36+15.98/60     -(122+59.12/60)];
CL4{3}{2}{6} = [36+7.4/60     -(122+55.71/60)];
CL4{3}{2}{7} = [35+58.2/60     -(122+49.6/60)];
CL4{3}{2}{8} = [35+24.3/60 	-(123+1.05/60)];
CL4{3}{2}{9} = [34+43.3/60 	-(123+32.1/60)];  % @16:16 6/17
CL4{3}{2}{10} = [34+16.7/60 	-(123+33.5/60)];  % @17:23 6/18
CL4{3}{2}{11} = [34+8.3/60 	-(123+34.7/60)];  % @23:36 6/18

CL4{3}{3}{1} = Start;  %Battle Born 
CL4{3}{3}{2} = [036+31.196/60	-(122+19.011/60)];
CL4{3}{3}{3} = [036+08.483/60	-(122+34.646/60)];
CL4{3}{3}{4} = [035+29.085/60   -(123+00.358/60)];
CL4{3}{3}{5} = [34+39.32/60     -(123+32.75/60)];
CL4{3}{3}{6} = [33+52.12/60     -(123+30.8/60)];
CL4{3}{3}{7} = [33+1.2/60     -(123+29.8/60)];
CL4{3}{3}{8} = [32+29.4/60 	-(123+53.5/60)];
CL4{3}{3}{9} = [32+6.4/60 	-(124+29.3/60)];
CL4{3}{3}{10} = [31+30.55/60 	-(125+17.5/60)];
CL4{3}{3}{11} = [31+8.4/60 	-(125+50.7/60)];

CL4{3}{4}{1} = Start;  %Noman
CL4{3}{4}{2} = Start;  
CL4{3}{4}{3} = Start;  
CL4{3}{4}{4} = [036+30.958/60   -(122+37.084/60)];
CL4{3}{4}{5} = [36+3.22/60      -(122+48.5/60)];
CL4{3}{4}{6} = [35+43.3/60     -(122+52.15/60)];
CL4{3}{4}{7} = [35+6.0/60     -(122+51.64/60)];
CL4{3}{4}{8} = [34+10.7/60 	-(122+52.9/60)];
CL4{3}{4}{9} = [33+15.4/60 	-(123+12.7/60)];
CL4{3}{4}{10} = [32+35.6/60 	-(123+29.8/60)];
CL4{3}{4}{11} = [32+11.7/60 	-(123+52.2/60)];

CL4{3}{5}{1} = Start;  %Boaty Liscous
CL4{3}{5}{2} = Start;
CL4{3}{5}{3} = Start;  
CL4{3}{5}{4} = Start;
CL4{3}{5}{5} = Start;
CL4{3}{5}{6} = Start;
CL4{3}{5}{7} = Start;
CL4{3}{5}{8} = Start;
CL4{3}{5}{9} = Start;
CL4{3}{5}{10} = Start;
CL4{3}{5}{11} = [36+15.5/60 	-(122+21.9/60)];

CL4{3}{6}{1} = Start;  %Pacific Rowers
CL4{3}{6}{2} = Start;  
CL4{3}{6}{3} = Start;
CL4{3}{6}{4} = Start;
CL4{3}{6}{5} = Start;
CL4{3}{6}{6} = Start;
CL4{3}{6}{7} = Start;
CL4{3}{6}{8} = Start;
CL4{3}{6}{9} = Start;
CL4{3}{6}{10} = Start;
CL4{3}{6}{11} = [36+5.1/60 	-(122+28.7/60)];

%Compute Daily Distances
for k = 1:length(CL4)  %Cycle through classes

  for i = 1:length(CL4{k})  %Cycle through boats to set first distance to go.
    CL4_DistToGo{k}{i}{1} = TotalDistance;
  end


  for i = 1:length(CL4{k})  %Cycle through boats
    for j = 2:length(CL4{k}{i});  %Cycle through days.
      CL4_DailyDistance{k}{i}{j} = greatcircle(CL4{k}{i}{j}(1),CL4{k}{i}{j}(2),CL4{k}{i}{j-1}(1),CL4{k}{i}{j-1}(2))*km2nm;
      CL4_DistToGo{k}{i}{j} = greatcircle(CL4{k}{i}{j}(1),CL4{k}{i}{j}(2),Finish(1),Finish(2))*km2nm;
      CL4_DistMadeGood{k}{i}{j} = CL4_DistToGo{k}{i}{j-1}-CL4_DistToGo{k}{i}{j};
    end
  end

end



%Print Last days progress
for k = 1:length(CL4)  %Cycle through classes
disp([Class_Names{k} ': 24 Hour progress to 0800 ' datestr(now,'mm/dd')]);  
disp(['DailyDist/DMG/DTG (nm)']);
  for i = 1:length(CL4{k})  %Cycle through boats 
    disp([Team_Names{k}{i} '   '  num2str(round(CL4_DailyDistance{k}{i}{end})) '/' num2str(round(CL4_DistMadeGood{k}{i}{end})) '/' num2str(round(CL4_DistToGo{k}{i}{end}))]);     
  end
  disp(' ');
end




%First index is class{k}, second index is boat{i}, third index is day number{j}
%Compute Ranges and Bearings from PW.
KK = 3;
II = 2;
Dev = 14.5;

for k = length(CL4):-1:1  %Cycle through classes
   for i = 1:length(CL4{k})  %Cycle through boats
    %Ranges{k}{i} = greatcircle(CL4{KK}{II}{end}(1),CL4{KK}{II}{end}(2),CL4{k}{i}{end}(1),CL4{k}{i}{end}(2))*km2nm;
    [latt lonn Ranges{k}{i} BRG{k}{i}] = loxodrome(CL4{KK}{II}{end}(1),CL4{KK}{II}{end}(2),CL4{k}{i}{end}(1),CL4{k}{i}{end}(2),1);
    Ranges{k}{i} = Ranges{k}{i}*km2nm;
    BRG{k}{i}=BRG{k}{i}-Dev;
    if(BRG{k}{i} < 0)
        BRG{k}{i} = BRG{k}{i}+360;
    end
    %disp([num2str(dist*km2nm) '  ' num2str(Ranges{k}{i})]);
     end
end

disp(' ');

%Print Ranges and Bearings
disp(['Rng and Brg From PW at 0800 ' datestr(now,'mm/dd') ' (nm/degM)']); 
for k = length(CL4):-1:1  %Cycle through classes
   for i = 1:length(CL4{k})  %Cycle through boats
       if((k~=KK) || (i ~= II))
          disp([Team_Names{k}{i} '  ' num2str(round(Ranges{k}{i})) '/' num2str(round(BRG{k}{i}))]);
       end
   end
end

