#!/afs/sipb/project/perldev/p -w

use strict;
use IO::File;

use vars qw( $q_name $baseopts );

$q_name = '/afs/zone.mit.edu/user/bert/THESIS_DATA/current/queue';

use vars qw( $x $y @xlim @ylim $xstep $ystep $i $j @ilim @jlim $line );

sub round ($) { return int($_[0] + ($_[0]>0 ? +.5 : -.5)); }
sub opts ($) { $line++;  print "$line> @_\n"; }

$xstep = $ystep = .06;

@xlim = (-.72,1.38);
@ylim = (-.42,.6);

@ilim = map round($_/$xstep), @xlim;
@jlim = map round($_/$ystep), @ylim;

# set up the file

IO::File->new( $q_name, 'r' )
  and die "$q_name already exists!\n";

select( IO::File->new( $q_name, 'w' )
	or die "$q_name couldn't be opened for writing: $!\n" );

print "****> -d -E .3 -0 0.322,0 -h 0.0179 -e 0.104 -s 0.023 -n 256 -t 0.01"
	  . " -I 200 -i 1200 -@ 10 -q $xstep -w $ystep\n";

# pass 1: "even" only, only third angles (1/12)

$line = 'A000';

for ($i = $ilim[0];  $i <= $ilim[1];  $i++) {
  $x = $i * $xstep;
  for ($j = $jlim[0];  $j <= $jlim[1];  $j++) {
    $y = $j * $ystep;
    opts "-x $x,$x -y $y,$y -a 30 -A 0" unless ($i % 2) || ($j % 2)

  }
}

# pass 2: fill in angles (+1/6 -> total 1/4)

$line = 'B000';

for ($i = $ilim[0];  $i <= $ilim[1];  $i++) {
  $x = $i * $xstep;
  for ($j = $jlim[0];  $j <= $jlim[1];  $j++) {
    $y = $j * $ystep;
    unless (($i % 2) || ($j % 2)) {
      opts "-x $x,$x -y $y,$y -a 30 -A 10";
      opts "-x $x,$x -y $y,$y -a 30 -A 20";
    }
  }
}

# pass 3: fill in diagonals (+1/4 -> total 1/2)

$line = 'C000';

for ($i = $ilim[0];  $i <= $ilim[1];  $i++) {
  $x = $i * $xstep;
  for ($j = $jlim[0];  $j <= $jlim[1];  $j++) {
    $y = $j * $ystep;
    if (($i % 2) && ($j % 2)) {
      opts "-x $x,$x -y $y,$y -a 10 -A 0";
    }
  }
}

# pass 4: fill in the rest (+1/2 -> all)

$line = 'D000';

for ($i = $ilim[0];  $i <= $ilim[1];  $i++) {
  $x = $i * $xstep;
  for ($j = $jlim[0];  $j <= $jlim[1];  $j++) {
    $y = $j * $ystep;
    if (($i % 2) != ($j % 2)) {
      opts "-x $x,$x -y $y,$y -a 10 -A 0";
    }
  }
}
