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' 


1 comment:

  1. Hi!
    I'd like to know how to use different font types. I read something about in GrADS tutorial, but I don't know where can I download another fonts.
    Do you know something about?