function [ jd, p, t, s, sig, c ] = 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 1
%
%
% Outputs:jd Nx1 double containing date in julian day
%         p Nx1 double containing the pressure 
%         t Nx1 double containing the temperature
%         s Nx1 double containing the salinity
%         sig Nx1 double containing sigma
%         c Nx1 double containing conductivity
%
% Example:
% [jd, p, t, s, sig] = ctd_import_profile('run_24_ASCII.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 = 1;
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 = []; t = []; c = []; s = []; p = []; sig = [];
while ischar(tline)
  data = strsplit(tline);
  jd(end+1, 1) = str2double(data(1));
  t(end+1,1) = str2double(data(2));
  c(end+1,1) = str2double(data(3));
  p(end+1,1) = str2double(data(4));
  s(end+1,1) = str2double(data(5));
  sig(end+1,1) = str2double(data(6));
  tline = fgetl(fid);
end;
fclose(fid);
end
