clearvars

duraFileName = 'f18340.026.dura.csv';

fid = fopen(duraFileName);

cellIndex = 1;
while ~feof(fid)
    tempLine = fgetl(fid);
    if strcmp(tempLine(1:2), '0x')
        duraCell(cellIndex, :) = strsplit(tempLine, ',');
        cellIndex = cellIndex + 1;
    end
end
%duraCell = duraCell';
duraTable = cell2table(duraCell);

duraTableHeader = {'CRC', 'DataType', 'DFTimeStampGMT', 'CTDTimeStamp',	'CTDPressureDBar', ...
    'CTDTemperatureC', 'CTDSalinityPSS', 'SampleCounter', 'PowerCycleCounter', 'ErrorCounter', ...
    'HousingTempC',	'HousingRelHumidity', 'DFSupplyVolts', 'DFCurrentAmps', 'DFComputedPH', ...
    'DFBackupBattVolts',	'DFRefElectrodeVRSVolts', 'DFRefElectrodeVRSStdev', ...
    'DFCounterElectrodeVKVolts', 'DFCounterElectrodeVKStddev', 'DFCounterElectrodeAmps', 'DF_IBAmps'};				
duraTable.Properties.VariableNames = duraTableHeader;

load cal18340CalCurrent.mat;

[phfree,phtot]= phcalc(str2double(duraTable.DFRefElectrodeVRSVolts), str2double(duraTable.CTDPressureDBar), ...
    str2double(duraTable.CTDTemperatureC), str2double(duraTable.CTDSalinityPSS), cal.pH.k0, cal.pH.k2, cal.pH.pcoefs);
