#! /usr/local/bin/tcsh -f # sorry, on 386bsd, "#! /bin/csh -f" causes mysterious behavir. #! /bin/csh -f # # psddraw -- show crt,wave,dso,tcl data files on PostScript # # 0.0: Sep. 23, 1994 by Dai Ishijima # set prog=$0 # # デフォルトの設定 # -l, -a に相当 # set layout=landscape set filetype=unknown set words=unknown set title="`date`" set name='' set offset=0 # # データファイルを PostScript の moveto, lineto, stroke の並びに # 変換するための awk script # set awkscript=`cat << END-OF-AWK-SCRIPT \ ((NR % 128) == 1) && (NR > 1) { \ print NR, \$1, "L S N" \ } \ ((NR % 128) == 1) { \ print NR, \$1, "M" \ } \ ((NR % 128) != 1) { \ print NR, \$1, "L" \ } \ END-OF-AWK-SCRIPT` # nx, ny: x, y方向の分割数 # sc: サイズ # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 set nx=(1 2 3 2 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6) set ny=(1 1 1 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6) set sc=(10 10 6 8 6 6 5 5 5 5 5 5 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3) # 用紙の寸法 set xmax=230 set ymax=160 # # コマンドラインを調べてデータファイルの数を数える # @ nfiles = 0 @ n = 1 while ($n <= $#argv) set i = $argv[$n] if ((x$i =~ x-*) && (x$i != x-)) then if (x$i == x-l) then set layout=landscape else if (x$i == x-p) then set layout=portrait else if (x$i == x-n) then @ n++ set title="$argv[$n]" else if (x$i =~ x-[sxo]) then @ n++ else if (x$i !~ x-[lpnsxcdwta124o]) then sh -c "echo $prog":" unknown option $i 1>&2" exit 1 endif else @ nfiles ++ if (x$i != x-) then if (!(-r $i)) then sh -c "echo $prog":" can\'t open $i 1>&2" exit 1 endif endif endif @ n++ end # ファイル指定がないときは標準入力 if ($nfiles == 0) then set argv=($argv -) @ nfiles = 1 endif # ファイルが多い時はエラー if ($nfiles > $#nx) then sh -c "echo $prog":" too many '('$nfiles')' files 1>&2" exit 1 endif # # データを表示する場所を決める # set xx=$nx[$nfiles] set yy=$ny[$nfiles] set scale=$sc[$nfiles] if (x$layout == xportrait) then set xoff=() set yoff=() @ x = $xx - 1 while ($x >= 0) @ y = 0 while ($y < $yy) @ ofs = ($xmax * (2 * $x + 1)) / (2 * $xx) set xoff=($xoff $ofs) @ ofs = ($ymax * (2 * $y + 1)) / (2 * $yy) set yoff=($yoff $ofs) @ y++ end @ x-- end else set xoff=() set yoff=() @ y = 0 while ($y < $yy) @ x = 0 while ($x < $xx) @ ofs = ($xmax * (2 * $x + 1)) / (2 * $xx) set xoff=($xoff $ofs) @ ofs = ($ymax * (2 * $y + 1)) / (2 * $yy) set yoff=($yoff $ofs) @ x++ end @ y++ end endif # # PostScript の初期設定部 # cat << END-OF-HEADER %!PS-Adobe-2.0 %%Creator: psddraw %%DocumentFonts: Helvetica %%BoundingBox: 85 85 540 740 %%Pages: (atend) %%EndComments % 長さの単位は (mm) % 枠の大きさ /BoxWidth 100 def /BoxHeight 80 def % 枠線の間隔 /GridStep 10 def % 枠の下のタイトルの位置 /TitleX 0 def /TitleY -50 def % 日付を表示する位置 /DateX 0 def /DateY 230 def % 省略形 awk script で使っている /M {moveto} def /L {lineto} def /S {stroke} def /N {newpath} def % 単位の変換 /mm {25.4 div 72 mul} def /pt {72 div 25.4 mul} def /FillCirc { gsave currentpoint newpath 3 mm 0 360 arc stroke fill grestore } def % センタリングして文字列を表示 /Cshow { dup stringwidth pop 2 div neg 0 rmoveto show } def % 枠線を描く手続き /Grid { BoxWidth 2 div neg GridStep BoxWidth 2 div { newpath BoxHeight 2 div neg moveto 0 BoxHeight rlineto stroke } for BoxHeight 2 div neg GridStep BoxHeight 2 div { newpath BoxWidth 2 div neg exch moveto BoxWidth 0 rlineto stroke } for } def % 単位を (mm) にする 72 25.4 div dup scale /Helvetica findfont 12 pt scalefont setfont % 左余白、下余白をとった位置を原点にする 30 30 translate END-OF-HEADER # # ここからまた csh スクリプト # # 日付の表示 echo DateX DateY moveto echo '('"$title"') show' # フォントの設定 echo /Helvetica findfont echo 12 pt $scale 10 div sqrt div scalefont setfont while ($#argv > 0) if (x$1 == x-c) then set filetype=crt else if(x$1 == x-d) then set filetype=dso else if(x$1 == x-w) then set filetype=wave else if(x$1 == x-t) then set filetype=tcl else if(x$1 == x-a) then set filetype=unknown set words=unknown else if (x$1 == x-1) then set words=1024 else if (x$1 == x-2) then set words=2048 else if (x$1 == x-4) then set words=4096 else if (x$1 == x-o) then shift; set words="$1" else if (x$1 == x-s) then shift; set name="$1" else if (x$1 == x-x) then shift; set offset="$1" else if (x$1 == x-n) then shift; else if (x$1 == x-p) then ; else if ((x$1 !~ x-[lp]) && (x$1 != x-) && (x$1 =~ x-*)) then sh -c "echo $prog":" unknown option $1 1>&2" exit 1 else # データの表示 echo gsave echo $yoff[1] $xoff[1] translate if ($layout == landscape) then echo 90 rotate endif echo $scale 10 div dup scale echo 0.1 $scale 10 div sqrt div setlinewidth echo Grid echo TitleX TitleY moveto if ((x"$name" != x) && (x"$name" != xunknown)) then echo "($name)" Cshow else if (x$1 == x-) then echo "()" Cshow set argv[1]='' else echo "($1)" Cshow endif echo BoxWidth 2 div neg 0 translate echo 0.2 $scale 10 div sqrt div setlinewidth echo newpath if (($filetype == dso) || (x$1 =~ x*dso??.???)) then echo 100 1024 div echo 10 25 div scale echo $offset -128 translate dso2crt $1 | awk "$awkscript" else if (($filetype == tcl) || (x$1 =~ x*tcl??.???)) then if (x$words == xunknown) then if (x$1 == x) then set cwords=1024 else #set cwords=`ls -l $1 | awk '{print $4/2}'` set cwords=`ls -l $1 | awk '{print $5/2}'` endif else set cwords=$words endif echo 100 $cwords div echo 10 100 div scale echo $offset -512 translate tcl2wave $1 | head -$cwords | awk "$awkscript" else if (($filetype == wave) || (x$1 =~ x*wave??.???)) then if ((x$words == xunknown) && (x$1 != x)) then set cwords=`wc -l <$1` else set cwords=$words endif echo 100 $cwords div echo 10 100 div scale echo $offset -512 translate cat $1 | head -$cwords | awk "$awkscript" else if (($filetype == dl) || (x$1 =~ x?????-??.???)) then if ((x$words == xunknown) && (x$1 != x)) then set cwords=`wc -l <$1` else set cwords=$words endif echo 100 $cwords div echo 8 6553 div scale echo $offset 0 translate cat $1 | head -$cwords | awk "$awkscript" else if (x$1 =~ x??-??.?????) then if ((x$words == xunknown) && (x$1 != x)) then set cwords=`wc -l <$1` else set cwords=$words endif echo 100 $cwords div #1.25V/div # echo 8 10 div scale # 1V/div echo 8 8 div scale echo $offset 0 translate awk '{print $2}' $1 | head -$cwords | awk "$awkscript" else echo 100 1024 div echo 10 25 div scale echo $offset -128 translate cat $1 | awk "$awkscript" endif echo stroke echo grestore shift xoff; shift yoff endif shift end cat <