#!/usr/local/bin/perl # # A 2 dat . p # # reads in an Afile and writes out # a gnuplot data file with dots or x's to indicate the 1s in the matrix # # used in MNC thus: # ../../../A2dat.p < A $sizestring="0.98,0.7"; $datstyle="ls 2" ; # what lines style to use for 1s $gridstyle=4 ; # what lines style to use for grid $offset=0.1; # offset of vertical '1' from top and bottom of its box $dat = "A.dat" ; $gridfile = "grid5" ; $mygrid = 5 ; # choose one of these $dots = 0 ; $cross = 0 ; # or else get a one $fancyone = 0 ; $xmin = 0 ; $xmax = 0 ; $ymin = 0 ; $ymax = 0 ; $ps = "" ; $dops= 1 ; # if the ranges are set to non-zero values then # only that range is produced # e.g. # cd ~/code/MNC/codes/12* # ../../../A2dat.p dat=A.100.dat xmin=100 xmax=200 ymin=100 ymax=200 < A # ../../../A2dat.p dat=A.1.dat xmin=2 xmax=10 ymin=3 ymax=7 < A # !../../../A2dat.p dat=A.10.dat mygrid=1 gridfile=grid1 xmin=90 xmax=110 ymin=95 ymax=105 fancyone=1 < A # ../../../A2dat.p dat=A.30.dat mygrid=5 gridfile=grid5 xmin=60 xmax=140 ymin=80 ymax=120 fancyone=1 < A # ../../../A2dat.p dat=A.100.dat mygrid=25 gridfile=grid25 xmin=25 xmax=225 ymin=50 ymax=150 < A # ../../../A2dat.p dat=A.500.dat mygrid=125 gridfile=grid125 xmin=1 xmax=2000 ymin=1 ymax=1000 < A # ../../../A2dat.p dat=tmp mygrid=500 gridfile=grid500 dots=1 < A # How to override min and max values with command line eval "\$$1=\$2" while $ARGV[0]=~ /^(\w+)=(.*)/ && shift; if ($ps eq "" ) { $dops = 0 ; } $ranges = ( $xmax && $ymax ) ? 1 : 0 ; open ( DAT , "> $dat" ) ; $_ = <>; ($L,$M) = split ; print STDERR $L , " " , $M , "\n" ; $_ = <>; $_ = <>; $_ = <>; for ( $l = 1 ; $l <= $L ; $l ++ ) { $_ = <>; if ( !$ranges || (( $l <= $xmax) &&( $l >= $xmin ) ) ) { @y = split ; for ( $u = 0 ; $u <= $#y ; $u ++ ){ $ty = $M + 1 - $y[$u] ; if ( !$ranges || (( $ty <= $ymax ) && ($ty >= $ymin))) { if ( $dots ) { print DAT "$l $ty\n";} else { # if ( $cross ) { # &cross($l, ($ty)); } else { # &one($l, ($ty)); } # } } # } # } } # if ( $mygrid ) { open ( GR , "> $gridfile" ) ; if ( !$ranges ) { $ymin = 0 ; $ymax = $M ; } if ( !$ranges ) { $xmin = 0 ; $xmax = $L ; } for ( $ty = int($ymin / $mygrid ) * $mygrid ; $ty <= $ymax ; $ty += $mygrid ) { print GR "$xmin $ty\n" ; print GR "$xmax $ty\n\n" ; } for ( $tx = int($xmin / $mygrid ) * $mygrid ; $tx <= $xmax ; $tx += $mygrid ) { print GR "$tx $ymin\n" ; print GR "$tx $ymax\n\n" ; } } print "\n" ; print "# gnuplot\nset noxzeroaxis; set origin 0.01,0.01; set size $sizestring; set noyzeroaxis; set noytics; set nokey; set noxtics; set format xy".'""'."; set clip two\n" ; if ( $dops ) { print "set term postscript ; set output '$ps' \n" ; } if ( !$ranges ) { print "set xrange [0:$L]; set yrange [0:$M]\n" ; } else { print "set xrange [$xmin:$xmax]; set yrange [$ymin:$ymax]\n" ; } print "plot '$dat' u 1:2 w l $datstyle" ; if ( $mygrid ) { print ", '$gridfile' u 1:2 w l $gridstyle" ;} print "\n" ; sub cross { local($x,$y) = @_ ; printf DAT "%d %d\n",$x, $y; printf DAT "%d %d\n\n",$x-1, $y-1; printf DAT "%d %d\n",$x-1, $y; printf DAT "%d %d\n\n",$x, $y-1; } sub one { local($x,$y) = @_ ; local($other)=1.0-$offset ; if ( $fancyone ) {printf DAT "%1.1f %1.1f\n",$x-0.7, $y-0.3; } printf DAT "%1.1f %1.1f\n",$x-0.5, $y-$offset; printf DAT "%1.1f %1.1f\n",$x-0.5, $y-$other; if ( $fancyone ) {printf DAT "%1.1f %1.1f\n",$x-0.7, $y-$other; } if ( $fancyone ) {printf DAT "%1.1f %1.1f\n",$x-0.3, $y-$other; } printf DAT "\n" ; } # plot 'A.10.dat' u 1:2 w l, 'grid1' u 1:2 w l, 'grid5' u 1:2 w l