%Rev_1km64v_TRMM_analysis.m  August 28, 2014
%This program looks at the 1km data and for now makes plots similar to that
%used for CONSTRAIN.

%first load in all the time values
time_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'time');

%first load in all the z values
z_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'z');

%now the buoya values
buoya_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'BUOYA');

%now the buoyas values
buoyas_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'BUOYAS');

%now all the QCFLUX values (liquid water flux)
QCFLUX_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'QCFLUX');

%now all the QIFLUX values (ice flux)
QIFLUX_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'QIFLUX');

%now all the QTFLUX values (Nonprecipitating water flux (Total))
QTFLUX_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'QTFLUX');

%now all the QTFLUX values (Nonprecipitating water flux (SGS))
QTFLUXS_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'QTFLUXS');

%now all the QPFLUX values (Precipitating-water turbulent flux (Total))
QPFLUX_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'QPFLUX');

%now all the QPFLUXS values (Precipitating-water turbulent flux (SGS))
QPFLUXS_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'QPFLUXS');

%now all the TLFLUX values (LWSE Flux (Total))
TLFLUX_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'TLFLUX');

%now all the TLFLUXS values (LWSE Flux (SGS))
TLFLUXS_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'TLFLUXS');

%now all the Cloud Fraction
CLD_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'CLD_SGS');

%and qn (total cloud water)
QN_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'QN');

%precip flux
PRECIP_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'PRECIP');

%and TKE
TKE_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'TKE');

%TKE_SGS
TKES_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'TKES');

%CWP
CWP_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'CWP');

%IWP
IWP_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'IWP');

%ZINV (inversion height)
ZINV_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'ZINV');

%PREC (surface precip)
PREC_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'PREC');

figure(7)
plot(time_1km, CWP_1km, '-b', 'LineWidth', 3); 
axis([275 277.5 0 100]);
legend('SHOC 1km Revelle',2);
set(gca,'FontSize',16);
xlabel('Time (hours)','FontSize',16,'FontWeight','bold');
ylabel('CWP (g m^{-2})','FontSize',16,'FontWeight','bold');

figure(8)
contourf(time_1km,z_1km,QN_1km,10);
axis([275 277.5 0 15000]);
caxis([0 .08]);
colorbar('location','eastoutside');
set(gca,'FontSize',16);
xlabel('Time (days)','FontSize',16,'FontWeight','bold');
ylabel('Height (m)','FontSize',16,'FontWeight','bold');
title('QN (g kg^{-2}) Revelle 1km','FontSize',16,'FontWeight','bold');

figure(9)
contourf(time_1km,z_1km,CLD_1km,10);
axis([275 277.5 0 15000]);
caxis([0 1]);
colorbar('location','eastoutside');
set(gca,'FontSize',16);
xlabel('Time (days)','FontSize',16,'FontWeight','bold');
ylabel('Height (m)','FontSize',16,'FontWeight','bold');
title('Cloud Fraction Revelle 1km','FontSize',16,'FontWeight','bold');

figure(10)
contourf(time_1km,z_1km,buoya_1km,10);
axis([275 277.5 0 15000]);
caxis([-.004 .004]);
colorbar('location','eastoutside');
set(gca,'FontSize',16);
xlabel('Time (days)','FontSize',16,'FontWeight','bold');
ylabel('Height (m)','FontSize',16,'FontWeight','bold');
title('Buoyancy Production (m^{2} s^{-3}) Revelle 1km','FontSize',16,'FontWeight','bold');

figure(11)
contourf(time_1km,z_1km,TKE_1km,10);
axis([275 277.5 0 15000]);
caxis([0 10]);
colorbar('location','eastoutside');
set(gca,'FontSize',16);
xlabel('Time (days)','FontSize',16,'FontWeight','bold');
ylabel('Height (m)','FontSize',16,'FontWeight','bold');
title('TKE Resolved (m^{2} s^{-2}) Revelle 1km','FontSize',16,'FontWeight','bold');

figure(12)
contourf(time_1km,z_1km,PRECIP_1km,10);
axis([275 277.5 0 15000]);
caxis([0 25]);
colorbar('location','eastoutside');
set(gca,'FontSize',16);
xlabel('Time (days)','FontSize',16,'FontWeight','bold');
ylabel('Height (m)','FontSize',16,'FontWeight','bold');
title('Precip Flux (mm d^{-1}) Revelle 1km','FontSize',16,'FontWeight','bold');

%TABS
TABS_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'TABS');
%WMAX
WMAX_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'WMAX');
%W2
W2_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'W2');

figure(13)
plot(time_1km, WMAX_1km, '-b', 'LineWidth', 3); 
axis([275 277.5 0 120]);
legend('SHOC 1km Revelle',2);
set(gca,'FontSize',16);
xlabel('Time (hours)','FontSize',16,'FontWeight','bold');
ylabel('WMAX (m s^{-1})','FontSize',16,'FontWeight','bold');

figure(14)
contourf(time_1km,z_1km,TABS_1km,10);
axis([275 277.5 0 15000]);
caxis([200 300]);
colorbar('location','eastoutside');
set(gca,'FontSize',16);
xlabel('Time (days)','FontSize',16,'FontWeight','bold');
ylabel('Height (m)','FontSize',16,'FontWeight','bold');
title('Temperature (K) Revelle 1km','FontSize',16,'FontWeight','bold');

figure(15)
contourf(time_1km,z_1km,TABS_1km,100);
axis([275 277.5 0 1000]);
caxis([292 300]);
colorbar('location','eastoutside');
set(gca,'FontSize',16);
xlabel('Time (days)','FontSize',16,'FontWeight','bold');
ylabel('Height (m)','FontSize',16,'FontWeight','bold');
title('Temperature (K) Revelle 1km','FontSize',16,'FontWeight','bold');

figure(16)
contourf(time_1km,z_1km,W2_1km,10);
axis([275 277.5 0 15000]);
caxis([0 5]);
colorbar('location','eastoutside');
set(gca,'FontSize',16);
xlabel('Time (days)','FontSize',16,'FontWeight','bold');
ylabel('Height (m)','FontSize',16,'FontWeight','bold');
title('Vert. Vel. Variance (m^{2} s^{-2}) Revelle 1km','FontSize',16,'FontWeight','bold');

%PW
PW_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'PW');

%PWOBS
PWOBS_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'PWOBS');

%LWP
LWP_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'LWP');

%LHF
LHF_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'LHF');

%LHFOBS
LHFOBS_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'LHFOBS');

%SHF
SHF_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'SHF');

%SHFOBS
SHFOBS_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'SHFOBS');

%RADLWUP
RADLWUP_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'RADLWUP');

%RADLWDN
RADLWDN_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'RADLWDN');

%RADSWUP
RADSWUP_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'RADSWUP');

%RADSWDN
RADSWDN_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'RADSWDN');

%SWNT
SWNT_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'SWNT');

%SWNS
SWNS_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'SWNS');

%LWNT
LWNT_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'LWNT');

%LWNS
LWNS_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'LWNS');

figure(17)
plot(time_1km, LWP_1km, '-b', 'LineWidth', 3); 
axis([275 277.5 0 200]);
legend('SHOC 1km Revelle',2);
set(gca,'FontSize',16);
xlabel('Time (hours)','FontSize',16,'FontWeight','bold');
ylabel('GCSS LWP (g m^{-2})','FontSize',16,'FontWeight','bold');

figure(18)
plot(time_1km, PW_1km, '-b', 'LineWidth', 3); 
hold on;
plot(time_1km, PWOBS_1km, '-k', 'LineWidth', 3); 
hold off;
axis([275 277.5 0 100]);
legend('SHOC 1km Revelle','SHOC 1km Revelle Obs',2);
set(gca,'FontSize',16);
xlabel('Time (hours)','FontSize',16,'FontWeight','bold');
ylabel('Precipitable Water (mm)','FontSize',16,'FontWeight','bold');

figure(19)
plot(time_1km, LHF_1km, '-b', 'LineWidth', 3); 
hold on;
plot(time_1km, LHFOBS_1km, '-k', 'LineWidth', 3);
hold off;
axis([275 277.5 0 200]);
legend('SHOC 1km Revelle','SHOC 1km Revelle Obs',4);
set(gca,'FontSize',16);
xlabel('Time (hours)','FontSize',16,'FontWeight','bold');
ylabel('Latent Heat Flux (W m^{-2})','FontSize',16,'FontWeight','bold');

figure(20)
plot(time_1km, SHF_1km, '-b', 'LineWidth', 3);
hold on;
plot(time_1km, SHFOBS_1km,'-k','LineWidth',3);
hold off;
axis([275 277.5 0 50]);
legend('SHOC 1km Revelle', 'SHOC 1km Revelle Obs',1);
set(gca,'FontSize',16);
xlabel('Time (hours)','FontSize',16,'FontWeight','bold');
ylabel('Sensible Heat Flux (W m^{-2})','FontSize',16,'FontWeight','bold');

figure(21)
plot(time_1km, LWNS_1km, '-b', 'LineWidth', 3);
hold on;
plot(time_1km, RADLWUP_1km(1,:) - RADLWDN_1km(1,:),'-k','LineWidth',3);
hold off;
axis([275 277.5 0 80]);
legend('SHOC 1km Revelle LWNS', 'SHOC 1km Revelle RADLWUP - RADLWDN',3);
set(gca,'FontSize',16);
xlabel('Time (hours)','FontSize',16,'FontWeight','bold');
ylabel('Net Surface LW (W m^{-2})','FontSize',16,'FontWeight','bold');

figure(22)
plot(time_1km, LWNT_1km, '-b', 'LineWidth', 3);
hold on;
plot(time_1km, RADLWUP_1km(63,:) - RADLWDN_1km(63,:),'-k','LineWidth',3);
hold off;
axis([275 277.5 0 300]);
legend('SHOC 1km Revelle LWNT', 'SHOC 1km Revelle RADLWUP - RADLWDN',3);
set(gca,'FontSize',16);
xlabel('Time (hours)','FontSize',16,'FontWeight','bold');
ylabel('Net TOA LW (W m^{-2})','FontSize',16,'FontWeight','bold');

figure(23)
plot(time_1km, SWNS_1km, '-b', 'LineWidth', 3);
hold on;
plot(time_1km, RADSWDN_1km(1,:) - RADSWUP_1km(1,:),'-k','LineWidth',3);
hold off;
axis([275 277.5 0 1500]);
legend('SHOC 1km Revelle SWNS', 'SHOC 1km Revelle RADSWUP - RADSWDN',3);
set(gca,'FontSize',16);
xlabel('Time (hours)','FontSize',16,'FontWeight','bold');
ylabel('Net Surface SW (W m^{-2})','FontSize',16,'FontWeight','bold');

figure(24)
plot(time_1km, SWNT_1km, '-b', 'LineWidth', 3);
hold on;
plot(time_1km, RADSWDN_1km(63,:) - RADSWUP_1km(63,:),'-k','LineWidth',3);
hold off;
axis([275 277.5 0 1500]);
legend('SHOC 1km Revelle SWNT', 'SHOC 1km Revelle RADSWUP - RADSWDN',3);
set(gca,'FontSize',16);
xlabel('Time (hours)','FontSize',16,'FontWeight','bold');
ylabel('Net TOA SW (W m^{-2})','FontSize',16,'FontWeight','bold');

%THTEND
THTEND_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'THTEND');
PRES_1km = readncdf('sam-kp-Rev_1km_64v_TRMM/OUT_STAT/REVELLE_SHOC_128x128x64_1km_64v_10s.nc', 'PRES');

figure(25)
contourf(time_1km,z_1km,THTEND_1km,20);
axis([275 277.5 0 15000]);
caxis([-15 12]);
colorbar('location','eastoutside');
set(gca,'FontSize',16);
xlabel('Time (days)','FontSize',16,'FontWeight','bold');
ylabel('Height (m)','FontSize',16,'FontWeight','bold');
title('L.S. Horiz. Adv. Temp. Tend. (K day^{-1}) Revelle 1km','FontSize',16,'FontWeight','bold');