function [ jd, fchl, fchl_delta, input_u ] = ctd_import_profile( filename, start_line )
%CTD_IMPORT Import data from CTD
%
% Inputs: 
%    Required:
%        filename string containing file name
%    Optional:
%        start_line integer containing the line at which data start
%          default: line 2
%
%
% Outputs:jd Nx1 double containing date in julian day
%         fchl Nx1 double containing the chlorophyll a fluorescence in volts
%         fchl_delta Nx1 double containing the delta for fchl in volts
%         input_tension Nx1 double containing the tension received by the instrument
%
% Example:
%   [jd, fchl, fchl_delta] = ctd_import_profile('run_29_ANALOG.001');
%
% Tested with: Matlab R2015a
%
% Author: Nils Haentjens, Ms, University of Maine
% Email: nils.haentjens@maine.edu
% Created: 14th July 2015
% Last update: 21th July 2015
%
% Inspired by:
%   read_acs91_v2
%     Written by Emmanuel Boss, UMAINE, 2009 for TARA.
%     Modified for 007 - Nov 6 2013
%     Modified by James Allen, 7/7/15

% Check input
if nargin > 2
   error('Too many input arguments')
elseif nargin < 1
   error('Not enough input arguments')
end
if nargin < 2;
  start_line = 2;
end;

% Read file
[fid, errmsg] = fopen(filename);
if fid < 0; error(errmsg); end;

% Skip first part
for foo=1:start_line;
  tline = fgetl(fid);
end;

% Get data
jd = []; fchl = []; fchl_delta = []; input_u = [];
while ischar(tline)
  data = strsplit(tline);
  jd(end+1, 1) = str2double(data(1));
  fchl(end+1,1) = str2double(data(4));
  fchl_delta(end+1,1) = str2double(data(3));
  input_u(end+1,1) = str2double(data(2));
  tline = fgetl(fid);
end;
fclose(fid);
end
