% rot_ang.m
   set(gcf,'Defaultaxesfontsize',8);
% coordinates of the starting point   
   x0=-63;y0=32;
% coordinates of the ending point   
   xd=-64-30/60;yd=30+30/60;
% mean latitude
   phi=31./180*pi;
% set a grid size   
   nx=8;ny=8;
% get angle
%   alf=atan(abs(yd-y0)/abs(xd-x0))
    alf=0
%   dx=20*cos(alf)/111;
%   dy=20*sin(alf)/111;
   dy=20/111;
   dx=dy/cos(phi);
% create a grid

   [xn,yn]=meshgrid(-dx*(nx-1):dx:dx*(nx-1),-dy*(ny-1):dy:dy*(ny-1));

% rotate on angle alf (positive countercclk)
   %alf=-alf
   xrt=xn*cos(alf)-yn*sin(alf);
   yrt=xn*sin(alf)+yn*cos(alf);
   
   xi=xn+xd;yi=yn+yd;
   xx=xrt+xd;yy=yrt+yd;
   
    xx=xx';xx=xx(:);
    yy=yy';yy=yy(:);
    t=length(xx);
 
   plot(xi,yi,'.k')
   hold on
   plot(xi(4:2:12,2:2:10),yi(4:2:12,2:2:10),'sb','markersize',12)
   plot(xi(4:2:12,3:2:9),yi(4:2:12,3:2:9),'*r','markersize',10)
   plot(xi(5:4:10,2),yi(5:4:10,2),'*r','markersize',10)
   plot(xi(7:4:12,10),yi(7:4:12,10),'*r','markersize',10)
   hold off
   k=0;
   for i=[1:15]
       for j=[1:15]
   k=k+1;        
   text(xi(i,j)',yi(i,j)',['   ',num2str(k)],'fontsize',7)
   end
       end
  k=225;
   for i=[1:15]
       for j=[1:4]
   k=k+1;        
   text(ax(i,j)',ay(i,j)',['   ',num2str(k)],'fontsize',7)
   end
       end
  
   grid
   axis tight
   axis equal
   ylabel('Latitude')
   xlabel('Longitude')
   title('Cold Eddy C1; 06/26/2004')
   for i=[1:t]
   text(xx(i),yy(i),[' ',num2str(i)],'fontsize',7);
   end
   
% create coord matrix
   
    coord(:,1)=(1:t)';
    coord(:,2)=-floor(abs(xx));
    coord(:,3)=(abs(xx)-floor(abs(xx)))*60;
    coord(:,4)=floor(yy);
    coord(:,5)=(yy-floor(yy))*60;
    
 xcor(:,2)=[coord(55:-1:47,4);coord(62,4);coord(77:85,4);coord(100,4);...
coord(115:-1:107,4);coord(122,4);coord(137:145,4);coord(160,4);coord(175:-1:167,4)];

 xcor(:,3)=[coord(55:-1:47,5);coord(62,5);coord(77:85,5);coord(100,5);...
coord(115:-1:107,5);coord(122,5);coord(137:145,5);coord(160,5);coord(175:-1:167,5)];

 xcor(:,4)=[coord(55:-1:47,2);coord(62,2);coord(77:85,2);coord(100,2);...
coord(115:-1:107,2);coord(122,2);coord(137:145,2);coord(160,2);coord(175:-1:167,2)];

 xcor(:,5)=[coord(55:-1:47,3);coord(62,3);coord(77:85,3);coord(100,3);...
coord(115:-1:107,3);coord(122,3);coord(137:145,3);coord(160,3);coord(175:-1:167,3)];

  xcor(:,1)=[(55:-1:47)';62;(77:85)';100;...
(115:-1:107)';122;(137:145)';160;(175:-1:167)'];

   
    fid=fopen('mtx_fc1','w');
    fprintf(fid,['%i     %i %6.1f     %i %6.1f   %i\n'],xcor');
    fclose(fid)
 
    
    fid=fopen('mtx_fc1','w');
    fprintf(fid,'  loc#   lat   min      lon    min   c/x\n');
    for i=[1:49]
    fprintf(fid,['   %i     %i %6.1f     %i %6.1f   %i\n'],xcor(i,:));
    if(mod(i,2)~=0)
    fprintf(fid,'CTD\n');
    else
    fprintf(fid,'XBT\n')
    end
    
    end
    fclose(fid)

%%% NEW ADDITION
%%% ===========================================================
%%% ===========================================================
% coordinates of the ending point   
   xd=-64-30/60;yd=30+30/60;
% mean latitude
   phi=31./180*pi;
% set a grid size   
   nx=8;ny=8;
% get angle
%   alf=atan(abs(yd-y0)/abs(xd-x0))
    alf=0
%   dx=20*cos(alf)/111;
%   dy=20*sin(alf)/111;
   dy=20/111;
   dx=dy/cos(phi);
% create a grid
% basic grid
   [xn,yn]=meshgrid(-dx*(nx-1):dx:dx*(nx-1),-dy*(ny-1):dy:dy*(ny-1));
% additional grid   
   [ax,ay]=meshgrid(-dx*(nx+4-1):dx:-dx*(nx),-dy*(ny-1):dy:dy*(ny-1));
   ax=ax+xd;ay=ay+yd;
% rotate on angle alf (positive countercclk)
   %alf=-alf
   xrt=xn*cos(alf)-yn*sin(alf);
   yrt=xn*sin(alf)+yn*cos(alf);
   
   xi=xn+xd;yi=yn+yd;
   xx=xrt+xd;yy=yrt+yd;
   
 
   plot(xi,yi,'.k')
   hold on
   plot(ax,ay,'.k')
   plot(xi(4:2:12,2:2:10),yi(4:2:12,2:2:10),'sb','markersize',12)
   plot(xi(4:2:12,3:2:9),yi(4:2:12,3:2:9),'*r','markersize',10)
   plot(xi(5:4:10,2),yi(5:4:10,2),'*r','markersize',10)
   plot(xi(7:4:12,10),yi(7:4:12,10),'*r','markersize',10)
%  additional grid  
   d2=plot(ax(4:2:12,2:2:4),ay(4:2:12,2:2:4),'sb','markersize',12);
   d3=plot(ax(5:2:12,2:2:4),ay(5:2:12,2:2:4),'*r','markersize',10);
   d4=plot(xi(12,1),yi(12,1),'*r','markersize',10);
   d5=plot(ax(4,3),ay(4,3),'*r','markersize',10);
   hold off
% numbering "old" matrix   
   k=0;
   for i=[1:15]
       for j=[1:15]
   k=k+1;        
   text(xi(i,j)',yi(i,j)',['   ',num2str(k)],'fontsize',7)
   end
       end
% numbering "new" matrix       
  k=225;
   for i=[1:15]
       for j=[1:4]
   k=k+1;        
   text(ax(i,j)',ay(i,j)',['   ',num2str(k)],'fontsize',7)
   end
       end
  
   grid
   axis tight
   axis equal
   ylabel('Latitude')
   xlabel('Longitude')
   title('Cold Eddy C1; 06/27/2004')
   
   xi=xi';xi=xi(:);
   yi=yi';yi=yi(:);
   t=length(xi);
 
   ax=ax';ay=ay';
   ax=ax(:);ay=ay(:);
% "old" matrix
    t=length(xi)
    coord(:,1)=(1:t)';
    coord(:,4)=-floor(abs(xi));
    coord(:,5)=(abs(xi)-floor(abs(xi)))*60;
    coord(:,2)=floor(yi);
    coord(:,3)=(yi-floor(yi))*60;
% "new" matrix     
    t1=length(ax)
    coord1(:,1)=(226:t1+225)';
    coord1(:,4)=-floor(abs(ax));
    coord1(:,5)=(abs(ax)-floor(abs(ax)))*60;
    coord1(:,2)=floor(ay);
    coord1(:,3)=(ay-floor(ay))*60;
% additional coordinates
    vcor=[coord(166,:);coord1((273-225):-4:(241-225),:);...
    coord1(240-225,:);coord1(239-225:4:271-225,:)];

    fid=fopen('mtx_fc1_addition','w');
    fprintf(fid,'  loc#    lon   min      lat    min   c/x\n');
    for i=[1:20]
    fprintf(fid,['   %i     %i %6.1f     %i %6.1f   %i\n'],vcor(i,:)');
    if(mod(i,2)~=0)
    fprintf(fid,'XBT\n');
    else
    fprintf(fid,'CTD\n')
    end
    
    end
    fclose(fid)
  
    gtext(['updated on ',num2str(datestr(now))])