# **************************************** # Making batch file for legend drawing # **************************************** # Data format # xlen ylen strP dx dy # ipt scl llen # strTX[NR] strLW[NR] strSS[NR] strSG[NR] strSW[NR] # ......... ......... ......... ......... ......... # ......... ......... ......... ......... ......... # xlen, ylen : width and height of graph # strP : position of legend box in the graph # "bl" bottom left # "br" bottom right # "tr" top right # "tl" top left # "ot" out top # "or" out right # dx, dy : minimum distance from axis to legend box # ipt : font size in point # scl : width/height of 1 font # llen : length of line # sx, sy : width and height of legend box # xx, yy : bottom left of the legend box # strTX[] : text # strLW[] : element of line (width, color, type) # strSS[] : type of symbol (type and dimension) # strSG[] : fill color of symbol (color) # strSW[] : external line of symbol (thickness and color) # BEGIN{ FS="$"; } { #******************************* # Treatment of input file data #******************************* # gsub(/^ +/, "", $i);gsub(/ +$/, "", $i); # erase of blanks at top and end of the strings # if(NR==1){ for(i=1;i<=5;i++){gsub(/^ +/, "", $i);gsub(/ +$/, "", $i);} xlen=$1;ylen=$2;strP=$3;dx=$4;dy=$5; } if(NR==2){ for(i=1;i<=3;i++){gsub(/^ +/, "", $i);gsub(/ +$/, "", $i);} ipt=$1;scl=$2;llen=$3; } if(3<=NR){ for(i=1;i<=5;i++){gsub(/^ +/, "", $i);gsub(/ +$/, "", $i);} strTX[NR-2]=$1;strLW[NR-2]=$2;strSS[NR-2]=$3;strSG[NR-2]=$4;strSW[NR-2]=$5; } } END{ #******************************* # Calculation and output #******************************* nd=NR-2; lmax=0; for(i=1;i<=nd;i++){ ss=strTX[i] gsub(/(@%%)[0-9]+(%%)/,"",ss);gsub(/(@%%%%)/,"",ss);gsub(/\\[0-9]+/,"\\",ss);gsub(/(@\+)/,"",ss);gsub(/(@\-)/,"",ss);gsub(/(@\#)/,"",ss); if(lmax_legend0.txt\n",0,0; printf "echo %d %d >>_legend0.txt\n",1+lmax+1+llen+1,0; printf "echo %d %d >>_legend0.txt\n",1+lmax+1+llen+1,nd; printf "echo %d %d >>_legend0.txt\n",0,nd; #===================================== # making file for line length #===================================== for(i=1;i<=nd;i++){ printf "echo %d %.1f >_legend%d.txt\n",1+lmax+1,nd-i+0.5,i; printf "echo %d %.1f >>_legend%d.txt\n",1+lmax+1+llen,nd-i+0.5,i; } #===================================== # difining dimension of legend box #===================================== sx=(ipt*(1+lmax+1+llen+1))*0.0353*scl; sy=((2+ipt+2)*nd)*0.0353; if(match(strP,"bl")!=0){xx=dx;yy=dy;} if(match(strP,"br")!=0){xx=xlen-sx-dx;yy=dy;} if(match(strP,"tr")!=0){xx=xlen-sx-dx;yy=ylen-sy-dy;} if(match(strP,"tl")!=0){xx=dx;yy=ylen-sy-dy;} if(match(strP,"ot")!=0){xx=xlen-sx-dx;yy=ylen+dy;} if(match(strP,"or")!=0){xx=xlen+dx;yy=dy;} #===================================== # output of legend box #===================================== printf "psbasemap -R0/%d/0/%d -JX%.1f/%.1f -G255 -P -X%.1f -Y%.1f -O -K>>%s\n",1+lmax+1+llen+1,nd,sx,sy,xx,yy,"%fig%"; printf "psxy _legend0.txt -R -J -G255/255/255 -W3 -N -O -K>>%s\n","%fig%"; #===================================== # output of line elements #===================================== for(i=1;i<=nd;i++){ if(match(strLW[i],"---")==0)printf "psxy _legend%d.txt -R -J -W%s -N -O -K>>%s\n",i,strLW[i],"%fig%"; } #===================================== # output of symbol #===================================== for(i=1;i<=nd;i++){ if(match(strSS[i],"---")==0){ if(match(strSG[i],"---")!=0&&match(strSW[i],"---")!=0){ printf "echo %.f %.1f | psxy -R -J -S%s -N -O -K>>%s\n",1+lmax+1+0.5*llen,nd-i+0.5,strSS[i],"%fig%"; } if(match(strSG[i],"---")==0&&match(strSW[i],"---")!=0){ printf "echo %.f %.1f | psxy -R -J -S%s -G%s -N -O -K>>%s\n",1+lmax+1+0.5*llen,nd-i+0.5,strSS[i],strSG[i],"%fig%"; } if(match(strSG[i],"---")==0&&match(strSW[i],"---")==0){ printf "echo %.f %.1f | psxy -R -J -S%s -G%s -W%s -N -O -K>>%s\n",1+lmax+1+0.5*llen,nd-i+0.5,strSS[i],strSG[i],strSW[i],"%fig%"; } } } #===================================== # output of text #===================================== for(i=1;i<=nd;i++){ if(i==nd){ printf "echo 1 %.1f %d 0 0 ML %s | pstext -R -J -N -O >> %s\n",nd-i+0.5,ipt,strTX[i],"%fig%"; }else{ printf "echo 1 %.1f %d 0 0 ML %s | pstext -R -J -N -O -K>> %s\n",nd-i+0.5,ipt,strTX[i],"%fig%"; } } }