function [time] = StampDAQtimeConverter(rows, text, hr_set)
% Take the time (given in character format) from any StampDAQ Excel file
% and convert it into seconds.
% Warning: the most common error is to put down too many rows.
%
% Synopsis: [time] = StampDAQtimeConverter(rows, text)
%
% input:    rows = (required) Gives the number of rows of time to be
%                  used.
%           text = (required) Using xlsread, this is the text part of
%                      [data, text] = xlsread('file_name').
%           hr_set = (required) set equal to 0 (zero) if hours can be
%                    represented as a single digit: 1, 2, 3, etc. Set equal
%                    to 1 (one) if two digits are used for the hours
%                    position: 10, 11, or 12.
%
% output:   time = rows x 1 matrix of time in seconds.



% Creation of the time matrix ahead of time cuts down on the time it take
% MATLAB to evaluate the code later.
time = zeros(rows, 1);


% We stared the count at two due to the fact that the 'time' label is in
% the first or 1 position. The data starts on the second column.
for x = 2:(rows + 1);

    row = text{x,1}; % select the time row by row.

        hours_char = row(2+hr_set); % select the hours part of the character

        % The following three steps are repeated for hours, minutes, and
        % seconds. Becuase there is no comand that directly transfers
        % information from character format into numerical format we must
        % go through a series of steps to undergo this transformation.
        hours_cell = cellstr(hours_char);
        hours_str = cell2mat(hours_cell);
        hours = str2num(hours_str);


        minutes_char = row(4+hr_set:5+hr_set); % select the minutes part of the character
        minutes_cell = cellstr(minutes_char);
        minutes_str = cell2mat(minutes_cell);
        minutes = str2num(minutes_str);


        seconds_char = row(7+hr_set:8+hr_set); % select the seconds part of the character
        seconds_cell = cellstr(seconds_char);
        seconds_str = cell2mat(seconds_cell);
        seconds = str2num(seconds_str);

    % Transfer all the time measurements above into seconds
    time_total_sec = hours*3600 + minutes*60 + seconds;

    % This if statement is used to give the initial time measurement.
    if x == 2; % the first time through the code.
        time_innitial = time_total_sec;
    end

    % Make the initial time zero.
    time_total_sec = time_total_sec - time_innitial;

    % Because the first time measurement being read starts on the second
    % column for the text matrix we need to subtract 1 from it to make
    % it the first row position for the time matrix. We do this for all the
    % time measurement.
    time((x-1),1) = time_total_sec;
end