%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  New template code for TAMU Theses and Dissertations starting Fall 2012.  
%  For more info about this template or the 
%  TAMU LaTeX User's Group, see http://www.howdy.me/.
%
%  Author: Wendy Lynn Turner 
%	 Version 1.0 
%  Last updated 8/5/2012
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                           APPENDIX D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\phantomsection

\chapter{\uppercase{MATLAB Post Processing Code}}
\label{app:matlab}
\section{MATLAB Code}
The code below can be pasted into an m--file and the necessary inputs inserted as described in Chapter~\ref{chap:Stats}.

clear all

close all

clc

\%Mesh Size\%

\% number of nodes           = 1005

\% number of nodes in x      = 67

\% number of nodes in y      = 15

\% number of elements        = 924

\% number of elements in x   = 66

\% number of elements in y   = 14

\% number of parameters      = 580

\% number of parameters in x = 58

\% number of parameters in y = 10

\% number of left elements   = 6

\% number of right elements  = 6

\% number of top elements    = 0

\% number of bottom elements = 6

nelm = 924;

elmx = 66;

elmy = 14;

\%Load node data

xnode = [ ];

ynode = [ ];

\%Foundation information and relative node info

d = -6.08; \%known depth of foundation if available

yplot = -10; \%depth to which the data is plotted, deeper than foundation 

ynodeplot = 13; \%y node corresponding to plotting depth

found =; \% xnode where foundation starts : xnode where foundation ends

\%Load IP DATA from Output

Charge = [  ];

\%Arrange data into a single array

array = zeros(nelm,1);

org = ceil(nelm/5)

for i = 1:org

  array(1+5*(i-1):5+5*(i-1),1)=Charge(i,:); 
  
end


array = array(:,:).*1000;

pseud = zeros(elmy,elmx);

\%Organize data into pseudosection

for i = 1:elmx

pseud(:,i) = array(((1+(elmy)*(i-1)):((elmy)+(elmy)*(i-1))),1);   

end

\%Pull chargeability from around foundation

foundation = pseud(:,found);

\%Vertical ratio

curve = zeros(elmy,3);

for j=1:4

for i = 1:elmy-1

curve(i,j) = foundation(i,j)./foundation(i+1,j);    

end

end

\%Foundation Depth

A = [0, 2];

B = [d, d];

datadepth = [-5.7,-5.7]; \%depth to which data is collected

figure(1)

plot(curve(1:ynodeplot,1),ynode(1:ynodeplot,2),'m')

hold on

plot(curve(1:ynodeplot,2),ynode(1:ynodeplot,2),'k')

hold on

plot(curve(1:ynodeplot,3),ynode(1:ynodeplot,2),'r')

hold on

plot(curve(1:ynodeplot,4),ynode(1:ynodeplot,2),'g')

hold on

line(A,datadepth,'Color','k');

hold on

line(A,B);

store=legend('   ','   ','  ','  ','  ','  ')

 legend(store, 'Location', 'Southwest')
 
ylabel('depth (m)')

xlabel('chargeabiltiy ratio')

title('XX Bridge Foundation')

axis([0 2 yplot 0])


slope = zeros(elmy,6);

for i = 1:4

   slope(:,i)=gradient(foundation(:,i)); 
   
end

A = [-40, 40];

B = [d, d];

figure(2)

plot(slope(1:ynodeplot,1),ynode(1:ynodeplot,2),'m')

hold on

plot(slope(1:ynodeplot,2),ynode(1:ynodeplot,2),'k')

hold on

plot(slope(1:ynodeplot,3),ynode(1:ynodeplot,2),'r')

hold on

plot(slope(1:ynodeplot,4),ynode(1:ynodeplot,2),'g')

hold on

line(A,datadepth,'Color','k');

hold on

line(A,B)

legend(' ', ' ', ' ',' ',' ', ' ','Location','Southwest')

xlabel('Slope of Chargeabiltiy')

ylabel('Depth (m)')

title('XX Bridge Foundation')

axis([-40 40 yplot 0])
