A Fortran GET CGI example

This program or CGI takes a 6 digit hexadecimal number and converts it to the corresponding HTML color.  That color is displayed in a band across the center of a table.  The program also calculates and displays new colors that result from increasing or decreasing each digit.  The additional colors are shown in smaller squares, along with the corresponding hexadecimal number.  Up to 48 additional colors may be shown.  If the calculated increment is outside the hexadecimal range 0 through F, "No Color" will be shown.


COLORIT uses the GET method to receive data, reading the input string from the environment variable QUERY_STRING using the intrinsic routine getenv.  The character string received via the getenv character string is parsed to retrieve the name=value data pair sent by the form.  In a GET method string, the QUERY_STRING string consists of everything to the right of the question mark in the input URL.  For example, input=8CDC5F is the name=value pair that we want to process in the sample URL https://transition.fcc.gov/fcc-bin/colorit?input=8cdc5f.

The source code for this program (HTML and Fortran CGI), is available as a text file.

FORTRAN notes:

  • The QUERY_STRING is a character string.  If numbers are contained in the string, they are received as ASCII characters and must be converted to numbers before use.
  • In this example, the HTML output is established by the statements
          55 Format("Content-type: text/html", //)
  • This code must be placed before any other output is written to stdout.  If you don't, you will get an error message when to try to call the CGI.
  • The carriage returns ("//") are VERY IMPORTANT!  Also, note the placement of the " quotation marks. Compare to the corresponding C language statements:
          printf("Content-type: text/html\n\n"); or
          puts("Content-type: text/html\n");
  • For HTML output, the HTML tags are contained inside Format statements, as shown in the example Fortran code.  BE SURE to have the usual HTML ending tags, or you may not see any HTML output or receive an execution error.
  • Carefully watch use of  ' or " in Format statements: it's too easy to miss one ' or " or add too many.
  • When generating output, statements must be no longer than the 72 character limit in Fortran 77.  Another Format statement or a continuation character in Column 6 of subsequent lines within the Format statement may be needed for longer statements.
  • The Fortran program can incorporate subroutines, called in the usual manner, although none are needed for this example.
  • Fortran carriage control characters are not required when generating HTML output.  Use the HTML tags to perform this function.  However, to keep source HTML code tidy and readable, you can include returns at the end of HTML lines:
          111 format("HTML Line 1",/, "Line 2",/)
  • The program has not been optimized.  Certainly there are better ways to do some of the tasks or changes that could reduce number of lines of code, but that work is not necessary for this simple example.  No Fortran or CGI library functions were used in the preparation or execution of this example, since COLORIT program was designed as a stand-alone CGI.

Dale Bickel, Senior Electronics Engineer, Audio Division, Media Bureau

For information on AM and FM radio broadcasting, please visit the Audio Division website, and the Broadcast Radio Links page.

For information on Television broadcasting, please visit the Video Division website.

FCC > Media Bureau > Audio Division, (202) 418-2700, and Video Division, (202) 418-1600.


Sunday, December 13, 2015