function s = at_stordat_qc
% AT_STORDAT_QC - Shell function for creating the web graphics for the stordats.

% Brian Schlining
% 20 Aug 1999

%=======================
% Read in all the files
%=======================
filepath = '//tsunami.shore.mbari.org/oasis/eqpac/pete/realtimeprc/ftp_nasa/';
files    = getfname([filepath 'stor*.ftp']);
[numFiles c] = size(files);

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

%load stemp
%numFiles = length(s);

%===================================
% Create a map of stordat locations
%===================================
%try
%   axesm('mercator')
%   load coast
%   fillm(lat, long, [0 1 0]);
%   hold on;
%   plotm([s.lat],[s.lon],'ro')
%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(s(i).filename);

   % Position plot
   lat = strmatch('Latitude',s(i).fields);
   long = strmatch('Longitude',s(i).fields);
   try
      mlat = round(nanmedian(s(i).data(:,lat)));
   catch
      mlat = NaN;
   end

   if mlat > 0
      elat = 'N';
   elseif mlat < 0
      elat = 'S';
   else
      elat = ' ';
   end

   try
      mlon = abs(round(nanmedian(s(i).data(:,long))));
   catch
      mlon = NaN;
   end

   mlat = abs(mlat);

   start = min(find(~isnan(s(i).data(:,long))));
   finish = max(find(~isnan(s(i).data(:,long))));


   plot(s(i).data(start,long),s(i).data(start,lat),'go','MarkerFaceColor',[0 1 0]);
   text(s(i).data(start,long),s(i).data(start,lat),'Deployed','Color','g')
   hold on
   plot(s(i).data(finish,long),s(i).data(finish,lat),'ro','MarkerFaceColor',[1 0 0]);
   text(s(i).data(finish,long),s(i).data(finish,lat),'Most Recent','Color','r')
   plot(s(i).data(:,long),s(i).data(:,lat),'k.');
   hold off
   ylabel('Latitude')
   xlabel('Longitude')
   title(['From:' s(i).original_file_name ', Median Position: ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   grid;
   axis equal
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   at_setfontsize
   writegif([outPath 'Pos_' n]);
   close;


   d = strmatch('Date',s(i).fields,'exact');

   % Temperature plot
   t = strmatch('Temperature',s(i).fields);
   plot(s(i).data(:,d),s(i).data(:,t));
   datetick('x',6);
   ylabel(['Temperature (' char(s(i).units(t)) ')'] );
   xlabel('Date')
   title(['From:' s(i).original_file_name ', Temperature at ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   set(gca,'YLim',[20 32])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   at_setfontsize
   writegif([outPath 'Temp_' n]);
   close;

   % ED plot
   t = strmatch('Ed',s(i).fields);
   plot(s(i).data(:,d),s(i).data(:,t));
   datetick('x',6);
   ylabel(char(s(i).units(min(t))))
   xlabel('Date')
   title(['From:' s(i).original_file_name ', Downwelled irradiance at ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   set(gca,'YLim',[0 250])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   legend(s(i).fields(t),-1)
   at_setfontsize
   writegif([outPath 'Ed_' n]);
   close;

   % Lu plot
   t = strmatch('Lu',s(i).fields);

   for xx = 1:length(t)                % Discard the Lu/Lu[CHL] fields
      cs = char(s(i).fields(t(xx)));
      if strcmp(cs(end),']')
         t(xx) = NaN;
      end
   end
   t = t(find(~isnan(t)));

   plot(s(i).data(:,d),s(i).data(:,t));
   datetick('x',6);
   ylabel(char(s(i).units(min(t))))
   xlabel('Date')
   title(['From:' s(i).original_file_name ', Upwelled radiance at ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   set(gca,'YLim',[0 5])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   legend(s(i).fields(t),-1)
   at_setfontsize
   writegif([outPath 'Lu_' n]);
   close;

   % Lw plot
   t = strmatch('Lw',s(i).fields);
   plot(s(i).data(:,d),s(i).data(:,t));
   datetick('x',6);
   ylabel(char(s(i).units(min(t))))
   xlabel('Date')
   title(['From:' s(i).original_file_name ', Water-leaving radiance at ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   set(gca,'YLim',[0 2])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   legend(s(i).fields(t),-1)
   at_setfontsize
   writegif([outPath 'Lw_' n]);
   close;

   % NLw plot
   t = strmatch('Nlw',s(i).fields);
   plot(s(i).data(:,d),s(i).data(:,t));
   datetick('x',6);
   set(gca,'YLim',[-0.1 0.2])
   set(gcf,'PaperUnits',PaperUnits,'PaperPosition',PaperPosition)
   ylabel(char(s(i).units(min(t))))
   xlabel('Date')
   title(['From:' s(i).original_file_name ', Normalized water-leaving radiance at ' num2str(mlat) elat ' ' num2str(mlon) 'W'])
   legend(s(i).fields(t),-1)
   at_setfontsize
   writegif([outPath 'Nlw_' n]);
   close;



end
