function a_array = m1_convert_file(file_to_convert)
% fluor_convert - Convert a fluorometer file into a data array.
%
% Use as: out_array = m1_convert_file(input_file)
%
% Inputs: input_file = Path of input file
%
% Output: a_array = an array of data elements from the file.
%
% Example:
%   out_array = m1_convert_file('C:\sample_file.txt')
%out_array =
%
% 1.0e+005 *
%
%    7.3191    324.01390    0.0111    0.0011    0.0011
%    7.3191    324.01390    0.0178    0.0017    0.0057
%    7.3191    324.01390    0.0177    0.0017    0.0057
%    7.3191    324.01390    0.0177    0.0017    0.0057
%    7.3191    324.01390    0.1000    0.0100    0.0100
% Where Col(1)=datenum,  Col(2)=OASIS time, Col(3)=reference, Col(4)=signal, and Col(5)=thermistor.
% This program is to be used on both the M1 ecobb and the M1 ecofl data
% files...  which are currently located at: \\Tornado\oasis\m1

% MC Harlan
% 21 Nov 2003

fid_in = fopen(file_to_convert, 'r');

% Get rid of the header
while ~feof(fid_in)
    pointer = ftell(fid_in);
    line = deblank(fgetl(fid_in));
    if (isempty(line) | ~strcmp(line(1), '#'))
        % Called if line does not stat with #.
        % Rewinds fid_in to the start of the last line read.
        fseek(fid_in, pointer, -1);   
        break;
    end
end

% Sample input file below. The number of liens of data can vary now.
%(1)324.01390  11/20/03	00:26:35	1779	168	567
%(2)11/20/03	00:26:36	1776	168	567
%(3)11/20/03	00:26:37	1773	168	567
%(4)11/20/03	00:26:38	1771	168	567
%(5)11/20/03	00:26:39	1770	167	567
%(6) --blank --

line_cnt = 0;
while ~feof(fid_in)  %Read until EOF
    line = fgetl(fid_in);
    % If it's not a blank line here then it's a line with a date in it.
    if ~isempty(line)
        [oasis_time,line] = strtok(line); % row 1 has OASIS time as the first token
        % This loop will continue until a blank line is reached
        while ~isempty(line)
             [item1,line] = strtok(line); %Break each line into 5 items
             [item2,line] = strtok(line);
             [item3,line] = strtok(line);
             [item4,line] = strtok(line);
             [item5,line] = strtok(line);
             
             line_cnt = line_cnt + 1;
             a_array(line_cnt, 1) = datenum([item1, ' ',item2]); %Load the items into the array to be returned
             a_array(line_cnt, 2) = str2double(oasis_time);
             a_array(line_cnt, 3) = str2double(item3);
             a_array(line_cnt, 4) = str2double(item4);
             a_array(line_cnt, 5) = str2double(item5);
             line = fgetl(fid_in);
        end
    end
end     % end of while

fclose(fid_in);
return;