%  Plot_SHIS_RSH_Radiance.m
%
%  Used to evaluate individually processed RSH files
%
%  23 March 2017 ROK UW-SSEC

files = dir('*_rad_pcfilt.nc');
filename = files(1).name;

% Load variables from netCDF file
timeUTC = double(ncread(filename,'timeUTC'));
Latitude = double(ncread(filename,'Latitude'));
Longitude = double(ncread(filename,'Longitude'));
FOVangle = double(ncread(filename,'FOVangle'));
wavenumber = double(ncread(filename,'wavenumber'));
radiance = double(ncread(filename,'radiance'));
%
% Extract 900 cm-1 window channel radiance
ind_900 = 666;
rad_900 = radiance(ind_900,:);
wn_900 = wavenumber(ind_900);
bt_900 = rad2bt(wn_900,rad_900);
%
num_xtrack_fovs = 17;  % This might change!
num_scanlines = size(radiance,2)/num_xtrack_fovs;
%
bt_map_900 = reshape(bt_900,num_xtrack_fovs,num_scanlines);
Latitude_map = reshape(Latitude,num_xtrack_fovs,num_scanlines);
Longitude_map = reshape(Longitude,num_xtrack_fovs,num_scanlines);
%
% Compute brightness temperatures
bt = nan(size(radiance));
for kk = 1:size(radiance,2)
    bt(:,kk) = rad2bt(wavenumber,radiance(:,kk));
end
%
% Plot radiance
figure(1)
clf
%
subplot(3,1,1)
% plot(wavenumber,radiance(:,:)); grid on;
% ylim([0 150]);
% set(gca,'FontSize',12)
% ylabel('S-HIS Radiance')
% xlabel('Wavenumber')
% title(filename,'interpreter','none')
plot(wavenumber,bt(:,:)); grid on;
ylim([190 320]);
xlim([550 2800])
set(gca,'FontSize',12)
ylabel('S-HIS BT (K)')
xlabel('Wavenumber')
title(filename,'interpreter','none')
%
% figure(2)
subplot(3,1,2)
pcolor(bt_map_900)
set(gca,'FontSize',12)
ylabel('X-Track Index')
xlabel('Scanline Number')
title('Window Channel (900 cm^{-1}) Brightness Temperature')
colorbar
%
coastline = load('coast');
%
% figure(3)
% worldmap([35 40],[-125 -115])
% pcolorm(Latitude_map,Longitude_map,bt_map_900)
% plotm(coastline.lat,coastline.long,'k');
% colorbar
% set(gca,'FontSize',12)
% ylabel('Latitude')
% xlabel('Longitude')
% title(filename,'interpreter','none')
%
% figure(4)
subplot(3,1,3)
pcolor(Longitude_map,Latitude_map,bt_map_900)
hold on
plot(coastline.long,coastline.lat,'k');
colorbar
grid on
set(gca,'FontSize',12)
ylabel('Latitude')
xlabel('Longitude')
title('Window Channel (900 cm^{-1}) Brightness Temperature Map')

%
% pause  % to adjust figure size manually
%
outfilename = [filename(1:end-3) '_BT_map'];
saveas(gcf,outfilename,'png')

