function s = at_stordat_ts
% AT_STORDAT_TS - Shell function for creating time series web graphics for the stordats.

% Brian Schlining
% 17 Sep 1999

%=======================
% Read in all the files
%=======================
filepath = '//tsunami.shore.mbari.org/oasis/eqpac/stordat/';
files    = getfname([filepath 'TimeSeries_*.out']);
[numFiles c] = size(files);

for i = 1:numFiles
   fprintf(1,'Reading: %s (%i/%i)\n',deblank(files(i,:)),i,numFiles)
   a{i} = readout([filepath deblank(files(i,:))]);
end

%===============================================
% Create Quality Control Graphs of stordat info
%===============================================
outPath = 'd:\web\extern\bog\images\stordat\';
PaperPosition = [0 0 350 230];
PaperUnits = 'points';
for i = 1:numFiles


   [p n ext] = fileparts(a{i}.Filename);

   % Get lat and lon labels
   mlat = str2num(n(12:13));
   elat = n(14);

   mlon = str2num(n(15:17));
   elon = n(18);
   switch lower(elon)
   case 'w'
      lon = -mlon;
   otherwise
      lon = mlon;
   end

   s{i} = avgout(a{i},lon);

   % get date
   d = s{i}.TIME_TAG;
   fields = fieldnames(s{i});

   % Temperature plot
   if strmatch('T_w',fields)
      plot(d,s{i}.T_w);
      datetick('x');
      ylabel(['Temperature (C^o)'] );
      xlabel('Date')
      set(gca,'YLim',[20 32])
   else
      axes
      text(.3,.5,'No temperature data is avalable')
      axis off
   end
   title(['Temperature at ' num2str(mlat) elat ' ' num2str(mlon) elon])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   at_setfontsize
   writegif([outPath 'Temp_' n]);
   close;

   % ED plot
   t = strmatch('ED',fields);
   Color = lines(length(t));

   for nl = 1:length(t)
      plot(d,getfield(s{i},fields{t(nl)}),'Color',Color(nl,:));
      if nl == 1
         hold on
      end
   end
   hold off
   datetick('x');
   ylabel('\muW cm^-^2 nm^-^1')
   xlabel('Date')
   title(['Downwelled irradiance at ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   set(gca,'YLim',[0 250])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   [lH oH] = legend(fields(t),-1);
   tH = findobj(oH,'Type','Text');
   set(tH,'Interpreter','none')
   at_setfontsize
   writegif([outPath 'Ed_' n]);
   close;

   % Lu plot
   t = strmatch('LU_',fields);
   Color = lines(length(t));

   for nl = 1:length(t)
      plot(d,getfield(s{i},fields{t(nl)}),'Color',Color(nl,:));
      if nl == 1
         hold on
      end
   end
   hold off
   datetick('x');

   ylabel('\muW cm^-^2 nm^-^1 sr^-^1')
   xlabel('Date')
   title(['Upwelled radiance at ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   set(gca,'YLim',[0 5])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   [lH oH] = legend(fields(t),-1);
   tH = findobj(oH,'Type','Text');
   set(tH,'Interpreter','none')
   at_setfontsize
   writegif([outPath 'Lu_' n]);
   close;

   % Lw plot
   t = strmatch('LU0',fields);
   Color = lines(length(t));

   for nl = 1:length(t)
      plot(d,getfield(s{i},fields{t(nl)}),'Color',Color(nl,:));
      if nl == 1
         hold on
      end
   end
   hold off
   datetick('x');

   ylabel('\muW cm^-^2 nm^-^1 sr^-^1')
   xlabel('Date')
   title(['Water-leaving radiance at ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   set(gca,'YLim',[0 2])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   [lH oH] = legend(fields(t),-1);
   tH = findobj(oH,'Type','Text');
   set(tH,'Interpreter','none')
   at_setfontsize
   writegif([outPath 'Lw_' n]);
   close;

   % NLw plot
   t = strmatch('LUWN',fields);
   Color = lines(length(t));

   for nl = 1:length(t)
      plot(d,getfield(s{i},fields{t(nl)}),'Color',Color(nl,:));
      if nl == 1
         hold on
      end
   end
   hold off
   datetick('x');

   ylabel('\muW cm^-^2 nm^-^1 sr^-^1')
   xlabel('Date')
   title(['Normalized water-leaving radiance at ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   set(gca,'YLim',[-0.1 0.2])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   [lH oH] = legend(fields(t),-1);
   tH = findobj(oH,'Type','Text');
   set(tH,'Interpreter','none')
   at_setfontsize
   writegif([outPath 'NLw_' n]);
   close;

   % CHL plot
   t = strmatch('CHL',fields);
   Color = lines(length(t));

   for nl = 1:length(t)
      plot(d,getfield(s{i},fields{t(nl)}),'Color',Color(nl,:));
      if nl == 1
         hold on
      end
   end
   hold off
   datetick('x');

   ylabel('\mug L^-^1')
   xlabel('Date')
   title(['Chlorophyll concentration at ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   set(gca,'YLim',[0 2])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   [lH oH] = legend(fields(t),-1);
   tH = findobj(oH,'Type','Text');
   set(tH,'Interpreter','none')
   at_setfontsize
   writegif([outPath 'NLw_' n]);
   close;


end
