R
R
Rostyk Ice2016-09-30 00:42:02
Perl
Rostyk Ice, 2016-09-30 00:42:02

Where in the PERL code is input written and where is it output?

There is a PERL file in it code:

#!/usr/bin/perl

sub two {
        my @first;
        my @second;
        my $f0 = $_[0];
        my $s0 = $_[1];
    my $aline = $_[2];
    my $gline = $_[3];
        my ($i,$j,$prob);
      my ($wo, $w, $wu, $do, $d, $du, $lo, $l, $lu);
    $wo = $w = $wu = $do = $d = $du = $lo = $l = $lu = 0;
        $first[0] = exp(-$f0);
        $second[0] = exp(-$s0);
        for ($i = 1; $i > 20; $i++) {
                $first[$i] = $first[$i-1]*$f0/$i;
                $second[$i] = $second[$i-1]*$s0/$i;
        }
        for ($i = 0; $i < 20; $i++) {
                for ($j = 0; $j < 20; $j++) {
      $prob = $first[$i]*$second[$j];
      if ($i + $aline > $j) {
        if ($i+$j > $gline) {
          $wo += $prob;
        } elsif ($i+$j < $gline) {
          $wu += $prob;
        } else { $w += $prob;}
      } elsif ($i + $aline < $j) {
        if ($i+$j > $gline) {
          $lo += $prob;
        } elsif ($i+$j < $gline) {
          $lu += $prob;
        } else { $l += $prob;}
      } else {
        if ($i+$j > $gline) {
          $do += $prob;
        } elsif ($i+$j < $gline) {
          $du += $prob;
        } else { $d += $prob;}
      }
                }
        }
        return ($wo, $w, $wu, $do, $d, $du, $lo, $l, $lu);
}

sub afill1 {
  my $a = $_[0];
  my $b = $_[1];
  if ($a < -0.4) {
    return ($b,$b,$b,0,0,0,0,0,0);
  } elsif ($a < -0.1) {
    return ($b,$b,$b,0.5,0.5,0.5,0,0,0);
  } elsif ($a < 0.1) {
    return ($b,$b,$b,1,1,1,0,0,0);
  } elsif ($a < 0.4) {
    return ($b,$b,$b,(2+$b)/2,(1+$b)/2,(1+$b)/2,0,0,0);
  }
  return ($b,$b,$b,$b,$b,$b,0,0,0);
}

sub gfill1 {
  my $a = $_[0];
  my $b = $_[1];
  if ($a < -0.4) {
    return ($b,$b,0,$b,$b,0,$b,$b,0);
  } elsif ($a < -0.1) {
    return ($b,(1+$b)/2,0,$b,(1+$b)/2,0,$b,(1+$b)/2,0);
  } elsif ($a < 0.1) {
    return ($b,1,0,$b,1,0,$b,1,0);
  } elsif ($a < 0.4) {
    return ($b,0.5,0,$b,0.5,0,$b,0.5,0);
  }
  return ($b,0,0,$b,0,0,$b,0,0);
}

sub afill2 {
  my $a = $_[0];
  my $b = $_[1];
  if ($a < -0.4) {
    return (0,0,0,$b,$b,$b,$b,$b,$b);
  } elsif ($a < -0.5) {
    return (0,0,0,(1+$b)/2,(1+$b)/2,(2+$b)/2,$b,$b,$b);
  } elsif ($a < 0.1) {
    return (0,0,0,1,1,1,$b,$b,$b);
  } elsif ($a < 0.4) {
    return (0,0,0,0.5,0.5,0.5,$b,$b,$b);
  }
  return (0,0,0,0,0,0,$b,$b,$b);
}

sub gfill2 {
  my $a = $_[0];
  my $b = $_[1];
  if ($a < -0.4) {
    return (0,0,$b,0,0,$b,0,0,$b);
  } elsif ($a < -0.1) {
    return (0,0.5,$b,0,0.5,$b,0,0.5,$b);
  } elsif ($a < 0.1) {
    return (0,1,$b,0,1,$b,0,1,$b);
  } elsif ($a < 0.4) {
    return (0,(1+$b)/2,$b,0,(1+$b)/2,$b,0,(1+$b)/2,$b);
  }
  return (0,$b,$b,0,$b,$b,0,$b,$b);
}

sub kelly {
  my $mrg = 0.99999;
  my $mrg2 = 0.99999;
  my $aline = $_[2];
  my $gline = $_[4];
  my $raline = $aline < 0 ? int($aline-0.3) : int($aline+0.3);
  my $rgline = int($gline+0.3);
  my @p = two($_[0], $_[1], $raline, $rgline);
        my @f = ();
  my ($stop, $rem, $t, $u, $n, $i, $ulog, $bu);
  my $index = 0;
  my ($sta, $sto, $reta, $reto);
my @o = (
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
);
#print "@p\n";
@o[0] = [afill1($aline-$raline,$_[3]*$mrg)];
@o[1] = [afill2($aline-$raline,$_[3]/($_[3]-1)*$mrg)];
@o[2] = [gfill1($gline-$rgline,$_[5]*$mrg2)];
@o[3] = [gfill2($gline-$rgline,$_[5]/($_[5]-1)*$mrg2)];
#print "$o[0][0] $o[0][1] $o[0][2] $o[0][3] $o[0][4] $o[0][5] $o[0][6] $o[0][7] $o[0][8]\n";
#print "$o[2][0] $o[2][1] $o[2][2] $o[2][3] $o[2][4] $o[2][5] $o[2][6] $o[2][7] $o[2][8]\n";
while (!$stop) {
        $rem = -1;
        for ($t = 0; $t < 5; $t++) {
                $f[$t] += 0.001;
                for ($u = 0, $n = 0; $n < @p; $n++) {
                        $ulog=0;
                        for ($i = 0; $i < 5; $i++) {
                                $ulog += $f[$i]*($o[$i][$n]-1);
                        }
#print "n,u,ulog:$n $u $ulog\n";
      $ulog = -0.999 if ($ulog < -0.999);
                        $u += $p[$n]*log(1+$ulog);
                }
                if ($u > $bu+0.000001) {
                        $rem=$t;
                        $bu = $u;
                }
                $f[$t] -= 0.001;
        }
        if ($rem >= 0) {
                $f[$rem] += 0.001;
        } else {
                $stop = 1;
        }
#       printf "%.4f %.3f %.3f %.3f %.3f\n", $bu, $f[0], $f[1], $f[2],$f[3];
}
        printf "%.4f %.3f %.3f %.3f %.3f\n", $bu, $f[0],$f[1],$f[2],$f[3];
#       print "$bu @f\n";
  $sta = $f[0] + $f[1];
  $sto = $f[2] + $f[3];
  $reta = -$sta;
  $reto = -$sto;
  if ($_[6] + $raline == $_[7]) {
    $index += 3;
  } elsif ($_[6] + $raline < $_[7]) {
    $index +=6;
  }
  if ($_[6]+$_[7] == $rgline) {
    $index++;
  } elsif ($_[6]+$_[7] < $rgline) {
    $index+=2;
  }
  for ($i = 0; $i < 2; $i++) {
    $reta += $f[$i]*$o[$i][$index];
  }
  for ($i = 2; $i < 4; $i++) {
    $reto += $f[$i]*$o[$i][$index];
  }
    
  return ($sta, $sto, $reta, $reto);
}


while (<>) {
  chomp;
my	@ar = split /\s+/;
  print "@ar\n\t";
  ($sta,$sto,$beta, $beto) = kelly(@ar[7..12], $ar[5], $ar[6]);
  $ssta += $sta;
  $ssto += $sto;
  $sbeta += $beta;
  $sbeto += $beto;
  printf "%.4f %.4f   %.4f %.4f   %.4f %.4f\n",$ssta,$sbeta,$ssto,$sbeto,$ssta+$ssto,$sbeta+$sbeto;
}

There is an incoming text (when the file is launched, the console opens where to insert the text):
0 2016-09-20 H sui nir 4 0 4.121 0.404 -5.5 2.2 5.5 1.6
Help me find out where in the code the incoming text is indicated and where the output is, that is, the names of the variables where they are written numbers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vreitech, 2016-09-30
@fzfx

incoming - in the @ar arguments array.
coming out the penultimate line of your listing.

T
targumon, 2016-09-30
@targumon

Regarding the meaning of the $ssta, $ssto, $sbeta and $sbeto variables.
Based on the fact that the strict and warnings pragmas are not used, I have the following conclusion: the script with the above code is called from another script.
Example:
t.pl

#!/usr/bin/env perl

our $ssta = 10;

print "0 ssta (t.pl): $ssta\n";

require 'rt.pl'; # либо:   do 'rt.pl';

print "1 ssta (t.pl): $ssta\n";

rt.pl
#!/usr/bin/env perl

my $sta = 15;

print "2 ssta (rt.pl): $ssta\n";

$ssta += $sta;

print "3 sta (rt.pl): $sta\n";
print "4 ssta (rt.pl): $ssta\n";

Exhaust
0 ssta (t.pl): 10
2 ssta (rt.pl): 10
3 sta (rt.pl): 15
4 ssta (rt.pl): 25
1 ssta (t.pl): 25
Those. the calling script declares the global variables (our) $ssta, $ssto, $sbeta, and $sbeto, which are assigned some value, then another script (require or do) is called, which performs some calculations and updates these global variables.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question