Common Gateway Interface

Introduction

The Common Gateway Interface (CGI) is a standard protocol for interfacing external applications with Web servers. Regular HTML documents produce static pages. Static pages do not change unless the page designer alters the HTML source. A CGI program executes in real time, producing dynamic Web pages that change depending on server parameters or that produce output in response to requests from a Web browser. For a nice example, visit my NCEP Reanalysis Plotter, which takes information submitted by an individual's Web browser and plots a customized GrADS image from the reanalysis data available on Blizzard.

Create a Dynamic Web Page

snow Here, you will learn all about CGI by experimenting with several examples of CGI scripts. See my CGI examples and then download cgi.tar into your own public_html directory on Blizzard. (Please note that a server move has broken a few things. These will be repaired before the next offering of this course.) Then tar xvf cgi.tar and view your own page at http://frost.atms.unca.edu/~astudent/cgi/ Study the source code behind the HTML forms and the source code for the CGI scripts. Improve wxplot.cgi to accomplish the following:

  • Plot more than one day of data with the dates chosen by the user.
  • Overlay the time series for temperature at two specified stations.
  • Plot multiple variables from the same site on the same plot (these options must include at least air temperature and dewpoint).
  • Clean up your page to make it somewhat attractive and useful. Be creative.

Post your finished HTML page on your password-protected Web site, along with the text of your Python CGI script. You can post the text by wrapping your Python code with HTML headers in an HTML file that looks like this: <HTML>
  <BODY>
    <PRE>
Your Python code goes here
    </PRE>
  </BODY>
</HTML>

Coding Tips

You might find some useful information about the plotting utility within the documentation for matplotlib.

You may notice that the Oklahoma Mesonet files do not contain dewpoint data. The files instead contain relative humidity (RELH) and air temperature (TAIR). Review the parameter description for the Mesonet data files. Use the following equations to calculate the dewpoint from the relative humidity within your code:

td

Here, RH is the relative humidity (%), e is the vapor pressure (mb), es is the saturation vapor pressure (mb), T is the air temperature (°C), and Td is the dewpoint temperature (°C).

North Carolina's Public Liberal Arts University