function [new_data, new_meta_data, header, append, data, meta_data, time_esecs] ...
    = co2_read (nc_directory, ascii_directory, mat_directory, filename)

co2_filename = 'co2new';

mid = fopen([mat_directory filename '.mat']);
if(mid ~= -1),
    load ([mat_directory filename '.mat'], 'data', 'meta_data', 'header', 'time_esecs');
    data_prev = data;
    meta_data_prev = meta_data;
    time_prev = time_esecs;
else
    data_prev = [];
    time_prev = [];
end

data = [];
meta_data = [];
header = []; time_esecs=[];

tmp = textread([ascii_directory '/' co2_filename '.txt'], '%f', 'delimiter', '\t');

data = (reshape(tmp, [6, (size(tmp,1)/6)]))';

header = {'mm/dd/yyyy'; 'HH:MM'; 'time_esecs'; 'Depth'; 'Latitude'; 'Longitude';  ...
    'ZeroCorEquil'; 'WaterxCO2'; 'ZeroCorAir' ; 'AirxCO2'; 'O2'};


excelDates = data(:,1);
matlabDates = datenum('30-Dec-1899') + excelDates;

mdy = datestr(matlabDates, 'mm/dd/yyyy');
hhmm = datestr(matlabDates, 'HH:MM');

time_edays = matlabDates - datenum('1-jan-1970');
time_esecs = time_edays*(3600*24);

data(:,1) = time_esecs;

data(:,5:9) = data(:,2:6);
data(:,2) = 0;
data(:,3) = 36.8333;
data(:,4) = -121.9033;

for t = 1:length(data),
    meta_data {t, 1} = mdy(t,1:10);
    meta_data {t, 2} = hhmm(t,1:5);
end

append = 0;

if ((mid ~= -1) && exist('data', 'var')),
    new_data = data(length(data_prev)+1:end,:);
    new_meta_data = meta_data(length(data_prev)+1:end,:);
    append = 1;
else
    new_data = data;
    new_meta_data = meta_data;
end

%co2_ssds_netcdf(nc_directory, data)

end
