function Run_StressCode(imagenum)
% Running a window executable file in MatLab
% Running stress code for monolayer stress microscopy
% copyright Md. Mydul Islam Miku 8/3/16, miku@knights.ucf.edu 


tic
cd ('C:\code\Trac_MSM_Code\Data')

if exist('FEM') ~= 7
    mkdir('FEM');
end

for i=1:imagenum %image number


cd (['C:\code\Trac_MSM_Code\Data\Tractions\Time',num2str(i)]); % specify command directory to Tractions/Time1

copyfile('domain.dat','C:\code\Trac_MSM_Code\Data\Tractions'); %if exist Time1.... TimeN, copying the data
copyfile('traction.dat','C:\code\Trac_MSM_Code\Data\Tractions');

cd ('C:\code\Trac_MSM_Code\Data'); % change the command folder again to run the stress code.

system ('island.exe'); %running the stress code

cd ('C:\code\Trac_MSM_Code\Data\Tractions');

delete ('C:\code\Trac_MSM_Code\Data\Tractions\domain.dat'); %deleting dat file to get new dat files for a new Time set data
delete ('C:\code\Trac_MSM_Code\Data\Tractions\traction.dat');

mkdir(['C:\code\Trac_MSM_Code\Data\FEM\Time',num2str(i)]);

cd (['C:\code\Trac_MSM_Code\Data\Tractions\Time',num2str(i)]);
movefile('C:\code\Trac_MSM_Code\Data\FEM\bforce.dat');
movefile('C:\code\Trac_MSM_Code\Data\FEM\stresses.dat');
movefile('C:\code\Trac_MSM_Code\Data\FEM\node_coords.dat');

end

cd ('C:\code\Trac_MSM_Code\Data') %finally change the directory again

toc
end


%ends the program