How does GrADS work internally when drawing?

Jennifer Adams jma at COLA.IGES.ORG
Thu Mar 20 11:34:21 EDT 2008


On Mar 18, 2008, at 6:12 PM, Stefan Gofferje wrote:

> Hi,
>
> could one of the developers maybe give some understanding how the
> drawing process of GrADS works? I have a couple of charts in mind
> but no
> idea how to realize them because I don't understand how GrADS handles
> the parameters. Especially interesting for me is how to manipulate the
> output of one parameter depending on the values of another in map
> projections but also line and bar outputs.
The maskout() and const() functions are particularly handy for this,
but for specific help, you need to ask a more specific question.

> One example: Let's say we have gxout bar. E.g. the GFS model has one
> parameter for the precipitation rate as mm and a couple of parameters
> which indictae the precip type and can be 1 or 0, like CRAIN, CSNOW,
> CICEP...
> How would I draw bars which height indicates the precip strenght
> but the
> color changes like blue for rain, cyan for snow, red for ice
> pellets and
> such?
Here's how it's done for the meteograms:

'define ptot  = const(0.5*(p+abs(p)),0,-u)'
'define pconv = const(0.5*(pc+abs(pc)),0,-u)'

* Rain (Total Precipitation)
'set gxout bar'
'set barbase 0'
'set bargap 50'
'set ccolor 42'
'd ptot'

* Snow
'set ccolor 44'
'd ptot*csnow'

* Sleet (Freezing Rain)
'set ccolor 45'
'd ptot*cfrzr'

* Ice Pellets
'set ccolor 46'
'd ptot*cicep'

* Convective Precipitation
'set bargap 80'
'set ccolor 2'
'd pconv'


>
> If I draw on a map, e.g. gxout grid, is there a possibility to draw
> own
> stuff, like e.g. take the temperature and if it is below zero, draw an
> exclamation mark at this grid position? How would I do this?


Here's something quick -- it draws a '0' at every grid point where a
variable has a certain range of value (e.g., for t between 299 and 300):
'set gxout grid'
'set grid off'
'set gridln off'
'set digsiz 0.01'   ;* this is small so the zeros will look like tiny
dots
'd const(maskout(maskout(t,300-t),t-299),0)'

To draw an ascii character at a grid point location based on it's
value, you'd have to write a script and go through the grid point-by-
point, something like this:
xstart = 1
xend   = 360
ystart = 1
yend   = 181
'clear'
'set x 'xstart' 'xend
'set y 'ystart' 'yend
'set gxout contour'
'set clevs 0'
'd t*99999'   ;* this is to create a scaling environment -- no
contours are drawn
var='t-300'
xx = xstart
while (xx < xend)
   yy = ystart
   while (yy < yend)
      'set x 'xx
      'set y 'yy
      'd 'var
       line = sublin(result,1)
       val = subwrd(line,4)
       if (val < 0)
           'q gr2xy 'xx' 'yy
           positions = sublin(result,1)
           xpos = subwrd(positions,3)
           ypos = subwrd(positions,6)
           'set strsiz 0.05 0.05'                 ;* here's where you
set the size of the ascii character you want to draw
           'draw string 'xpos' 'ypos' ~'      ;* here's where you
change the ascii character you want to use as a mark
       endif
     yy = yy + 1
   endwhile
   xx = xx + 1
endwhile


> Can I
> define ownfunction and then just say set gxout grid; d ownfunction?
sure, if ownfunction is a valid GrADS expression. The syntax for
defining variables is:
'define var = 'ownfunction
or the implied define:
'var = 'ownfunction


Hope this gives you some ideas.
--Jennifer



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20080320/4edc6bd8/attachment.html 


More information about the gradsusr mailing list