% Replace line below with location of your root directory
cd ~/llc_4320/regions/AMODE/matlab

% Size of domain
nx=720;
ny=886;
nz=90;
suf1=['_' int2str(nx) 'x' int2str(ny)];
suf2=[suf1 'x' int2str(nz)];

% Read horizontal grid information.
% (XC,YC) is longitude/latitude coordinates of centers of grid cells
% (XG,YG) is longitude/latitude coordinates of southwest corners
% hFacC is the landmask of centers of grid cells, 0 is land, >0 is wet
XC=readbin(['../grid/XC' suf1],[nx ny]);
YC=readbin(['../grid/YC' suf1],[nx ny]);
XG=readbin(['../grid/XG' suf1],[nx ny]);
YG=readbin(['../grid/YG' suf1],[nx ny]);
hFacC=readbin(['../grid/hFacC' suf2],[nx ny]);

% Read vertical grid information.
load thk90
dpt=dpt90(1:nz);   % depth of vertical level in m
thk=thk90(1:nz);   % thickness of vertical level in m
clear *90

% The model output is hourly, one file per hour.
% The first 10 digits of filename denote the model
% time step (ts), and I give example below how to
% convert time step to a date (dte).
ts=27936;
dte=ts2dte(ts,25,2011,9,10);

% Example of reading and plotting of level k
% of potential temperature Theta
k=1; % vertical level to plot
fnm=['../Theta/' myint2str(ts,10) '_Theta_15505.8983.1_720.886.90'];
fld=readbin(fnm,[nx ny nz]);
fld(find(hFacC==0))=nan;
figure(1), clf
colormap(jet)
pcolorcen(XC',YC',fld(:,:,k)');
grid on
colorbar
title(['Theta (deg C) at ' int2str(dpt(k)) ' m depth on ' dte])

% Example of reading and plotting of level k
% of zonal velocity U
k=10; % vertical level to plot
fnm=['../U/' myint2str(ts,10) '_U_15505.8983.1_720.886.90'];
fld=readbin(fnm,[nx ny nz]);
fld(find(hFacC==0))=nan;
figure(2), clf
colormap(jet)
pcolorcen(XC',YC',fld(:,:,k)');
grid on
colorbar
title(['Zonal velocity U (m/s) at ' int2str(dpt(k)) ' m depth on ' dte])

% Example of reading and plotting of level k
% of meridional velocity V
k=20; % vertical level to plot
fnm=['../V/' myint2str(ts,10) '_V_15505.8982.1_720.886.90'];
fld=readbin(fnm,[nx ny nz]);
fld(find(hFacC==0))=nan;
figure(3), clf
colormap(jet)
pcolorcen(XC',YC',fld(:,:,k)');
grid on
colorbar
title(['Meridional velocity (m/s) at ' int2str(dpt(k)) ' m depth on ' dte])
