! cgi_example.f90 -- ! Example of using CGI to implement an Internet service ! ! Example belonging to "Modern Fortran in Practice" by Arjen Markus ! ! This work is licensed under the Creative Commons Attribution 3.0 Unported License. ! To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ ! or send a letter to: ! Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. ! ! program cgi_example use cgi_protocol implicit none type(dict_struct), pointer :: dict => null() ! Initialisation is important! integer :: i integer :: luout integer :: steps real :: xmin real :: xmax real :: param real :: x, y character(len=20) :: param_string ! ! Get the CGI information ! and write the start of the HTML file (plus the start of the table) ! (Note: we include the text entry and submit button, so the user ! can easily select a new value) ! call cgi_begin( output_html, dict, luout ) call cgi_get( dict, "param", param ) call cgi_get( dict, "param", param_string ) write( luout, '(a)' ) '' write( luout, '(a)' ) 'Table of function values' write( luout, '(a)' ) '' write( luout, '(a,a,a)' ) & 'Parameter: ' write( luout, '(a)' ) '' write( luout, '(a)' ) '' write( luout, '(3a)' ) ' ' write( luout, '(a)' ) '' ! ! Produce the table of function values ! xmin = 0.0 xmax = 10.0 steps = 201 do i = 1,steps x = (i-1) * 0.05 y = func(param, x) write( luout, '(a)' ) '' write( luout, '(a,f10.4,a,f10.4,a)' ) & ' ' write( luout, '(a)' ) '' enddo write( luout, '(a)' ) '
xf(x) = exp(-x) * cos(ax)
', x, '', y, '
' write( luout, '(a)' ) '' write( luout, '(a)' ) '' ! ! We are done ! call cgi_end contains real function func( param, x ) real :: param, x func = exp(-x) * cos(param*x) end function func end program cgi_example