#!/usr/bin/perl -wT
$ENV{LD_LIBRARY_PATH} = ".";
#$ENV{'PATH'} = '.';
use CGI;use CGI::Carp qw ( fatalsToBrowser );
#from http://www.sitepoint.com/uploading-files-cgi-perl-2/
$CGI::POST_MAX = 1024 * 5000;
$query = new CGI;
#print $query->header();
@keywords = $query->keywords;
print "keywords: @keywords\n";
#my $version = $query->param("version"); 
#print "version: $version\n";
#print "Content-type: text/html\n\n";

print <<HTML;
<html>
<head>
<title>CF-Convention compliance checker for NetCDF format</title>
</head>
<body>
<h1>CF-Convention compliance checker for NetCDF format</h1>
<!--
This form allows you to run the 'cfchecks.py' script to check that the contents 
of a NetCDF file comply with the <b>Climate and Forecasts (CF) Metadata Convention</b>. 
The CF-checker was developed at the Hadley Centre for Climate Prediction and Research, UK Met Office 
by Rosalyn Hatcher. This work was supported by PRISM (PRogramme for Integrated Earth System Modelling). 
<p>
Development and maintenance for the CF-checker has now been taken over by the 
NCAS-CMS (National Centre for Atmospheric Science - Computational Modelling Support). If you have suggestions for 
improvement then please e-mail Rosalyn Hatcher at NCAS-CMS
<a href="mailto:r.s.hatcher@reading.ac.uk">(r.s.hatcher@reading.ac.uk)</a>.
<p>

To check your file, please use the drop down menu to select the version of the CF conventions to check against, enter the file name in the box below then press
<em>Check file</em>. You can use the <em>Browse...</em> button to help you 
select the file. 
<p>
For details of the NetCDF format and the CF Convention go to the BADC 
<A href='http://badc.nerc.ac.uk/help/formats/netcdf/'>NetCDF format</A> or 
<A href='http://badc.nerc.ac.uk/help/formats/netcdf/index_cf.html'>CF Convention</A> pages or visit the 
<A href='http://www.cfconventions.org/'>CF conventions home page</A>.
<p>
-->
<FORM action="/cgi-bin/cf-checker.pl" METHOD="post"  ENCTYPE="multipart/form-data">
Check against CF version:
<select name="cfversion">
<option>auto</option>
<option>1.0</option>
<option>1.1</option>
<option>1.3</option>
<option>1.4</option>
<option>1.5</option>
</select>
<TABLE>
<TR>
<TD>File:
<TD><INPUT TYPE="file" NAME="upload" VALUE="" SIZE=40>
<TD><INPUT TYPE="submit" NAME="submit" VALUE="Check file">
</TABLE>
</FORM>
<P>
Official web interface to the CF Compliance Checker is available at <A href='http://titania.badc.rl.ac.uk/cgi-bin/cf-checker.pl'>BADC</A>.
<BR>
An alternative web interface to the CF Compliance Checker is available at <A href='http://puma.nerc.ac.uk/cgi-bin/cf-checker.pl'>NCAS-CMS</A>.

<P>
HTML
    
#$query = CGI->new;
#print "<html><head><title>CF-Convention compliance checker for NetCDF format</title></head>\n";

#print "cf-checker.<br><br>\n\n"; 

if(0) {
my $basedir = "/home/www/cgi-bin";
my $opt_a = "$basedir/data/area-type-table.xml";
my $opt_s = "$basedir/data/cf-standard-name-table.xml";
my $opt_u = "$basedir/data/udunits2.xml";
my $opt_v = "1.5";
my $ifile = $basedir."/data/tmp4.nc";
my $command = "$basedir/cfchecks-2.0.4.py -a $opt_a -s $opt_s -u $opt_u -v $opt_v $ifile";

#print "config:<br>\n$basedir<br>\n$opt_a<br>\n$opt_s<br>\n$opt_u<br>\n$opt_v<br>\n";
#print "<br>\ncommand: $command<br>\n\n";

my $result=`$command 2>&1`;
$result =~ s/\n/\n<BR>/g;
chomp($result);
#my $result=qx/$command/;

#print "<br>\nresult: [$result]<br>\n\n";
print "[$result]<br>\n\n";
}

print <<HTML;
</body>
</html>
HTML
