function wrt_html2(cruise_name,sect_info,box_cx,box_cy)
% wrt_html(cruise_name,sect_info,box_cx,box_cy)

% This program writes several html files:
% 1) nav_exten.html - displays the clickable map with sections labelled
% 2) cont_[sec_name].html,  vect_[sec_name].html (contour and vector images)
% 3) sec_list.html : a table with links to contour and vector html files,
%        as well as start,end info for each section
% modified from Jules 98/07/17
% further modified to make sec. 508 compliant ("accessibility" protocols)

global CONTOUR_PREFIX VECTOR_PREFIX  NEW_EXTENSION
global XYDATA
global ALLFIG
CONTOUR_PREFIX = 'cont_';
VECTOR_PREFIX = 'vect_';
dday = XYDATA.dday;
year_base = XYDATA.year_base;
x = XYDATA.x; 
y = XYDATA.y;
dpix=72*.2;

%------------------------------ (1) nav_exten.html --------------------
%"_exten" is gif, jpg, or png (probably)
filename = fullfile(ALLFIG.outpath, 'nav_exten.html'); % sprintf('nav_exten.html');
message = sprintf('Writing %s ',filename);
disp(message);
nav_extenfid=fopen(filename,'w');

%generate nav_exten.html

%write the HTML header
fprintf(nav_extenfid,'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n');
fprintf(nav_extenfid,'<html  lang="en">\n');
fprintf(nav_extenfid,'<BODY>\n');
fprintf(nav_extenfid,'<P>Select section by clicking on Capital letter</P>\n');
part1 = '<a href="sec_list.html"> Table of details of all sections</a>';
part2 = '<a href="../index.html"> Back to cruises</a>';
fprintf(nav_extenfid,'<P>%s, or %s</P>\n', part2, part1);
fprintf(nav_extenfid,'<P><MAP NAME="%s">\n\n',cruise_name);
%write the stuff for the hands
for ii=1:length(sect_info)
   %lower left box is for contour
   if sect_info(ii).llnum <= 4
      fprintf(nav_extenfid,'<AREA SHAPE="poly" HREF="%s%s.html" coords="',...
         VECTOR_PREFIX,sect_info(ii).name);
   else
      fprintf(nav_extenfid,'<AREA SHAPE="poly" HREF="%s%s.html" coords="',...
         CONTOUR_PREFIX,sect_info(ii).name);
   end
   fprintf(nav_extenfid,'%3d  ',...
          round([box_cx(ii)-dpix box_cy(ii)+dpix ...
                box_cx(ii)+dpix box_cy(ii)+dpix ...
                box_cx(ii)+dpix box_cy(ii)-dpix ...
                box_cx(ii)-dpix box_cy(ii)-dpix ]));
   fprintf(nav_extenfid,'">\n');
end

%write the trailer (including referring to the file the hand works on')
fprintf(nav_extenfid,'</MAP>\n<IMG USEMAP="#%s" SRC="nav.%s" ALT= "Map showing labelled sections which link to the plots ">',...
   cruise_name, NEW_EXTENSION);
fprintf(nav_extenfid,'</P>\n\n</BODY>\n</HTML>\n');
fclose(nav_extenfid);

disp('Done with nav_exten.html ... on to cont_a.html etc. ');

%----------------------- (2) cont_[sec_name].html --------------------

%now loop through sect_info and write vect_*.html and cont_*.html files
%   llnum code:
%          1 both, long
%          2 both, lat
%          3 both, time
%          4 vec only
%          5 cont only, long
%          6 cont only, lat
%          7 cont only, time
% must convert all the files too. 
for sec_num=1:length(sect_info)
   sec_name=sect_info(sec_num).name;

    for figtype=1:2
      if figtype == 2 & sect_info(sec_num).llnum > 3; break; end;
      if (figtype==1 & sect_info(sec_num).llnum < 5)   %write the vect html file and convert
         thistype=VECTOR_PREFIX;theothertype=CONTOUR_PREFIX;
         thisdesc='vector';theotherdesc='contour';
      else     %write the contour html file and convert
         thistype=CONTOUR_PREFIX;theothertype=VECTOR_PREFIX;
         thisdesc='contour';theotherdesc='vector';
      end

      filename=sprintf('%s%s.html',thistype,sec_name);
      filename = fullfile(ALLFIG.outpath, filename);
      fid=fopen(filename,'w');
      mess = sprintf('Writing to %s',filename);
      disp(mess);
      if (fid<=0)
         error(sprintf('cannot open %s',filename))
      end
      fprintf(fid,'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n');
      fprintf(fid,'<html  lang="en">\n');
      fprintf(fid,'<BODY>\n');
      part1 = '<a href="nav_exten.html">Back to sections</a>';
      part2 = '<a href="../index.html"> back to cruises</a>';
      fprintf(fid,'%s, or %s\n', part1, part2);
      gap = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
      if sect_info(sec_num).llnum < 4
         part2 = sprintf('<a href="%s%s.html"> View %s plot </a>',...
               theothertype, sec_name, theotherdesc);
      else
         part2 = ' ';
      end
      part1 = sprintf('<a href="%s%s.eps"> Download %s (.eps) file </a>',...
               thistype,sec_name,thisdesc);
      fprintf(fid,'<br>%s %s\n', part1, gap);
      fprintf(fid,'%s %s\n', part2, gap);
      fprintf(fid,'<a href="sec_list.html"> Table of details of all sections</a> \n\n');
      longd = '             LONGDESC= "../v_c_longdesc.html" ';
      fprintf(fid,'<IMG  SRC="%s%s.%s"  ALT= "Color-coded plot of ocean currents" \n %s>', ...
         thistype, sec_name, NEW_EXTENSION, longd);
      fprintf(fid,'\n</BODY>\n</HTML>');
      fclose(fid);
   end
end

%------------------------------ sec_list.html ------------------------------

load sectinfo; %reload 
filename = sprintf('sec_list.html');
filename = fullfile(ALLFIG.outpath, filename);
mess = sprintf('Writing %s ',filename);
disp(mess);
fid=fopen(filename,'w');

% Now write out the sec_list.html file (sec. 508)

%here's the top:
fprintf(fid,'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n');
fprintf(fid,'<html  lang="en">\n');
fprintf(fid,'<BODY  BGCOLOR="#FDF5E6" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000">\n');
%fprintf(fid,'<CENTER><P><B>more section details </B></P></CENTER>');
part1 = '<a href="nav_exten.html">Back to sections</a>';
part2 = '<a href="../index.html"> back to cruises</a>';
fprintf(fid,'%s, or %s\n', part1, part2);
fprintf(fid,'<p>\n</p>\n');
%start the table
partone = '<TABLE BORDER=1 CELLSPACING=3 CELLPADDING=3 BGCOLOR="#EEE8AA" ';
parttwo = ' summary="This table gives the details of each cruise track section for which a plot exists." >';
fprintf(fid, '%s\n%s\n', partone, parttwo);
fprintf(fid,'<CAPTION>More Section Details</CAPTION>\n');
fprintf(fid,'<TR>\n');
fprintf(fid,'<TH>section name </TH>\n');
fprintf(fid,'<TH>dday range </TH>\n');
fprintf(fid,'<TH>date range </TH>\n');
fprintf(fid,'<TH>start, end lon </TH>\n');
fprintf(fid,'<TH>start, end lat </TH>\n');
fprintf(fid,'<TH>contour link </TH>\n');
fprintf(fid,'<TH>vector link</A> </TH>\n');
fprintf(fid,'</TR>\n\n');

for ii=1:length(sect_info)
   fprintf(fid,'  <TR>\n');
   fprintf(fid,'  <TH>%s </TH>\n',sect_info(ii).name);
   sect_dday=sect_info(ii).dates;
   fprintf(fid,'  <TD>%5.2f  to %5.2f </TD>\n',sect_dday(1),sect_dday(2));
   fprintf(fid,'  <TD>%s to %s </TD>\n',...
      to_date(year_base,sect_dday(1),'s'),to_date(year_base,sect_dday(2),'s'));
   jj=find((sect_dday(1)<=dday)&(dday<=sect_dday(2)));
   fprintf(fid,'  <TD>start: %5.2f; end: %5.2f </TD>\n',x(jj(1)),x(jj(end)));
   fprintf(fid,'  <TD>start: %5.2f; end: %5.2f </TD>\n',y(jj(1)),y(jj(end)));
   if sect_info(ii).llnum ~= 4
      fprintf(fid,'  <TD><A HREF="cont_%s.html">contour</A> </TD>\n',sect_info(ii).name);
   else
      fprintf(fid,'  <TD>  none  </TD>\n');  % no contour plot
   end
   if sect_info(ii).llnum <= 4
      fprintf(fid,'  <TD><A HREF="vect_%s.html">vector</A> </TD>\n',sect_info(ii).name);
   else
      fprintf(fid,'  <TD>  none  </TD>\n');  % no vector plot
   end
   fprintf(fid,'  </TR>\n');
end

%the last bit
fprintf(fid,'\n</TABLE>\n</BODY>\n</HTML>\n');
fclose(fid);


