%
% =========================================================================
% MVP_timer  Version 1.0 31-Dec-2011
%
% Usage:
%   MVP_timer
%
% Description:
%   This MATLAB script sets up a timer which will run every 5 minutes (300 s)
%   and check to see if there are any new MVP .m1 files that need to be
%   processed and added to the MVP logfile which will be visualized with
%   the Video Plamkton Recorder software.
%   Note: the timer can be stopped by typing stop(t) at the MATLAB command
%   line and can be deleted by typing deleta(t)
%
% Input:
%   N/A
%
% Output:
%   N/A
%
% Author:
%   Blair Greenan
%   Bedford Institute of Oceanography
%   31-Dec-2011
%   Matlab 7.13
%   blair.greenan@dfo-mpo.gc.ca
%
% Revision History:
%
% =========================================================================

% clear all existing variables
close all, clear all
% clear all global variables
clear global
% create the two global variables required for this program
global dlength VPRindex MVP_tem_downcast MVP_sal_downcast MVP_tem_upcast MVP_sal_upcast MVP_logfile
% set initial value for the VPR index (this is arbitrary)
VPRindex=100000
% set the number of m1 files processed to zero
dlength = 0
% NOTE: You should set the name of the MVP logfile before executing this
% script.  If you just want to add to the existing logfile, no change is
% necessary
MVP_logfile = 'PRISM_MVP_TOW2.Y12';
% Check to see if there is already an existing MVP_TS.mat file that is
% compiling temperature and salinity data
if ~exist('MVP_TS_downcast.mat')
    MVP_tem_downcast = (zeros(1,1000)*NaN)';
    MVP_sal_downcast = (zeros(1,1000)*NaN)';
    % open a new .mat file for the MVP temperature and salinity data
    save S:\mvp\nbp1201\rois\vprlog\MVP_TS_downcast.mat MVP_tem_downcast MVP_sal_downcast;
end
if ~exist('MVP_TS_upcast.mat')
    MVP_tem_upcast = (zeros(1,1000)*NaN)';
    MVP_sal_upcast = (zeros(1,1000)*NaN)';
    % open a new .mat file for the MVP temperature and salinity data
    save S:\mvp\nbp1201\rois\vprlog\MVP_TS_upcast.mat MVP_tem_upcast MVP_sal_upcast;
end
% Set up the timer.  The Period (seconds) sets how often the TimerFcn
% gets called.
t = timer('StartDelay',10,'Period',300,'ExecutionMode', ...
	  'fixedRate','TimerFcn', 'MVP_callback');
% Start the timer  
start(t)
