#!/usr/local/bin/perl
#
# simple test script

use CGI;

$query = new CGI;

$yy = $query->param('yy');
$mm   = $query->param('mm');
$dd   = $query->param('dd');

$year=$yy+1900;
if($year<1996){
    $year+=100;
}
$daystamp= sprintf "%04d/%02d/%02d",$year,$mm,$dd;

# Form the names for the real keograms

$han = sprintf "../HAN.%02d%02d/HAN_%02d%02d%02d.jpg",$yy,$mm,$yy,$mm,$dd;
$muo = sprintf "../MUO.%02d%02d/MUO_%02d%02d%02d.jpg",$yy,$mm,$yy,$mm,$dd;
$kil = sprintf "../KIL.%02d%02d/KIL_%02d%02d%02d.jpg",$yy,$mm,$yy,$mm,$dd;
$kev = sprintf "../KEV.%02d%02d/KEV_%02d%02d%02d.jpg",$yy,$mm,$yy,$mm,$dd;
$abk = sprintf "../ABK.%02d%02d/ABK_%02d%02d%02d.jpg",$yy,$mm,$yy,$mm,$dd;
$lyr = sprintf "../LYR.%02d%02d/LYR_%02d%02d%02d.jpg",$yy,$mm,$yy,$mm,$dd;
$sod = sprintf "../SOD.%02d%02d/SOD_%02d%02d%02d.jpg",$yy,$mm,$yy,$mm,$dd;

# Form the names for the small keograms

$han_s = sprintf "../HAN_s.%02d%02d/HAN_%02d%02d%02d_s.jpg",$yy,$mm,$yy,$mm,$dd;
$muo_s = sprintf "../MUO_s.%02d%02d/MUO_%02d%02d%02d_s.jpg",$yy,$mm,$yy,$mm,$dd;
$kil_s = sprintf "../KIL_s.%02d%02d/KIL_%02d%02d%02d_s.jpg",$yy,$mm,$yy,$mm,$dd;
$kev_s = sprintf "../KEV_s.%02d%02d/KEV_%02d%02d%02d_s.jpg",$yy,$mm,$yy,$mm,$dd;
$abk_s = sprintf "../ABK_s.%02d%02d/ABK_%02d%02d%02d_s.jpg",$yy,$mm,$yy,$mm,$dd;
$lyr_s = sprintf "../LYR_s.%02d%02d/LYR_%02d%02d%02d_s.jpg",$yy,$mm,$yy,$mm,$dd;
$sod_s = sprintf "../SOD_s.%02d%02d/SOD_%02d%02d%02d_s.jpg",$yy,$mm,$yy,$mm,$dd;

$hankasalmi="<IMAGE SRC=\"../not_available.gif\" ALT=\"Not available\">\n";
$sodankyla="<IMAGE SRC=\"../not_available.gif\" ALT=\"Not available\">\n";
$muonio="<IMAGE SRC=\"../not_available.gif\" ALT=\"Not available\">\n";
$kilpisjarvi="<IMAGE SRC=\"../not_available.gif\" ALT=\"Not available\">\n";
$kevo="<IMAGE SRC=\"../not_available.gif\" ALT=\"Not available\">\n";
$abisko="<IMAGE SRC=\"../not_available.gif\" ALT=\"Not available\">\n";
$longyearbyen="<IMAGE SRC=\"../not_available.gif\" ALT=\"Not available\">\n";

if (-e $han_s) {
    $hankasalmi = sprintf "<A HREF=\"%s\"s><IMAGE SRC=\"%s\" ALT=\"%s\"></A>",$han,$han_s,$han;
}

if (-e $sod_s) {
    $sodankyla = sprintf "<A HREF=\"%s\"s><IMAGE SRC=\"%s\" ALT=\"%s\"></A>",$sod,$sod_s,$sod;
}

if (-e $muo_s) {
    $muonio = sprintf "<A HREF=\"%s\"s><IMAGE SRC=\"%s\" ALT=\"%s\"></A>",$muo,$muo_s,$muo;
}

if (-e $kil_s) {
    $kilpisjarvi = sprintf "<A HREF=\"%s\"s><IMAGE SRC=\"%s\" ALT=\"%s\"></A>",$kil,$kil_s,$kil;
}

if (-e $kev_s) {
    $kevo = sprintf "<A HREF=\"%s\"s><IMAGE SRC=\"%s\" ALT=\"%s\"></A>",$kev,$kev_s,$kev;
}

if (-e $abk_s) {
    $abisko = sprintf "<A HREF=\"%s\"s><IMAGE SRC=\"%s\" ALT=\"%s\"></A>",$abk,$abk_s,$abk;
}


if (-e $lyr_s) {
    $longyearbyen = sprintf "<A HREF=\"%s\"s><IMAGE SRC=\"%s\" ALT=\"%s\"></A>",$lyr,$lyr_s,$lyr;
}

#------------------------------------------------------------
# Okay, if there is no directory for the full sized keograms, we'll assume
# the station is closed

$lyr_dir= sprintf "../LYR.%02d%02d",$yy,$mm;

if (! -e $lyr_dir) {
    $longyearbyen = sprintf "<IMAGE SRC=\"../station_closed.gif\" ALT=\"Station closed\">\n";
}

print "Content-type:text/html\n\n";

print <<EndOfHtml;

<HTML>
<HEAD>
<TITLE>FMI/ASC Keograms </TITLE>
<style type="text/css">
a.ind {
  font-family: Arial,Helvetica,sans-serif;
  font-size: 14pt;
  font-weight: bold;
  line-height: normal;
  text-decoration: none;
}
a.ind:hover {
  background-color: #ffffff;
  color: #009900;
}
</style>
<SCRIPT language="Javascript">
    function changecolor(lay) {
    var lay
     document.layers[lay].bgColor = "#00cc00";
     }

    function changeback(lay) {
    var lay
     document.layers[lay].bgColor = "#009900";
     }
</SCRIPT>

</HEAD>

<BODY bgcolor="#ffffff">
<table bgcolor=#009900 width=100% border=0 cellspacing=0 cellpadding=0 align=top>
<tr>
<td width=20></td>
<td width=150 align=left><a href=http://www.fmi.fi><img border=0 src=/fmi_logo.gif></a></td>
<td width=150 align=left><a href=http://www.geo.fmi.fi><img border=0 src=/geo_logo.gif></a></td>
<td width=150 align=right><img src=/search_logo.gif width=150 height=40></td>
<td width=50 align=right halign=center>
<form method="post" action="/cgi-bin/htsearch">
<input type=hidden name=method value=and>
<input type=hidden name=format value=Long>
<input type=hidden name=sort value=Score>
<input type=hidden name=config value=htdig>
<input type=hidden name=restrict value="">
<input type=hidden name=exclude value="">
<input type="text" size="10" name="words" value="">
</form></td>
</tr></table>
<br>
<br>


<h2>FMI/GEO All-sky camera keograms $daystamp</h2>

<P>
Please note that these keograms are <em>raw data</em> thus <em>NOT SUITABLE</em> for 
publicications in this format. If you would like to do research based on our data, 
please contact <A
HREF=\"mailto:Kirsti.Kauristie\@fmi.fi\">Kirsti.Kauristie\@fmi.fi</A> for 
    detailed instrument description, proper keograms and data interpretation. The camera in Sodankyl&auml; is run by the <A HREF="http://www.sgo.fi/">Sodankyl&auml; Geophysical Observatory</A>.
</P>

<HR>
<CENTER>
Do YOU know how to <A
HREF="../../asc_reading_keos.shtml">INTERPRET</A> the raw data given here?
</CENTER>

<HR>

<CENTER>
<TABLE>
<TR ALIGN=center>
<TD><em>Hankasalmi</em>
<TD><em>Muonio</em>
<TD><em>Kilpisj&auml;rvi</em></TD>
<TD><em>Kevo</em></TD>
<TD><em>Abisko</em></TD>
<TD><em>Longyearbyen</em></TD>
<TD><em>Sodankyl&auml;</em>
</TR>



<TR>
<TD>$hankasalmi</TD>
<TD>$muonio</TD>
<TD>$kilpisjarvi</TD>
<TD>$kevo</TD>
<TD>$abisko</TD>
<TD>$longyearbyen</TD>
<TD>$sodankyla</TD>
</TR>
</TABLE>
</CENTER>
<hr>

<CENTER><FONT SIZE=-1>&copy; Finnish Meteorological Institute, Geophysical Research</FONT>
</CENTER>    
EndOfHtml
;



#-------------------------------------------------------------------
# Add the name of the computer requesting the form to a list

# Get the name of the remote host; separate the domain name

$remhost = $ENV{REMOTE_HOST};
if($remhost eq ''){
    $remhost = $ENV{REMOTE_ADDR};
    $domain = $remhost;
}
else {
    $remhost =~ /\D\.(\D*)\.(\D*)/;
    $domain=$1.".".$2;
}

$today=`date +"%Y/%m/%d %T"`;
chop($today);
umask 002;

if(open(SEARCHLIST,">>/xx/home/aft/syrjasuo/public_html/Searchstats/keorequests.txt")){
    print SEARCHLIST "$today $remhost asked for keograms on $daystamp\n";
    close(SEARCHLIST);
}
