* * Script to draw lines, which sets vrange and create a legend automatically * * Written MC, LSCE, Mars 2000, Modified CBAR_LINE script * Modify by B.-J. Tsuang, NCHU, Nov 2005 * function lineplot (args) * nusage=41 usage.0 ='lineplot: draw lines, which sets vrange and creates a legend automatically' usage.1=' lineplot -x X -y Y -h 0|1 -p -s 0|1|2 -v v1 v2 ... vn -l "l1" "l2" ... "ln"' usage.2='' usage.3=' parameters: ' usage.4=' -x X x position of the lenend center on graph (in) (default at the center of the graph)' usage.5=' -y Y y position on graph (in) (default at the bottom of the graph)' usage.6=' -h 0|1 1: draw legend horizontally (default); 0: vertically.' usage.7=' -p if set, user can click on graphic to place legend.' usage.8=' -s 0|1|2 0: GrADS default symbol (white_line green_line yellow_line ..)' usage.9=' 1: (symbol white_line green_line ...)(default)' usage.10=' 2: (white_line green_line red_line ...)' usage.11=' -v v1 v2 ... vn variables for line plot, the variables can be any' usage.12=' grads vaild variable without "-", including define variables' usage.13=' -l "l1" "l2" ... "ln" legend for each variables, must be double, e.g., "ERA40" "NCEP2"' usage.14=' Use lineplot without parameters to get a short discription.' usage.15=' Function call and switches can be uppercase and lowercase.' usage.16=' Defaults are 0 and no text.' usage.17=' If one keyword misses a value, lineplot uses the default for the remaining values.' usage.18='' usage.19=' Example calls of lineplot:' usage.20='' usage.21=' set time jan1980 dec2000' usage.22=' set x 1' usage.23=' set y 1' usage.24=' define diff=p.1-slp.2' usage.25=' lineplot -v p.1 slp.2 diff -l "ERA40" "NCEP2" "ERA40-NCEP2" -s 2' usage.26=' lineplot -v ta.3 ta.1 ta.2 -l "obs" "ERA40" "NCEP2" -s 1' usage.27=' lineplot -v t(lev=1000) t(lev=850) t(lev=700) -l "1000 hPa" "850 hPa" "700 hPa" -s 2' usage.28='' usage.29=' to place the legend center at (3 in, 7.8 in) from the left bottom corner ' usage.30=' lineplot -v ta.3 ta.1 -l "obs" "ERA40" -x 3 -y 7.8' usage.31=' to place the lenged manually ' usage.32=' lineplot -v ta.3 ta.1 -l "obs" "ERA40" -p' usage.33=' line plot only:' usage.34=' lineplot -v ta.3 ta.1 -s 2' usage.35=' legend only:' usage.36=' lineplot -l "obs" "ERA40" -s 2' usage.37=' draw legend vertically:' usage.38=' lineplot -l "obs" "ERA40" -h 0' usage.39='' usage.40='' * ********************************************************************************** ********************************************************************************** *********************** STANDARDS ************************************************** i=1 f=subwrd(args,i) herr=0 xerr=0 yerr=0 nerr=0 terr=0 xx=0 yy=0 k=0 l=0 m=0 nl=0 nvar=0 placeit=0 drawHorizontal=1 ss=1 *********************** HELP ************************************************** if (f='') i=0 while (inl);nl=nl;endif #if (nn!=0 & nn!=nl) # if (nn>nl) # say '# of lines greater # of texts' # say 'Rest will be lines with empty strings' # else # say '# of lines lower # of texts' # say 'discard # of lines; take # of texts' # endif #endif #if (nl>10) # say '# limit to 10' # say 'discard the rest' # nl=10 #endif *********************** lineplot ************************************************** i=0 vstring="" while(i0);plot(vstring);endif *********************** FILL TEXT ************************************************** p=0 while (pnl); texts.p=''; endif endwhile *********************** GRAPHICS ************************************************** 'query gxinfo' ****** example: rec2 => Page Size = 11 by 8.5 rec2 = sublin(result,2) ****** rec3 => X Limits = 1.3 to 10.2 rec3 = sublin(result,3) ****** rec4 => Y Limits = 1.58 to 6.92 rec4 = sublin(result,4) xsiz = subwrd(rec2,4) ysiz = subwrd(rec2,6) yhi = subwrd(rec4,6) ylo = subwrd(rec4,4) xhi = subwrd(rec3,6) xlo = subwrd(rec3,4) xd = xsiz - xhi yd = ysiz - ylo xwid = xsiz/20 ywid=yd/20 if (xx=0); xx=(xlo+xhi)/2; endif; if (yy=0) if (drawHorizontal=1) yy=ylo else yy=ylo+ywid*nl endif endif; #if (yy=0); yy=yhi; endif; if (placeit=1) say '' say 'Click where you want the left upper corner of the legend' 'query bpos' x = subwrd(result,3) y = subwrd(result,4) say 'Print legend at X Y: 'x' 'y xx=x yy=y endif xl=xx xr=xl+xwid y=yy y=y+ywid 'set strsiz 0.12 0.13' *********************** DRAW LEGEND ************************************************** * calculate the legend length o=0 length=0 while (o(xhi-xlo)) length=(xhi-xlo) endif o=0 while (oxhi) # change new line xl=xx-length/2 y=y+ywid endif endif xr=xl+xwid else y=y-ywid endif if(_style.old!=0) 'set line '_col.old' '_style.old' '_thick.old 'draw mark '_mark.old' 'xl' 'y' 0.1' 'draw line 'xl' 'y' 'xr' 'y 'draw mark '_mark.old' 'xr' 'y' 0.1' else x=(xl+xr)/2. 'set line '_col.old' '_style.old' '_thick.old 'draw mark '_mark.old' 'x' 'y' 0.1' endif 'set string 1 l 5' if (texts.o!='') 'draw string '%(xr+0.1)%' 'y' 'texts.o endif endwhile return #exit *********************** END ************************************************** ********************************************************************************** ********************************************************************************** ********************************************************************************** function plot(args) # say "plot " args * Get arguments if (args='?') say 'usage: plot v1 v2 ... vn' say 'v1 = variable 1' say 'v2 = variable 2' say 'vn = variable n' return else i=0 i1=i+1 var.i=subwrd(args,i1) while (var.i!='') i=i+1 i1=i+1 var.i=subwrd(args,i1) endwhile nvar=i endif # Find vrange 'set gxout stat' i=0 while (irangeMax);rangeMax=localMax;endif endif i=i+1 endwhile if((rangeMax-rangeMin)>0) mul=1 while((rangeMax-rangeMin)