function [data,whan] = GPS_RT17_plots (data,whan)
% GPS_RT17_plots: calls plot routine for GPS items when RT17s are available
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% signal tracking plot

% file name string
j01=findstr(data.GPS.GPS_file,'.');
filename01=data.GPS.GPS_file(1:(j01(end)-1));
j02=findstr(filename01,'\');
filename02=filename01((j02(end)+1):end);

if (isempty(data.GPS.observables)==0)
   column=[];
   data.config.single_axes=1;
   data.config.disp_position=0;
   data.config.single_label='';
   data.config.single_label='SV Tracking (PRN (Elev))';
   
   % add plot field data
   bigness=size(data.GPS.tracking_prn,2);
   for (i=1:4)
      data.config.field_ranges(end+1,1:8)=[0 bigness-1 1 0 0 0 data.config.field_ranges(end,7) i];
      if (i==1)
         data.config.field_names(end+1,:)={'L1 Valid'};
         data.colour{i}='b';
         data.linetype{i}='.';
         data.linescale{i}=0.5;
      elseif (i==2)
         data.config.field_names(end+1,:)={'L1 Slip'};
         data.colour{i}='b';
         data.linetype{i}='x';
         data.linescale{i}=6;
      elseif (i==3)
         data.config.field_names(end+1,:)={'L2 Valid'};
         data.colour{i}='g';
         data.linetype{i}='.';
         data.linescale{i}=0.5;
      elseif (i==4)
         data.config.field_names(end+1,:)={'L2 Slip'};
         data.colour{i}='g';
         data.linetype{i}='x';
         data.linescale{i}=6;
      end;
      data.config.field_location(end+1,:)=[6 i 0];
      data.config.field_labels{end+1}=data.GPS.tracking_prn;
      column(i)=size(data.config.field_ranges,1);
   end;
   
   % get loaded fields
   if (isempty(data.GPS.position)==0)
      for (j=1:size(data.config.field_names,1))
         if (strcmp(data.config.field_names{j},'Sol Type')==1)
            data.colour{5}='k';
            data.linetype{5}='-';
            data.linescale{5}=1;
            data.config.field_location(end+1,:)=data.config.field_location(j,:);
            data.config.field_location(end,3)=1;
            data.config.field_names{end+1}='solution';
            data.config.field_ranges(end+1,:)=data.config.field_ranges(j,:);
            data.config.field_ranges(end,1:3)=[-4 (bigness-1) 1];
            data.config.field_labels{end+1}=[{'No GPS','Auto','DGPS','Float','Fix'},data.GPS.tracking_prn(2:end)];
            column(5)=size(data.config.field_ranges,1);
         end;
      end;
   end;
   
   if (isempty(column)==1)
      return;
   end;
   
   % plot titles
   filename=sprintf('SV Tracking Plot (GPS file - %s)',filename02);
   titlename=sprintf('SV Tracking Plot (GPS file - %s)',dir_clip(data.GPS.GPS_file,50));
   
   %  generate analysis plot
   [data,fig]=analysis_plot(data,column,titlename,filename,0);
   data.temp=[];
   rmfield(data,'temp');
   
   % add additional function buttons
   if ((data.GPS.loaded==1)&(isempty(data.GPS.observables)==0)&(data.config.auto_close==0))
      bhandle=plot_buttons(fig);
      set(bhandle,'UserData',data.GPS.observables.cycle_slip.slips);
   end;
end;

% update waitbar
waitbar(1/6,whan);
drawnow;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% slips vs elevation plot

if (isempty(data.GPS.observables)==0)
   column=[];
   data.config.single_axes=1;
   data.config.disp_position=0;
   data.config.single_label='';
   data.config.single_label='Cycle Slips (PRN (Elev))';
   
   % add plot field data
   for (i=1:2)
      data.config.field_ranges(end+1,1:8)=[0 bigness-1 1 0 0 0 data.config.field_ranges(end,7) i];
      if (i==1)
         data.config.field_names(end+1,:)={'L1 Slip'};
         data.colour{i}='b';
         data.linetype{i}='x';
         data.linescale{i}=6;
      elseif (i==2)
         data.config.field_names(end+1,:)={'L2 Slip'};
         data.colour{i}='g';
         data.linetype{i}='x';
         data.linescale{i}=6;
      end;
      data.config.field_location(end+1,:)=[7 i 0];
      data.config.field_labels{end+1}=data.GPS.tracking_prn;
      column(i)=size(data.config.field_ranges,1);
   end;
   
   if (isempty(column)==1)
      return;
   end;
   
   % file name string
   filename=sprintf('Cycle Slips vs. Elevation Plot (GPS file - %s)',filename02);
   titlename=sprintf('Cycle Slips vs. Elevation Plot (GPS file - %s)',dir_clip(data.GPS.GPS_file,50));
   
   %  generate analysis plot
   [data,fig]=analysis_plot(data,column,titlename,filename,0);
   data.temp=[];
   rmfield(data,'temp');
end;

% update waitbar
waitbar(2/6,whan);
drawnow;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% cycle-slip plots

if (isempty(data.GPS.observables)==0)
   column=[];
   data.config.single_axes=0;
   data.config.disp_position=0;
   data.config.single_label='';
   
   % get loaded fields
   column=[];
   for (j=1:size(data.config.field_names,1))
      if (strcmp(data.config.field_names{j},'L1 Cycle Slip Counts')==1)
         data.config.field_ranges(j,8)=1;
         column(data.config.field_ranges(j,8))=j;
      elseif (strcmp(data.config.field_names{j},'L2 Cycle Slip Counts')==1)
         data.config.field_ranges(j,8)=2;
         column(data.config.field_ranges(j,8))=j;
      else
         data.config.field_ranges(j,8)=0;
      end;
   end;
   
   if (isempty(column)==1)
      return;
   end;
   
   % file name string
   filename=sprintf('Cycle Slip Plot (GPS file - %s)',filename02);
   titlename=sprintf('Cycle Slip Plot (GPS file - %s)',dir_clip(data.GPS.GPS_file,50));
   
   %  generate analysis plot
   [data,fig]=analysis_plot(data,column,titlename,filename,0);
   data.temp=[];
   rmfield(data,'temp');
   
   % add additional function buttons
   if ((data.GPS.loaded==1)&(isempty(data.GPS.observables)==0)&(data.config.auto_close==0))
      bhandle=plot_buttons(fig);
      set(bhandle,'UserData',data.GPS.observables.cycle_slip.slips);
   end;
end;

% update waitbar
waitbar(3/6,whan);
drawnow;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% solution plots

if (isempty(data.GPS.position)==0)
   column=[];
   data.config.single_axes=0;
   data.config.disp_position=0;
   data.config.single_label='';
   
   % get loaded fields
   column=[];
   for (j=1:size(data.config.field_names,1))
      if (strcmp(data.config.field_names{j},'SV #')==1)
         data.config.field_ranges(j,8)=1;
         column(data.config.field_ranges(j,8))=j;
         sv_no_field=j;
      elseif (strcmp(data.config.field_names{j},'PDOP')==1)
         data.config.field_ranges(j,8)=2;
         column(data.config.field_ranges(j,8))=j;
      elseif (strcmp(data.config.field_names{j},'Sol Type')==1)
         data.config.field_ranges(j,8)=3;
         column(data.config.field_ranges(j,8))=j;
         data.config.field_labels{j}={'No GPS';'Auto';'DGPS';'Float';'Fix'};
      else
         data.config.field_ranges(j,8)=0;
      end;
   end;
   
   if (isempty(column)==1)
      return;
   end;
   
   % file name string
   filename=sprintf('Solution Plot (GPS file - %s)',filename02);
   titlename=sprintf('Solution Plot (GPS file - %s)',dir_clip(data.GPS.GPS_file,50));
   
   %  generate analysis plot
   [data,fig]=analysis_plot(data,column,titlename,filename,0);
   data.temp=[];
   rmfield(data,'temp');
   
   % add additional function buttons
   if ((data.GPS.loaded==1)&(isempty(data.GPS.observables)==0)&(data.config.auto_close==0))
      bhandle=plot_buttons(fig);
      set(bhandle,'UserData',data.GPS.observables.cycle_slip.slips);
   end;
end;

% update waitbar
waitbar(4/6,whan);
drawnow;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% "Time since last message" plots

if ((isempty(data.GPS.position)==0)|(isempty(data.GPS.observables)==0))
   column=[];
   j=0;
   data.config.single_axes=0;
   data.config.disp_position=0;
   data.config.single_label='';
   
   % get axis upper limits
   maximus=0;
   if (isempty(data.GPS.position)==0)
      pos_dT=[data.GPS.position(2:end,1)  (data.GPS.position(2:end,1)-data.GPS.position(1:(end-1),1))];
      maximus(end+1)=max(pos_dT(:,2));
   end;
   if (isempty(data.GPS.observables)==0)
      obs_dT=[data.GPS.observables.time(2:end,1)  (data.GPS.observables.time(2:end,1)-data.GPS.observables.time(1:(end-1),1))];
      maximus(end+1)=max(obs_dT(:,2));
   end;
   maximus=max(maximus);
   if (maximus==0)
      maximus=1;
   elseif (maximus==round(maximus))
      maximus=maximus+1;
   else
      maximus=ceil(maximus);
   end;
   if (maximus<=2)
      prec=1;
   else
      prec=0;
   end;
   
   % compute position "time between messages"
   if (isempty(data.GPS.position)==0)
      j=j+1;
      time_vector=sortrows(data.GPS.position,1);
      j01=find(isnan(time_vector(:,2))==1);
      if (isempty(j01)==0)
         time_vector(j01,:)=[];
      end;
      data.temp.pos_dT=[time_vector(2:end,1)  (time_vector(2:end,1)-time_vector(1:(end-1),1))];
      data.config.field_ranges(end+1,:)=[0 maximus NaN prec 0 0 inf 1];
      data.config.field_names(end+1,:)={'Type 11 (sec)'};
      data.config.field_location(end+1,:)=[9 1 0];
      data.config.field_labels{end+1}=[];
      column(j)=size(data.config.field_ranges,1);
   end;
   
   % compute observable "time between messages"
   if (isempty(data.GPS.observables)==0)
      j=j+1;
      data.temp.obs_dT=[data.GPS.observables.time(2:end,1)  (data.GPS.observables.time(2:end,1)-data.GPS.observables.time(1:(end-1),1))];
      data.config.field_ranges(end+1,:)=[0 maximus NaN prec 0 0 inf 1];
      data.config.field_names(end+1,:)={'Type 17 (sec)'};
      data.config.field_location(end+1,:)=[9 2 0];
      data.config.field_labels{end+1}=[];
      column(j)=size(data.config.field_ranges,1);
   end;
   
   % file name string
   filename=sprintf('Time Between Messages Plot (GPS file - %s)',filename02);
   titlename=sprintf('Time Between Messages Plot (GPS file - %s)',dir_clip(data.GPS.GPS_file,50));
   
   %  generate analysis plot
   [data,fig]=analysis_plot(data,column,titlename,filename,0);
   data.temp=[];
   rmfield(data,'temp');
   
   % add additional function buttons
   if ((data.GPS.loaded==1)&(isempty(data.GPS.observables)==0)&(data.config.auto_close==0))
      bhandle=plot_buttons(fig);
      set(bhandle,'UserData',data.GPS.observables.cycle_slip.slips);
   end;
end;

% update waitbar
waitbar(5/6,whan);
drawnow;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% vel & accel plot

if (isempty(data.GPS.position)==0)
   column=[];
   data.config.single_axes=0;
   data.config.disp_position=1;
   data.config.single_label='';
   
   % get loaded fields
   column=[];
   for (j=1:size(data.config.field_names,1))
      if ((strcmp(data.config.field_names{j},'Vel (m/s)')==1)|(strcmp(data.config.field_names{j},'GPS Vel (m/s)')==1))
         data.config.field_ranges(j,8)=1;
         column(data.config.field_ranges(j,8))=j;
      elseif ((strcmp(data.config.field_names{j},'Accel (m/s²)')==1)|(strcmp(data.config.field_names{j},'GPS Accel (m/s²)')==1))
         data.config.field_ranges(j,8)=2;
         column(data.config.field_ranges(j,8))=j;
      else
         data.config.field_ranges(j,8)=0;
      end;
   end;
   
   if (isempty(column)==1)
      return;
   end;
   
   % file name string
   filename=sprintf('Vel & Accel Plot (GPS file - %s)',filename02);
   titlename=sprintf('Vel & Accel Plot (GPS file - %s)',dir_clip(data.GPS.GPS_file,50));
   
   %  generate analysis plot
   [data,fig]=analysis_plot(data,column,titlename,filename,0);
   data.temp=[];
   rmfield(data,'temp');
   
   % add additional function buttons
   if ((data.GPS.loaded==1)&(isempty(data.GPS.observables)==0)&(data.config.auto_close==0))
      bhandle=plot_buttons(fig);
      set(bhandle,'UserData',data.GPS.observables.cycle_slip.slips);
   end;
end;

% update waitbar
waitbar(6/6,whan);
drawnow;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;
