%This program analyzes the data in the plot file from the gap system.
%Zachary Wolf
%3/9/01

%Input the data from gapplt.rnn
%disp(' ')
%in_file = input('Please input the name of the file to be analyzed :', 's')
%load(in_file)
load('gap.dat')

%Put the data into arrays
z = gap(:,1);
v_tilt = gap(:,2);
v_ui = gap(:,3);
v_uo = gap(:,4);
v_li = gap(:,5);
v_lo = gap(:,6);
v_fu = gap(:,7);
v_fl = gap(:,8);
d_tilt = gap(:,9);
d_ui = gap(:,10);
d_uo = gap(:,11);
d_li = gap(:,12);
d_lo = gap(:,13);
d_fu = gap(:,14);
d_fl = gap(:,15);
gap_out = gap(:,16);
gap_in = gap(:,17);
frac_grad = gap(:,18);
height_out = gap(:,19);
height_in = gap(:,20);
roll = gap(:,21);
x = gap(:,22);

%Plot the voltages
figure
plot(z, v_ui, 'm+', z, v_uo, 'b+',...
     z, v_li, 'c+', z, v_lo, 'r+',...
     z, v_fu, 'k+', z, v_fl, 'y+')
legend('Vui', 'Vuo', 'Vli', 'Vlo', 'Vfu', 'Vfl')
title('Capacitive Sensor Voltages')
xlabel('Z (m)')
ylabel('V (V)')
figure
plot(z, v_tilt, 'm+')
title('Tilt Sensor Voltage')
xlabel('Z (m)')
ylabel('V (V)')

%Plot the distances
figure
plot(z, d_ui, 'm+', z, d_uo, 'b+',...
     z, d_li, 'c+', z, d_lo, 'r+',...
     z, d_fu, 'k+', z, d_fl, 'y+')
legend('Dui', 'Duo', 'Dli', 'Dlo', 'Dfu', 'Dfl')
title('Capacitive Sensor Distance From The Sensor To The Steel Minus The Garage Distance')
xlabel('Z (m)')
ylabel('D (mm)')
figure
plot(z, d_tilt, 'm+')
title('Arm Tilt Minus The Tilt In The Garage')
xlabel('Z (m)')
ylabel('Th (mrad)')

%Plot the gaps
figure
plot(z, gap_in, 'm+', z, gap_out, 'b+')
legend('Gap in', 'Gap out')
title('Magnet Gap At The Inner And Outer Sensor Positions')
xlabel('Z (m)')
ylabel('Gap (mm)')
figure
plot(z, frac_grad, 'm+')
title('Fractional Gradient vs Z')
xlabel('Z (m)')
ylabel('Fractional Gradient')

%Plot the heights
figure
plot(z, height_in, 'm+', z, height_out, 'b+')
legend('Height in', 'Height out')
title('Gap Center Height At The Inner And Outer Sensor Positions Minus The Garage Height')
xlabel('Z (m)')
ylabel('Height (mm)')

%Plot the roll
figure
plot(z, roll, 'm+')
legend('Magnet Roll')
title('Magnet Roll Minus The Garage Roll')
xlabel('Z (m)')
ylabel('Roll Angle (mrad)')

%Plot x
figure
plot(z, x, 'm+')
legend('Magnet X Position')
title('Magnet X Position Minus The Garage X Position')
xlabel('Z (m)')
ylabel('X Position (mm)')
