setting "clevs" in a script....
Shauna Weaver
kinkelas at OFFUTT.AF.MIL
Thu Feb 21 11:53:45 EST 2008
Eric,
Can you provide one of these similar scripts you mention for color tables -
something with more of a rainbow color table rather than black, blue, and
red?
Thanks so much,
Shauna
On Thu, 3 May 2007 12:14:57 -0700, =?ISO-8859-1?Q?Eric_Salath=E9?=
<salathe at WASHINGTON.EDU> wrote:
>On May 3, 2007, at 10:33 AM, Goodson,Ron [Edm] wrote:
>> The recent question regarding settings clev reminded me that I was
>> going
>> to send out this bit of scripting, should anybody want it.
>
>
>
>Along these lines, I have a few scripts that I can't live without
>anymore either. The first (blueredblack) makes a color table that
>runs black-blue-white-red-black. You call it with, for example,
>"blueredblack 51" to create 51 color gradations (a negative value
>will reverse the table). I've written similar scripts for other color
>tables.
>
>The second one I use to set contour levels. You call it as "clv x0 dx
>xn" where x0 is the lowest level, xn the highest, and dx the
>interval. Eg, "clv 0 2 100" will create 51 contour levels from 0 to
>100 with an interval of 2 (0 2 4 6...100).
>
>The last piece is to make a color bar that does not label all the
>contour values. This is just a modified cbarn.gs to allow skipping
>levels. If you call "cbarn 5" with the above clv call, you'll get
>colorbar labels at 0 10 20 ... 100.
>
>Using these together, you can make attractive maps with very smooth
>color gradients like these
><http://www.atmos.washington.edu/~salathe/reg_climate_mod/ECHAM-MM5/
>seadiffs/pcpabs_son.html>
>
>-Eric
>
>--
>Eric Salathé
>CSES Climate Impacts Group
><salathe at washington.edu>
>University of Washington <http://www.atmos.washington.edu/
>~salathe>
>206-616-5351
>
>
>************* blueredblack ******************
>
>function blueredblack(arg)
>
>if (arg<0)
>nx = -1*arg
>dir = -1
>else
>nx = arg
>dir = 1
>endif
>
>nx4 = nx/4
>
>ix = 0
>rbcols = ''
>
>** black to blue
>
>g=0
>b=0
>r=0
>
>x=0
>
>while (ix<=nx4)
>
>colix = ix+20
>'set rgb '%colix' 'r' 'g' 'b
>
>if (dir>0)
>rbcols = rbcols%' '%colix
>else
>rbcols = colix%' '%rbcols
>endif
>
>x = x + 1/nx4
>y = x
>
>ix = ix+1
>r = 0
>g = 0
>b = 255*y
>
>endwhile
>
>
>** blue to white
>
>g=0
>b=255
>r=0
>
>x=1
>
>while (ix<=2*nx4)
>
>x = x - 1/nx4
>y = x*x
>
>colix = ix+20
>'set rgb '%colix' 'r' 'g' 'b
>
>if (dir>0)
>rbcols = rbcols%' '%colix
>else
>rbcols = colix%' '%rbcols
>endif
>
>ix = ix+1
>r = 255*(1-y)
>g = 255*(1-y)
>b = b
>
>endwhile
>
>
>** white to red
>
>r=255
>g=255
>b=255
>
>x = 0
>
>while (ix<=3*nx4)
>
>x = x + 1/nx4
>y = x*x
>
>colix = ix+20
>'set rgb '%colix' 'r' 'g' 'b
>
>if (dir>0)
>rbcols = rbcols%' '%colix
>else
>rbcols = colix%' '%rbcols
>endif
>
>ix = ix+1
>r = r
>g = 255*(1-y)
>b = 255*(1-y)
>
>endwhile
>
>** red to black
>
>r=255
>g=0
>b=0
>
>x = 1
>
>while (ix<=nx)
>
>x = x - 1/nx4
>y = x
>
>colix = ix+20
>'set rgb '%colix' 'r' 'g' 'b
>
>if (dir>0)
>rbcols = rbcols%' '%colix
>else
>rbcols = colix%' '%rbcols
>endif
>
>ix = ix+1
>r = 255*y
>g = 0
>b = 0
>
>endwhile
>
>'set rbcols '%rbcols
>
>
>******************** clv ***********************
>function clv(arg)
>
>c1 = subwrd(arg, 1)
>c2 = subwrd(arg, 3)
>dc = subwrd(arg, 2)
>
>c = c1
>
>clevs = ''
>
>while (c<=c2)
> clevs = clevs%' '%c
> c = c + dc
>endwhile
>
>'set clevs '%clevs
>
>
>*
>* Script to plot a colorbar
>*
>* The script will assume a colorbar is wanted even if there is
>* not room -- it will plot on the side or the bottom if there is
>* room in either place, otherwise it will plot along the bottom and
>* overlay labels there if any. This can be dealt with via
>* the 'set parea' command. In version 2 the default parea will
>* be changed, but we want to guarantee upward compatibility in
>* sub-releases.
>*
>*
>* modifications by mike fiorino 940614
>*
>* - the extreme colors are plotted as triangles
>* - the colors are boxed in white
>* - input arguments in during a run execution:
>*
>* run cbarn skip sf vert xmid ymid
>*
>* sf - scale the whole bar 1.0 = original 0.5 half the size, etc.
>* vert - 0 FORCES a horizontal bar = 1 a vertical bar
>* xmid - the x position on the virtual page the center the bar
>* ymid - the x position on the virtual page the center the bar
>* skip - intervals to skip in numeric label
>*
>* if vert,xmid,ymid are not specified, they are selected
>* as in the original algorithm
>*
>
>function colorbar (args)
>
>skip=subwrd(args,1)
>sf=subwrd(args,2)
>vert=subwrd(args,3)
>xmid=subwrd(args,4)
>ymid=subwrd(args,5)
>
>if(skip='');skip=1;endif
>if(sf='');sf=1.0;endif
>
>*
>* Check shading information
>*
> 'query shades'
> shdinfo = result
> if (subwrd(shdinfo,1)='None')
> say 'Cannot plot color bar: No shading information'
> return
> endif
>
>*
>* Get plot size info
>*
> 'query gxinfo'
> rec2 = sublin(result,2)
> rec3 = sublin(result,3)
> rec4 = sublin(result,4)
> xsiz = subwrd(rec2,4)
> ysiz = subwrd(rec2,6)
> ylo = subwrd(rec4,4)
> xhi = subwrd(rec3,6)
> xd = xsiz - xhi
>
> ylolim=0.6*sf
> xdlim1=1.0*sf
> xdlim2=1.5*sf
> barsf=0.8*sf
> yoffset=0.2*sf
> stroff=0.05*sf
> strxsiz=0.12*sf
> strysiz=0.13*sf
>*
>* Decide if horizontal or vertical color bar
>* and set up constants.
>*
> if (ylo<ylolim & xd<xdlim1)
> say "Not enough room in plot for a colorbar"
> return
> endif
> cnum = subwrd(shdinfo,5)
>*
>* logic for setting the bar orientation with user overides
>*
> if (ylo<ylolim | xd>xdlim1)
> vchk = 1
> if(vert = 0) ; vchk = 0 ; endif
> else
> vchk = 0
> if(vert = 1) ; vchk = 1 ; endif
> endif
>*
>* vertical bar
>*
>
> if (vchk = 1 )
>
> if(xmid = '') ; xmid = xhi+xd/2 ; endif
> xwid = 0.2*sf
> ywid = 0.5*sf
>
> xl = xmid-xwid/2
> xr = xl + xwid
> if (ywid*cnum > ysiz*barsf)
> ywid = ysiz*barsf/cnum
> endif
> if(ymid = '') ; ymid = ysiz/2 ; endif
> yb = ymid - ywid*cnum/2
> 'set string 1 l 5'
> vert = 1
>
> else
>
>*
>* horizontal bar
>*
>
> ywid = 0.4
> xwid = 0.8
>
> if(ymid = '') ; ymid = ylo/2-ywid/2 ; endif
> yt = ymid + yoffset
> yb = ymid
> if(xmid = '') ; xmid = xsiz/2 ; endif
> if (xwid*cnum > xsiz*barsf)
> xwid = xsiz*barsf/cnum
> endif
> xl = xmid - xwid*cnum/2
> 'set string 1 tc 5'
> vert = 0
> endif
>
>
>*
>* Plot colorbar
>*
>
>
> 'set strsiz 'strxsiz' 'strysiz
> num = 0
> nskp = 0
> while (num<cnum)
> rec = sublin(shdinfo,num+2)
> col = subwrd(rec,1)
> hi = subwrd(rec,3)
>
> if (vert)
> yt = yb + ywid
> else
> xr = xl + xwid
> endif
>
> if(num!=0 & num!= cnum-1)
>
> 'set line 'col
> 'draw recf 'xl' 'yb' 'xr' 'yt
>
> 'set line 1 1 3'
>
> if (vert)
>* draw sides
> 'draw line 'xl' 'yb' 'xl' 'yt
> 'draw line 'xr' 'yb' 'xr' 'yt
> else
>* draw top/bot
> 'draw line 'xl' 'yb' 'xr' 'yb
> 'draw line 'xl' 'yt' 'xr' 'yt
> endif
> endif
>
> if(num = 0 )
>* low end
> if(vert = 1)
>* draw bottom triangle (low)
> xm=(xl+xr)*0.5
>
> 'set line 'col
> 'draw polyf 'xl' 'yt' 'xm' 'yb' 'xr' 'yt' 'xl' 'yt
>
> 'set line 1 1 3'
> 'draw line 'xl' 'yt' 'xm' 'yb
> 'draw line 'xm' 'yb' 'xr' 'yt
> else
>* draw right side triangle (low)
> ym=(yb+yt)*0.5
>
> 'set line 'col
> 'draw polyf 'xl' 'ym' 'xr' 'yb' 'xr' 'yt' 'xl' 'ym
>
> 'set line 1 1 3'
> 'draw line 'xl' 'ym' 'xr' 'yb
> 'draw line 'xr' 'yt' 'xl' 'ym
>
> if (nskp=0)
> 'draw line 'xr' 'yb' 'xr' 'yt
> endif
>
> endif
>
> endif
>
> if(num = cnum-1 )
>* high end
> if( vert = 1)
>* draw top triangle
> 'set line 'col
> 'draw polyf 'xl' 'yb' 'xm' 'yt' 'xr' 'yb' 'xl' 'yb
>
> 'set line 1 1 3'
> 'draw line 'xl' 'yb' 'xm' 'yt
> 'draw line 'xm' 'yt' 'xr' 'yb
> else
>* draw bottom triangle
> 'set line 'col
> 'draw polyf 'xr' 'ym' 'xl' 'yb' 'xl' 'yt' 'xr' 'ym
>
> 'set line 1 1 3'
> 'draw line 'xr' 'ym' 'xl' 'yb
> 'draw line 'xl' 'yt' 'xr' 'ym
> endif
>
> endif
>
> if (num<cnum-1)
> if (vert)
> xp=xr+stroff
> if (nskp=0)
> 'draw string 'xp' 'yt' 'hi
> endif
> else
> yp=yb-stroff
> if (nskp=0)
> 'draw string 'xr' 'yp' 'hi
> endif
> endif
> endif
>
> num = num + 1
> nskp = nskp+1
> if(nskp=skip); nskp=0; endif;
> if (vert); yb = yt;
> else; xl = xr; endif;
> endwhile
>return
More information about the gradsusr
mailing list