%
% This script should be edited to enable the data sets that get included
% in the plots. All the actual work of plotting the data is performed in 
% processDist.m 
%

doLoadPOSPac = 1;
POSPacFile = '..\POSPac\POSPac.txt';


disp('***************************************************************');
disp(Section);
disp('***************************************************************');


% If you want to filter the end/start time set the following. For no
% filter set to -1.


% What's the outlier threshold - used to create Google Earth files
ProcessOutliers = 0;
dOutlierThres = 20;


% Now set by caller
% For position CDFs
%HorzAxisMax = 3;
%VertAxisMax = 6;
%RollPitchAxisMax = 0.5;
%HeadingAxisMax   = 1.0;

InputDataPath = '..';

% Along vehicle offset between the Zephyr "SG" antenna and the sharkfin "AG" (automotive grade) or "SF" antenna 
SharkFinOffset = 0.72;

InputDataName = ...
{
    % Cols:
    %  'File name'
    %  'Legend Name'
    %  'Directory name'
    %  'File Type'
    %  'TOW Column Index'
    %  'Lat Column Index'
    %  'Lon Column Index'
    %  'Alt Column Index'
    %  'LAT/LON Unit'
    %  'Alt WGS84/MSL'
    %  'Antenna Offset in Meters'
    %  'Need time tag rounding'? Aardvark often has 1ms offsets
    %   Velocity North  (Lat)
    %   Velocity East  (Lon)
    %   Velocity Hgt   (Hgt)
    %   Sigma East
    %   Sigma North
    %   Sigma Up
    %   T02 position type
    % 20 - Roll
    % 21 - Pitch
    % 22 - Heading
    % 23 - Xrotation (mechanical/sensor mounting correction - degrees)
    % 24 - Yrotation (mechanical/sensor mounting correction - degrees)
    % 25 - Zrotation (mechanical/sensor mounting correction - degrees)
    % 26 - Roll estimated 1 sigma
    % 27 - Pitch estimated 1 sigma
    % 28 - Heading estimated 1 sigma

    % T02 type 29
    % viewdat -d29 --mat dataFile.T02 > output.mat
    % 
    % You can use the following:-
    % viewdat -d29 -mb dataFile.T02 > output.txt
    % you then need to change the file extensions below to ".txt" and the 'MAT' field to 'TXT'
    % The .mat format loads much faster (~100x).

   {'WAAS.mat',         'WAAS',          'WAAS',        'MAT',2,11, 12 ,13,'DEG','WGS84',0, 0, 14, 15, 16, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,NaN}
   {'Stinger-RTX.mat',  'Stinger-RTX',   'Stinger-RTX', 'MAT',2,11, 12 ,13,'DEG','WGS84',0, 0, 14, 15, 16, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, 
   {'L1-RTX.mat',       'L1-RTX',        'L1-RTX',      'MAT',2,11, 12 ,13,'DEG','WGS84',0, 0, 14, 15, 16, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, 
   {'RTX.mat',         'Standard RTX',    'RTX',        'MAT',2,11, 12 ,13,'DEG','WGS84',0, 0, 14, 15, 16, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, 
   {'RTK.mat',         'RTK',             'RTK',        'MAT',2,11, 12 ,13,'DEG','WGS84',0, 0, 14, 15, 16, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, 


%%   {'BD910.mat',         'BD910-WAAS',    'BD910SG',    'MAT',2,11, 12 ,13,'DEG','WGS84',0, 0, 14, 15, 16, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, 
   

   % Following from a T02 used the sharkfin antenna = 72cm in front of the Zephyr "control" point
%%   {'BD910.mat',         'BD910-SF-WAAS',          'BD910SF', 'MAT',2,11, 12 ,13,'DEG','WGS84',SharkFinOffset, 0, 14, 15, 16, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, 



   % Novatel
   {'BESTPOSA.txt',      'Novatel INS+RTK (No DMI)',     'Novatel',  'TXT',2,3, 4 ,5,'DEG','WGS84',0, 0, 15, 14, 16, 6, 7, 8, NaN, 17, 18, 19, -0.557, -1.417, 0.427,  NaN, NaN, NaN}, 
   {'BESTGNSSPOSA.txt',  'Novatel RTK Only',             'Novatel',  'TXT',2,3, 4 ,5,'DEG','WGS84',0, 0, NaN, NaN, NaN, 6, 7, 8, NaN, NaN, NaN, NaN, NaN, NaN, NaN,  NaN, NaN, NaN}, 
 
   % Type 33:14
   {'Type33-14.txt',  'Stinger PVT 33-14 in Barra', 'Barra',       'TXT',2,3, 4 ,5,'RAD','WGS84',0, 0, 9, 10, 11,  6,  7,  8, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ,NaN},

   % Inertial - T04 type 35:2
   % viewdat -d35:2 --mat dataFile.T04 > output.mat
   {'Barra.mat',  'Barra (LC Stinger-RTX No DMI)', 'Barra',        'MAT',2,13, 14 ,15,'DEG','WGS84',0, 0, 16, 17, 18,  20,  19,  21, NaN, 52, 53, 54, -0.292, -1.876, -0.579, 61, 62 ,63},
   {'Wildebeest.mat',  'W-beest1 (IMU + RTK + DMI)',     'Wildebeest',   'MAT',2,13, 14 ,15,'DEG','WGS84',0, 0, 16, 17, 18,  20,  19,  21, NaN, 52, 53, 54, -0.776, -1.634, -1.780, 61, 62 ,63},
   {'Wildebeest.mat',  'W-beest2 (IMU + RTK No DMI)',    'WBeest2-NoDMI','MAT',2,13, 14 ,15,'DEG','WGS84',0, 0, 16, 17, 18,  20,  19,  21, NaN, 52, 53, 54, -0.721, -1.433, -1.384, 61, 62 ,63},
   {'Vectallica.mat',  'Vectallica (IMU + RTK + DMI)',   'Vectallica',   'MAT',2,13, 14 ,15,'DEG','WGS84',0, 0, 16, 17, 18,  20,  19,  21, NaN, 52, 53, 54,  0.480, -3.062,  0.456, 61, 62 ,63},
   {'RealTime.txt',    'POSLV-RealTime',  'POSpac',                'TXT',1, 2,  3 , 4,'DEG','WGS84',0, 0,  6,  5, 7, NaN, NaN, NaN, NaN,  11, 12, 13,  0,      0,      0,     NaN, NaN, NaN} 
};

%% Example of analyzing magnetometer attitude setting
InputDataName = {
   % Col:
   %  1 - 'File Name',
   %  2 - 'Legend Name',
   %  3 - 'Directory Name',
   %  4 - 'File Type',
   %  5 - 'TOW Column Index',
   %  6 - 'Attitude Unit',
   %  7 - 'Need time tag round?'      
   %  8 - 'Roll Index',
   %  9 - 'Pitch Index',
   % 10 - 'Heading Index',
   % 11 - 'Xrotation' (mechanical/sensor mounting correction - degrees),
   % 12 - 'Yrotation' (mechanical/sensor mounting correction - degrees),
   % 13 - 'Zrotation' (mechanical/sensor mounting correction - degrees),
   % 14 - 'Roll estimated 1 sigma',
   % 15 - 'Pitch estimated 1 sigma',
   % 16 - 'Heading estimated 1 sigma'
   % 17 - 'Filtered Roll Index',
   % 18 - 'Filtered Pitch Index',
   % 19 - 'Filtered Heading Index',
   % 20 - 'Filtered Roll estimated 1 sigma',
   % 21 - 'Filtered Pitch estimated 1 sigma',
   % 22 - 'Filtered Heading estimated 1 sigma'  
    {'MagHeadingB1.txt',  'RT VB1 MAG',  'VectorB1', 'TXT', 3, 'RAD', 1, 5, 7, 9, 0, 0, 0, 6, 8, 10, 11, 13, 15, 12, 14, 16}
    {'MagHeadingB2.txt',  'RT VB2 MAG',  'VectorB2', 'TXT', 3, 'RAD', 1, 5, 7, 9, 0, 0, 0, 6, 8, 10, 11, 13, 15, 12, 14, 16}
    {'MagHeadingC107.txt','RT VC107 MAG','VectC107', 'TXT', 3, 'RAD', 1, 5, 7, 9, 0, 0, 0, 6, 8, 10, 11, 13, 15, 12, 14, 16}
    {'MagHeadingC140.txt','RT VC140 MAG','VectC140', 'TXT', 3, 'RAD', 1, 5, 7, 9, 0, 0, 0, 6, 8, 10, 11, 13, 15, 12, 14, 16}
};% End of setting
%%
if(doLoadPOSPac == 1)
  POSPac = load(POSPacFile);
end


if(CreateKMZ == 1)
  if(StartTime == -1)
    KMZStart = 0;
  else
    KMZStart = StartTime;
  end

  if(EndTime == -1)
    KMZEnd = 1e10;
  else
    KMZEnd = EndTime;
  end

    CommandString = ['perl ..\..\WinAstra-Utils\POSPac2KML.pl ',POSPacFile, ...  
                     ' 100 FFFFFF 1 1 ', ...
                     num2str(KMZStart), ' ', ...
                     num2str(KMZEnd), ...
                     ' > ', ...
                     Section,'-Truth.kml'];
    system(CommandString);
    system('copy ..\..\WinAstra-Utils\Arrow.png');
    zip([Section,'-Truth.zip'],{[Section,'-Truth.kml'],'Arrow.png'});
    system(['mv ',Section,'-Truth.zip ',Section,'-Truth.kmz']);
    system(['del ',Section,'-Truth.kml']);
    system(['del Arrow.png']);

end


if(StartTime >= 0)
  i = find(POSPac(:,1) >= StartTime);
  POSPac = POSPac(i,:);
end

if(EndTime >= 0)
  i = find(POSPac(:,1) <= EndTime);
  POSPac = POSPac(i,:);
end

% Do the work....
processDist;

%% Replace processDist with processMagDist if process magnetometer attitude
processMagDist;
