#!/usr/bin/perl
#
sub htencode {
    local($htencd) = shift;
    $htencd =~ s/&/&amp;/g;
    $htencd =~ s/"/&quot;/g;
    $htencd =~ s/</&lt;/g;
    $htencd =~ s/>/&gt;/g;
    $htencd;
}
  do "acqPATHs.pl";
  $acd = $ENV{"QUERY_STRING"};
  if ($acd =~ /^[a-e]$/) {
    $path = "$AMDBPATH/reg/$acd.gd";
  } else {
    $path = "$AMDBPATH/grd/$acd.gd";
  }
  print "Content-type: text/html; charset=iso-8859-1\n\n";
#
  $htmlbody =<<EOM;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<link rel="stylesheet" type="text/css" href="/AMXS/amxs.css">
<title>AMXS headdb</title>
<script type="text/javascript">
<!--
function cancel() {
  location.replace("/AMXS/forms/blank.html");
}
//-->
</script>
</head>
<body bgcolor="ivory" style="margin: 4px 7px;">
<form name="FM">
<hr>
<b>[ head -2 &nbsp; __ACD__.gd ]</b> &nbsp; &nbsp; &nbsp; &nbsp;
 <input type="button" value="OK" onclick="cancel()"><br>
EOM
  $htmlbody =~ s/__ACD__/$acd/;
  print $htmlbody;
#
  if (open(IN, "head -2 $path 2>&1 |")) {
    print "<pre>\n";
    $line = <IN>;
      $nc1 = substr($line,8,4); $nc2 = substr($line,12,4);
      if ($nc2 eq "    ") {
        $nc = $nc1+0;
        if (($nc<0) || ($nc>=400)) { $nc = -1; }
        elsif ($nc<200) { $nc += 800; }
        else { $nc -= 200; }
      } else { $nc = $nc2+0; }
      print "<pre>\n"; print &htencode("#--- Ncoord = " . $nc . "\n");
    print &htencode($line);
    $line = <IN>; print &htencode($line);
    print "</pre>\n";
    close(IN);
  } else {
    print "\n<font color=\"red\"><b>ERROR:</b></font>\n";
    print " File open fail.\n";
  }
#
  print "</form>\n</body>\n</html>\n";
  exit(0);
