******************************************************************************* * USAGE * cbarn_xy.gs [] * *------------------------------------------------------------------------------ * PURPOSE * This script will plot a colorbar at a fixed place specified by , * , , and . * * If height (= - ) is bigger than length (= - ), * the colorbar will be plotted vertically. * * If optional is not provided, the script will determine the size * of the labels according to the size of the colorbar. * * If a negative is provided, the labels will be omitted. * ******************************************************************************* function cbarn_xy(args) *-------------------------------------------------------------- * get input parameters [] *-------------------------------------------------------------- xmin=subwrd(args,1) xmax=subwrd(args,2) ymin=subwrd(args,3) ymax=subwrd(args,4) lbsz=subwrd(args,5) if( xmin='' | xmax='' | ymin='' | ymax='' ) say say '## cbarn_xy.gs ##################################################' say '# #' say '# USAGE: cbarn_xy.gs [] #' say '# #' say '# If ] is negative, the labels will be omitted. #' say '# #' say '#################################################################' say return endif if( xmin>=xmax | ymin>=ymax ) say say '## cbarn_xy.gs #################################' say '# #' say '# ERROR: invalid #' say '# #' say '################################################' say return endif if( lbsz='' ) lbsz=0 endif *-------------------------- * get dimension of colorbar *-------------------------- length=xmax-xmin height=ymax-ymin *--------------- * get mid points *--------------- xmid=(xmin+xmax)*0.5 ymid=(ymin+ymax)*0.5 *----------------- * get shading info *----------------- 'query shades' shdinfo=result if( subwrd(shdinfo,1)='None' ) say say '## cbarn_xy.gs #############' say '# #' say '# ERROR: no shading info #' say '# #' say '############################' say return endif *-------------------------- * get number of colors used *-------------------------- nc=subwrd(shdinfo,5) *========================= * plot horizontal colorbar *========================= if( length>height ) *--------------------------------------- * set length of each section in colorbar *--------------------------------------- dx=length/nc *---------------- * set string size *---------------- if( lbsz=0 ) ss=height*0.8 if( ss>0.2 ); ss=0.2; endif else ss=lbsz endif *------------------------- * set y-position of labels *------------------------- ylab=ymin-ss*0.5 *----------- * set string *----------- 'set strsiz ' ss 'set string 1 tc 5' *------------------------------- * plot first section as triangle *------------------------------- n=1 x0=xmin rec=sublin(shdinfo,n+1) col=subwrd(rec,1) lab=subwrd(rec,3) x1=x0+dx 'set line ' col 'draw polyf ' x0 ' ' ymid ' ' x1 ' ' ymax ' ' x1 ' ' ymin ' ' x0 ' ' ymid 'set line 1' 'draw line ' x0 ' ' ymid ' ' x1 ' ' ymax 'draw line ' x1 ' ' ymax ' ' x1 ' ' ymin 'draw line ' x1 ' ' ymin ' ' x0 ' ' ymid if( lbsz>=0 ) 'draw string ' x1 ' ' ylab ' ' lab endif x0=x1 n=n+1 *----------------------------------- * plot center sections as rectangles *----------------------------------- while( n=0 ) 'draw string ' x1 ' ' ylab ' ' lab endif x0=x1 n=n+1 endwhile *------------------------------ * plot last section as triangle *------------------------------ rec=sublin(shdinfo,n+1) col=subwrd(rec,1) x1=x0+dx 'set line ' col 'draw polyf ' x0 ' ' ymax ' ' x1 ' ' ymid ' ' x0 ' ' ymin ' ' x0 ' ' ymax 'set line 1' 'draw line ' x0 ' ' ymax ' ' x1 ' ' ymid 'draw line ' x1 ' ' ymid ' ' x0 ' ' ymin 'draw line ' x0 ' ' ymin ' ' x0 ' ' ymax *======================= * plot vertical colorbar *======================= else *--------------------------------------- * set height of each section in colorbar *--------------------------------------- dy=height/nc *---------------- * set string size *---------------- if( lbsz=0 ) ss=length*0.8 if( ss>0.2 ); ss=0.2; endif else ss=lbsz endif *------------------------- * set x-position of labels *------------------------- xlab=xmax+ss*0.5 *----------- * set string *----------- 'set strsiz ' ss 'set string 1 l 5' *------------------------------- * plot first section as triangle *------------------------------- n=1 y0=ymin rec=sublin(shdinfo,n+1) col=subwrd(rec,1) lab=subwrd(rec,3) y1=y0+dy 'set line ' col 'draw polyf ' xmin ' ' y1 ' ' xmax ' ' y1 ' ' xmid ' ' y0 ' ' xmin ' ' y1 'set line 1' 'draw line ' xmin ' ' y1 ' ' xmax ' ' y1 'draw line ' xmax ' ' y1 ' ' xmid ' ' y0 'draw line ' xmid ' ' y0 ' ' xmin ' ' y1 if( lbsz>=0 ) 'draw string ' xlab ' ' y1 ' ' lab endif y0=y1 n=n+1 *----------------------------------- * plot center sections as rectangles *----------------------------------- while( n=0 ) 'draw string ' xlab ' ' y1 ' ' lab endif y0=y1 n=n+1 endwhile *------------------------------ * plot last section as triangle *------------------------------ rec=sublin(shdinfo,n+1) col=subwrd(rec,1) y1=y0+dy 'set line ' col 'draw polyf ' xmid ' ' y1 ' ' xmax ' ' y0 ' ' xmin ' ' y0 ' ' xmid ' ' y1 'set line 1' 'draw line ' xmid ' ' y1 ' ' xmax ' ' y0 'draw line ' xmax ' ' y0 ' ' xmin ' ' y0 'draw line ' xmin ' ' y0 ' ' xmid ' ' y1 endif return