% ----------------------- Diplomatikh Ergasia ----------------------------

% -------------- Graphikes Parastaseis apo dedomena Fortran --------------

clear all 
close all

%NR= 13 ;NCH= 17 ;NBL=4; MOMENTS = 35; M0=4;
fid = fopen('Propeller_Graph.txt');
M0  = fscanf(fid,'%g %g',1);
N0  = fscanf(fid,'%g %g',1);
NBL = fscanf(fid,'%g %g',1);
NR  = fscanf(fid,'%g %g',1);
NCH = fscanf(fid,'%g %g',1);
MOMENTS = fscanf(fid,'%g %g',1);
MM=10*(M0+2-1)+1 ;

% Prepare the new file.
vidObj = VideoWriter('Propeller_Movement.avi','Uncompressed AVI');
open(vidObj);

for IN=1:MOMENTS
 %transpose matrix
  face_T = fscanf(fid,'%g %g',[3,NCH*NR*NBL]);
  back_T = fscanf(fid,'%g %g',[3,NCH*NR*NBL]);
  wake_T = fscanf(fid,'%g %g',[3,MM*NBL*(IN)]); %[3,(M0+2)*NBL*(IN)]);
 %RefSurf= fscanf(fid,'%g %g',[3,(N0+2)*(M0)*NBL]);

  for Z=1:NBL ;for M=1:NR 
     K1 = 1   + (M-1)*NCH + (Z-1)*NR*NCH ; 
     K2 = NCH + (M-1)*NCH + (Z-1)*NR*NCH ;
     plot3(face_T(3,K1:K2),face_T(2,K1:K2),face_T(1,K1:K2),'r') %Wing -->(-3,2,1)
     hold on
     plot3(back_T(3,K1:K2),back_T(2,K1:K2),back_T(1,K1:K2),'b')
     hold on
  end ;end 

%   for M=1:(N0+2)*(M0)*NBL
%      plot3(RefSurf(1,M),RefSurf(2,M),RefSurf(3,M),'r*') %Wing -->(-3,2,1)
%      hold on
%   end 

  for I=1:IN
  for Z=1:NBL ;for M=1:MM %(M0+2)       
     %L1 = M + (M0+2)*(Z-1) + (I-1)*(M0+2)*NBL ;
     L1 = M + MM*(Z-1) + (I-1)*MM*NBL ;
     if (I==IN)
     plot3(wake_T(3,L1),wake_T(2,L1),wake_T(1,L1),'b*')
     else
     plot3(wake_T(3,L1),wake_T(2,L1),wake_T(1,L1),'g*')    
     end
%       wake_T(1,L1)
%       wake_T(2,L1)
%       wake_T(3,L1)
%       pause 
     hold on
  end ;end
  end
  xlabel(' x ')  ; xlim([-6.5 0.5]) %; xlim([-1 4])
  ylabel(' y ')  ; ylim([-1 7]) %; ylim([-1 1])
  zlabel(' z ')  ; zlim([-3.5 0.5]) %; zlim([-1 1])
% axis equal
% axis square 
  az =0;%-45 ; %azimuth
  el =0;% 40 ;   %elavation
  view(az,el) %view point specification of plot3D
  
  currFrame = getframe;
  writeVideo(vidObj,currFrame);
  close all

end