function completed = NBP1201_climate_TS_and_VPR(fname)
%
% =========================================================================
% NBP1201_climate_TS_and_VPR  Version 1.0 17-Jan-2012
%
% Usage:
%   NBP1201_climate_TS_and_VPR(filename)
%
% Description:
%   This MATLAB function opens an VPR log file and the Ross Sea TS
%   climatology.  The climatology is plotted in a light grey background.
%   The recent VPR TS data are plotted in color overlaid on the
%   climatology.
%
% Input:
%   An VPR log data filename
%
% Output:
%   - MATLAB figure
%
% Author:
%   Blair Greenan
%   Bedford Institute of Oceanography
%   Matlab 7.13
%   blair.greenan@dfo-mpo.gc.ca
%
% Revision History:
%
% =========================================================================
%
%
% Check to see if the TS climatology plot already exists.  If so, clear the
% figure for this update
hfig = findobj('Type','Figure');
if (any(hfig == 99))
    clf(99)
end
% If Figure 99 exists, then make it the active figure window.  If Figure 99
% does not exist, then create it.
figure(99)
%
% Set up the color scheme for the TS plot. The Orsi climatology will be set
% as a light grey background
climate_color=[0.8 0.8 0.8];
vpr_color_upcast=[1 0 0];

%#######################################################
%###############   CLIMATE DATA    #####################
%#######################################################
load .\rossclimII_update;
%> whos
% Name              Size                   Bytes  Class     Attributes
%
%  ans               1x11                      22  char
%  batg_array      207x436                 722016  double
%  ggam            207x436x40            28880640  double
%  goxy            207x436x40            28880640  double
%  gprs            207x436x40            28880640  double
%  gptm            207x436x40            28880640  double
%  gsal            207x436x40            28880640  double
%  gtem            207x436x40            28880640  double
%  latg_array      207x436                 722016  double
%  levels           40x1                      320  double
%  long_array      207x436                 722016  double
%
S_all=gsal(:,:,:);
T_all=gtem(:,:,:);
%
%#######################################################
%###############      VPR DATA     #####################
%#######################################################
% Open the VPR log file
eval(['vpr_data = load(''', fname, ''');'])
%

%****************************************************
%******************  PLOT the data    ***************
%****************************************************
% (1) Climate.
B=batg_array(:);
% Use the points which bottom depth is less than 2000m.
r_shallow=find(B(:)<2000);
hold on;
for ii=1:40
    T=T_all(:,:,ii);
    S=S_all(:,:,ii);
    S=S(:);
    T=T(:);
    S=S(r_shallow);
    T=T(r_shallow);
    plot(S,T,'.','color',climate_color,'markersize',1);
    hold on
end
% (2) VPR
plot(vpr_data(:,14),vpr_data(:,15),'r.', 'markersize', 1)
% (3) Temp 1.937 line
set(gca,'xlim', [33 35], 'ylim', [-2.5 2.5])
plot([33 35],[-1.937 -1.937],'k-','color',[0.4 0.4 0.4],'linewidth',0.5);
hold off;
axis square;
xlabel('Salinity');
ylabel('Temperature (\circC)');
title('NBP1201 VPR and Climate TS diagram');
eval(['print -djpeg -r600 S:\VPR\', fname,'.jpg'])

completed = 1;

