%
% =========================================================================
% MVP_callback  Version 1.0 31-Dec-2011
%
% Usage:
%   Called by the MVP_timer function
%
% Description:
%   This MATLAB script checks to see if there are any new .m1 MVP data
%   files in the working directory that need to be processed.  If so, the
%   load and convert function is called. After the MVP logfile is
%   generated, a function is called to plot the MVP TS data overlaid on the
%   Ross Sea climatology
%
% Input:
%   N/A
%
% Output:
%   N/A
%
% Author:
%   Blair Greenan
%   Bedford Institute of Oceanography
%   28-Dec-2011
%   Matlab 7.13
%   blair.greenan@dfo-mpo.gc.ca
%
% Revision History:
%
% =========================================================================

global dlength MVP_logfile
% Set the directory where the MVP .m1 files are going to be copied to
% d = dir('F:\Backup 2011-12-12\Science Projects\Current\Ross Sea\Data\MVP\MVP_timer\*.m1');
d = dir('S:\mvp\nbp1201\rois\vprlog\*.m1');
% Check how many .m1 files are in the above directory
dl = length(d) - dlength
% For the number of new files that have been copied to the directory,
% execute the load and convert program which reads the .m1 files, stores
% the data as a .mat file and then converts it to the Video Plankton
% Recorder (VPR) logfile format and appends these results to the logfile if
% it already exists.
for jj = dl-1:-1:0
    m1_filename = d(end-jj).name;
    % load the MVP .m1 data file, generate a .mat file and append data to a
    % VPR-type logfile for vizualization in the VPR software package
    load_MVP_m1_convert2vpr(m1_filename,MVP_logfile);
    % Use the .m1 filename to generate the .mat filename which is generated
    % by the function call above
    [token, remain] = strtok(m1_filename, '.');
    mat_filename = [token '.mat'];
    % call function to plot TS climatology and MVP data overlay
    NBP1201_climate_TS_and_MVP(mat_filename);
end
% Reset the counter of the number of .m1 files in the directory which is
% used to determine if there are any new files to process
dlength = length(d);


