function [ARCHIVE_TIME_COMP, ARCHIVE_SIGNAL_COMP, ARCHIVE_TIME_BIN_COMP, ...
          ARCHIVE_SIGNAL_MEAN_COMP, ARCHIVE_SIGNAL_STD_COMP, ARCHIVE_SIGNAL_N_COMP, ...
          ARCHIVE_SIGNAL_MED_COMP, ARCHIVE_SIGNAL_16PER_COMP, ARCHIVE_SIGNAL_84PER_COMP, ...
          ARCHIVE_SIGNAL_MIN_COMP, ARCHIVE_SIGNAL_MAX_COMP] = dmc_extractor
  
% dmc_extractor.m
% 
% SYNTAX:       [ARCHIVE_TIME_COMP, ARCHIVE_SIGNAL_COMP, ARCHIVE_TIME_BIN_COMP, ...
%                ARCHIVE_SIGNAL_MEAN_COMP, ARCHIVE_SIGNAL_STD_COMP, ARCHIVE_SIGNAL_N_COMP, ...
%                ARCHIVE_SIGNAL_MED_COMP, ARCHIVE_SIGNAL_16PER_COMP, ARCHIVE_SIGNAL_84PER_COMP, ...
%                ARCHIVE_SIGNAL_MIN_COMP, ARCHIVE_SIGNAL_MAX_COMP] = dmc_extractor;
%
% Use a graphical user interface to consolidate data from multiple archive
% files into a single dataset.
%
% Date Created:  June 11, 2004
% Date Modified: June 22, 2004
%
% Brandon Sackmann
% University of Maine
% School of Marine Sciences & 
% Ira C. Darling Marine Center
% 193 Clark's Cove Road
% Walpole, Maine 04573
%
% Tel: (207) 563-3146 x343
% Fax: (207) 563-3119
% Email: brandon.sackmann@maine.edu

% *****************
% DMC_EXTRACTOR_GUI
% *****************
guiHandles = dmc_extractor_gui;

% *************************
% CALCULATE START/END TIMES
% *************************
month_val_start = get(guiHandles.monthstart,'value');
month_str_start = get(guiHandles.monthstart,'string');
month_str_start = char(month_str_start(month_val_start));
day_val_start = get(guiHandles.daystart,'value');
day_str_start = get(guiHandles.daystart,'string');
day_str_start = char(day_str_start(day_val_start));
year_val_start = get(guiHandles.yearstart,'value');
year_str_start = get(guiHandles.yearstart,'string');
year_str_start = char(year_str_start(year_val_start));
hour_val_start = get(guiHandles.hourstart,'value');
hour_str_start = get(guiHandles.hourstart,'string');
hour_str_start = char(hour_str_start(hour_val_start));
min_val_start = get(guiHandles.minstart,'value');
min_str_start = get(guiHandles.minstart,'string');
min_str_start = char(min_str_start(min_val_start));
sec_val_start = get(guiHandles.secstart,'value');
sec_str_start = get(guiHandles.secstart,'string');
sec_str_start = char(sec_str_start(sec_val_start));

month_val_end = get(guiHandles.monthend,'value');
month_str_end = get(guiHandles.monthend,'string');
month_str_end = char(month_str_end(month_val_end));
day_val_end = get(guiHandles.dayend,'value');
day_str_end = get(guiHandles.dayend,'string');
day_str_end = char(day_str_end(day_val_end));
year_val_end = get(guiHandles.yearend,'value');
year_str_end = get(guiHandles.yearend,'string');
year_str_end = char(year_str_end(year_val_end));
hour_val_end = get(guiHandles.hourend,'value');
hour_str_end = get(guiHandles.hourend,'string');
hour_str_end = char(hour_str_end(hour_val_end));
min_val_end = get(guiHandles.minend,'value');
min_str_end = get(guiHandles.minend,'string');
min_str_end = char(min_str_end(min_val_end));
sec_val_end = get(guiHandles.secend,'value');
sec_str_end = get(guiHandles.secend,'string');
sec_str_end = char(sec_str_end(sec_val_end));

start_time = datenum([month_str_start ' ' day_str_start ', ' year_str_start ' ' hour_str_start ':' min_str_start ':' sec_str_start]);
end_time   = datenum([month_str_end ' ' day_str_end ', ' year_str_end ' ' hour_str_end ':' min_str_end ':' sec_str_end]);

% ****************************************************
% DETERMINE WHICH DATA FILES HAVE RELEVANT INFORMATION
% ****************************************************
datadir = get(guiHandles.datadir,'string');
cd(datadir);

rawlist   = dir('*_RAW.mat');
for i = 1:length(rawlist)
    tmptimes(i,:) = rawlist(i).name(end-20:end-8);
    tmpdate = datenum(['12/31/' num2str((str2num(tmptimes(i,1:4))-1))]);
    tmpdate = tmpdate+str2num(tmptimes(i,5:7));
    tmpdate = datestr(tmpdate);
    rawtimes(i) = datenum([tmpdate ' ' tmptimes(i,8:9) ':' tmptimes(i,10:11) ':' tmptimes(i,12:13)]);
end
rawgood = find(rawtimes>=start_time & rawtimes<end_time);
rawfirst = min(rawgood-1);
if rawfirst > 0
    rawgood = [rawfirst rawgood];
end
rawlistgood = rawlist(rawgood);

statslist = dir('*_STATS.mat');
for i = 1:length(statslist)
    tmptimes(i,:) = statslist(i).name(end-22:end-10);
    tmpdate = datenum(['12/31/' num2str((str2num(tmptimes(i,1:4))-1))]);
    tmpdate = tmpdate+str2num(tmptimes(i,5:7));
    tmpdate = datestr(tmpdate);
    statstimes(i) = datenum([tmpdate ' ' tmptimes(i,8:9) ':' tmptimes(i,10:11) ':' tmptimes(i,12:13)]);
end
statsgood = find(statstimes>=start_time & statstimes<end_time);
statsfirst = min(statsgood-1);
if statsfirst > 0
    statsgood = [statsfirst statsgood];
end
statslistgood = statslist(statsgood);

% ***************************
% COMPILE DATA PRODUCTS - RAW
% ***************************
ARCHIVE_TIME_COMP = [];
ARCHIVE_SIGNAL_COMP = [];
for j = 1:length(rawlistgood)
    load(rawlistgood(j).name)
    ARCHIVE_TIME_COMP = [ARCHIVE_TIME_COMP; ARCHIVE_TIME];
    ARCHIVE_SIGNAL_COMP = [ARCHIVE_SIGNAL_COMP; ARCHIVE_SIGNAL];
end
gooddat = find(ARCHIVE_TIME_COMP>=start_time & ARCHIVE_TIME_COMP<end_time);
ARCHIVE_TIME_COMP = ARCHIVE_TIME_COMP(gooddat,:);
ARCHIVE_SIGNAL_COMP = ARCHIVE_SIGNAL_COMP(gooddat,:);

% *****************************
% COMPILE DATA PRODUCTS - STATS
% *****************************
ARCHIVE_TIME_BIN_COMP = [];
ARCHIVE_SIGNAL_MEAN_COMP = [];
ARCHIVE_SIGNAL_STD_COMP = [];
ARCHIVE_SIGNAL_N_COMP = [];
ARCHIVE_SIGNAL_MED_COMP = [];
ARCHIVE_SIGNAL_16PER_COMP = [];
ARCHIVE_SIGNAL_84PER_COMP = [];
ARCHIVE_SIGNAL_MIN_COMP = [];
ARCHIVE_SIGNAL_MAX_COMP = [];
for j = 1:length(statslistgood)
    load(statslistgood(j).name)
    ARCHIVE_TIME_BIN_COMP = [ARCHIVE_TIME_BIN_COMP; ARCHIVE_TIME_BIN];
    ARCHIVE_SIGNAL_MEAN_COMP = [ARCHIVE_SIGNAL_MEAN_COMP; ARCHIVE_SIGNAL_MEAN];
    ARCHIVE_SIGNAL_STD_COMP = [ARCHIVE_SIGNAL_STD_COMP; ARCHIVE_SIGNAL_STD];
    ARCHIVE_SIGNAL_N_COMP = [ARCHIVE_SIGNAL_N_COMP; ARCHIVE_SIGNAL_N];
    ARCHIVE_SIGNAL_MED_COMP = [ARCHIVE_SIGNAL_MED_COMP; ARCHIVE_SIGNAL_MED];
    ARCHIVE_SIGNAL_16PER_COMP = [ARCHIVE_SIGNAL_16PER_COMP; ARCHIVE_SIGNAL_16PER];
    ARCHIVE_SIGNAL_84PER_COMP = [ARCHIVE_SIGNAL_84PER_COMP; ARCHIVE_SIGNAL_84PER];
    ARCHIVE_SIGNAL_MIN_COMP = [ARCHIVE_SIGNAL_MIN_COMP; ARCHIVE_SIGNAL_MIN];
    ARCHIVE_SIGNAL_MAX_COMP = [ARCHIVE_SIGNAL_MAX_COMP; ARCHIVE_SIGNAL_MAX];
end
gooddat = find(ARCHIVE_TIME_BIN_COMP>=start_time & ARCHIVE_TIME_BIN_COMP<end_time);
ARCHIVE_TIME_BIN_COMP = ARCHIVE_TIME_BIN_COMP(gooddat,:);
ARCHIVE_SIGNAL_MEAN_COMP = ARCHIVE_SIGNAL_MEAN_COMP(gooddat,:);
ARCHIVE_SIGNAL_STD_COMP = ARCHIVE_SIGNAL_STD_COMP(gooddat,:);
ARCHIVE_SIGNAL_N_COMP = ARCHIVE_SIGNAL_N_COMP(gooddat,:);
ARCHIVE_SIGNAL_MED_COMP = ARCHIVE_SIGNAL_MED_COMP(gooddat,:);
ARCHIVE_SIGNAL_16PER_COMP = ARCHIVE_SIGNAL_16PER_COMP(gooddat,:);
ARCHIVE_SIGNAL_84PER_COMP = ARCHIVE_SIGNAL_84PER_COMP(gooddat,:);
ARCHIVE_SIGNAL_MIN_COMP = ARCHIVE_SIGNAL_MIN_COMP(gooddat,:);
ARCHIVE_SIGNAL_MAX_COMP = ARCHIVE_SIGNAL_MAX_COMP(gooddat,:);