function gpttraj4plot(timemat,trajmat,colours,endslice,plotslice,enhance)
%
% function gpttraj4plot(timemat,trajmat,colours,endslice,plotslice,enhance)
%
%    GPTTRAJ4PLOT - Plot GPT data set in 2x3 plot, including trajectory
%    data

    npart = length(trajmat) ;

    if ( nargin < 6 ) || ( isempty(enhance) )
        enhance = 0 ;
    end
    
    if ( nargin < 5 ) || ( isempty(plotslice) )
        plotslice = 1 ;
    end

    if ( nargin < 4 ) || ( isempty(endslice) )
        endslice = 1 ;
    end

    if ( nargin < 3 ) || ( isempty(colours) )
        for i = 1:npart
            colours(i,:) = 'xk-' ;
        end
    elseif ( size(colours,1) == 1 )
        colour = colours ;
        for i = 1:npart
            colours(i,:) = colour ;
        end
    end

    endtimemat = timemat(endslice) ;
    plottimemat = timemat(plotslice) ;
    goodparts = [endtimemat.ID] ;
    survpart = length(goodparts) ;

%    figure ;
    subplot(2,3,[1:3]), hold on ;
    xlabel(['z (m)']), ylabel(['y (mm)']) ;
    for i = 1:npart
        fpart = find(goodparts == i) ;
        if ~isempty(fpart)
            z = trajmat(i).z(1:endslice) ;
            y = trajmat(i).y(1:endslice) ;
        else
            z = trajmat(i).z(1:end) ;
            y = trajmat(i).y(1:end) ;
        end
        plot(z,y.*1e3,colours(i,2:3)) ;
        plot(z(end),y(end).*1e3,colours(i,1:2)) ;
    end ; hold off ;
    if ( strcmp(enhance,'enhance') )
        jpgplot ;
    end

    subplot(2,3,4), hold on ;
    xlabel(['x (mm)']), ylabel(['y (mm)']) ;
    for i = 1:survpart
        plot(plottimemat.x(i).*1e3,plottimemat.y(i).*1e3,colours(goodparts(i),1:2)) ;
    end ; hold off ;
    axis square ;
    if ( strcmp(enhance,'enhance') )
        jpgplot ;
    end

    subplot(2,3,5), hold on ;
    xlabel(['x (mm)']), ylabel(['x'' (mrad)']) ;
    for i = 1:survpart
        plot(plottimemat.x(i).*1e3,plottimemat.xp(i).*1e3,colours(goodparts(i),1:2)) ;
    end ; hold off ;
    axis square ;
    if ( strcmp(enhance,'enhance') )
        jpgplot ;
    end

    subplot(2,3,6), hold on ;
    xlabel(['y (mm)']), ylabel(['y'' (mrad)']) ;
    for i = 1:survpart
        plot(plottimemat.y(i).*1e3,plottimemat.yp(i).*1e3,colours(goodparts(i),1:2)) ;
    end ; hold off ;
    axis square ;
    if ( strcmp(enhance,'enhance') )
        jpgplot ;
    end

    return

