function contour_agc(theSite)
%
%   contour_agc(theSite)
%
%   Program to create colored contour plots of the ADCP agc variable for
%   the Massachusetts Bay Internal Wave Experiment.

%Soupy Alexander, 4/2004

%This Matlab m-file was used to create portions of U.S. Geological Survey 
%Data Series 85. Although this program has been used by the USGS, no 
%warranty, expressed or implied, is made by the USGS or the United States 
%Government as to the accuracy and functioning of the program and related 
%program material nor shall the fact of distribution constitute any such 
%warranty, and no responsibility is assumed by the USGS in connection 
%therewith.

%Citation:  Butman, Bradford, Alexander, P. Soupy, Anderson, S.P., 
%Lightsom, F.L., Scotti, Alberto, and Beardsley, R.C., 2004, The 
%Massachusetts Bay Internal Wave Experiment, August 1998:  Data Report:  
%U.S. Geological Survey Data Series 85, 1 DVD-ROM.

filePath = 'C:\SCHTUFF\MASS_BAY\MBAY_IWAVE\REPORT\DATAFILES\';

% %Full Data Record
% startTime = [1998 08 07 00 00 00];
% endTime = [1998 09 02 00 00 00];
% theStep = 1/24;
% theTickSpace = 2;
% tickCommand = 'datetick(''x'', 6, ''keepticks'', ''keeplimits'')';

% %August 19 - August 24
% startTime = [1998 08 19 00 00 00];
% endTime = [1998 08 25 00 00 00];
% theStep = 5/(24*60);
% theTickSpace = 1;
% tickCommand = 'datetick(''x'', 6, ''keepticks'', ''keeplimits'')';

%August 22
startTime = [1998 08 22 00 00 00];
endTime = [1998 08 23 00 00 00];
theStep = 1/(24*60);
theTickSpace = 2/24;
tickCommand = 'datetick(''x'', 15, ''keepticks'', ''keeplimits'')';

if strcmp(upper(theSite), 'B')
    theFile = '5372adc-a.nc';
    maxDepth = 80;
elseif strcmp(upper(theSite), 'C')
    theFile = '5352adc-a.nc';
    maxDepth = 50;
end

timeRange = julian(startTime):theStep:julian(endTime);
tickTime = julian2datenum(floor(min(timeRange))):theTickSpace:...
    julian2datenum(ceil(max(timeRange)));

theTitle = ['Echo Intensity, Site ' upper(theSite)];


currID = netcdf(fullfile(filePath, theFile), 'nowrite');
theU = currID{'u_1205'}(:);
theU = ridfill_nan(theU);
theV = currID{'w_1204'}(:);
theV = ridfill_nan(theV);
theTime = singleJD(currID{'time'}(:), currID{'time2'}(:));
fileDepth = currID{'depth'}(:);
adcpDepth = [4:2:max(fileDepth)];

theAGC = currID{'AGC_1202'}(:);
theAGC = ridfill_nan(theAGC);
theAGCi = interp2(fileDepth(:)', theTime(:), theAGC, adcpDepth(:), timeRange, 'linear');


figure, orient landscape

%Do the plotting
[c, h] = contourf(julian2datenum(timeRange), adcpDepth, theAGCi');
axis ij
set(gca, 'xtick', tickTime)
xlim([julian2datenum(min(timeRange)-(max(timeRange)-min(timeRange))*0.05) ...
        julian2datenum(max(timeRange)+(max(timeRange)-min(timeRange))*0.05)])
eval(tickCommand);
shading flat
xlabel('Time')
ylabel('Depth (m)')
title(theTitle)
colorbar
ylim([0 maxDepth])
