function [ jd, scat_angle, bb ] = ecoVSF_import_profile( filename, start_line )
%ecoVSF_IMPORT Import data from Eco VSF or BB3 
%
% 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
%         scat_angle Mx1 double containing the scattering angle
%         bb NxM double containing the backscattering of the file
%
% Example:
%   [ jd, scat_angle, bb ] = ecoVSF_import_profile('run_23_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
[jd, bb] = import_file(filename, start_line);

scat_angle = [104, 130, 151];

bb = bb';
end

function [jd, bb] = import_file(filename, start_line)
  % Read file for a
  [fid, errmsg] = fopen(filename);
  if fid < 0; error(errmsg); end;

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

  % Get Scattering angle
  bb_index = 4:6;
  
  % Get data
  bb=[]; jd = [];
  while ischar(tline)
    data = strsplit(tline);
    jd(end+1, 1) = str2double(data(1));
    bb(:, end+1) = str2double(data(bb_index));
    tline = fgetl(fid);
  end;
  fclose(fid);
end
