% ---------------------------------------------------------------------------------------
% Pacific Earthquake Enginering Research Center Summer Intern Research Project
%
% Written by: WaiChing Sun [stvsun@ucdavis.edu]
% Purpose: generate the animation that visualize the motions
% of the structures composed by beam or quad
% Input: One input file that recorded the node coordinates
% Files that recorded the motion of every nodes
% Output: the movie on a new figure as well as a avi output
% file.
% Notice: THe following command has been added in order to
% recrod all nodes displacement in one input file.
%----------------------------------------------------------------------------------------
% set nodeList {}
% for {set i 1} {$i <= 76} {incr i 1} {
% lappend nodeList $i
% }
% eval "recorder Node AllXDispforStories.out disp -time -node $nodeList -dof 1-dT 0.025"
% eval "recorder Node AllYDispforStories.out disp -time -node $nodeList -dof 1-dT 0.025"
% Last Update: 8/27/2004
%---------------------------------------------------------------------------------------------
%---------------------------------------------------------------------------------------------
function poremovie
% Set Display Property
set(gcf,'defaulttextfontsize',10);
set(gcf,'defaultaxesfontsize',10);
set(gcf,'defaulttextfontname','Times');
set(gcf,'defaultaxesfontname','Times');
orient landscape;
% Input the x y coordinate files
[filetag, pathname] = uigetfile('*.txt','Please open the node coordinate file *.txt',100,100);
[filetag1, pathname] = uigetfile('*.txt','Please Open the element file *.txt',100,100);
% Input the x y Displacement files
filetag4 = inputdlg({'Please enter the name of the 1st pore pressure file',...
'Please enter the name of the 2nd pore pressure file',...
'Please enter the name of the 3rd pore pressure file',...
'Please enter the name of the 4th pore pressure file',...
'Please enter the name of the 5th pore pressure file'},...
'Pore Pressure',[1 1 1 1 1],...
{'PWP1.out','PWP2.out','PWP3.out','PWP4.out','PWP5.out'});
% Define the vaild path
path(path,pathname);
answer = inputdlg({'Please enter the title of the animation',...
'Please name the x axis',...
'Please name the y axis'});
% Define the title and the x y label
display(answer);
title(answer(1));
xlabel(answer(2));
ylabel(answer(3));
nodecoord=load(filetag);
elecoord =load(filetag1);
name1 = char(filetag4(1));
porepressure = load(name1);
for sortcount = 2:1:5
temp = char(filetag4(sortcount));
pores = load(temp);
pores(:,1) = [];
porepressure = cat(2,porepressure,pores );
% dispx(:,sortcount) = load(tempnamex);
% dispy(:,sortcount) = load(tempnamey);
end
dispsize = size(porepressure);
%porepressure=load(filetag4);
[row, col] = size(nodecoord);
tag=nodecoord(1:row,1);
x=nodecoord(1:row, 2);
y=nodecoord(1:row, 3);
% Define Control Parameter
N = dispsize(1);
drawswitch=size(elecoord);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% this proceduce is used to generate the best fix axis %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (min(x) >= 0)
xmin= (min(x)-0.5*(max(x)+min(x)));%+min(scaleddispx));
xmax= (1.5*max(x));%+max(scaleddispx));
elseif (min(x) <0) & (max(x) >=0)
xmin = (1.5*min(x));
xmax = (1.5*max(x));
else
xmin= (1.5*min(x));%+min(scaleddispx));
xmax= (0.5*max(x));
end
if (min(y) >= 0)
ymin= (0.5*min(y));%+min(scaleddispx));
ymax= (1.2*max(y));%+max(scaleddispx));
elseif (min(y) <0) & (max(y) >=0)
ymin = (1.5*min(y));
ymax = (1.5*max(y));
else
ymin= (1.5*min(y));%+min(scaleddispx));
ymax= (0.5*max(y));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
prompt = {'Please enter the lower limit of the x axis below:',...
'Please enter the upper limit of the x axis below:',...
'Please enter the lower limit of the y axis below:',...
'Please enter the upper limit of the y axis below:'};
def= {num2str(xmin),num2str(xmax),num2str(ymin),num2str(ymax)};
dlgtitle ='Input for intervals';
limitanswer = inputdlg(prompt, dlgtitle,[1 2 3 4], def);
display(limitanswer);
% figure;
axislimits = str2double(limitanswer);
% display(axisstring);
% axislimits = eval(answer);
display(axislimits);
hold on;
disp(N);
set(gcf,'DoubleBuffer','on') % To turn it on
M = moviein(N);
msgbox('To generate higher resolution AVI file, please maximize the screen and press enter',...
'CAUTION','help');
pause; % please maximum the screen
for framenumber = 1:N
title(answer(1));
xlabel(answer(2));
ylabel(answer(3));
hold on;
axis equal;
axis(axislimits);
if (drawswitch(2)<4)
disp(' Case 1: beam element');
for i = 1:1:(drawswitch(1))
x1 = x(elecoord(i,2)-tag(1)+1)+scaleddispx(framenumber,(elecoord(i,2)+1)); % Notice that if the first
x2 = x(elecoord(i,3)-tag(1)+1)+scaleddispx(framenumber,(elecoord(i,3)+1)); % element is not used to
y1 = y(elecoord(i,2)-tag(1)+1)+scaleddispy(framenumber,(elecoord(i,2)+1)); % record the time increment
y2 = y(elecoord(i,3)-tag(1)+1)+scaleddispy(framenumber,(elecoord(i,3)+1)); % then '+1' must deleted.
xarray = [x1 x2];
yarray = [y1 y2];
plot(xarray,yarray,'EraseMode','background');
end
elseif (drawswitch(2)>4)&(drawswitch(2)<8)
for i = 1:(drawswitch(1))
x1 = x(elecoord(i,2)-tag(1)+1)
x2 = x(elecoord(i,3)-tag(1)+1)
x3 = x(elecoord(i,4)-tag(1)+1)
x4 = x(elecoord(i,5)-tag(1)+1)
y1 = y(elecoord(i,2)-tag(1)+1)
y2 = y(elecoord(i,3)-tag(1)+1)
y3 = y(elecoord(i,4)-tag(1)+1)
y4 = y(elecoord(i,5)-tag(1)+1)
% This will add the pore pressure
pore1 = porepressure(framenumber,(elecoord(i,2)+1));
pore2 = porepressure(framenumber,(elecoord(i,3)+1));
pore3 = porepressure(framenumber,(elecoord(i,4)+1));
pore4 = porepressure(framenumber,(elecoord(i,5)+1));
xarray = [x1 x2 x3 x4 x1];
yarray = [y1 y2 y3 y4 y1];
colorfill = [pore1 pore2 pore3 pore4 pore1];
plot(xarray,yarray,'k');
fill(xarray,yarray,colorfill);
end
end
%line(xarray,yarray,'EraseMode','background');
M(:,framenumber) = getframe(gcf);
%mov=addframe(mov,M); % adds the frame into mov
hold off;
%hold on;
xnull = x(length(nodecoord)); %+ scaleddispx(framenumber,(2*length(filetag)+1));
ynull = y(length(nodecoord)); %+ scaleddispy(framenumber,(2*length(filetag)+1));
plot(xnull,ynull);
axis equal;
% axis([-5*max(x) 5*max(x) 1.5*min(y) 1.5*max(y)]);
hold off;
% refresh;
% pause(0.25);
end
% create avi movie file
% low resolution option
%question_ans = questdlg('Do you want to have a AVI output file?',...
% 'OUTPUT', 'Yes', 'No', 'No');
% if strcmp(question_ans,'Yes')
% movie2avi(M,'animation1','fps',8);
% end
%create avi movie file
% high resolution option
question_ans = questdlg('Do you want to have a AVI output file?',...
'OUTPUT', 'Yes', 'No', 'No');
if strcmp(question_ans,'Yes')
movie2avi(M,'structanim','fps',8,'compression','indeo5');
end