clear all; close all;
%-----User input---------------
ID = 1.5; %cylinder ID in inches
D = 5.60; %distance in inches
P = 180; %pressure in psi
fpin = 'GP22_180psi.txt'
%--------------------------------

%calc work
Cyl_area = pi() * (ID/2)^2; %in^2
F = P * Cyl_area; %pounds
W = F * D/12; %ft-lbs
W = 1.35582 * W; %Joules
fprintf('Mechanical work = %f J\n',W);



%calc regen J, Joules = Volts * Amps * Seconds
fid = fopen(fpin,'r');

tline = fgetl(fid);

E = 0;

while ischar(tline)
    %disp(tline)
    A = sscanf(tline,'%s %s %f %f');
    E = E + (A(20)*A(21)*.1); %10HZ sample rate
    tline = fgetl(fid);
end
fclose(fid);
fprintf('Regen = %f J\n',E);
fprintf('Eff = %f\n',E/W);