#!/usr/bin/perl
#
  do "acqPATHs.pl";
  $wdr = $ENV{"QUERY_STRING"};
  if ($wdr ne "") { $wdr .= "/"; }
  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 gsview</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" method="POST">
<hr>
<b>Download PS file </b>(for GSview) &nbsp; &nbsp; &nbsp; 
<input type="button" value="OK" onclick="cancel()"><br>
EOM
  print $htmlbody;
#
  $n = 0;
  opendir(DIR, "$DATAPATH/$wdr");
  while ($fnam = readdir(DIR)) {
    if ($fnam =~ /^(\w+\.)*ps$/) {
      if (-f "$DATAPATH/$wdr$fnam") { $rnam[$n] = $fnam; $n++; }
    }
  }
  closedir(DIR);
  if ($n == 0) {
    print "&nbsp; &nbsp; &nbsp; No PS files found in this directory.\n";
  } else {
    print "&nbsp; &nbsp; &nbsp; Click the filename in the list below.\n";
    print "<table>\n";
    @dnam = sort(@rnam);
    if ($n < 30) { $nl = 5; }
    else { $nl = ($n + 5 - (($n-1) % 6)) / 6; }
    for ($l=0; $l<$nl; $l++) {
      print " <tr>\n";
      for ($c=0; $c<6; $c++) {
        $m = $c*$nl + $l;
        if ($m < $n) {
          $fnm = $dnam[$m];
          print "  <td> &nbsp; <a href=\"/cgi/AMXS/psdload.cgi?$wdr$fnm\">";
          print "$fnm</a></td>\n";
        }
        else { print "  <td> &nbsp; </td>\n"; }
      }
      print " </tr>\n";
    }
    print "</table>\n";
  }
#
  print "</form>\n</body>\n</html>\n";
  exit(0);
