Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Tuesday, June 17, 2014

Tutorial: Basic Font Control in GrADS

When using GrADS you will most likely run into a situation where you will have to use superscripts or subscripts, and greek letters.  This is actually really simple to do in GrADS.  This tutorial will provide some basic information on how to control the font in GrADS, including superscript/subscript syntax.

GrADS comes with 5 fonts:
  • font 0 -- Simplex Roman 
  • font 1 -- Complex Roman
  • font 2 -- Complex Italic
  • font 3 -- Complex Greek
  • font 4 -- Duplex Roman
  • font 5 -- Triplex Roman
The simplest way to change the font is by using the 'set font' command.  By default the font is set to value Simplex Roman (value 0).  To change the font using the set font command simply input the desired font number.  For example, to change the font to Complex Italic:

    'set font 2'

Font 3 is where the Greek symbols and characters are.  The image below shows the alphabet and the following Greek character representations of each letter (in both upper and lower case).
 
Greek Fonts 

The other font numbers all follow standard alpha-numeric characters printed out in slightly different styles.  If you want to see the specifics of each font, simply type the word "font" followed by the number you want to learn about.  For example to see the details of the Complex Greek font, simply type:

    'font 3'

If you wanted to mix fonts it would be cumbersome to try to draw a series of "partial" strings next to each other with interspersing 'set font' commands.  Luckily, GrADS has a feature that allows you to change the font within the string.  To change the font within a string, all you need to do is type the accent Grave: [`] (and yes I had to google what this was called) followed by the font number you are interested in.  For example:

    'draw string 4.5 4.5 pi symbol = `3p `0'

 This will write out the words: "pi symbol =" followed by the Greek symbol for pi (π).  The `0 is set in, to reset the font to the default after the symbol. 

You can use this same method to get superscripts and subscripts within your text.  Similarly to the font changes, you use the Grave [`] followed by the font location identifier.  The identifiers are shown below.
  • `a = Above (Superscript)
  • `n = Normal (Normal Text)
  • `b = Below (Subscript)
 So to write out x^2, you would type:

   'draw string x`a2`n'
 
 The `n is once again put in there for housecleaning, so you simply return to the normal font.  Putting it all together, we can write the formula for the area of a circle.

     'draw string 4.5 4.5 A = `3p`0r`a2`n'  
 
 or if π isn't your thing ...

    'draw string 4.5 4.5 A = (`3t`0/2)r`a2`n'


 
That is about it for this tutorial.  Hopefully you have a better understanding on how to use the fonts in GrADS.  I will mention that there is a way to import and use custom fonts, though I will not discuss how to do that here, if you want more information go to this websiteNow, as a final tip, the degrees symbol is represented by the period (.) in the Greek font:

   'draw string 4.5 4.5 `3.`0' 

 

Thursday, May 16, 2013

Some tips on running GrADS from the Windows Command Line and .bat scripts

If you are using GrADS through a linux operating system, chances are you are familiar with running GrADS from the command line, so this post is mostly aimed at the Windows users.  This post will go through the basic instructions for running GrADS from your command line along with arguments and options.  So lets first begin with a question.

Why would you want to run GrADS from the command line if your mouse is perfectly capable of opening GrADS via the "double click?"

The best answer that I can give you is that running GrADS from the command line vs. double clicking gives you the option to include arguments.  Furthermore, the command syntax used is the same used in .bat scripts.

Now, there are a number of different options available that you can include on the command line when you open the program.  The most important is the -help option.  So if you type:

    'grads -help'

Into the command line, you will get a whole list of options you can include when you run the program.

 The options I have found to have been the most useful are these:

  • -l/p: Choosing to open GrADS in landscape or portrait mode
  • -b: running GrADS as a batch process (program is hidden from view)
  • -c: Allows you to execute a command (likely a script)
  • -x: Exits GrADS automatically after executing your command


There are other options that you can see with the -help command, but these are the ones I have found most useful.

Example: grads -lcx 'run script.gs'

This example would open GrADS in landscape mode and run the file "script.gs" and then exit after it was done.

Now, you can actually carry this command line method over to a Windows batch (.bat) script.  Basically, a batch script is similar to a GrADS script, in that it is a file that can execute a bunch of Windows commands at once.  Now, you can include a command to run GrADS with options within your batch script.

Now, this can be very useful as this way you can actually pass arguments from your windows script into your GrADS script.  For example, if you wanted to set your lat/lon boundaries in your windows script, or your display color, you can do that.  All you need to do, is set these variables inside your batch script, and call GrADS with the arguments attached.

Batch Script:
      set display="white"
      set minlat="20"
      set maxlat="50"
      set minlon="-125"
      set maxlon="-65"

     grads -lc 'run script.gs '%display%' '%minlat%' '%maxlat%' '%minlon%' '%maxlon%

GrADS Script:     function script(args)
     display=subwrd(args,1)
     minlat=subwrd(args,2)
     maxlat=subwrd(args,3)
     minlon=subwrd(args,4)
     maxlon=subwrd(args,5)

Now, what you see in the GrADS script, that may be new to you, is the function declaration at the top.  This is required if you want your script to read in the arguments that you laid out in the batch script.  All this line does, is essentially tell GrADS that you are looking for arguments.  You also see in the batch script you have spaces between each argument denoted by the ' '.  This allows you to separate your arguments in GrADS using the subwrd() function.

But the ability to pass arguments from the windows script into the GrADS script can be very helpful, especially if you are running scripts that need variable input (e.g., date or time).  As this method could allow you to run GrADS without having to constantly change the script around.

In any case, I just wanted to provide a few tips on running GrADS from the command line in Windows.  I didn't go too in depth into windows scripting (I leave that to brighter minds), but hopefully you have an idea as to how to run GrADS in a batch script as well as how to pass arguments from one to the other.