function plotfix (lim)

%   plotfix (lim)
%
%   lim  -  upper limit for the color scale
%
%   plotfix plots a graph showing the time to init versus the
%   initialisation time. The maximum position error is presented in
%   colorcoded style. As input the file test.fix is read in. It is
%   generated by the perl script plot plotGGK.pl and contains information
%   like init time, time to init and maximum position errors during the
%   hold phase for each fix.
%
%   Ralf Stolz 10-9-92
%   
%   $Revision: 1.1 $  $Date: 2002/10/28 19:09:23 $


% Get the data
load test.fix

% Rescale the time to per day style
test (:,1) = test(:,1)/86400;

% Sort the fixes according to maximum position error
test1 = sortrows (test, 7);

% Create a figure
h = figure;

% Setup the new colormap
f = zeros(1, 20);

cmap = [[0:1/79:0.8 0]', [1:-1/43:0 f 0]', [f 0 0 f 0 0 f 0]'];

colormap (cmap);

% Get the color scaling
cmax = size (cmap, 1);

step = lim/cmax;

nextlim = step;

% Get the index of the last fix
imax = size (test1, 1);

% Loop over the fixes and plot them with their position error in colorcoded
% style
iold = 1;
c    = 1;

for i = 1:imax
    if (test1 (i, 7) > nextlim)
        plot (test1 (iold:(i - 1), 1), test1 (iold:(i - 1), 2), '*', 'Color', cmap (c, :));
        hold on;
        
        c = c + 1;
        
        if (c > cmax)
            break;
        end
            
        iold = i;
        nextlim = nextlim + step;
    end
end

plot (test1 (iold:imax, 1), test1 (iold:imax, 2), '*', 'Color', cmap (cmax, :));

% Set the tick label style on the time axis to a nice format
datetick ('x', 15);

% Rescale the time axis to the best fit
xmin = min (test1 (:, 1));
xmax = max (test1 (:, 1));

xlim ([xmin xmax]);

% Switch the grid on
grid on;

% Set a nice font size
set (gca, 'FontSize', 12);

% Print the axis labels
xlabel ('GPS time [h:min]');
ylabel ('Time to initialize [s]');

% Create the colorbar
surface ([0 1], [0 1], [0 0; 0 0], 'CDataMapping', 'scaled');
set (gca, 'CLim', [0 lim]);
set (gca, 'CLimMode','manual' );
colorbar;

% Set the font size as well for the colorbar
axes (findobj (gcf, 'Tag', 'Colorbar'));
set (gca, 'FontSize', 12);

colorbar 

% Print the axis label for the colorbar
ylabel ('Max position error [m]');
