function [ret_val] = OpTimeseries(handles, basetitle, timelabel)
% Parameters:
%   handles  - Application handles (GUI)
%   basetitle - String containing mission name
%   timelabel - current time & date
% Returns:
%   ret_val - return value code (not used)
%
ret_val = 0;

pathname = get(handles.editPathname, 'string');
mysettings.seagliderID    = str2num(get(handles.editSeagliderID, 'string')); 

diveNumbers = [get(handles.listboxDiveNumbers, 'String')];
diveNumbers = str2num(char(diveNumbers));

id_dive = sprintf('%03d%04d',mysettings.seagliderID,diveNumbers(1)); 
basetitle = ['SG' num2str(mysettings.seagliderID) ' ' basetitle]

[loginfo,eng,results] = dd_get_dive_data(id_dive,1,pathname); 

mysettings.mission = results.GLOBALS.project;

existingPath = pwd;
cd(pathname);

hWaitBar = waitbar(0, '1','Name','Extracting operational data from all dives...');

runs = available_profiles({'nc'}, mysettings.seagliderID); 
nruns = length(runs);

data = [];
%vbd_data = [];
%gc_count = 0;
for ix = 1:nruns;
  waitbar(ix / nruns, hWaitBar, sprintf('%.0f%% complete', (ix / nruns) * 100.0));
  irun = runs(ix);
  id_dive = sprintf('%03d%04d',mysettings.seagliderID,irun); % billr
  base_file = sprintf('p%s',id_dive);
  
  [loginfo,eng,results] = get_dive_data(id_dive,1); 
  
  
  % these variables have 1 value per dive 
  humid = loginfo.HUMID;
  int_pressure = loginfo.INTERNAL_PRESSURE;
  V24 = loginfo.a24V_AH(1); % the 'a' is pre-pended to the original param name cuz Matlab variables can't start with a #
  V10 = loginfo.a10V_AH(1);
  pings = loginfo.XPDR_PINGS;
  calls = loginfo.a_CALLS; % the 'a' is pre-pended to the original param name cuz Matlab variables can't start with a '_'
  errors = loginfo.ERRORS;
  interrupts = errors(2);
  vbd_err = errors(11);
  vbd_retries = errors(14);

  data = [data; [irun humid int_pressure V24 V10 pings calls interrupts vbd_err vbd_retries]];

  % these variables have more than 1 value per dive 
%{  
  volts = loginfo.gc_vbd_volts;
  num_elem =   numel(volts);
  this_count = (1:num_elem)';
  this_count = this_count + gc_count;
  gc_count = gc_count + num_elem;
  secs = loginfo.gc_vbd_secs;
  depth = loginfo.gc_depth;
  retry = loginfo.gc_vbd_retries;
  pot2_start = loginfo.gc_vbd_pot2_ad_start

  vbd_data = [vbd_data; [this_count volts secs depth retry pot2_start]];
%}

end

close(hWaitBar);

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    hFigPlot = figure('Name','Internal Humidity & Pressure Timeseries');
    set(hFigPlot, 'UserData', 'Plot_Humid_Int_Press');
    set(gca,'YLim',[5,60]);
    hold on;
    title(basetitle, 'FontSize', 12);
    x_label  =  'Dive #';
    xlabel(x_label, 'FontSize', 10); 

    if nruns > 1
        plot(data(:,1), data(:,2));
        plot(data(:,1), data(:,3), 'g');
    else
        scatter(data(:,1), data(:,2),  'filled');
        scatter(data(:,1), data(:,3),'g',  'filled');
    end

    grid on;
    lg = legend('Internal Humidity (percent)', 'Internal Pressure (psi)', 'Location','East');
    set(lg,'color','none'); % make transparent
 
    v = axis;
    ytxt = v(3) -0.1*(v(4)-v(3));
    xtxt = v(1);
    text(xtxt , ytxt, timelabel);

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    hFigPlot = figure('Name','Voltage Timeseries');
    set(hFigPlot, 'UserData', 'Plot_Voltage');
    set(gca,'YLim',[8,28]);
    hold on;
    title(basetitle, 'FontSize', 12);
    x_label  =  'Dive #';
    xlabel(x_label, 'FontSize', 10); 
    y_label  =  'Volts';
    ylabel(y_label, 'FontSize', 10); 

    if nruns > 1
        plot(data(:,1), data(:,4), 'r');
        plot(data(:,1), data(:,5), 'b');
    else
        scatter(data(:,1), data(:,4),'r',  'filled');
        scatter(data(:,1), data(:,5),'b',  'filled');
    end

    grid on;
    lg = legend('24V', '10V', 'Location', 'East');
    set(lg,'color','none'); % make transparent
 
    v = axis;
    ytxt = v(3) -0.1*(v(4)-v(3));
    xtxt = v(1);
    text(xtxt , ytxt, timelabel);


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % bar graphs
    %
    hFigPlot = figure('Name','Timeseries Bar Graphs');
    clf;
    set(hFigPlot, 'UserData', 'Plot_Discontinuous_Operational1');
 

    % upper-left: XPDR pings
    h(1) = subplot(3,2,1);
    cla;
    hold on;
    x_label  =  'Dive #';
    xlabel(x_label, 'FontSize', 10); 
    ylabel('# XPDR Pings','FontSize',10);
    bar(data(:,1), data(:,6), 'b');
    title(['# XPDR Pings' ' (' basetitle ')']) % since Matlab can't have a 'super' title for the whole plot, cram basetitle in here
    grid on;


    % upper-right: Calls
    h(2) = subplot(3,2,2);
    cla;
    x_label  =  'Dive #';
    xlabel(x_label, 'FontSize', 10); 
    ylabel('# Calls','FontSize',10);
    hold on;
    bar(data(:,1), data(:,7), 'b');
    title('# Calls')
    grid on;


    %  middle: Interrupts
    h(3) = subplot(3,2,3);
    cla;
    x_label  =  'Dive #';
    xlabel(x_label, 'FontSize', 10); 
    ylabel('# Interrupts','FontSize',10);
    hold on;
    bar(data(:,1), data(:,8), 'b');
    title('# Spurious Interrupts')
    grid on;

    %  bottom-left: VBD_ERR
    h(4) = subplot(3,2,5);
    cla;
    x_label  =  [ 'Dive #' ' (' timelabel ')']; % since can't find bottom-left of whole plot, cram timelabel in here
    xlabel(x_label, 'FontSize', 10); 
    ylabel('# VBD Errors','FontSize',10);
    hold on;
    bar(data(:,1), data(:,9), 'b');
    title('# VBD Errors')

    grid on;

    %  bottom_right: VBD_Retries
    h(5) = subplot(3,2,6);
    cla;
    x_label  =  'Dive #';
    xlabel(x_label, 'FontSize', 10); 
    ylabel('# VBD Retries','FontSize',10);
    hold on;
    bar(data(:,1), data(:,10), 'b');
    title('# VBD Retries')
    grid on;
 

    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % gc_vbd bar plots
    %
%{    
    hFigPlot = figure('Name','gc_vbd Timeseries Bar Graphs');
    clf;
    set(hFigPlot, 'UserData', 'Plot_Discontinuous_Operational2');

    % upper-left: vbd secs
    h(1) = subplot(3,2,1);
    cla;
    hold on;
    x_label  =  'GC event #';
    xlabel(x_label, 'FontSize', 10); 
    ylabel('gc_vgd_secs','FontSize',10);
    bar(vbd_data(:,1), vbd_data(:,3), 'b');
    title('gc_vgd_secs')
    grid on;


    % upper-right: vbd volts
    h(2) = subplot(3,2,2);
    cla;
    hold on;
    x_label  =  'GC event #';
    xlabel(x_label, 'FontSize', 10); 
    ylabel('gc_vgd_volts','FontSize',10);
    bar(vbd_data(:,1), vbd_data(:,2), 'b');
    title('gc_vgd_volts')
    grid on;


    % middle-left: gc_depth
    h(3) = subplot(3,2,3);
    cla;
    hold on;
    x_label  =  'GC event #';
    xlabel(x_label, 'FontSize', 10); 
    ylabel('gc_depth','FontSize',10);
    bar(vbd_data(:,1), vbd_data(:,4), 'b');
    title('gc_depth')
    grid on;


    % middle-right: gc_vbd_retries
    h(4) = subplot(3,2,4);
    cla;
    hold on;
    x_label  =  'GC event #';
    xlabel(x_label, 'FontSize', 10); 
    ylabel('gc_vbd_retries','FontSize',10);
    bar(vbd_data(:,1), vbd_data(:,5), 'b');
    title('gc_vbd_retries')
    grid on;


    % middle-right: gc_vbd_pot2_ad_start
    h(5) = subplot(3,2,6);
    cla;
    hold on;
    x_label  =  'GC event #';
    xlabel(x_label, 'FontSize', 10); 
    ylabel('gc_vbd_pot2_ad_start','FontSize',10);
    bar(vbd_data(:,1), vbd_data(:,6), 'b');
    title('gc_vbd_pot2_ad_startretries')
    grid on;
%}

% Restore original path
cd(existingPath);


