Using Fortran programs as CGI scripts

[who]

[how]

[what]

[where]

Introduction How the library routines work Documentation provided on this page Source code distribution

Introduction

In the last weeks (time of writing is 10 February 1999) I encountered a few posts on comp.lang.fortran and the comp.infosystems.www.* newsgroups dealing with usage of Fortran programs as back end for CGI executables called from HTML forms. Worth mentioning among these the
examples by D.Bickel

If you do not know what CGI are refer to the NCSA tutorial.

Since it was at least a couple of years that the idea of a general library for using CGI in Fortran programs (I mean directly, not via an intermediate shell script as I did so far) was lurking in my mind, the above postings instigated me to put my hands on the keyboard and write down the code.

One more proof that Real Programmers Do It in Fortran :-)

L.Chiappetti - 11 February 1999
modified cgiheader.f 18 October 2000
modified Bickel's link 20 May 2002


How to do it

The library addresses the following problems :


Material provided

The material I provide here (without any express or implied guarantee etc. etc.) for demonstration purposes is :

Source code distribution

Since the relevant material consists of quite a few lines of code, I consider simple to give access to each source file, more than preparing gzipped tar files or anything like that. You should just retrieve via Web (Save As...) all the source files
listed below and read the relevant comments. Then compile the routines and place them in a relocatable library, or anyhow link the test program, or any CGI program of yours against them in the way you are accustomed to.

Portability issues

Not all routines listed below have been written ad-hoc. A few of them (those "below the red line" are taken by libraries I developed for other purposes). The latter have either been extensively used on several OSs (starting from VAX/VMS to SunOS, Ultrix, HP-UX, Digital Unix and Solaris). The few routines for which a separate version is necessary for different systems are clearly indicated.

However note I did not do any extensive tests on my new CGI routines. I just tried them on my DU 3.2 Alpha with NCSA httpd 1.5.2. While I did not expect any portability issue in most of my code, I must say I was pleasantly surprised to see that the POST method worked with plain Fortran i/o. In the past I noticed in fact that the POST method (which uses stdin to communicate between form and CGI) sometimes had problems :

  1. in some cases httpd seemed to append a carriage-return (control-M) to the end of the query string, which then makes its way into the value of the last variable
  2. in other cases on Digital machines, if the last string on stdin (or any file) is not terminated by a line-feed it's ignored by a Fortran READ
Source code is here !

ItemSource File NameOperating SytemComments
demo main prova.f all here
include file cgi.inc all here
subroutine cgiheader.f all here
subroutine cgiretrieve.f all here
subroutine cgitoken.f all here
subroutine get_named_variable.f all here
subroutine get_next_variable.f all here
subroutine urldecode.f all here
subroutine urlencode.f all here
additional routines
function true_length.f all here
function bindex.f all here
subroutine upcase.f all here
subroutine get_global_default.f all here
subroutine z_get_global.f Unix VAX/VMS READ THIS !
C routine zc_getenv.c Unix only here

sax.iasf-milano.inaf.it/~lucio/WWW/cgi-lib/index.html :: original creation 2005 apr 13 12:22:07 CEST :: last edit 2005 Apr 13 12:22:07 CEST