\ cancel mode verify ! ! log_key.jnl ! ! Description : makes a vertical lograthmic color key for shade/fill plots for ! given min & max values, variable & viewport(main). ! $6-$10 needs to be adjusted to get the key at the ! required location with required size ! ! Argument description ! -------- ------------------------------------------------------------ ! Mandatory argumnets ! $1 (int) : lower value of the color key ; should be an integer power(0-4) of 10 ! $2 (int) : high " ; " power(1-5) of 10 ! $3 (text) : variable to be filled/shaded in double quotes like "rose[d=1]" ! ! Optional arguments ! $4 (text) : name of main view port (like vmain) ! $5 (text) : fill/shade command with qualifiers in double quotes like ! "fill/nolab/nokey" (defualt is "fill/nokey") ! $6 (real) : key position : x_low | default values of $6-$10 is for making ! $7 (real) : " : x_high | a color key of a main viewport defined with ! $8 (real) : " : y_low | xlim=0:0.96/ylim=0:1 (window aspect=1.0) ! $9 (real) : " : y_high | ! $10(real) : key size : text ( /text qualifier to "define view" ) ! ! Usage : ! go log_key key_low key_high variable [view_main] [fill_command] [key_xlo] [key_xhi] [key_ylo] [key_yhi] [key_txt] ! ! Example : ! set data etopo20.cdf ! set region/x=29.8:120/y=-20.2:50 ! go log_key 1, 10000,"rose[d=1]" ! <== with minimum argumnets ! .....OR..... ! define view/xlim=0:0.96/ylim=0:1 vmain ! go log_key 1, 10000,"rose[d=1]",vmain,"fill/nokey/nolab",0.81,1.00,0.10,0.90,0.50 ! ! <== with all arguments !----------------------------------------------------------------------------------------- ! mandatory let key_lo = $1" $1 is not an integer power of 10 : correct it " exit ENDIF IF `INT(b) LT b` THEN say " key_high -> $2 is not an integer power of 10 : correct it " exit ENDIF IF `a GT b` THEN say " key_low{$1} > key_high{$2} : CORRECT key_low & key_high " exit ENDIF IF `key_lo LT 1` THEN say " with current set up, the possible min value of " say " key_low is 1 but given value is $1" exit ENDIF IF `b GT 6` THEN say " with current set up, the possible max value of " say " key_high is 100000 but given value is $2" exit ENDIF ! get the "levels" according to given key_low and key_high ! levs is the possible levels let levs = {'(1,10,1)', '(10,100,10)', '(100,1000,100)', \ '(1E3,1E4,1E3)','(1E4,1E5,1E4)','(1E5,1E6,1E5)'} let lev`a+1` = levs[x=`a+1`] IF `a+1 LT b` THEN repeat/i=`a+2`:`b`:1 ( ;\ let lev`i` = lev`i-1` + levs[x=`i`] ;\ ) ENDIF let lev_dummy = lev`b` define symbol levf = `lev_dummy` ! define the fill command for the main plot as a "symbol" define symbol qt = \" define symbol cmnd = (\$comnd)/nolab/lev=(-inf)(\$qt)(\$levf)(\$qt)(inf) (\$var) ! save current reg to "save" & set new reg as required by the key. ! the log key will be drawn before the main fill/shade plot. define region/default save define reg/x=1:2 kreg set reg kreg ! define a x_axis and log y_axis (y_min is 1 and y_max is 100000) ! the data points on y_axis (ie lev_da) should be exactly matching ! with the fill levels defined by levf (ie. levs). let lev_da = {1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90, \ 100,200,300,400,500,600,700,800,900,1000,2000,\ 3000,4000,5000,6000,7000,8000,9000,10000,20000,\ 30000,40000,50000,60000,70000,80000,90000,100000,\ 200000,300000,400000,500000,600000,700000,800000,\ 900000,1000000} define axis/y ydummy=lev_da define axis/y key_y=Y[gy=ydummy,y=`key_lo`:`key_hi`] def axis/x=1:2:1 key_x let key_da=x[gx=key_x]-x[gx=key_x]+y[gy=key_y] define axis/y ylog=LOG(Y[gy=key_y]) ! define two viewports with same xlimits,yilmits & text ! one vieport will be used for getting tics and labels ! other vieport will be used for getting the colors define view/text=`keytxt`/xlim=`keyxlo`:`keyxhi`/ylim=`keyylo`:`keyyhi` key_v1 define view/text=`keytxt`/xlim=`keyxlo`:`keyxhi`/ylim=`keyylo`:`keyyhi` key_v2 ! tics and numeric lables set view key_v1 ppl axset 0,0,0,1 ; ppl axlabp 0,1; ppl axlsze .25,.25 ! plot/vlog/i=1/nolab/color=white key_da[gy=ylog@asn] ! lograthmic colors set view key_v2 ppl axlsze 0 0 ; ppl tics 0 0 0 0 0 0; ppl axset 1,1,1,1 ppl axlabp -1 -1 ! fill/pal=blue_darkred/set/nolab/nokey/levels=($qt)($levf)($qt) key_da[gy=ylog@asn] fill/pal=blue_darkred/set/nolab/nokey/levels=(-inf)($levf)(inf) key_da[gy=ylog@asn] ! ppl fill ! restore defaults ppl axlsze .1,.1 ; ppl tics .125 .25 .125 .25 -1 -1 cancel reg kreg SET REGION save ! get the main fill/shade plot ! for labelling or any other needs it is better to have the main viewport ! as the active one. set view ($vmn) ($cmnd) ! cancel defined symbols and variables cancel var key* ; cancel var lev* ; cancel var a ; cancel var b cancel symbol cmnd,vmn,var,levf,qt,comnd ! end of log_key.jnl set mode/last verify