% Creates Figure 1 of Kunkel & Faszewski (1995) Biol. Bull. 189:197-198.
% Further process the data to produce info for a KineMage '.kin' file.
clear;
load pa50814a.3d1;
pa = pa50814a;
pa50814a = 1;
[scans cols]=size(pa);
Time= pa(:,2);
x= pa(:,3);
y= pa(:,4);
z= pa(:,5);
SmVbi= pa(:,6);
SmVei= pa(:,7);
uVxi=  pa(:,8);
uVyi=  pa(:,10);
uVzi=  pa(:,12);
for i = 1:14, 
 for j = 1:7,
   ij = (i-1)*7 + j;
   xi(ij)=x(ij);
   yi(ij)=y(ij);
   zi(ij)=z(ij);
   X(i,j)=x(ij);
   Y(i,j)=y(ij);
   XY(i,j)=-(x(ij)^2 + y(ij)^2)^0.5;
   TIM(i,j)=Time(ij);
   uVxy(i,j) =(uVxi(ij)^2 + uVyi(ij)^2+uVzi(ij)^2)^0.5;
   Z(i,j)=z(ij);
   uVx(i,j)=uVxi(ij);
   uVy(i,j)=uVyi(ij);
   uVz(i,j)=-uVzi(ij);
   SmVb(i,j)=SmVbi(ij);
   SmVe(i,j)=SmVei(ij);
  end
end
for j = 1:7,
   dXY(1,j) = 0;
 end 
for i = 2:14,
 for j = 1:7,
   dXY(i,j)=dXY(i-1,j)-((X(i,j)-X(i-1,j))^2 + (Y(i,j)-Y(i-1,j))^2)^0.5;
  end
end
xmax =-2000;

% Load the outline of the follicle

load pa50814a.wri;
[wri,ydi]=size (pa50814a);
magxy=4.3;
for i = 1:wri, 
xout(i)=magxy*(pa50814a(i,1)-180);
yout(i)=-(magxy*(pa50814a(i,2)-300));
zout(i)= 0;
end

% Load the outline of the bracket

load pa50814b.wri;
[wri,ydi]=size (pa50814b);
magxy=4.3;
for i = 1:wri, 
xbrak(i)=magxy*(pa50814b(i,1)-180);
ybrak(i)=-(magxy*(pa50814b(i,2)-300));
end

figure(1);
clf;
colormap([0 0 0]);
whitebg('k');
subplot(2,1,1);
mesh(dXY,Z,uVxy);
hold on;
axis([xmax 0 -300 300 0 200]);
view(-12,20);
xlabel('scan-axis (µm)');
ylabel('Z-axis (µm)');
zlabel('uV-total');
text(120,0,40,'V');
text(-1900,0,0,'A');
text(xmax,200,230,'A. Pattern of proton flux from penultimate follicle');
hold off;
blt;
subplot(2,1,2);
plot (-xout,-yout,'w-');
hold on;
plot (-xbrak,-ybrak,'w:');
plot (-xi,-yi,'w.');
axis([-2800 1000 -1800 1000]);
xlabel('X-axis (µm)');
ylabel('Y-axis (µm)');
text(-2600,700,'B. XY-positions of scans in Z-axis');
text(-150,-800,'scan-axis');
text(-1900,-1100,'1');
text(-1000,-600,'2');
text(100,450,'3');
text(300,100,'anterior');
text(-200,-100,'V');
text(-1700,-900,'A');
text(-2600,-1000,'posterior');
hold off;
blt;
xyz=[x y z];

