[207] | 1 | * |
---|
| 2 | * Script to plot a colorbar |
---|
| 3 | * |
---|
| 4 | * The script will assume a colorbar is wanted even if there is |
---|
| 5 | * not room -- it will plot on the side or the bottom if there is |
---|
| 6 | * room in either place, otherwise it will plot along the bottom and |
---|
| 7 | * overlay labels there if any. This can be dealt with via |
---|
| 8 | * the 'set parea' command. In version 2 the default parea will |
---|
| 9 | * be changed, but we want to guarantee upward compatibility in |
---|
| 10 | * sub-releases. |
---|
| 11 | * |
---|
| 12 | * |
---|
| 13 | * modifications by mike fiorino 940614 |
---|
| 14 | * |
---|
| 15 | * - the extreme colors are plotted as triangles |
---|
| 16 | * - the colors are boxed in white |
---|
| 17 | * - input arguments in during a run execution: |
---|
| 18 | * |
---|
| 19 | * run cbarn sf vert xmid ymid |
---|
| 20 | * |
---|
| 21 | * sf - scale the whole bar 1.0 = original 0.5 half the size, etc. |
---|
| 22 | * vert - 0 FORCES a horizontal bar = 1 a vertical bar |
---|
| 23 | * xmid - the x position on the virtual page the center the bar |
---|
| 24 | * ymid - the x position on the virtual page the center the bar |
---|
| 25 | * |
---|
| 26 | * if vert,xmid,ymid are not specified, they are selected |
---|
| 27 | * as in the original algorithm |
---|
| 28 | * |
---|
| 29 | |
---|
| 30 | function colorbar (args) |
---|
| 31 | |
---|
| 32 | sf=subwrd(args,1) |
---|
| 33 | vert=subwrd(args,2) |
---|
| 34 | xmid=subwrd(args,3) |
---|
| 35 | ymid=subwrd(args,4) |
---|
| 36 | |
---|
| 37 | if(sf='');sf=1.0;endif |
---|
| 38 | |
---|
| 39 | * |
---|
| 40 | * Check shading information |
---|
| 41 | * |
---|
| 42 | 'query shades' |
---|
| 43 | shdinfo = result |
---|
| 44 | if (subwrd(shdinfo,1)='None') |
---|
| 45 | say 'Cannot plot color bar: No shading information' |
---|
| 46 | return |
---|
| 47 | endif |
---|
| 48 | |
---|
| 49 | * |
---|
| 50 | * Get plot size info |
---|
| 51 | * |
---|
| 52 | 'query gxinfo' |
---|
| 53 | rec2 = sublin(result,2) |
---|
| 54 | rec3 = sublin(result,3) |
---|
| 55 | rec4 = sublin(result,4) |
---|
| 56 | xsiz = subwrd(rec2,4) |
---|
| 57 | ysiz = subwrd(rec2,6) |
---|
| 58 | ylo = subwrd(rec4,4) |
---|
| 59 | xhi = subwrd(rec3,6) |
---|
| 60 | xd = xsiz - xhi |
---|
| 61 | |
---|
| 62 | ylolim=0.6*sf |
---|
| 63 | xdlim1=1.0*sf |
---|
| 64 | xdlim2=1.5*sf |
---|
| 65 | barsf=0.8*sf |
---|
| 66 | yoffset=0.2*sf |
---|
| 67 | stroff=0.05*sf |
---|
| 68 | strxsiz=0.08*sf |
---|
| 69 | strysiz=0.10*sf |
---|
| 70 | * |
---|
| 71 | * Decide if horizontal or vertical color bar |
---|
| 72 | * and set up constants. |
---|
| 73 | * |
---|
| 74 | if (ylo<ylolim & xd<xdlim1) |
---|
| 75 | say "Not enough room in plot for a colorbar" |
---|
| 76 | return |
---|
| 77 | endif |
---|
| 78 | cnum = subwrd(shdinfo,5) |
---|
| 79 | * |
---|
| 80 | * logic for setting the bar orientation with user overides |
---|
| 81 | * |
---|
| 82 | if (ylo<ylolim | xd>xdlim1) |
---|
| 83 | vchk = 1 |
---|
| 84 | if(vert = 0) ; vchk = 0 ; endif |
---|
| 85 | else |
---|
| 86 | vchk = 0 |
---|
| 87 | if(vert = 1) ; vchk = 1 ; endif |
---|
| 88 | endif |
---|
| 89 | * |
---|
| 90 | * vertical bar |
---|
| 91 | * |
---|
| 92 | |
---|
| 93 | if (vchk = 1 ) |
---|
| 94 | |
---|
| 95 | if(xmid = '') ; xmid = xhi+xd/2 ; endif |
---|
| 96 | xwid = 0.2*sf |
---|
| 97 | ywid = 0.5*sf |
---|
| 98 | |
---|
| 99 | xl = xmid-xwid/2 |
---|
| 100 | xr = xl + xwid |
---|
| 101 | if (ywid*cnum > ysiz*barsf) |
---|
| 102 | ywid = ysiz*barsf/cnum |
---|
| 103 | endif |
---|
| 104 | if(ymid = '') ; ymid = ysiz/2 ; endif |
---|
| 105 | yb = ymid - ywid*cnum/2 |
---|
| 106 | 'set string 1 l 3' |
---|
| 107 | vert = 1 |
---|
| 108 | |
---|
| 109 | else |
---|
| 110 | |
---|
| 111 | * |
---|
| 112 | * horizontal bar |
---|
| 113 | * |
---|
| 114 | |
---|
| 115 | ywid = 0.4 |
---|
| 116 | xwid = 0.8 |
---|
| 117 | |
---|
| 118 | if(ymid = '') ; ymid = ylo/2-ywid/2 ; endif |
---|
| 119 | yt = ymid + yoffset |
---|
| 120 | yb = ymid |
---|
| 121 | if(xmid = '') ; xmid = xsiz/2 ; endif |
---|
| 122 | if (xwid*cnum > xsiz*barsf) |
---|
| 123 | xwid = xsiz*barsf/cnum |
---|
| 124 | endif |
---|
| 125 | xl = xmid - xwid*cnum/2 |
---|
| 126 | 'set string 1 tc 3' |
---|
| 127 | vert = 0 |
---|
| 128 | endif |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | * |
---|
| 132 | * Plot colorbar |
---|
| 133 | * |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | 'set strsiz 'strxsiz' 'strysiz |
---|
| 137 | num = 0 |
---|
| 138 | while (num<cnum) |
---|
| 139 | rec = sublin(shdinfo,num+2) |
---|
| 140 | col = subwrd(rec,1) |
---|
| 141 | hi = subwrd(rec,3) |
---|
| 142 | if (vert) |
---|
| 143 | yt = yb + ywid |
---|
| 144 | else |
---|
| 145 | xr = xl + xwid |
---|
| 146 | endif |
---|
| 147 | |
---|
| 148 | if(num!=0 & num!= cnum-1) |
---|
| 149 | 'set line 1 1 10' |
---|
| 150 | 'draw rec 'xl' 'yb' 'xr' 'yt |
---|
| 151 | 'set line 'col |
---|
| 152 | 'draw recf 'xl' 'yb' 'xr' 'yt |
---|
| 153 | if (num<cnum-1) |
---|
| 154 | if (vert) |
---|
| 155 | xp=xr+stroff |
---|
| 156 | 'draw string 'xp' 'yt' 'hi |
---|
| 157 | else |
---|
| 158 | yp=yb-stroff |
---|
| 159 | 'draw string 'xr' 'yp' 'hi |
---|
| 160 | endif |
---|
| 161 | endif |
---|
| 162 | endif |
---|
| 163 | |
---|
| 164 | if(num = 0 ) |
---|
| 165 | |
---|
| 166 | if(vert = 1) |
---|
| 167 | |
---|
| 168 | xm=(xl+xr)*0.5 |
---|
| 169 | 'set line 1 1 10' |
---|
| 170 | 'draw line 'xl' 'yt' 'xm' 'yb |
---|
| 171 | 'draw line 'xm' 'yb' 'xr' 'yt |
---|
| 172 | 'draw line 'xr' 'yt' 'xl' 'yt |
---|
| 173 | |
---|
| 174 | 'set line 'col |
---|
| 175 | 'draw polyf 'xl' 'yt' 'xm' 'yb' 'xr' 'yt' 'xl' 'yt |
---|
| 176 | |
---|
| 177 | else |
---|
| 178 | |
---|
| 179 | ym=(yb+yt)*0.5 |
---|
| 180 | 'set line 1 1 10' |
---|
| 181 | 'draw line 'xl' 'ym' 'xr' 'yb |
---|
| 182 | 'draw line 'xr' 'yb' 'xr' 'yt |
---|
| 183 | 'draw line 'xr' 'yt' 'xl' 'ym |
---|
| 184 | |
---|
| 185 | 'set line 'col |
---|
| 186 | 'draw polyf 'xl' 'ym' 'xr' 'yb' 'xr' 'yt' 'xl' 'ym |
---|
| 187 | |
---|
| 188 | endif |
---|
| 189 | |
---|
| 190 | endif |
---|
| 191 | |
---|
| 192 | if (num<cnum-1) |
---|
| 193 | if (vert) |
---|
| 194 | xp=xr+stroff |
---|
| 195 | 'draw string 'xp' 'yt' 'hi |
---|
| 196 | else |
---|
| 197 | yp=yb-stroff |
---|
| 198 | 'draw string 'xr' 'yp' 'hi |
---|
| 199 | endif |
---|
| 200 | endif |
---|
| 201 | |
---|
| 202 | if(num = cnum-1 ) |
---|
| 203 | |
---|
| 204 | if( vert = 1) |
---|
| 205 | 'set line 1 1 10' |
---|
| 206 | 'draw line 'xl' 'yb' 'xm' 'yt |
---|
| 207 | 'draw line 'xm' 'yt' 'xr' 'yb |
---|
| 208 | 'draw line 'xr' 'yb' 'xl' 'yb |
---|
| 209 | |
---|
| 210 | 'set line 'col |
---|
| 211 | 'draw polyf 'xl' 'yb' 'xm' 'yt' 'xr' 'yb' 'xl' 'yb |
---|
| 212 | else |
---|
| 213 | |
---|
| 214 | 'set line 1 1 10' |
---|
| 215 | 'draw line 'xr' 'ym' 'xl' 'yb |
---|
| 216 | 'draw line 'xl' 'yb' 'xl' 'yt |
---|
| 217 | 'draw line 'xl' 'yt' 'xr' 'ym |
---|
| 218 | |
---|
| 219 | 'set line 'col |
---|
| 220 | 'draw polyf 'xr' 'ym' 'xl' 'yb' 'xl' 'yt' 'xr' 'ym |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | endif |
---|
| 224 | |
---|
| 225 | endif |
---|
| 226 | |
---|
| 227 | if (num<cnum-1) |
---|
| 228 | if (vert) |
---|
| 229 | xp=xr+stroff |
---|
| 230 | 'draw string 'xp' 'yt' 'hi |
---|
| 231 | else |
---|
| 232 | yp=yb-stroff |
---|
| 233 | 'draw string 'xr' 'yp' 'hi |
---|
| 234 | endif |
---|
| 235 | endif |
---|
| 236 | |
---|
| 237 | num = num + 1 |
---|
| 238 | if (vert); yb = yt; |
---|
| 239 | else; xl = xr; endif; |
---|
| 240 | endwhile |
---|
| 241 | return |
---|
| 242 | |
---|