clear all;
atr='';
P='';
n=0;
int=[];
t=0;
A=[0 0 0];
B=[1 -1 1];
C=[-1 1 1];
D=[-1 -1 -1];
E=[1 1 -1];
lasterr('');
clc
namef=input('podaj plik, ktory cie interesuje w ''    :');
f=    input('podaj ksztalt punktu w apostrofie       :');
gr=   input('podaj grubosc punktu: 0...1,2...        :');
colr= input('podaj kolor punktu { r g w y b c }      :');
clc
disp('  prosze czekac...');
disp('  ^C - wyjscie');

  eval(['load ' namef],'lasterr');
  if lasterr~='' break 
  end;

   clf reset
   whitebg('w')
   xlabel('X')
   ylabel('Y')
   zlabel('Z')
 
    if namef(2)=='a' atr=A;
      elseif namef(2)=='b' atr=B; 
      elseif namef(2)=='c' atr=C;
      elseif namef(2)=='d' atr=D;
      elseif namef(2)=='e' atr=E;
    end      
             
    namef=strrep(namef,'.dat',' ');
    eval(['int=' namef ';']);
    
    hold on
    colr(2)=f;
    hndl=plot3(int(:,1),int(:,2),int(:,3),colr); 
    set(hndl,'LineWidth',gr); 
    set(hndl,'MarkerSize',gr);
    p=[p,'Trajektorie atraktora (',num2str(atr),')'];  
    title(p);  
    
   
  nn=str2num(namef(3));	%luskanie rozmiaru szescianu

  for i=-nn:nn;
   for j=-nn:nn;
    for k=-nn:nn;
     
     a=linspace(0,k,20);
     b=linspace(j,j,20);
     c=linspace(i,i,20);
     plot3(a,b,c,'m.');
     plot3(b,a,c,'m.');
     plot3(b,c,a,'m.');
     
    end
   end
  end

  if namef(4)~='_'       %wyluskanie kroku
	liczkrok=namef(4:6);
	liczkrok=strrep(liczkrok,'_','.');
	lkrok=1/str2num(liczkrok);
   else
	liczkrok=namef(5:7);
	liczkrok=strrep(liczkrok,'_','. ');
	lkrok=1/str2num(liczkrok);
  end

  hold on
  hndl=plot3(atr(1),atr(2),atr(3),'k.');
  set(hndl,'MarkerSize',18);
  hndl=plot3(E(1),E(2),E(3),'k.');
  set(hndl,'MarkerSize',18);  
  hndl=plot3(B(1),B(2),B(3),'k.');
  set(hndl,'MarkerSize',18);  
  hndl=plot3(C(1),C(2),C(3),'k.');
  set(hndl,'MarkerSize',18);  
  hndl=plot3(D(1),D(2),D(3),'k.');
  set(hndl,'MarkerSize',18);  
  colr(2)='o';

k=0;
n=0;
d=30;     % k¹t obrotu

  while (k~=6)
   k=menu('direction','left','right','up','down','plotflat','quit');
   if (k==2)
    n=n-d;
    view(n,d)
   elseif (k==1)
    n=n+d;
    view(n,d)
   elseif (k==4)
    t=t+d;
    view(n,t)
   elseif (k==3)
    t=t-d;
    view(n,t)
   elseif (k==5) 
	k1=0;
	                   %rysowanie plaszczyzn np. (x=3,Y,Z)
	while (k1~=4)
        k1=menu('plotflat','YZ','XZ','XY','Exit'); 
      
	 if (k1==1) 
	   pml=-nn-lkrok;
	   pmp=nn+lkrok; 
	   tekst='(Y,Z) for X=';
	   figure
  	   axis([-nn nn -nn nn])
	   ylabel('Z')
	   h = uicontrol('Style','pushbutton','Units','normalized', ...
	'String','>>','Position',[.12 0 .10 .05], ...
	'Callback','pml=pml+lkrok;dec1=find(int(:,1)==pml);plot(int(dec1,2),int(dec1,3),colr);title([tekst,num2str(pml)])');
	   h1 = uicontrol('Style','pushbutton','Units','normalized', ...
	'String','<<','Position',[.01 0 .10 .05], ...
	'Callback','pml=pml-lkrok;dec1=find(int(:,1)==pml);plot(int(dec1,2),int(dec1,3),colr);title([tekst,num2str(pml)])');
	   hm = uicontrol('Style','text','Units','normalized', ...
                 'String','--------->>','Position',[0.23 0 .56 .05]);
	    h = uicontrol('Style','pushbutton','Units','normalized', ...
	'String','exit','Position',[.8 0 .2 .05], ...
	'Callback','close(gcf)');
	   
	 elseif (k1==2) 
	   pml=-nn-lkrok;
	   pmp=nn+lkrok; 
	   tekst='(X,Z) for Y=';
	   figure
	   ylabel('Z')
	   h = uicontrol('Style','pushbutton','Units','normalized', ...
	'String','>>','Position',[.12 0 .10 .05], ...
	'Callback','pml=pml+lkrok;dec1=find(int(:,2)==pml);plot(int(dec1,1),int(dec1,3),colr);title([tekst,num2str(pml)])');
	   h1 = uicontrol('Style','pushbutton','Units','normalized', ...
	'String','<<','Position',[.01 0 .10 .05], ...
	'Callback','pml=pml-lkrok;dec1=find(int(:,2)==pml);plot(int(dec1,1),int(dec1,3),colr);title([tekst,num2str(pml)])');
	   hm = uicontrol('Style','text','Units','normalized', ...
                 'String','--------->>','Position',[0.23 0 .56 .05]);
	    h = uicontrol('Style','pushbutton','Units','normalized', ...
	'String','exit','Position',[.8 0 .2 .05], ...
	'Callback','close(gcf)');
	   
	 elseif (k1==3) 
	   pml=-nn-lkrok;
	   pmp=nn+lkrok; 
	   tekst='(X,Y) for Z=';
	   figure
	   ylabel('Y');
	   h = uicontrol('Style','pushbutton','Units','normalized', ...
	'String','>>','Position',[.12 0 .10 .05], ...
	'Callback','pml=pml+lkrok;dec1=find(int(:,3)==pml);plot(int(dec1,1),int(dec1,2),colr);title([tekst,num2str(pml)])');
	   h1 = uicontrol('Style','pushbutton','Units','normalized', ...
	'String','<<','Position',[.01 0 .10 .05], ...
	'Callback','pml=pml-lkrok;dec1=find(int(:,3)==pml);plot(int(dec1,1),int(dec1,2),colr);title([tekst,num2str(pml)])');
	   hm = uicontrol('Style','text','Units','normalized', ...
                 'String','--------->>','Position',[0.23 0 .56 .05]);
	    h = uicontrol('Style','pushbutton','Units','normalized', ...
	'String','exit','Position',[.8 0 .2 .05], ...
	'Callback','close(gcf)');
	   
	 end
        end

   end
  end

   
whitebg
clf 
close    

%--------------------
