GEMPAK Scripting Tutorial

pix
Go back to home page

This page provides information on writing GEMPAK scripts, with the ultimate goal of executing scripts via CGI and displaying the graphics on the web.

This page is obsolete.

The latest page is at itmetr.net.

last modified: 05:06 PM MDT, Sun 15 Jun 2008

  • What is GEMPAK? Read this official description now.

  • Before you start playing with gempak and encountering the dreaded error message No space left on device, please read these tips for hung gempak processes.

  • There are only several links on the gempak home page that us newbies will need to visit. You don't need to visit these in depth just yet:

  • Visit snprof.cgi for an example of a simple gempak-powered web site. When you hit the "Plot" button, be prepared to wait for 15 seconds or so. "List" is a bit faster. As described below, option #1 for the task is to download and modify snprof.cgi.

  • Visit crontab obs for an example of gempak-generated images that are refresehd automatically every hour by crontab. As described below, option #2 for the task is to set up a similar page at your website, with your own crontab schedule calling scripts that you have designed.

  • Download the sample scripts in gpscripts.tar. Configured to immediately work on Gentry, after you change a few bfiedler to yourname. Option #2 for the task basically consists of modifying a few of scripts contained within.

  • On Gentry type du -h /data/gempak. You will see Gentry has access to about 79 gigabyte of data in gempak format. There is software system known as gempak that can be used to decode, plot and manipulate the data. The gempak data consist of obs and forecast products in a binary format unreadable to your eyes. The obs and forecasts are stored for about nine days, and then mostly discarded. The data comes in through a satellite dish on the roof of Sarkey's Energy Center. NOAA, with your tax dollars, is collecting and distributing the data. But OU paid for the dish and the receiver.

GIF from gempak (with crontab)

Unisys owns gempak AND the rights to GIF. Not too surprising, Unisys is happy to offer GIF output from gempak. The first gemapak script from gpscripts.tar that you are invited to play with is corrected.csh. The script originates from the gempak script examples, under Creating images for WWW, where you will find a script to create ETA gif images. That script DOES NOT run on Gentry, for a couple of reasons. First, the GDATTIM and GVCORD variables are set incorrectly for the version of gempak we are running (5.8.2a). Secondly, there is a modification needed for running on Gentry; for the configuration on Gentry we need to invoke the command:

source /usr/local/nawips/Gemenviron

early in the script. You may want to inspect Gemenviron with a text editor, or with this "browser":

less /usr/local/nawips/Gemenviron

(Use the up/down arrow key to "cruise" around; enter q to quit).

Also, for your covenience, corrected.csh has been altered to send GIF files to a directory mydump. You must make that directory first, and corrected.csh must be executable by you. Here we go:

mkdir mydump
chmod u+x correctd.csh
corrected.csh
If all went well, you will find a bunch of newly rendered GIF files in mydump: eta_emsl.gif, eta_emsl.gif.1, eta_emsl.gif.2 and so on. These aren't the most amazing graphical renderings of a forecast product, but that is where we begin...

sat2gif.csh makes ir_sat.gif, and surfaceobs.csh makes nyobs.gif. These scripts are designed to be run automatically, at a time specified by you using crontab. But first change all the bfiedler to yourname in all these scripts. You can read about crontab at Crontab Tutorial or Linux Cron Howto. But beware the crontab on Gentry is even easier to use than documented in those references. Those references advise about using crontab -e to edit a file owned by root in /var/spool/cron/crontabs. On Gentry you can put the cron commands in a file owned by you, for example mycron.txt. Then invoke your commands with crontab mycron.txt. You can see your schedule with crontab -l. You can kill you scheduled jobs with crontab -r, edit you mycron.txt with any text editor, and resubmit your schedule again with crontab mycron.txt.

Now, an explanation of the modification within corrected.csh:

setenv DISPLAY :1.0

Believe it or not, when gempak makes a gif, it grabs information about color depth, etc. from the x-session you opened with Gentry. When called with crontab, gempak might croak even before you display the gif, if your remote computer display is set to 16 or 24 bit color, rather than 8 bit. So Gentry has a kluge set up to grab X-resources from a dummy 8-bit display, accessed with the above setenv command. You might think this kluge is unnecessary, given what is said about the "GIF" option in device, but only the option "GF" with the above kluge worked for me for some scripts, particularly those executed by crontab.

PostScript from gempak

The following three example scripts make postscript output, and show how to fix an annoying "feature" of gempak. If you look at one the GIFs that you just made, you will see that the map is drawn on top of the contours for the data. Certainly for upper air data, the plot will look more natural with the contours on top of the map. Included in gpscripts.tar are four more gempak scripts for your enjoyment and education:

  • eta2ps.csh, makes eta.ps showing the lastest 48hr eta forecast...with kluge to put data on top of map

  • ua2psA.csh, makes oun.ps showing the lastest 00Z sounding from OUN, but with the grid on top of the data

  • ua2psB.csh, as above, but with the data on top of the grid gempak does not make .eps directly, but rather makes .ps. But we can convert to .eps with a utility called ps2eps, which you can install in a directory bin within your home directory. This should be fun! You can earn your deputy system administator badge by installing ps2eps :

    Grab ps2eps.tar.gz. ps2eps is a perl script that can be put in your bin. But you will also need to compile the little bbox program within the distribution, and also put that in your bin. Read the Readme.txt. Usage is as:

    ps2eps -help
    ps2eps eta.ps
    

    Beware that the first line in your postscript file must begin with %!PS-Adobe. Although just %!PS in the first line is a valid postscipt value for many operations, it is not valid for ps2eps.

To see how nice gempak .eps or .pdf files will look in your dissertation (as a .pdf or .ps file), use the fewfigs.tex as
ps2eps ounA.ps
ps2eps ounB.ps
ps2eps eta.ps
latex fewfigs
dvips -o fewfigs.ps fewfigs
gv fewfigs.ps
lpr -P thenameofcolorprinter fewfigs.ps
Or
eps2pdf ounA.eps
eps2pdf ounB.eps
eps2pdf eta.eps
pdflatex fewfigs
acroread fewfigs.pdf

gempak from the command line

I personally don't enjoy running gempak from the command line, but some instructions follow. Like GrADS, or Python, gempak can be run from the command line. Unlike grads, all the gempak variables are "remembered" as shell variables, so after you run one of the above scripts (ua2psA.csh for example), running from the command line is snap. Type:

snprof

You will see all your previous variables flash before your eyes. Then, at the GEMPAK-SNPROF> prompt, enter run then just hit enter (i.e. enter a totally blank command line, this is the reason for the mysterious blank line seen in the scripts after run). Then enter exit. When back in the unix command line, enter gpend, and you've made ounA.ps again. Of course, you may want to attempt more from the command line, e.g. phelp or title=4/3/my new title. Don't forget to type gpend when you are back to the unix command line!

Learning more

Gempak has various front-end GUIs already known to many students of meteorology. To access garp, ntrans, etc., enter ntl on a metlab workstations in the SOM plaza lab. Playing with the GUIs should give you an idea of the breadth of data available through gempak.

Now might be good time to visit the official tutorial. It may be just what you need. But here you are being thrown into the "deep end", namely script writing, so you may want to go straight to the tutorial section on GEMPAK batch scripts.

Cut and paste one of the gempak script examples, and make modification appropriate for Gentry, and for producing GIF images.

You may then want to visit the "GEMPAK Programs" section of the online gempak documentation. There are indeed a lot.

Gempak also contains the programs to create data files in gempak format. You might need to do this if you wanted to compare your model soundings with observed soundings, using gempak plotting programs. But you won't learn much about creating gempak data files in this tutorial. (Have a look a sncfil and snedit to learn how to create upper air data files).


Now it is your turn to think about nifty online uses of gempak.

  • Option #1, with Python: If you have not done so yet, visit snprof.cgi for an example of a simple gempak-powered web site. You can grab it as gpcgi.tar. Before you set it up, you may want to visit the CGI tutorial. But notice that the examples here were csh scripts, but the snprof.cgi is a Python script. I have not yet successfully executed a gempak command from Python, so a kluge is used within Python to execute a csh script with the desired gempak commands. You are free to design your gempak-powered, interactive website. It does not need to be too original, perhaps just a "webified" version of gempak script examples, with a simple user interface that allows some choice.

  • Option #2, no Python, but with crontab:: Modify the examples as seen in cron obs to make a few original products (plots) for your website. Put the directory gpscripts within your home directory, and make a directory gp within your public_html directory. Move the index.shtml file found within gpscripts into gp. Read the Readme within gpscripts. After the examples are working, creatively modify them.

    this is an obsolete site
    go to new site
    go to obsolete home page

    pix
    Move to top of page