sub gcprepare {
  return 1;
}

sub gctask {
  my ($task,$taskarg,$portion,$din,$dout) = @_;
  my $pOutSizeMin, $pOutSizeMax, $pOutStrategy;
  my $pInSizeMin, $pInSizeMax, $pInStrategy;
  my $cTimeMin, $cTimeMax, $cTimeStrategy;
  my $mSize, $mProg, $pCount;
  if ($taskarg =~ /(\d+)\s+(\d+)\s+(\w+)\s+(\d+)\s+(\d+)\s+(\w+)\s+(\d+)\s+(\d+)\s+(\w+)\s+(\d+)\s+(\w+)\s+(\d+)/) 
  {
    $pOutSizeMin   = $1;
    $pOutSizeMax   = $2;
    $pOutStrategy  = $3;
    $pInSizeMin    = $4;
    $pInSizeMax    = $5;
    $pInStrategy   = $6;
    $cTimeMin      = $7;
    $cTimeMax      = $8;
    $cTimeStrategy = $9;
    $mSize         = $10;
    $mProg         = $11;
    $pCount        = $12;
  }
  print STDERR "
pOutSizeMin   = $pOutSizeMin
pOutSizeMax   = $pOutSizeMax
pOutStrategy  = $pOutStrategy
pInSizeMin    = $pInSizeMin
pInSizeMax    = $pInSizeMax
pInStrategy   = $pInStrategy
cTimeMin      = $cTimeMin
cTimeMax      = $cTimeMax
cTimeStrategy = $cTimeStrategy
mSize         = $mSize
mProg         = $mProg
pCount        = $pCount
---
portion       = $portion\n";

  open F, "<$din";
  my $indata = <F>;
  close F;
  
  my $TimeToSleep = 0;
  if    ($cTimeStrategy eq 'C') { $TimeToSleep = $cTimeMin; }
  elsif ($cTimeStrategy eq 'R') { $TimeToSleep = $cTimeMin+int(rand($cTimeMax-$cTimeMin+1)); }
  elsif ($cTimeStrategy eq 'I') { $TimeToSleep = $cTimeMin+int(($cTimeMax-$cTimeMin)*$portion/$pCount); }
  elsif ($cTimeStrategy eq 'D') { $TimeToSleep = $cTimeMax-int(($cTimeMax-$cTimeMin)*$portion/$pCount); }
  print STDERR "TimeToSleep   = $TimeToSleep\n";

  my $ResDataSize = 0;
  if    ($pInStrategy eq 'C') { $ResDataSize = $pInSizeMin; }
  elsif ($pInStrategy eq 'R') { $ResDataSize = int ($pInSizeMin+rand($pInSizeMax-$pInSizeMin+1)); }
  elsif ($pInStrategy eq 'I') { $ResDataSize = $pInSizeMin+int(($pInSizeMax-$pInSizeMin)*$portion/$pCount); } 
  elsif ($pInStrategy eq 'D') { $ResDataSize = $pInSizeMax-int(($pInSizeMax-$pInSizeMin)*$portion/$pCount); }
  print STDERR "ResDataSize   = $ResDataSize\n\n";  

  if ($mProg ne 'N')
  {
    my $p='';
    if    ($mProg eq 'M') { $p='matrix'; }
    elsif ($mProg eq 'L') { $p='matrix_light'; }
    elsif ($mProg eq 'U') { $p='matrix_ultralight'; }
    # print STDERR "$p:\n";
    $p = "./$p" if ($^O ne 'MSWin32');
    $p = "$p $mSize ".($cTimeStrategy ne 'E' ? $TimeToSleep : '');
    `$p`;
  }
  else
  {
    sleep($TimeToSleep);
  }
  
  my $ResData="";
  for (my $i=0; $i<$ResDataSize; $i++)
  {
    $ResData=$ResData.($i%10);
  }
  open F,">$dout";
  printf F $ResData;
  close F;

  return 1;
}
1;