#!/usr/bin/perl


## top line of table
@rlist = ('OD550AER'  ,'ANGSTROMAER','CONCPM10AER','CONCAERN'   ,'CONCSS',
	  'CONCOC'    ,'CONCBC'     ,'CONCSO4'    ,'EmiALL'     ,'LoadHighALL',
	  'LoadMidALL','LoadLowALL' ,'PRCOAER'    ,'PROCBCPOM'  ,'PROCDUST',
	  'PROCSO4'   ,'PROCSS'     ,'SedDryALL'  ,'WetALL'     ,'OD550ALL');



@table = ([],          [],           [],           [],           [],   
	  [],          [],           [],           [],           [],
          [],          [],           [],           [],           [],
          [],          [],           [],           []);

## left column of table
@pslist = ('SURFOBS','ABSOLUT','MODSAT','MODMEDIAN','FRACTION','ANAOD');

@ylist = ('1997','2000','96-01','96-02AVG');


## switch to activate other web servers with other 
## directories
$machine="dataipsl";

$httpbase='http://dataipsl.ipsl.jussieu.fr/AEROCOM/DATA/';
$dirperl='/cgi-bin/AEROCOM/';
$dirunix = '/bipbip/AEROCOM/';

if ( $machine eq 'boulimix' ) {
    $httpbase='http://boulimix/w3data/schulz/AEROCOM/';
    $dirperl='/cgi-bin/w3data/schulz/';
    $dirunix = '/home/aerocom0/';
}

if ( $ctyp eq 'inca_atlas' ) {$dirperl=$dirperl.'inca_work/';}
elsif ( $ctyp eq 'synthesis' ) {$dirperl=$dirperl.'surfobs/';}
else {($dirperl=$dirperl.$ctyp.'/');}

$httpmodels=$httpbase;
$dirunixbase = $dirunix;
$prfxst = ''; 

    if  ( $ctyp =~ /synthesis/ )  { 
	$prfxst = '_';
    }	
    if  ( $ctyp =~ /surfobs/ )  { 
	$httpmodels = $httpbase . 'SURFOBS/';
	$dirunix = $dirunix . 'SURFOBS/';
	$prfxst = '_';
    }	
    if  ( $ctyp =~ /lidar/ )  { 
	$httpmodels = $httpbase . 'LIDAR/';
	$dirunix = $dirunix . 'LIDAR/';
	$prfxst = '_';
    }	


# looping over all regions / printing one file per species

@stlist =('AMN','AMS','AFS','AFN','Europe','Acrtic','Antarctic','OCAsia','OCAtlanN','OCAtlanS','OCInd','OCPac',
'Oceania','WORLD','AsiaN','AsiaS');

for($st=0; $st<@stlist; $st++) {


# checking for availaibily of image    
for($i=0; $i<@rlist; $i++) {
    chdir $dirunix."MODELS/plots" || next;

    for($p=0; $p<@pslist; $p++) {
	for($s=0; $s<@ylist; $s++) {
	    @flist=();
	    $tt1 = $rlist[$i].'_'.$pslist[$p].'_an'.$ylist[$s];
	    @flist=`ls $tt1*$stlist[$st]*`;

	    $cellnum=$p*@ylist+$s;

	    if (@flist>0) {
		$table[$cellnum][$i] = 1;
	    }
	    else {
		$table[$cellnum][$i] = 0;
	    }
	}
    }
}

# printing header
chdir $dirunix."INTERFACE_DOC";
$outfile = ">".$stlist[$st]."synthesisov.html";
open (OUT , $outfile); print OUT "";
$outfile2 = ">>".$stlist[$st]."synthesisov.html";
open (OUT , $outfile2);

print OUT
"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html>
<head>
<title>OVERVIEW TABLE AEROCOM SYNTHESIS </title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
</head>
<body>
<table width='900' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td width='420 height='250' valign='middle' background='../MODELS/plots/EmiALL_PROC_an2000_mALLYEAR_WORLD.ps.png'>&nbsp;<br></td>
    <td width='480' height='250' align ='center' valign='middle' ><p><strong><em>Overview of availability of 
        images for <br><font size='4' color='#FF0000'>
    <br><font size='5' color='#FF0000'>Region: ", $stlist[$st],"</font><br>
        </font>
        <br>
        on AEROCOM  SYNTHESIS <a href='../synthesis.html'>WEB INTERFACE</a></em></strong><br>
        (note: images contain model results <br>but not necessarily observations)
        <br>
        <a href='javascript:history.back()'>&lt;- BACK to images</a><br>
      </p>
      </td>
  </tr>
</table>
<br>

<table border='1' cellspacing='0' cellpadding='0' bordercolor='#0099FF'>
    <tr>
    <td width='150'>&nbsp;</td>
    <td colspan='19' bgcolor='#0099FF'><strong>Parameters</strong></td>
    </tr>

    <tr align='center' bgcolor='#99FFFF'>
    <td width='150'>&nbsp;</td>";
    for($i=0; $i<@rlist; $i++) {
    print OUT "
    <td width='60'><strong><font size='1' 
    face='Arial, Helvetica, sans-serif'>",$rlist[$i],"</font></strong></td>"
    }		   
    print OUT  "</tr>";

# print row information
for($p=0; $p<@pslist; $p++) {
    for($s=0; $s<@ylist; $s++) {
	if ($s==0) {$test = $pslist[$p].'_'.$ylist[$s];}
	else {$test = $ylist[$s];}
	$cellnum=$p*@ylist+$s;
	if (($cellnum==35) || ($cellnum==70)){
    print OUT "<tr align='center' bgcolor='#99FFFF'>
    <td width='150'>&nbsp;</td>";
    for($i=0; $i<@rlist; $i++) {
    print OUT "
    <td width='60'><strong><font size='1' 
    face='Arial, Helvetica, sans-serif'>",$rlist[$i],"</font></strong></td>";
    }		   
    print OUT  "</tr>";
	}

	print OUT "
        <tr>
        <td width='150' align='right'><font size='-3' face='Arial, Helvetica, sans-serif'><strong>",
	$test,"</strong></font></td>";

# print table cell info 
	$cellnum=$p*@ylist+$s;
	for($i=0; $i<@rlist; $i++) {
	    if ($table[$cellnum][$i]==1 ) {
		print OUT "<td width='60' align='center' bgcolor='#00FF00'><font size='-3'>x</td>";
	    }
	    else {
		print OUT "<td width='60' bgcolor='#FFFFCC'>&nbsp;</td>";
	    }
	}
	print OUT "</tr>";
    }
}
print OUT "</table>";
close OUT;
}


