load swfl_coast.mat;
lon_coast=lon;
lat_coast=lat;



%cd ../../OUTDRY8r
%fn='calus2008_flt.nc'


%%open float file, get coordinates of trajectories
%% nc=netcdf(fn);
%% x=nc{'x'}(2:end,:);  %last index for for the number of floats %released
%% y=nc{'y'}(2:end,:);
%% close(nc);

%x_=nc_varget(fn,'lon');
%x=x_(2:end,:);

%y_=nc_varget(fn,'lat');
%y=y_(2:end,:);

%z_=nc_varget(fn,'depth');
%z=z_(2:end,:);

%dstart=nc_varget(fn,'dstart');
%ocean_time=nc_varget(fn,'ocean_time');
%ocean_time=ocean_time(2:end);

%cd ../wet/analout


%save floatdat_dry8r x y z ocean_time lat_coast lon_coast


load floatdat_dry8SW
jd=datenum(1968,5,24)+ocean_time./(3600.*24);


load windSWforcdat
%load windforcdat


jd_wind=datenum(1968,5,23)+ wind_time;  %time./(3600.*24);

[B,I,J]=UNIQUE(jd_wind);

Uwind_=interp1(jd_wind(I),Uwind(I),jd);
Vwind_=interp1(jd_wind(I),Vwind(I),jd);

mangle=nc_varget('swf_grid8.nc','angle',[0 0],[-1 -1]);

w=(Uwind+sqrt(-1).*Vwind).*exp(sqrt(-1).*mangle(200,200)); 


nxx=1250;    nyy=800;
Maxis=[-82.2937  -81.7934   26.3304   27.0197];
pax=[177.85 178.1 -38.81 -38.56];


%compos=[.5 .025 .23 .23];
compos=[.35 .12 .15 .15];
fltpos = [0.13 0.11 0.775 0.815]







% %check initial depths,  many NaNs at beginning, values start at t=25
% 
% figure;
% 
% for t=1:length(ocean_time),
% plot(z(t,:),'r.')
% title(['Depths at time ' num2str(t)])
% pause
% end



% %plot initial positions
% figure;
% plot(lon_coast, lat_coast)
% dasp(26)
% pause %for zoom
% hold on
% 
% plot(x(25,1:697),y(25,1:697),'r.')
% title('Initial Float Positions, 1st 25 steps NaN, 1st 100 locs=0')




%plot artificial reef floats





figure;

axes('pos',fltpos)
plot(lon_coast, lat_coast)
dasp(26)
pause %for zoom

xlimp=get(gca,'xlim');
ylimp=get(gca,'ylim');
%hold on

x(find(x==0))=NaN;
y(find(y==0))=NaN;

%fi=1:240;  %upper Calus
%fi=241:657;  %mid lower Calus
fi=658:897;  %artificial reef floats

for t=25:length(ocean_time)-2,
    clf
    figure(1)
    
    
    
    axes('pos',fltpos)
    
    if t<=30,
        
    plot(lon_coast, lat_coast,'k-',x(t,fi),y(t,fi),'r.')%,x(t,50),y(t,50),'b.')
    %set(gca,'xtick',xtickp,'ytick',ytickp)
    title(datestr(jd(t)))
    axis([xlimp ylimp])
    dasp(26)
    
    
    
    
    
    else,
        plot(lon_coast, lat_coast,'k-',x(t,fi),y(t,fi),'r.',...
            x(t-5:t-1,fi),y(t-5:t-1,fi),'b.')%,x(t,50),y(t,50),'b.')
        %set(gca,'xtick',xtickp,'ytick',ytickp)
        axis([xlimp ylimp])
        dasp(26)
        title(datestr(jd(t)))
    end
    
    xlabel('Longitude W')
    ylabel('Latitude N')
    
    theta = 0:.01:2*pi;   % for plotting a circle
    a5=axes('pos',compos);
        p=plot(20*cos(theta),20*sin(theta));
        set(p,'linewidth',2,'color','c');
        axis off;
        dasp;
        hold on;
        plot(0,0,'bo','Markersize',12,'markerfacecolor','b');
        H=quiver(0,0,real(w(t)),imag(w(t)));
        set(H,'linewidth',3,'color','c');
        axis([-20 20 -20 20]);
        mag=sqrt(Uwind_(t).^2+Vwind_(t).^2);
        mag=sprintf('%2.1f m s^-^1',mag);
        text(21.5,6,'Wind','color','black');
        text(21.5,2,'Spd/Dir','color','black');
        text(21.5,-2,mag,'color','black');
    
        %outfile=sprintf('../../OUTWET7SW/pngreefSW/swf_wet_f.%4d.png',t);
        %f = getframe(gcf);
        %[X, map] = frame2im(f);
        %imwrite(X,outfile,'png');

        
        
        
    pause(0.1)
end

