function L2 = l2_ion_importfile(filename, startRow, endRow)
%IMPORTFILE Import numeric data from a text file as column vectors.
%   [T_UTC,T_UNIX,T_SCLK,T_TID,TID,ORBIT,FOCUSMODE,ALT,LST,LONG,LAT,SZA,ION_MASS,CPS_DT,ABUNDANCE,SENSITIVITY,PRECISION,QUALITY]
%   = IMPORTFILE(FILENAME) Reads data from text file FILENAME for the
%   default selection.
%
%   [T_UTC,T_UNIX,T_SCLK,T_TID,TID,ORBIT,FOCUSMODE,ALT,LST,LONG,LAT,SZA,ION_MASS,CPS_DT,ABUNDANCE,SENSITIVITY,PRECISION,QUALITY]
%   = IMPORTFILE(FILENAME, STARTROW, ENDROW) Reads data from rows STARTROW
%   through ENDROW of text file FILENAME.
%
% Example:
%   [t_utc,t_unix,t_sclk,t_tid,tid,orbit,focusmode,alt,lst,long,lat,sza,ion_mass,cps_dt,abundance,sensitivity,precision,quality]
%   =
%   importfile('mvn_ngi_l2_ion-abund-17446_20151004T142729_v05_r01.csv',2,
%   54189);
%
%    See also TEXTSCAN.

% Auto-generated by MATLAB on 2015/10/19 13:01:45

%% Initialize variables.
delimiter = ',';
if nargin<=2
    startRow = 2;
    endRow = inf;
end

%% Format string for each line of text:
%   column1: text (%s)
%	column2: double (%f)
%   column3: double (%f)
%	column4: double (%f)
%   column5: double (%f)
%	column6: double (%f)
%   column7: text (%s)
%	column8: double (%f)
%   column9: double (%f)
%	column10: double (%f)
%   column11: double (%f)
%	column12: double (%f)
%   column13: double (%f)
%	column14: double (%f)
%   column15: double (%f)
%	column16: double (%f)
%   column17: double (%f)
%	column18: text (%s)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%s%f%f%f%f%f%s%f%f%f%f%f%f%f%f%f%f%s%[^\n\r]';

%% Open the text file.
fileID = fopen(filename,'r');

%% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines', startRow(1)-1, 'ReturnOnError', false);
for block=2:length(startRow)
    frewind(fileID);
    dataArrayBlock = textscan(fileID, formatSpec, endRow(block)-startRow(block)+1, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines', startRow(block)-1, 'ReturnOnError', false);
    for col=1:length(dataArray)
        dataArray{col} = [dataArray{col};dataArrayBlock{col}];
    end
end

%% Close the text file.
fclose(fileID);

%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.

%% Allocate imported array to column variable names
L2.t_utc = dataArray{:, 1};
L2.t_unix = dataArray{:, 2};
L2.t_sclk = dataArray{:, 3};
L2.t_tid = dataArray{:, 4};
L2.tid = dataArray{:, 5};
L2.orbit = dataArray{:, 6};
L2.fmode = dataArray{:, 7};
L2.alt = dataArray{:, 8};
L2.lst = dataArray{:, 9};
L2.long = dataArray{:, 10};
L2.lat = dataArray{:, 11};
L2.sza = dataArray{:, 12};
L2.ion_mass = dataArray{:, 13};
L2.cps_dt = dataArray{:, 14};
L2.abundance = dataArray{:, 15};
L2.sensitivity = dataArray{:, 16};
L2.precision = dataArray{:, 17};
L2.quality = dataArray{:, 18};


