clear

fid  = fopen('O:\DeploymentJune05-09\Shipboard software\june06-2009.006', 'rt');

i1= 0;i2= 0; i3= 0;i4= 0;
TensionMult = 1.42;
WinchTC = 1382;         %in*lbf/A
WinchRadius = 9.82;     %inches
motorTC = .82           %(in * lbf) / A

fprintf(1,'Reading the file...\n');
while ~feof(fid)
    tline = fgetl(fid);
   if  regexp(tline, 'EPWM')
       i1= i1+1;
       epwm(i1) = cellstr(tline);
    elseif regexp(tline, 'EPLW')
        i2= i2+1;
        eplw(i2) = cellstr(tline);
    elseif regexp(tline, 'EPLJ')
        i3 = i3+1;
        eplj(i3) = cellstr(tline);
    elseif regexp(tline, 'EPAD')
        i4 = i4+1;
        epad(i4) = cellstr(tline);
    end
end
fclose(fid);

clear r
clear date
clear time
clear ap
clear timeStamp

%Parse the winch motor string
fprintf(1,'Parsing Winch Motor String...\n');
r = epwm;
[date,r] = strtok(r);
[time,r] = strtok(r);
[ampm,r] = strtok(r);
temp = char(ampm);
ampm2 = temp(:,1:2);
b = blanks(length(date))';
temp = [char(date) b char(time) ampm2]; 
wmTimeStamp = datenum(temp);

[t,r] = strtok(r,',');
[temp,r] = strtok(r,',');
wmRCurrent = str2num(char(temp));
[temp,r] = strtok(r,',');
wmACurrent = str2num(char(temp));
[temp,r] = strtok(r,',');
wmPosition = str2num(char(temp));
[temp,r] = strtok(r,',');
wmVelocity = str2num(char(temp));
[temp,r] = strtok(r,',');
wmPError = str2num(char(temp));
[temp,r] = strtok(r,',');
wmVError = str2num(char(temp));
[temp,r] = strtok(r,',');
wmTemperature = str2num(char(temp));

%Parse the levelwind motor string
fprintf(1,'Parsing Levelwind Motor String...\n');
r = eplw;
[date,r] = strtok(r);
[time,r] = strtok(r);
[ampm,r] = strtok(r);
temp = char(ampm);
ampm2 = temp(:,1:2);
b = blanks(length(date))';
temp = [char(date) b char(time) ampm2]; 
lwTimeStamp = datenum(temp);

[t,r] = strtok(r,',');
[temp,r] = strtok(r,',');
lwRCurrent = str2num(char(temp));
[temp,r] = strtok(r,',');
lwACurrent = str2num(char(temp));
[temp,r] = strtok(r,',');
lwPosition = str2num(char(temp));
[temp,r] = strtok(r,',');
lwVelocity = str2num(char(temp));
[temp,r] = strtok(r,',');
lwPError = str2num(char(temp));
[temp,r] = strtok(r,',');
lwVError = str2num(char(temp));
[temp,r] = strtok(r,',');
lwTemperature = str2num(char(temp));

%Parse the Accel Pressure string
fprintf(1,'Parsing Acceleration/Pressure String...\n');
r = epad;
[date,r] = strtok(r);
[time,r] = strtok(r);
[ampm,r] = strtok(r);
temp = char(ampm);
ampm2 = temp(:,1:2);
b = blanks(length(date))';
temp = [char(date) b char(time) ampm2]; 
adTimeStamp = datenum(temp);

[t,r] = strtok(r,',');
[temp,r] = strtok(r,',');
adAx = str2num(char(temp));
[temp,r] = strtok(r,',');
adAy = str2num(char(temp));
[temp,r] = strtok(r,',');
adAz = str2num(char(temp));
[temp,r] = strtok(r,',');
adARatex = str2num(char(temp));
[temp,r] = strtok(r,',');
adARatey = str2num(char(temp));
[temp,r] = strtok(r,',');
adARatez = str2num(char(temp));
[temp,r] = strtok(r,',');
adDepth = str2num(char(temp));

%Parse the Labjack string
fprintf(1,'Parsing Labjack String...\n');
r = eplj;
[date,r] = strtok(r);
[time,r] = strtok(r);
[ampm,r] = strtok(r);
temp = char(ampm);
ampm2 = temp(:,1:2);
b = blanks(length(date))';
temp = [char(date) b char(time) ampm2]; 
ljTimeStamp = datenum(temp);

[t,r] = strtok(r,',');
[temp,r] = strtok(r,',');
ljLWMode = str2num(char(temp));
[temp,r] = strtok(r,',');
ljReqWinchRPM = str2num(char(temp));
[temp,r] = strtok(r,',');
ljLWBaseDACVoltage = str2num(char(temp));
[temp,r] = strtok(r,',');
ljWinchDACVoltage = str2num(char(temp));
[temp,r] = strtok(r,',');
ljLWDACVoltage = str2num(char(temp));
[temp,r] = strtok(r,',');
ljMotorTension = str2num(char(temp));
[temp,r] = strtok(r,',');
ljFlangeTension = str2num(char(temp));
[temp,r] = strtok(r,',');
ljTotalTension = str2num(char(temp));
[temp,r] = strtok(r,',');
ljBusVoltage = str2num(char(temp));
[temp,r] = strtok(r,',');
ljLWError = str2num(char(temp));
[temp,r] = strtok(r,',');
ljWinchCPS = str2num(char(temp));
[temp,r] = strtok(r,',');
ljLWDirection = str2num(char(temp));
[temp,r] = strtok(r,',');
ljEOTLeft = str2num(char(temp));
[temp,r] = strtok(r,',');
ljEOTRight = str2num(char(temp));
[temp,r] = strtok(r,',');
ljCableLeft = str2num(char(temp));
[temp,r] = strtok(r,',');
ljCableRight = str2num(char(temp));

ActualTension = ljTotalTension / TensionMult;
