Gsharp Web Edition in 5 minutes

For those of you who don't have time to work through the tutorial, here's a quick introduction to all the core elements of the Gsharp Web Edition.

Overview

The Gsharp Web Edition is a program that sits on your web server and creates images and HTML files. The web edition is driven by scripts written in the Gsharp Script Language. A typical script will perform the following actions:

  • Read data
  • Create plot using template generated by Gsharp
  • Create GIF image of plot
  • Send web page (including reference to generated GIF) in HTML to stdout.
  • If required, include an image map for the GIF, linking graph elements to further scripts.

Each of these stages is fully configurable. The script language is a powerful programming language with full flow control and with a rich set of functions for working with data and graphics. If the script is being driven by an HTML form then the form input can also be used to control the output.

Connecting Web Form to Gsharp Script

The first stage of developing your script is usually designing your plots in Gsharp. Once you have done this they should be saved as Gsharp Script Language (GSL).

Then you must decide how you would like your web site visitors to be able to configure the plots. Perhaps they should be able to decide the time range for the data or the variables to plot. Perhaps they should be able to highlight a certain day or add their own notes on the graph. Maybe they would like to choose between a 2D Contour or a 3D contour. Once you have decided on this then you need to design a web form with these questiosn on it. The action for this form will be our GSL script.

The next stage is to adapt your GSL script to include the FORM input. The Gsharp Web Edition will automatically process the FORM input and store it in datasets that can be used by the script. Let's say, for example, that we have a field on our form called graphType and our script has the graphType hardcoded to "line":

create Graph page_1.viewport_1.domain_2.graph_2
 ( XuNgraphType = "line",
 ...

Our form field graphType is stored in the string dataset FORM_graphType, so provided we make sure the field is a valid graphType we can just use:

create Graph page_1.viewport_1.domain_2.graph_2
 ( XuNgraphType = FORM_graphType,
 ...

We could also use the form input to control which data file to read or we could included it in our SQL query of our ODBC data source. e.g.

if (FORM_source= files") then
  import_ascii(FORM_day+".dat");
endif

Creating The Image File

When you configured your web server you specified a directory for writing temporary image files and you made sure this directory was accesible through your web server. The names of these two directories should be available as environment variables GsharpTmpFilesActualDir and GsharpTmpFilesWebDir.

We need to store our image in $GsharpTmpFilesActualDir. This can be done with commands something like this:

imgfile = "start"+getpid()+".gif";
make_image(708, 531, getenv("GsharpTmpFilesActualDir")+imgfile);

Creating The HTML

Finally your script needs to output some HTML to control what appears in the user's browser. This could be lines and lines of comples HTML and JavaScript or it could be something simple like:

<HTML>
<HEAD>
<TITLE>My first GsharpWE script</TITLE>
</HEAD>
<BODY>
<CENTER>
<IMG SRC=/GsharpTmpFiles/start10345.gif>
</BODY>

The important thing is that it includes a reference to the image that you have created. The code to do this would look something like this:

echo("<img src="+getenv("GsharpTmpFilesWebDir")+imgfile+">");

In Summary

The file $UNIDIR/example/GsharpWE/framework.gsw is a skeleton script showing the main elements of any Gsharp Web Edition script. Study this script, work through the tutorial, glance at the examples and you will soon be making your own scripts.