clear  all
close all
clc

load FMT.mat
dpath = '/';
p = 'CState6d';
nt = 216;
ts = 20;
dt = 180;
frame = [1*(1:nt)*ts];

time0 = datenum(2017,8,16,0,0,0);
time3 = [time0+(1:nt)*ts*dt./86400];

nxc = 660; nyc = 504; nzc = 50;
xc = [115 115+((1:nxc-1)*0.083333)];
yc = [-15 -15+((1:nyc-1)*0.083333)];
ctl = {'THETA   ' 'SALT    ' 'UVEL    ' 'VVEL    ' 'WVEL    ' 'PHIHYD  ' 'DRHODR  '};nctl = length(ctl);
lev = 1;%% plotting surface level (of 50 levels)


for jt = [1 nt]
    x1 = rdmds([dpath p],frame(jt));
    x1(x1==0)=nan;
    u = squeeze(x1(:,:,:,3));
    v = squeeze(x1(:,:,:,4));
    t = squeeze(x1(:,:,:,1));
    s = squeeze(x1(:,:,:,2));
    
    fig1 = figure;
    colormap(jet)
    subplot(2,2,1)
    pcol(xc,yc,squeeze(t(:,:,lev))');title(['T : ' datestr(time3(jt),30)]);colorbar
    subplot(2,2,2)
    pcol(xc,yc,squeeze(s(:,:,lev))');title('S');colorbar
    subplot(2,2,3)
    pcol(xc,yc,squeeze(u(:,:,lev))');title('U');caxis([-1 1]);colorbar
    subplot(2,2,4)
    pcol(xc,yc,squeeze(v(:,:,lev))');title('V');caxis([-1 1]);colorbar
    
    %% saviung ploty
    set(fig1,'Paperposition',[.5 .5 12 10]);
    set(fig1,'PaperOrientation','portrait');
    savename = ['mitstate_' num2str(jt) ];
    print ('-depsc2', [dpath savename])
    print ('-painters','-dpng', [dpath savename])
    close all
end
