Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 
Previous: GEMPAK Decoder Program Exercises Next: GEMPAK Scripting Exercises Table of contents Frames User Manual GEMPAK Online Tutorial

18 GEMPAK Batch scripts

Writing GEMPAK batch scripts


Many times, you may which to automate or schedule the generation of products that you find useful. You have seen GEMPAK's user interface which is designed to accept user input interactively. Perhaps you were wondering how to make GEMPAK output all the maps you need for your research project, or just to have certain charts scheduled to be updated each day. Well, you can do all these things with shell scripts.

Writing batch scripts can range from very simple redirection lists, to rather complicated shell programs. For all these examples it will be assumed you are using a C-shell (csh) for your user environment. You may use other shells if you feel more comfortable with those environments.

We'll start with redirection lists. So far you have seen that you can enter your variables at the GEMPAK command prompt. The CSH language can use files for input instead of the keyboard or other standard input device in a process known as indirection. In this proccess, we say that the input has been redirected from the keyboard to a file. To redirect the GEMPAK prompt input from a file, the CSH syntax would look as follows:

You have seen that at the GEMPAK prompt you can list the values assigned to variables using the list command. If those same lines were redirected from a text file, all those variables would be updated. A file used for redirection simply mimics what you would type. You can use the cut and paste tools in your window environment to save the output from the list command. Often then is very helpful since once you have set up the way you like the variables to be set, you can cut them and paste them into your redirection list.

Many times however, you will need to change variables such as the filename or the dtae/time used. For situation such as this, the standard restore defaults command won't work. You need some way of generating appropriate dates, times, filenames, etc. To do this you will need to use a shell script. You can use shell scripts to ascertain the correct filenames and dates when the program is executed, then ask the shell script to set up the indirection for you.

The Unix environment provides many useful tools which you may want to use to set up various scripts such as automated crontab entries which can execute your scripts at specified intervals. If you aren't familiar will all the Unix toold, or shell environments, you may want to consult on the the many references on the subject.

A word of warning, your scripts must be able to obtain the appropriate system and environmental resources, just as if you were running the programs from the user interface.


These are the rules for a shell script:

Lets look at an example of a C-shell script:

#!/bin/csh                            

source /home/gempak/dist/Gemenviron  

set YMD=`date -u '+%y%m%d'`          

set SFFILE=$GEMDATA/surface/sao/$YMD.gem  

echo -n "Enter the station ID you which to list: "
set STATION=$<                        

sflist << EOF                        
 SFFILE   = $SFFILE                 
 AREA     = @${STATION}
 DATTIM   = all
 SFPARM   = tmpf;dwpf;pmsl;sped;drct
 OUTPUT   = t
 IDNTYP   = stid
 r

 e
EOF

echo " "
exit(0)
# END of shell script

The shell program above can be copied and pasted into your account. Before you can execute it, you must allow the file to be executed. In Unix, you can use the command chmod a+x filename to allow execution of a file. Try executing the script above (note, you may have to edit the SFFILE location definition, and the location of the Gemenviron file if your locations aren't the same!).

The flag EOF in the script tells the CSH to accept input to the SFLIST command until it sees that flag later in the script. The commands between the two EOF's are used to enter the variables as if you were typing them. The SFFILE and AREA variables are using the value that the CSH variable was assigned in the section preceeding the GEMPAK command.

Why is the blank line required?
Try running SFLIST to see what you type following the run command.

Lets try a few more exercises...

18.0  GEMPAK Scripting Exercises

 


Previous: GEMPAK Decoder Program Exercises Next: GEMPAK Scripting Exercises Table of contents Frames User Manual GEMPAK Online Tutorial

 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Office of Programs University Corporation for Atmospheric Research (UCAR)   Unidata is a member of the UCAR Office of Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690