function at_stordat_html1(s)
% AT_STORDAT_HTML1 - Creates the main html page used by at_stordat

% Brian Schlining
% 30 Aug 1999

outPath = 'D:\eqpac_bog_web\extern\bog\netcdf\bog\';

fid = fopen([outPath 'at_stordat_main.html'],'wt');

fprintf(fid,'<!doctype html public "-//w3c//dtd html 4.0 transitional//en">\n');
fprintf(fid,'<html>\n');
fprintf(fid,'   <!-- HEADER -->\n');
fprintf(fid,'   <head>\n');
fprintf(fid,'      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n');
fprintf(fid,'      <meta name="Author" content="Brian Schlining">\n');
fprintf(fid,'      <link rel="stylesheet" type="text/css" href="rootstyle.css" title="rootStyle">\n');
fprintf(fid,'      <title>\n');
fprintf(fid,'         Brian Schlining at MBARI\n');
fprintf(fid,'      </title>\n');
fprintf(fid,'   </head>\n');
fprintf(fid,'   <!-- BODY -->\n');
fprintf(fid,'   <body bgcolor="FFFFFF">\n');
fprintf(fid,'      <!-- Title Table -->\n');
fprintf(fid,'      <table border=0 cellspacing=0 cellpadding=0 cols=2 width=606>\n');
fprintf(fid,'         <tr>\n');
fprintf(fid,'            <td rowspan=2 width=236  valign=top>\n');
fprintf(fid,'               <map name="top-dark-bottomleft">\n');
fprintf(fid,'                  <area shape=poly coords="64,9,64,49,130,95,193,49,195,9" href="http://www.mbari.org">\n');
fprintf(fid,'                  <area shape=default nohref>\n');
fprintf(fid,'               </map>\n');
fprintf(fid,'               <img src="images/top-dark-bottomleft3.gif" usemap="#top-dark-bottomleft" border=0 height=106 width=236 align=absbottom alt="MBARI">\n');
fprintf(fid,'            </td>\n');
fprintf(fid,'            <td width=370>\n');
fprintf(fid,'               <img src="images/top-dark-bottomright.gif" border=0 height=50 width=370 align=absbottom>\n');
fprintf(fid,'            </td>\n');
fprintf(fid,'         </tr>\n');
fprintf(fid,'         <tr >\n');
fprintf(fid,'            <td width=236 height=56 valign=top>\n');
fprintf(fid,'\n');
fprintf(fid,'               <div class="title">\n');
fprintf(fid,'                  <!-- Add the page title here -->\n');
fprintf(fid,'                  Stordat Quality Control\n');
fprintf(fid,'               <div>\n');
fprintf(fid,'            </td>\n');
fprintf(fid,'         </tr>\n');
fprintf(fid,'      </table>\n');
fprintf(fid,'      <!-- Content table -->\n');
fprintf(fid,'      <table  width=606 border=0 cellspacing=0 cellpadding=8 cols=2>\n');
fprintf(fid,'         <tr>\n');
fprintf(fid,'            <td width=606 valign=top>\n');
fprintf(fid,'               <div class="cell">\n');
fprintf(fid,'In addition to the equatorial Pacific moorings, ep1 and ep2, MBARI measures');
fprintf(fid,' spectral characteristics using STORDATs at several other sites. The following links are');
fprintf(fid,' the quality control plots of data that we have recently recieved from these STORDAT units:');
fprintf(fid,'<BR><BR>');

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

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

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

end


alat = abs(mlat);
alon = abs(mlon);

ulat = unique(mlat);
ulon = unique(mlon);

% Write out links for known positions
for ilat = 1:length(ulat)
   for ilon = 1:length(ulon)
      good = find(mlat == ulat(ilat) & mlon == ulon(ilon));
      if ~isempty(good)
         fprintf(fid,'<B>%02i%1s %03iW</B><BR>\n',alat(min(good)),elat(min(good)),alon(min(good)));
         for n = 1:length(good)
            [pth nm ext] = fileparts(s(good(n)).filename);
            d = strmatch('Date',s(good(n)).fields,'exact');
            fprintf(fid,'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
            at_stordat_html2(s(good(n)),nm,min(s(good(n)).data(:,d)));
            fprintf(fid,'<A HREF="%s.html">',nm);
            fprintf(fid,'File:%s, Deployed: %s</A><BR>\n', nm, datestr(min(s(good(n)).data(:,d))));
         end
         fprintf(fid,'<BR>');
      end
   end
end

% Write out links for unknown positions
good = find(isnan(mlat) | isnan(mlon));
if ~isempty(good)
   fprintf(fid,'<B>Position Unknown</B><BR>\n');
   for n = 1:length(good)
      [pth nm ext] = fileparts(s(good(n)).filename);
      d = strmatch('Date',s(good(n)).fields,'exact');
      fprintf(fid,'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
      at_stordat_html2(s(good(n)),nm,min(s(good(n)).data(:,d)));
      fprintf(fid,'<A HREF="%s.html">',nm);
      fprintf(fid,'File:%s, Deployed: %s</A><BR>\n', nm, datestr(min(s(good(n)).data(:,d))));
   end
   fprintf(fid,'<BR>');
end


fprintf(fid,'               </div>\n');
fprintf(fid,'            </td>\n');
fprintf(fid,'         </tr>\n');
fprintf(fid,'      </table>\n');
fprintf(fid,'      <map name="bottom2">\n');
fprintf(fid,'         <area shape=poly coords="33,35,33,52,70,52,70,35" href="http://www.mbari.org/~brian">\n');
fprintf(fid,'         <area shape=poly coords="242,34,242,51,326,51,326,34" href="http://mww.mbari.org">\n');
fprintf(fid,'         <area shape=poly coords="356,58,356,73,590,73,590,58" href="http://www.mbari.org">\n');
fprintf(fid,'         <area shape=default nohref>\n');
fprintf(fid,'      </map>\n');
fprintf(fid,'      <img src="images/bottom.gif" width="606" height="74" alt="Bottom" usemap="#bottom2" border=0>\n');
fprintf(fid,'   </body>\n');
fprintf(fid,'</html>\n');

fclose(fid);