#!/usr/bin/perl -w
#
# Perl code
# to convert contents of "clon_inventory" database from "clondb1"
# from "mysql" to "html" format
# to have a Place/Level view of all electronics in Hall B
#
#
#  SP, 06-Oct-2008


use DBI;
use Env;
sub HTML_open($$$);
sub HTML_close();
sub HTML_Rack($);
sub HTML_Rack_footnote();
sub HTML_Block_header($$);
sub HTML_Block($$);
sub HTML_Block_footnote();


#  Perl code:
#  ----------

#  init
$database        = "clon_inventory";
$user            = "clasrun";
$password        = "";
$hostname        = "clondb1";
$HallB_LOCs      = "SFS SFN SCS NCS FC CR Pie 125";
$HallB_RACKs[0]  = "SFS L0-1 L0-2 L0-3 L0-4 L0-5 L0-6 ";
$HallB_RACKs[1]  = "SFS PTarg L1-14 L1-15 L1-16 L1-17 L1-18 L1-19 ".
	                     "L1-20 L1-21 L1-22 L1-23 L1-24 L1-25 ";
$HallB_RACKs[2]  = "Pie dvcs1 dvcs2 dvcs3 ";
$HallB_RACKs[3]  = "SFN L1-1 L1-2 L1-3 L1-4 L1-5 L1-6 L1-7 L1-8 L1-9 ";
$HallB_RACKs[4]  = "SFN L1-10 L1-11 L1-12 L1-13 ";
$HallB_RACKs[5]  = "SFN Rack-1 Rack-2 Rack-3 Rack-4 L2-1 L2-2 L2-3 L2-4 L2-5 TestRack2 ";
$HallB_RACKs[6]  = "SFN L2-6 L2-7 L2-8 L2-9 L2-10 ";
$HallB_RACKs[7]  = "SFS L3-11 L3-12 L3-13 L3-14 L3-15 ";
$HallB_RACKs[8]  = "SFN L3-1 L3-2 L3-3 ";
$HallB_RACKs[9]  = "SFN L3-6 L3-7 L3-8 L3-9 L3-10 ";
$HallB_RACKs[10] = "SCS Rack-0 Rack-1 Rack-2 Rack-3 Rack-4 Rack-5 ";
$HallB_RACKs[11] = "NCS Rack-1 ";
$HallB_RACKs[12] = "FC C2-6 C2-7 C2-8 C2-9 C2-10 ";
$HallB_RACKs[13] = "FC C2-1 C2-2 C2-3 C2-4 C2-5 ";
$HallB_RACKs[14] = "FC C3-5 C3-6 C3-7 C3-8 ";
$HallB_RACKs[15] = "FC C3-1 C3-2 C3-3 C3-4 ";
$HallB_RACKs[16] = "CR Rack-1 Rack-2 Rack-3 Rack-4 Rack-5 Rack-6 Rack-7 ";
$HallB_RACKs_NN  = 17;
%BlockColor      = ("empty"    => "#CCCCCC",
		    "3U"       => "#EDEDED",
		    "ADB"      => "#8FBC8F",
		    "CAEN"     => "#FF0000",
		    "CAMAC"    => "#FFFF33",
		    "FASTBUS"  => "#00FFFF",
		    "FB_Power" => "#00BBFF",
		    "LeCroy"   => "#8F8FBD",
		    "NIM"      => "#97694F",
		    "VME"      => "#00FF00",
		    "VME64x"   => "#00FF00",
		    "VXI"      => "#CC66CC",
		    "Cerenkov" => "#996699",
		    "DCLV_PS"  => "#D8D8BF",
		    "DTM133"   => "#CCFF33",
		    "HVPatch"  => "#ADEAEA",
		    "Patch"    => "#33FF99",
		    "Pressure" => "#FFFFFF",
		    "Remote_P" => "#539DC2",
		    "Server"   => "#FFFFBB",
		    "Splitter" => "#CC9933",
		    "Support"  => "#666666",
		    "FAN"      => "#CCFFFF");
$i_rack          = 0;
$Rw1             = 180;
$Rw2             = 150;
$Rw3             = 146;
$Rh1             = 600;
$Rh2             = 560;
$Bww             = 720;
$Bw1             = 30;
$Bw2             = 100;
$Bw3             = 100;
$Bw4             = 150;
$Bw5             = 340;


#  decode command line args
$line=join(" ",@ARGV);
if ($line =~ s/-h//i) {
    die "\n      List of possible HallB_Location and Rack_names:
 ---------------------------------------------------------------------
 CR   Rack-1 Rack-2 Rack-3 Rack-4 Rack-5 Rack-6 Rack-7
 ---------------------------------------------------------------------
                                        |  SFS  L0-1...L0-6
 SFN  L1-1...L1-9, L1-10...L1-13        |  SFS  PTarg, L1-14...L1-25
 SFN  Rack-1...TestRack2, L2-6...L2-10  |
 SFN  L3-1...L3-3, L3-6...L3-10         |  SFS  L3-11...L3-15
 NCS  Rack-1                            |  SCS  Rack-0...Rack-5
 FC   C2-1...C2-5                 (Beam)|  FC   C2-6...C2-10
 FC   C3-1...C3-4                       |  FC   C3-5...C3-8
 Pie  dvcs1, dvcs2, dvcs3               V
\n\n";
# -----------------------------------------------
#   FC   C2-1 ... C2-5, C2-6 ... C2-10
#   FC   C3-1 ... C3-4, C3-5 ... C3-8
#   SCS  Rack-0 ... Rack-5
#   NCS  Rack-1
#   SFS  L0-1 ... L0-6
#   SFS  PTarg.Cryo, L1-14 ... L1-25
#   SFN  L1-1 ... L1-9, L1-10 ... L1-13
#   SFN  L2-2 ... TestRack2, L2-6 ... L2-10
#   SFN  L3-1 ... L3-3, L3-6 ... L3-10
#   SFS  L3-11 ... L3-15
}
if (($#ARGV < 0) || ($#ARGV >2)) {
    die "\n Usage:  Inv_mysql2html.pl HallB_Location Rack_1 Rack_N
     -h  for help\n\n";
}
$HallB_Location = $ARGV[0];
$Rack_1         = $ARGV[1];
$Rack_N         = $ARGV[2];

#print "\nARGV=========>>$#ARGV<<\n";
#print "line=========>>$line<<\n";
#print "ARGV[0,1,2]==>>$HallB_Location, $Rack_1, $Rack_N<<\n\n";


#  check command line args
if (!($HallB_LOCs =~ m/$HallB_Location/)) {
    die "\n Wrong \"HallB_Location\"   Help: Inv_mysql2html.pl -h\n\n"; }

for ($ii=0; $ii<$HallB_RACKs_NN; $ii++) {
    if (($HallB_RACKs[$ii] =~ m/$HallB_Location /i) &&
	($HallB_RACKs[$ii] =~ m/ $Rack_1 /i) &&
	($HallB_RACKs[$ii] =~ m/ $Rack_N /i)) { $ii += 200; }
}
if ($ii < 200) {
    die "\n Wrong combination of HallB_Location and Rack_names\n\n"; }
else { $ii -= 201; }

@RRR  = split(" ",$HallB_RACKs[$ii]);
$RRRn = $#RRR;
#print ">> @RRR;; RRRn=$RRRn;;\n";
#print ">> 0=$RRR[0], 1=$RRR[1], 5=$RRR[5];;\n";

$RRRn1 = $RRRn2 = 0;
for ($kk=1; $kk<=$RRRn; $kk++) {
    if ($RRR[$kk] =~ m/$Rack_1/i) { $RRRn1 = $kk; }
    if ($RRR[$kk] =~ m/$Rack_N/i) { $RRRn2 = $kk; }
}
if (($RRRn1 == 0) || ($RRRn2 == 0)) {
    die "\n Lost Rack_name: RRRn1=$RRRn1=$RRR[$RRRn1] RRRn2=$RRRn2=$RRR[$RRRn2]\n\n"; }
if ($RRRn1 > $RRRn2) {
    $RRRnt = $RRRn2; $RRRn2 = $RRRn1; $RRRn1 = $RRRnt;
    for ($kk=$RRRn1;$kk<=$RRRn2;$kk++) { $RRRt[$RRRn2+$RRRn1-$kk] = $RRR[$kk];}
    for ($kk=$RRRn1;$kk<=$RRRn2;$kk++) { $RRR[$kk] = $RRRt[$kk];}
}


#  connect to database
($dbh = DBI->connect("DBI:mysql:$database:$hostname", $user, $password))
    || die "Failed to connect to MySQL database\n";


#  design Header in HTML
HTML_open($HallB_Location,$Rack_1,$Rack_N);
print "\n";


#  design Rack structure in HTML
for ($kk=$RRRn1; $kk<=$RRRn2; $kk++) {
    $Rack_tmp = $RRR[$kk];
    print "Rack_tmp=$Rack_tmp,  kk=$kk\n";
    HTML_Rack($Rack_tmp);
}
HTML_Rack_footnote();


#  design Block table structure in HTML
for ($kk=0; $kk<$i_rack; $kk++) {
    print "------------------------------------------------------------\n";
    print "Rack_block_i{$Rack_name[$kk]}=$Rack_block_i{$Rack_name[$kk]}\n";
    for ($jj=0; $jj<$Rack_block_i{$Rack_name[$kk]}; $jj++) {
	HTML_Block_header($kk,$jj);
	HTML_Block($kk,$jj);
	HTML_Block_footnote();
    }
}


#  design Footnote in HTML and close HTML
HTML_close();


#  done
$dbh->disconnect;
print "\n";

exit(0);


# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------


sub HTML_open($$$) {
    my $loc_tmp   = $_[0];
    my $rack1_tmp = $_[1];
    my $rack2_tmp = $_[2];

#print "$loc_tmp, $rack1_tmp, $rack2_tmp\n";

#  make a local directory and open HTML_FILE
    $dirname = "SP";
    if (! -e $dirname) {system("mkdir $dirname");}
    open HTML_FILE, ">$dirname/$loc_tmp.$rack1_tmp.$rack2_tmp.html" or die $!;

#  get location description
    $sql_cmd = "SELECT LOC2_Description FROM Loc2 WHERE LOC2_Name='$loc_tmp'";
    ($sth=$dbh->prepare($sql_cmd)) || die "Can't prepare $sql_cmd: $dbh->errstr\n";
    ($sth->execute)                || die "Can't execute the query: $sth->errstr\n";
    @row= $sth->fetchrow_array();
    my $loc_tmp_name = $row[0];

#  put a header to HTML_FILE
#   <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
#   <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1251\">
# "
    print HTML_FILE "
<html>
<head>
   <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
   <title>$loc_tmp_name,  Racks $rack1_tmp to $rack2_tmp</title>
</head>
<body bgcolor=\"#CCCCCC\">
<a name=\"top\"></a>


<center>
<a href=\"#RR\"><hr></a>\n
<h1><font color=\"#009900\"> $loc_tmp_name,  Racks $rack1_tmp to $rack2_tmp
</font></h1>\n\n
<a name=\"RR\"></a>
<table border=\"0\" cellspacing=\"0\">
<tr>";
}

sub HTML_close() {
    my $sec;
    my $min;
    my $hour;
    my $mday;
    my $mon;
    my $year;
    my $wday;
    my $yday;
    my $isdst;

    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
    $year += 1900;
    $month_of_year = ('January', 'February', 'March',
		      'April',   'May',      'June',
		      'July',    'August',   'September',
		      'October', 'November', 'December')[$mon];
    $mon++;
    $day_of_week   = ('Sunday',   'Monday',
		      'Tuesday',  'Wednesday',
		      'Thursday', 'Friday', 'Saturday')[$wday];


#  put a Footnote in HTML and close HTML
    print HTML_FILE "\n

<!--  ###############     Signature     ###############  -->

<center>
<br><br>
<a href=\"#RR\"><hr></a>
<!-- <font face=\"Helvetica,Arial\"><font size=-1> -->
<h5>
<a href=\"http://www.jlab.org/~sergpozd\">Home page</a>
&nbsp;&nbsp;&nbsp;
<font color=\"#FF3300\">|</font>
&nbsp;&nbsp;&nbsp;
Last updated: $month_of_year $mday, $year.
&nbsp;&nbsp;&nbsp;
<font color=\"#FF3300\">|</font>
&nbsp;&nbsp;&nbsp;
<a href=\"mailto:sergpozd\@jlab.org\">
For more information send mail to Serguei A. Pozdniakov</a>
</h5>
<!-- </font></font> -->
</center>\n

</body>
</html>\n";

    close HTML_FILE;
    print "\nDone for today $day_of_week $mon/$mday/$year".
	" ($month_of_year $mday, $year)\n";
}

sub HTML_Rack($) {
    my $rack_tmp      = $_[0];
    my $i_block       = 0;
    my $i_HTML_block  = 0;
    my $p0            = 0;


#  remember Rack name and init Rack_block_i for next use in HTML_Block
    $Rack_name[$i_rack] = $rack_tmp;
    $Rack_block_i{$Rack_name[$i_rack]} = 0;

#  get list of blocks in Rack
    $sql_cmd = "SELECT ITM_ShortName,LOC4_Name,ITM_Description".
	       " FROM Item,Loc2,Loc3,Loc4".
	       " WHERE ITM_Description LIKE '%p%.e%.h%.w%'".
	       " AND ITM_Loc2Id=LOC2_ID".
	       " AND ITM_Loc3Id=LOC3_ID".
	       " AND ITM_Loc4Id=LOC4_ID".
	       " AND LOC2_Name='$HallB_Location' ".
	       " AND LOC3_Name='$Rack_name[$i_rack]' ".
	       " ORDER BY ITM_Description";
    ($sth=$dbh->prepare($sql_cmd)) || die "Can't prepare $sql_cmd: $dbh->errstr\n";
    ($sth->execute)                || die "Can't execute the query: $sth->errstr\n";

    while(@row=$sth->fetchrow_array) {
	$block_name[$i_block]  = $row[0];
	$block_loc4[$i_block]  = $row[1];
	$block_descr[$i_block] = $row[2];
	$block_href[$i_block]  = "12345";

#	if($i_block  == 0) {
#print "\n@row\n---------------\nblock_name  = $block_name[$i_block],
#block_loc   = $block_loc4[$i_block],\nblock_descr = $block_descr[$i_block]\n\n"; }

	if ((($block_name[$i_block] =~ m/crate/i) ||
	     ($block_name[$i_block] =~ m/Mainframe/i)) &&
	    (($block_name[$i_block] =~ m/3U crate/i) ||
	     ($block_name[$i_block] =~ m/ADB/i)      ||
	     ($block_name[$i_block] =~ m/CAMAC/i)    ||
	     ($block_name[$i_block] =~ m/FASTBUS/i)  ||
	     ($block_name[$i_block] =~ m/HV/i)       ||
	     ($block_name[$i_block] =~ m/NIM/i)      ||
	     ($block_name[$i_block] =~ m/VME/i)      ||
	     ($block_name[$i_block] =~ m/VXI/i)))
	{
#  remember block names and number of blocks in Rack for next use in HTML_Block
	    $Rack_block_name[$i_HTML_block]{$Rack_name[$i_rack]} = $block_loc4[$i_block];
#print "$Rack_block_name[$i_HTML_block]{$Rack_name[$i_rack]}\n";
	    $block_name[$i_block] = $block_loc4[$i_block];
	    ($clr_key) = split / /, $block_loc4[$i_block];
#  remember block href next use in HTML_Block
	    if ($block_loc4[$i_block] =~ m/"/i) {  # "
		($p,$block_href[$i_block]) = split /"/, $block_loc4[$i_block];  # "
	    }
	    else {
		($block_href[$i_block])    = split / /, $block_loc4[$i_block];
	    }
	    $Rack_block_href[$i_HTML_block]{$Rack_name[$i_rack]} = $block_href[$i_block];
#  remember number of blocks in Rack for next use in HTML_Block
	    $i_HTML_block++;
	    $Rack_block_i{$Rack_name[$i_rack]} = $i_HTML_block;
	}
        elsif ($block_name[$i_block] =~ m/FASTBUS Pow/i)  { $clr_key = "FB_Power";
	    if ($block_loc4[$i_block] =~ m/"/i) {  # "
		($p,$block_href[$i_block]) = split /"/, $block_loc4[$i_block];  # "
	    }
	    else {
		($block_href[$i_block])    = split / /, $block_loc4[$i_block];
	    }
	}
        elsif ($block_name[$i_block] =~ m/Pressure/i)     { $clr_key = "Pressure";
	     $block_href[$i_block]     = "Pressure";
	}
        elsif(($block_name[$i_block] =~ m/DCLV Power D/i) ||
	      ($block_name[$i_block] =~ m/24V Power S/i) ||
	      ($block_name[$i_block] =~ m/DCHV Distr/i))  { $clr_key = "Pressure";
	    $fsz = "";
	    if    ($block_name[$i_block] =~ m/DCHV Distr/i)   { $fsz = 1; }
	    elsif ($block_name[$i_block] =~ m/24V Power S/i)  { $fsz = 2; }
	    ($p,$block_name[$i_block]) = split /  /, $block_descr[$i_block];
	    ($block_href[$i_block])    = split / /,  $block_name[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"$fsz";
	}
        elsif(($block_name[$i_block] =~ m/AC Converter/i) ||
	      ($block_name[$i_block] =~ m/Beam Viewer/i) ||
	      ($block_name[$i_block] =~ m/BPM Temperature/i) ||
	      ($block_name[$i_block] =~ m/BPM Voltage to Freq/i) ||
	      ($block_name[$i_block] =~ m/Camera Pow/i) ||
	      ($block_name[$i_block] =~ m/DVCS-Laser Control/i) ||
	      ($block_name[$i_block] =~ m/Faraday Cup PreAmp/i) ||
	      ($block_name[$i_block] =~ m/Ion Pump P/i) ||
	      ($block_name[$i_block] =~ m/Line Conditioner/i) ||
	      ($block_name[$i_block] =~ m/Manual Channel Set/i) ||
	      ($block_name[$i_block] =~ m/Motor(\d+) Driver/i) ||
	      ($block_name[$i_block] =~ m/Motor Driver/i) ||
	      ($block_name[$i_block] =~ m/Octal Output Chass/i) ||

	      ($block_name[$i_block] =~ m/Tagger Beam Dump T/i) ||
	      ($block_name[$i_block] =~ m/5.5V Power/i) ||
	      ($block_name[$i_block] =~ m/4-way Drive/i)) { $clr_key = "Pressure";
	    ($p,$block_href[$i_block]) = split /  /, $block_descr[$i_block];
	    $fsz = 2;
	    if(($block_name[$i_block] =~ m/Line Conditioner/i) ||
	       ($block_name[$i_block] =~ m/Faraday Cup PreAmp/i)) { $fsz = 1; }
	    ($block_href[$i_block])    = split / /, $block_href[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"$fsz";
	}
        elsif(($block_name[$i_block] =~ m/Down Converter/i) ||
	      ($block_name[$i_block] =~ m/Valve Contr/i)) { $clr_key = "3U";
	    ($block_href[$i_block])    = split / /, $block_name[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"2";
	}
        elsif(($block_name[$i_block] =~ m/Vacuum Pump Manual Control/i) ||
	      ($block_name[$i_block] =~ m/Radiation Device/i)           ||
	      ($block_name[$i_block] =~ m/Delay Box/i)           ||
              ($block_name[$i_block] =~ m/Cerenkov/i))    { $clr_key = "Cerenkov";
	     $block_href[$i_block]     = "Cerenkov";
	     $block_href[$i_block]    .= "\"><font size=\"2";
	     $block_href[$i_block]    .= "\" font color=\"#FFFFFF";
	}
        elsif ($block_name[$i_block] =~ m/Splitter/i)     { $clr_key = "Splitter";
	    $fsz = 2;
	    if ($block_name[$i_block] =~ m/SY595/i) { $fsz = 1; }
	    ($p,$block_name[$i_block]) = split /$Rw2  /, $block_descr[$i_block];
	    ($block_href[$i_block])    = split / /,      $block_name[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"$fsz";
	}
        elsif ($block_name[$i_block] =~ m/Support/i)      { $clr_key = "Support"; }
	elsif(($block_name[$i_block] =~ m/Wire\/Flat/i) ||
	      ($block_name[$i_block] =~ m/LEMO Patch/i) ||
	      ($block_name[$i_block] =~ m/BNC Patch/i))   { $clr_key = "Patch";
	     if   ($block_name[$i_block] =~ m/Wire\/Flat/i) {
		 ($p,$block_href[$i_block]) = split /  /, $block_descr[$i_block];
		 ($block_href[$i_block],$p) = split / /,  $block_href[$i_block];
		 $block_href[$i_block]      = $block_href[$i_block]."_".$p.".pdf";
		 $block_href[$i_block]      = "../../man/Units/".$block_href[$i_block];
		 $block_href[$i_block]     .= "\"><font size=\"2";
	     }
	     elsif($block_name[$i_block] =~ m/Panel 16x8/i) {
		 ($p,$p2)                   = split /  /, $block_descr[$i_block];
		 $block_name[$i_block]      = $block_name[$i_block]." ".$p2;
		 $block_href[$i_block]      = "Panel\"><font size=\"2";
	     }
	     elsif($block_name[$i_block] =~ m/Panel 16 ch/i) {
		 $block_href[$i_block]      = "Panel\"><font size=\"1";
	     }
             else {
		 $block_href[$i_block]      = "Panel\"><font size=\"2";
	     }
	}
	elsif ($block_name[$i_block] =~ m/IDC Patch/i)    { $clr_key = "Splitter";
	    ($p,$block_name[$i_block]) = split /$Rw2  /, $block_descr[$i_block];
	    ($block_href[$i_block])    = split / /,      $block_name[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"2";
	}
	elsif ($block_name[$i_block] =~ m/HV Patch/i)     { $clr_key = "HVPatch";
	    ($p,$block_name[$i_block]) = split /$Rw2  /, $block_descr[$i_block];
	    ($block_href[$i_block])    = split / /,      $block_name[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"2";
	}
	elsif ($block_name[$i_block] =~ m/NIM FAN/i)      { $clr_key = "FAN"; }
	elsif ($block_name[$i_block] =~ m/FASTBUS Blow/i) { $clr_key = "FAN";
	    if ($block_loc4[$i_block] =~ m/"/i) {  # "
		($p,$block_href[$i_block]) = split /"/, $block_loc4[$i_block];  # "
	    }
	    else {
		($block_href[$i_block])    = split / /, $block_loc4[$i_block];
	    }
	}
	elsif ($block_name[$i_block] =~ m/Blower Fan/i)   { $clr_key = "FAN";
	    ($p,$block_href[$i_block]) = split /"/, $block_loc4[$i_block];  # "
	     $block_href[$i_block]    .= "\"><font size=\"2";
	}
        elsif ($block_name[$i_block] =~ m/IBDN Optics/i)  { $clr_key = "Server";
	     $block_href[$i_block]     = "Optics";
	}
        elsif(($block_name[$i_block] =~ m/Ethernet Patc/i) ||
	      ($block_name[$i_block] =~ m/Wireless/i) ||
	      ($block_name[$i_block] =~ m/I\/O Panel/i))  { $clr_key = "Server";
	    ($p,$block_href[$i_block]) = split /  /, $block_descr[$i_block];
	    ($p,$block_href[$i_block]) = split / /, $block_href[$i_block];
	     $block_href[$i_block]     = $p."_".$block_href[$i_block].".pdf";
	     $block_href[$i_block]     = "../../man/Units/".$block_href[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"1";
	}
        elsif ($block_name[$i_block] =~ m/net-to-GPIB/i)  { $clr_key = "Server";
	    ($p,$block_name[$i_block]) = split /"/, $block_descr[$i_block];  # "
	     $block_name[$i_block]     = "GPIB_\"".$block_name[$i_block]."\"";
	    ($p,$block_href[$i_block]) = split /  /, $block_descr[$i_block];
	    ($p,$block_href[$i_block]) = split / /, $block_href[$i_block];
	     $block_href[$i_block]     =~ s/\//./;
	     $block_href[$i_block]     = $p."_".$block_href[$i_block].".html";
	     $block_href[$i_block]     = "../../man/Units/".$block_href[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"1";
	}
	elsif(($block_name[$i_block] =~ m/Optic Converter/i) ||
	      ($block_name[$i_block] =~ m/Fiber Distrib/i) ||
	      ($block_name[$i_block] =~ m/HUB/i) ||
	      ($block_name[$i_block] =~ m/Optic Patch/i)) { $clr_key = "Server";
	    ($p,$block_name[$i_block]) = split /  /, $block_descr[$i_block];
	    ($block_href[$i_block],$p) = split / /,  $block_name[$i_block];
	     if ($block_name[$i_block] =~ m/EN106/i) {
		 $block_name[$i_block] = $p;
		 $block_href[$i_block] = $block_href[$i_block]."_".$p.".pdf";
		 $block_href[$i_block] = "../../man/Units/".$block_href[$i_block]; }
	     $block_href[$i_block]    .= "\"><font size=\"1";
	}
	elsif(($block_name[$i_block] =~ m/Server/i) ||
	      ($block_name[$i_block] =~ m/Switch/i) ||
	      ($block_name[$i_block] =~ m/Workstation/i)) { $clr_key = "Server";
	     if   ($block_descr[$i_block] =~ m/JFS524/i) {
		   $block_name[$i_block]  = "JFS524 Switch 24p";   $p2 = ".pdf"; }
	     elsif(($block_descr[$i_block] =~ m/Edge2850/i) ||
		   ($block_descr[$i_block] =~ m/R5400/i) ||
		   ($block_descr[$i_block] =~ m/X4200/i)) {
		  $p = $block_descr[$i_block];
		 ($p,$block_name[$i_block]) = split /  /, $p;      $p2 = ".pdf"; }
             else {
		   $block_name[$i_block]  = $block_loc4[$i_block]; $p2 = ".html"; 
	     }
	    ($p,$block_href[$i_block]) = split /  /, $block_descr[$i_block];
	    ($block_href[$i_block])    = split /"/,  $block_href[$i_block];  # "
	     @nn_href                  = split / /,  $block_href[$i_block];
#	     $block_href[$i_block]     = join("_",@nn_href);
	     $block_href[$i_block]     = join("_",$nn_href[0],$nn_href[1]);
	     $block_href[$i_block]     = "../../man/Units/".$block_href[$i_block].$p2;
	    $fsz = 2;
	    if (($block_name[$i_block] =~ m/ei24/i) ||
		($block_name[$i_block] =~ m/rs422/i) ||
		($block_name[$i_block] =~ m/Linksys/i) ||
		($block_name[$i_block] =~ m/JFS524/i) ||
		($block_name[$i_block] =~ m/FS105/i))   { $fsz = 1; }
	    $block_href[$i_block]     .= "\"><font size=\"$fsz";
	}
        elsif(($block_name[$i_block] =~ m/DCLV Power S/i) ||
	      ($block_name[$i_block] =~ m/Helium Level/i) ||
	      ($block_name[$i_block] =~ m/Motor Power S/i) ||
	      ($block_name[$i_block] =~ m/Gaussmeter/i) ||
	      ($block_name[$i_block] =~ m/Bipolar/i))     { $clr_key = "DCLV_PS";
	    ($p,$block_name[$i_block]) = split /  /, $block_descr[$i_block];
	     $block_name[$i_block]     =~ s/DC for Region /DCLV_R/;
	     $block_name[$i_block]     =~ s/ Sector /_S/;
	     $block_href[$i_block]     = "../../man/Units/";
	     if ($block_name[$i_block] =~ m/6651A/i) { $p = "HP_6651A.html"; }
             else {
		 ($p,$p2) = split / /,$block_name[$i_block];
		  $p = $p."_".$p2.".pdf";
	     }
	     $block_href[$i_block]    .= $p."\"><font size=\"2";
	}
        elsif(($block_name[$i_block] =~ m/Digital Delay/i) ||
	      ($block_name[$i_block] =~ m/Photon Tagger "OR"/i) ||
	      ($block_name[$i_block] =~ m/Temperature Controller/i) ||
	      ($block_name[$i_block] =~ m/Lock-In Amp/i)) { $clr_key = "DCLV_PS";
	     $block_name[$i_block]     =~ s/Delay\/Pulse //;
	    ($p,$block_href[$i_block]) = split /  /, $block_descr[$i_block];
	    ($p,$block_href[$i_block]) = split / /, $block_href[$i_block];
	    ($block_href[$i_block])    = split /,/, $block_href[$i_block];
             $p2 = ".pdf";
	     if ($block_href[$i_block] =~ m/DG535/i) { $p ="SRS"; $p2 = ".html"; }
	     $block_href[$i_block]     = $p."_".$block_href[$i_block].$p2;
	     $block_href[$i_block]     = "../../man/Units/".$block_href[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"2";
	}
        elsif(($block_name[$i_block] =~ m/Remote Power/i) ||
	      ($block_name[$i_block] =~ m/APC Pro 650/i)) { $clr_key = "Remote_P";
	    ($p,$block_href[$i_block]) = split /  /, $block_descr[$i_block];
	     if ($block_href[$i_block] =~ m/AP9211/i) {
		 $block_name[$i_block] = $block_href[$i_block]; }
	    ($p,$block_href[$i_block]) = split / /, $block_href[$i_block];
	     $block_href[$i_block]     = $p."_".$block_href[$i_block].".pdf";
	     $block_href[$i_block]     = "../../man/Units/".$block_href[$i_block];
	     $fsz = 1;
	     if ($block_href[$i_block] =~ m/PCM815SHNA/i) { $fsz = 2; }
	     $block_href[$i_block]    .= "\"><font size=\"$fsz";
	}
        elsif(($block_name[$i_block] =~ m/Cryogen Level Monitor/i) ||
	      ($block_name[$i_block] =~ m/Cold Cathode Gauge/i) ||
	      ($block_name[$i_block] =~ m/Vacuum SingleGauge/i) ||
	      ($block_name[$i_block] =~ m/Oscillosco/i)) { $clr_key = "FASTBUS";
	    ($p,$block_name[$i_block]) = split /  /, $block_descr[$i_block];
	    ($p,$block_href[$i_block]) = split / /, $block_name[$i_block];
             $p2 = ".html";
	     if(($block_href[$i_block] =~ m/LM500/i) ||
		($block_href[$i_block] =~ m/TPG/i)) {
		 $block_name[$i_block] = $block_href[$i_block];
		 $p2 = ".pdf";
	     }
	     $block_href[$i_block]     = $p."_".$block_href[$i_block];
	     $fsz = 1;
	     if ($block_href[$i_block] =~ m/HPS_943/i) {
		 ($p,$p2,$block_name[$i_block]) = split /  /, $block_descr[$i_block];
		 $fsz = 2;
		 $p2 = ".pdf";
	     }
	     $block_href[$i_block]     = "../../man/Units/".$block_href[$i_block].$p2;
	     $block_href[$i_block]    .= "\"><font size=\"$fsz";
	}
        elsif(($block_name[$i_block] =~ m/DC Power Supply/i) ||
              ($block_name[$i_block] =~ m/Generator  1KHz - 250MHz/i) ||
              ($block_name[$i_block] =~ m/Monitor/i) ||
              ($block_name[$i_block] =~ m/Multimeter/i))  { $clr_key = "FASTBUS";
	    $fsz = 1;
	    if ($block_name[$i_block] =~ m/Monitor/i)     { $fsz = " "; }
	    ($p,$block_name[$i_block]) = split /  /, $block_descr[$i_block];
             $p2 = ".html";
	    if(($block_name[$i_block] =~ m/Acopian 24PH30/i) ||
	       ($block_name[$i_block] =~ m/Sorensen XT/i) ||
	       ($block_name[$i_block] =~ m/Vacuum Mon/i)) { $fsz = 2; $p2 = ".pdf"; }
	    ($p,$block_href[$i_block]) = split / /, $block_name[$i_block];
	    if ($block_name[$i_block] =~ m/Sorensen XT7-6/i) {
		$block_name[$i_block] = "XT 7-6";
	    }
	     $block_href[$i_block]     = $p."_".$block_href[$i_block].$p2;
	     $block_href[$i_block]     = "../../man/Units/".$block_href[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"$fsz";
	}
        elsif ($block_name[$i_block] =~ m/Teslameter/i)   { $clr_key = "DTM133";
	    ($p,$block_name[$i_block]) = split /  /, $block_descr[$i_block];
	       ($block_name[$i_block]) = split / /,  $block_name[$i_block];
	     $block_href[$i_block]     = $block_name[$i_block];
	     $block_href[$i_block]    .= "\"><font size=\"1";
	}
	else {                                              $clr_key = "Pressure"; }

	$block_color[$i_block] = $BlockColor{$clr_key};

	($p,$e,$h,$w) = ($block_descr[$i_block] =~ m/p_(\d+).e_(\d+).h_(\d+).w_(\d+)/);
	$place[$i_block]  = $p + 0;
	$empty[$i_block]  = $e + 0;
	$height[$i_block] = $h + 0;
	$width[$i_block]  = $w + 0;

	if ($place[$i_block] > $p0) {
	    $p = $place[$i_block] - $p0 - $height[$i_block] - $empty[$i_block];
	    if ($p > 0) { $empty[$i_block] += $p; }
	    $p0 = $place[$i_block];
	}

	if ($width[$i_block] != $Rw2) {
	    if (($i_block > 0) && ($place[$i_block] == $place[$i_block-1])) {
		$bnn[$i_block]    = $bnn[$i_block-1] + 1;
		$Sww              = $Sww + $width[$i_block];
		$empty[$i_block]  = 0;
	    }
	    else {
		$bnn[$i_block]    = 1;
		$Sww              = $width[$i_block];
		$height[$i_block] = $height[$i_block] - 2;
	    }
	    $bni           = $bnn[$i_block] + 1;
	    $ww[$i_block]  = ($Rw3 - $Sww) % $bni;
	    $ww[$i_block]  = ($Rw3 - $Sww - $ww[$i_block]) / $bni;
print "  ------for_0   ww[$i_block]=$ww[$i_block]   width[$i_block]=$width[$i_block]\n";
	    for ($ii=1; $ii<$bnn[$i_block]; $ii++) {
		$ww[$i_block-$ii]  = $ww[$i_block];
print "  ------for_1   ww[$i_block-$ii]=$ww[$i_block-$ii]   width[$i_block]=$width[$i_block]\n";
	    }
	}
	else {
	    $bnn[$i_block] = 0;
	    $Sww           = 0;
	}

	$i_block++;
print "  <in>  i_block = $i_block   ";
print "$place[$i_block-1] $empty[$i_block-1] $height[$i_block-1] $width[$i_block-1]\n";
    }

    if ($Rack_name[$i_rack] =~ m/dvcs3/) {
	$Rh1                                               = "230\" bgcolor=\"#CCCCCC\">
  <tr><td></td></tr></table>\n
<table border=\"0\" cellspacing=\"0\" width=\"$Rw1\" height=\"370";
	$Rh2 = 330;
    }
    else {
	$Rh1 = 600;
	$Rh2 = 560;
    }

    if ($i_block == 0) {
	$empty[$i_block]  = $Rh2;
	$width[$i_block]  = $Rw2;
    }
    elsif ($place[$i_block-1] != $Rh2) {
	$empty[$i_block]  = $Rh2 - $place[$i_block-1];
	$width[$i_block]  = $Rw2;
    }

    if (($i_block == 0) || ($place[$i_block-1] != $Rh2)) {
	$place[$i_block]      = 0;
	$height[$i_block]     = 0;
	$block_name[$i_block] = "empty";
	$bnn[$i_block]        = 0;
	$Sww                  = 0;
 	$i_block++;
    }
print "  <out> i_block = $i_block   ";
print "$place[$i_block-1] $empty[$i_block-1] $height[$i_block-1] $width[$i_block-1]\n";


#  put a header of Rack to HTML_FILE
    print HTML_FILE "

<!--  ###############     Rack $Rack_name[$i_rack]     ###############  -->

<td valign=\"top\" align=\"left\">
<table border=\"0\" cellspacing=\"0\" width=\"$Rw1\" height=\"$Rh1\" bgcolor=\"#0066CC\">
  <tr><td valign=\"center\" align=\"center\" height=\"20\">
     <font color=\"#FFFFFF\"><b>                             $Rack_name[$i_rack]
     </font></b></td></tr>
  <tr><td valign=\"top\" align=\"center\">
<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" width=\"$Rw2\" height=\"$Rh2\" bgcolor=\"#CCCCCC\">";


#  put blocks of Rack to HTML_FILE
    for ($ii=0; $ii<$i_block; $ii++)
    {
	if ($bnn[$ii] == 1) {
	    $Sww = 1;
	    print HTML_FILE "
<tr><td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"$Rw3\" bgcolor=\"#CCCCCC\">";
	}

	if ($empty[$ii] != 0) {
	    print HTML_FILE "
  <tr><td height=\"$empty[$ii]\" bgcolor=\"#CCCCCC\"><spacer type=\"block\" height=\"1\"></td></tr>";
	}

	if ($bnn[$ii] == 1) {
	    print HTML_FILE "
  <tr     height=\"$height[$ii]\">";
	}

	if (($bnn[$ii] == 0) && ($Sww == 1)) {
	    $Sww = 0;
	    print HTML_FILE "
    <td  width=\"$ww[$ii-1]\"></td>
  </tr>
</table></td></tr>";
	}

	if     ($block_name[$ii] =~ m/empty/) {}
	elsif (($block_name[$ii] =~ m/Support/i) ||
	       ($block_name[$ii] =~ m/NIM FAN/i)) {
	    print HTML_FILE "
  <tr><td height=\"$height[$ii]\" bgcolor=\"$block_color[$ii]\"><spacer type=\"block\" height=\"1\"></td></tr>";
	}
	else {
	    if ($bnn[$ii] > 0) {
		print HTML_FILE "
    <td  width=\"$ww[$ii]\"></td>
    <td  width=\"$width[$ii]\" bgcolor=\"$block_color[$ii]\"><center>";
	    }
	    else {
		print HTML_FILE "
  <tr>
    <td   height=\"$height[$ii]\" bgcolor=\"$block_color[$ii]\"><center>";
	    }

	    if ($block_href[$ii] =~ m/Units/) {}
	    else {
		$block_href[$ii] = "#$Rack_name[$i_rack]-".$block_href[$ii];
	    }
	    print HTML_FILE "
      <a href=\"$block_href[$ii]\"><b>
                                                   $block_name[$ii]
    </b></a></td>";

	    if (($bnn[$ii] == 0) && ($Sww != 1)) {
		print HTML_FILE "</tr>";
	    }
	}
    }
#  put a table_close of Rack to HTML_FILE
    print HTML_FILE "
</table></td></tr>
</table></td>";


    if ($Rack_name[$i_rack] =~ m/L3-3/) {
	for ($ii=1; $ii<3; $ii++) {
	    print HTML_FILE "

<!--  ###############     Rack dapnia-$ii     ###############  -->

<td valign=\"bottom\" align=\"center\">
<table border=\"0\" cellspacing=\"0\" width=\"180\" height=\"520\" bgcolor=\"#0066CC\">
  <tr><td valign=\"center\" align=\"center\">
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"150\" height=\"480\" bgcolor=\"#CCCCCC\">
  <tr><td height=\"360\" align=\"center\" bgcolor=\"#CCCCCC\"><font size=+2>
dapnia <hr width=\"60\"> cea <hr width=\"60\"> saclay
  </font><br><br><br></td></tr>
</table></td></tr>
</table></td>";
	}
    }

    $i_rack++;
}

sub HTML_Rack_footnote() {

    print HTML_FILE "
</table>
</center>


<!--  ###############     Racks footnote     ###############  -->

<br><br>
<table border=\"0\" cellspacing=\"0\">
  <tr>
    <td width=\"160\" height=\"24\" valign=\"center\" align=\"center\">
    <table border=\"3\" cellspacing=\"0\" width=\"150\">
      <tr><td height=\"12\" bgcolor=\"#666666\"><spacer type=\"block\" height=\"1\"></td>
      </tr></table>
    <td width=\"20\"  align=\"center\"><b> - </b></td>
    <td width=\"200\" align=\"left\"><b>
                                                   Crate or Cable Support
  </b></td></tr>
  <tr>
    <td width=\"160\" height=\"24\" valign=\"center\" align=\"center\">
    <table border=\"3\" cellspacing=\"0\" width=\"150\">
      <tr><td height=\"12\" bgcolor=\"#CCCCCC\"><spacer type=\"block\" height=\"1\"></td>
      </tr></table>
    <td width=\"20\"  align=\"center\"><b> - </b></td>
    <td width=\"200\" align=\"left\"><b>
                                                   Empty place
  </b></td></tr>
  <tr>
    <td width=\"160\" height=\"24\" valign=\"center\" align=\"center\">
    <table border=\"3\" cellspacing=\"0\" width=\"150\">
      <tr><td height=\"12\" bgcolor=\"#CCFFFF\"><spacer type=\"block\" height=\"1\"></td>
      </tr></table>
    <td width=\"20\"  align=\"center\"><b> - </b></td>
    <td width=\"200\" align=\"left\"><b>
                                                    Ventilator, Fan
  </b></td></tr>
</table>
<br>\n";
}

sub HTML_Block_header($$) {
    my $Rii = $_[0];
    my $Bii = $_[1];
    my $Rname = $Rack_name[$Rii];
    my $Bname = $Rack_block_name[$Bii]{$Rack_name[$Rii]};
    my $Bhref = $Rack_block_href[$Bii]{$Rack_name[$Rii]};

#print "Rname=$Rname\; Bname=$Bname\; Bhref=$Bhref\;\n";
    print HTML_FILE "\n

<!--  ###############     $Rname-$Bhref     ###############  -->

<center><table border=0 cols=5 width=\"$Bww\">
<tr>
 <td width=\"$Bw1\"></td>
 <td width=\"$Bw2\"></td>
 <td width=\"$Bw3\"></td>
 <td width=\"$Bw4\"></td>
 <td width=\"$Bw5\"></td>
</tr>
<tr>
 <td colspan=\"5\"><center>
   <br><a name=\"$Rname-$Bhref\"><hr width=90%></a><br>
   <h2><font color=\"#FF00FF\"> $HallB_Location, $Rname, $Bname
   </font></h2></td>
</tr>
<tr>
 <td width=\"$Bw1\"><center>
   <b><font color=\"#009900\"> Slot<br>No
   </font></b></center></td>
 <td width=\"$Bw2\"><center>
   <b><font color=\"#009900\"> Property Tag
   </font></b></center></td>
 <td width=\"$Bw3\"><center>
   <b><font color=\"#009900\"> Serial No
   </font></b></center></td>
 <td width=\"$Bw4\"><center>
   <b><font color=\"#009900\"> Modules
   </font></b></center></td>
 <td width=\"$Bw5\"><center>
   <b><font color=\"#009900\"> Brief functional description
   </font></b></center></td>
</tr>
</table>
</center>";
}

sub HTML_Block($$) {
    my $Rii   = $_[0];
    my $Bii   = $_[1];
    my $Rname = $Rack_name[$Rii];
    my $Bname = $Rack_block_name[$Bii]{$Rack_name[$Rii]};
    my $itt   = 0;

print "Rack_name[$Rii]=$Rname, Rack_block_name[$Bii]{$Rack_name[$Rii]}=$Bname\n";

#  get list of modules (slots) in the Block
    $sql_cmd = "SELECT BFM_Brand, BFM_Format, BFM_Model, LOC5_Name, ".
	       " ITM_ShortName, LOC4_Name, ifnull(ITM_Description,''), ".
	       " ifnull(ITM_PropertyTag,'&nbsp;'), ifnull(ITM_SerialNum,'&nbsp;') ".
	       " FROM Item, BrandFormatModel, Loc2, Loc3, Loc4, Loc5".
	       " WHERE ITM_BrandId=BFM_ID".
	       " AND ITM_Loc2Id=LOC2_ID AND ITM_Loc3Id=LOC3_ID".
	       " AND ITM_Loc4Id=LOC4_ID AND ITM_Loc5Id=LOC5_ID".
	       " AND LOC2_Name='$HallB_Location' ".
	       " AND LOC3_Name='$Rname' ".
	       " AND LOC4_Name='$Bname' ".
	       " ORDER BY LOC5_Name,ITM_Description";
    ($sth=$dbh->prepare($sql_cmd)) || die "Can't prepare $sql_cmd: $dbh->errstr\n";
    ($sth->execute)                || die "Can't execute the query: $sth->errstr\n";


    while(@row=$sth->fetchrow_array) {
	$m_brand[$itt] = $row[0];
	$m_formt[$itt] = $row[1];
	$m_model[$itt] = $row[2];
	$m_slotN[$itt] = $row[3];
	$m_short[$itt] = $row[4];
	$m_loc_4[$itt] = $row[5];
	$m_descr[$itt] = $row[6];
	$m_descr[$itt] =~ s/p_\d+.e_\d+.h_\d+.w_\d+//;
	$m_P_Tag[$itt] = $row[7];
	$m_Ser_N[$itt] = $row[8];
	     @nn_Tag  = split(" ",$m_P_Tag[$itt]);
	if ($#nn_Tag < 0)       { $m_P_Tag[$itt] = '&nbsp;'; }
	     @nn_Ser  = split(" ",$m_Ser_N[$itt]);
	if ($#nn_Ser < 0)       { $m_Ser_N[$itt] = '&nbsp;'; }
#print "$m_brand[$itt]; $m_formt[$itt]; $m_model[$itt]; $m_slotN[$itt];
#       $m_short[$itt]; $m_loc_4[$itt]; $m_descr[$itt] \n";
	$p = $m_loc_4[$itt];
	if    ($m_slotN[$itt] =~ m/SFI/i) {
	    $m_slotN[$itt] =~ s/ slot //;
	}
	elsif ($m_slotN[$itt] =~ m/slot/i) {
	    ($p,$m_slotN[$itt]) = split / /,$m_slotN[$itt]; 
	    $m_slotN[$itt] =~ s/-/ /;
	}
	if ($m_formt[$itt] =~ m/Rack-mounted/i) {
	    if    ($Bname =~ m/CAMAC/)    { $m_formt[$itt] = "CAMAC" }
	    elsif ($Bname =~ m/FASTBUS/i) { $m_formt[$itt] = "FASTBUS" }
	    elsif ($Bname =~ m/NIM/i)     { $m_formt[$itt] = "NIM" }
	    elsif ($Bname =~ m/SY527/i)   { $m_formt[$itt] = "SY527" }
	    elsif ($Bname =~ m/SY1527/i)  { $m_formt[$itt] = "SY1527" }
	    elsif ($Bname =~ m/VME/i)     { $m_formt[$itt] = "VME" }
	    elsif ($Bname =~ m/VXI/i)     { $m_formt[$itt] = "VXI" }
	    elsif ($Bname =~ m/1458/i)    { $m_formt[$itt] = "LeCroyHV" }
	    elsif ($Bname =~ m/3U/i)      { $m_formt[$itt] = "3U" }
	}
	$itt++;
    }

#  put a header of Block table to HTML_FILE
    print HTML_FILE "\n
<center><table border=2 cols=5 width=\"$Bww\" bgcolor=\"#FFFFFF\">\n";

    for ($ii=0; $ii<$itt; $ii++)
    {
	if ($ii == 0) {
	    $td1="td width=\"$Bw1\"";
	    $td2="td width=\"$Bw2\"";
	    $td3="td width=\"$Bw3\"";
	    $td4="td width=\"$Bw4\"";
	    $td5="td width=\"$Bw5\""; }
	else {
	    $td1="td"; $td2="td"; $td3="td"; $td4="td"; $td5="td"; }

	print HTML_FILE "
<tr>
 <$td1>$m_slotN[$ii]</td>
 <$td2>
   <a href=\"https://clonwiki.jlab.org/CLONInv/htdocs/tag2list.php?Tag=$m_P_Tag[$ii]\">
                  $m_P_Tag[$ii]
   </a></td>
 <$td3>$m_Ser_N[$ii]</td>
 <$td4>
   <a href=\"../../man/$m_formt[$ii]/$m_brand[$ii]_$m_model[$ii].html\">
                  $m_brand[$ii] $m_model[$ii]
   </a></td><$td5>
                  $m_short[$ii]  $m_descr[$ii]
 </td>
</tr>\n";
    }
    print HTML_FILE "</table></center>\n";
}

sub HTML_Block_footnote() {

    print HTML_FILE "
<center><table width=\"$Bww\">
  <tr><td valign=\"center\" align=\"right\">
    <a href=\"http://www.jlab.org/~sergpozd\">  Home page</a>
       &nbsp;&nbsp; | &nbsp;&nbsp;
    <a href=\"index.html\">                     Up to higher level</a>
       &nbsp;&nbsp; | &nbsp;&nbsp;
    <a href=\"#top\">                           Back to top</a>
  </td></tr></table>
</center>\n";
}

