% MATLAB script for creating animations of LTRANS v.2
% Original code by Yong Kim  
% Adapted for LTRANS v.2 by Elizabeth North

[ncid, status] = mexnc ( 'open', 'baymouth_grid_macroms.nc')
%[varid,status] = mexnc('INQ_VARID',ncid,'lat_rho')

[lat] = mexnc ( 'get_var_double', ncid, 21 );
[lon] = mexnc ( 'get_var_double', ncid, 25 );
[h] = mexnc ( 'get_var_double', ncid, 18 );

n = 0;
for i = 2:1:109
    if i<1000, blank = '0'; end
    if i<100,  blank = '00'; end
    if i<10,   blank = '000'; end
    fname = ['para1000',blank,num2str(i),'.csv'];
    data = load(fname);

    surf(lon,lat,-h), shading interp
    hold on
    plot3(data(:,3),data(:,4),data(:,1),'b.','MarkerSize',3)
    axis([-76.7 -75.5 36.8 37.5 -30 0])
    hold off
 
    set(gca,'CameraPosition',[-74 35 226])
    %set(gca,'CameraPosition',[-74+.005*n 35+.01*n 220-.1*n]) %To rotate
    n = n+1;
    pause(.1)
    
    %time counter
    simtime = i/24;
    roundsimtime = round(simtime/0.001)*0.001; %round to 0.01 decimal place;
    simtimestr = num2str(roundsimtime)
    timedisplay = ['Day  ' simtimestr]
    text(-75.8,37.35,0,timedisplay)
    
    %Text label
    textlabel = 'LTRANS v.2 test case'
    text(-76,37.4,0,textlabel)
    
    exportfile = ['para1000',blank,num2str(i), '.jpg'] 
    print('-djpeg75', exportfile)
end
