function siltprofiler_plot(A,i0,i1)
%SILTPROFILER_PLOT_DEBUG   plot result from siltprofiler_read_asc
%
%
%   D = siltprofiler_read_asc(ascname)
%       siltprofiler_plot_debug(D,start,end)
%
% This function can be used to determine the valid indices of the cast:
% i.e. the range when the siltprofiler goes up and down, excluding
% the part when the siltprofiler is airborn, or affected by air 
% bubbles from the vessel.
%
%See also: SILTPROFILER_READ_ASC

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2010 Delft University of Technology
%       Gerben J. de Boer
%
%       g.j.deboer@tudelft.nl	
%
%       Fluid Mechanics Section
%       Faculty of Civil Engineering and Geosciences
%       PO Box 5048
%       2600 GA Delft
%       The Netherlands
%
%   This library is free software: you can redistribute it and/or
%   modify it under the terms of the GNU Lesser General Public
%   License as published by the Free Software Foundation, either
%   version 2.1 of the License, or (at your option) any later version.
%
%   This library is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%   Lesser General Public License for more details.
%
%   You should have received a copy of the GNU Lesser General Public
%   License along with this library. If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

OPT.export = 0;

   FIG = figure;setfig2screensize

    var2 = 1; % 1 = Pres/press (handig die verschillende names), 6 = altimeter (can be broken)
for var1 = 2:A.n_channel;

   varname1 = mkvar(A.varname{var1});
   varname2 = mkvar(A.varname{var2});
   
   n = length(A.(varname1));
   if i1==0; i1 = n;end

   clf;AX = subplot_meshgrid(2,2,[.1 0 .02],[.02 0 .1]);

   axes(AX(1))
      plot(A.(varname1)(1:n)  ,1:n  ,'k')
      hold on
      plot(A.(varname1)(i0:i1),i0:i1,'r','linewidth',2)
      
      % add scaled pressure
      x = xlim;
      d = max(A.(varname2)) - min(A.(varname2));
      plot((A.(varname2) - min(A.(varname2)))./d.*(x(2)-x(1)) + x(1),1:n,'color',[.5 .5 .5]);
      
      % lay-out
      ylabel ('count')
      set(gca,'xticklabel',{})
      grid on
      ylim([0 n])
   
   axes(AX(3))
      plot(A.(varname1)(1:n)  ,A.(varname2)(1:n)  ,'k');
      hold on
      plot(A.(varname1)(i0:i1),A.(varname2)(i0:i1),'r','linewidth',2)
      grid on
      xlabel ([A.varname{var1},' [',A.units{var1},']'])
      ylabel ([A.varname{var2},' [',A.units{var2},']'])
   
   axes(AX(4))
      plot(1:n  ,A.(varname2)(1:n)  ,'k')
      hold on
      plot(i0:i1,A.(varname2)(i0:i1),'r','linewidth',2)
      
      % add scaled pressure
      y = ylim;
      d = max(A.(varname2)) - min(A.(varname2));
      plot((A.(varname2) - min(A.(varname2)))./d.*(y(2)-y(1)) + y(1),'color',[.5 .5 .5]);
      
      % lay-out
      xlabel ('count')
     % ylabel ([A.varname{var2},' [',A.units{var2},']'])
      
      set(gca,'yticklabel',{})
      grid on
      xlim([0 n])
      title({A.name,A.datestr})

   delete(AX(2))
   
   if OPT.export
   print2screensize([filename(A.name),'_',varname1,'_debug.png'])
   end
   
   pausedisp
   
end   

try
   close(FIG)
end

