function output_array = m1_ecobb_calibrate(input_array)
% m1_ecobb_calibrate - Provide calibrated output data for the BB2F.
%
% Use as: output_array = m1_ecobb_calibrate(input_array)
%
% Inputs: input_array = Array of raw counts data.
%
% Output: output_array = an array of raw and calibrated data elements.
%
% Example:
%   output_array = m1_ecobb_calibrate(input_array)
%output_array =
%
% lalala - needs some work here
% Where Col(1)=datenum,  Col(2)=OASIS time, Col(3)=reference, Col(4)=signal, and Col(5)=thermistor.

% MC Harlan
% 21 Nov 2003

% take column 4, do some calculations, and produce column 6...

[rows,cols] = size(input_array); % returns the size of matrix X in separate variables.
fprintf(1,'rows=%d  cols=%d\n', rows, cols);
output_array = input_array;

ANGLE = 117.0;                % From calibration sheet
WAVELEN = 660.0;              % From calibration sheet
DARK_CNTS = 63.870968;       % From calibration sheet
CAL_SW = 0.00271;            % From calibration sheet
SCALE_FACTOR = 0.000003251;  % From calibration sheet
X = 1.1;                     % From Paul
SAL = 34.0;                  % From Paul

Bw = (1.38 * (660/500) ^ -4.32) * ((1 + (0.3 * SAL)/37)*10 ^ -4) * (1 + (cos(117))^2) * ((1 - 0.09) / (1 + 0.09));

for row = 1:rows
  raw_cnts = input_array(row, 4);  % RANGE = 0 to 4120 counts
  B_117_660 = (raw_cnts - DARK_CNTS) * SCALE_FACTOR;
  Bp = B_117_660 - Bw;  % Particle beta
  b_bp = 2 * pi * X * Bp;
  b_sw = 0.0029308 * (660/500) ^ -4.24;
  t_bbs = b_bp + (b_sw / 2.0);
  output_array(row, cols+1) = t_bbs; 
end

return;