(sorry for the horrendously mystifying subject line... I don't know
how to explain this in one sentence)


I have the following rather simple code (lots of possibly irrelevant
code omitted).


 1> my $data_dir = "/Users/punkish/Data/carbonmodel/cnnf/models";
 2> my $BAD = -9999;
 3>
 4> my $poly  =
[[85,71],[85,97],[114,97],[114,94],[115,94],[115,87],[110,86],[110,58],[104,58],[104,65],[99,65],[99,71],[85,71]];
 5> my @xy = ();
 6> for my $point (@$poly) {
 7>     my $x = $point->[0];
 8>     my $y = 183 - $point->[1];
 9>     push @xy, $x, $y;
10> }
11>
12> my $pdl1 = readflex("$data_dir/bau_nep");    # Get the entire piddle stack
13> my $ypdl1 = $pdl1->slice(":,:,0")->squeeze;  # Get one year's
piddle out of the stack...
14> my ($sum1, $area1) = pnpoly('year' => 0, 'pdl' => $ypdl1, 'xy' => \...@xy);
15> print " sum1: $sum1\n";
16> print "area1: $area1\n";
17>
18> print '-' x 50> . "\n";
19>
20> my $pdl2 = readflex("$data_dir/bau_harvest");    # Get the entire
piddle stack
21> my $ypdl2 = $pdl2->slice(":,:,0")->squeeze;      # Get one year's
piddle out of the stack...
22> my ($sum2, $area2) = pnpoly('year' => 0, 'pdl' => $ypdl2, 'xy' => \...@xy);
23> print " sum2: $sum2\n";
24> print "area2: $area2\n";
25>
26> sub pnpoly {
27>     my (%args) = @_;
28>
29>     my $year = $args{'year'};
30>     my $pdl  = $args{'pdl'};
31>     my $xy   = $args{'xy'};
32>     ..
..
..> }

The above produces the following output --

punk...@lucknow ~/Desktop/pnpoly$perl test.pl
 sum1: 157.945693969727
area1: 508
--------------------------------------------------
 sum2: BAD
area2: 0

If I comment the lines 12 .. 16, I get the following output

punk...@lucknow ~/Desktop/pnpoly$perl test.pl
--------------------------------------------------
 sum2: 24.8699569702148
area2: 508

If I comment the lines 20 .. 24, I get the following output

punk...@lucknow ~/Desktop/pnpoly$perl test.pl
 sum1: 157.945693969727
area1: 508
--------------------------------------------------
punk...@lucknow ~/Desktop/pnpoly$


Why on earth do I get an incorrect answer in the first case, that is,
when I call pnpoly twice? Note that I am calling it on two different
datasets completely independent of each other. Obviously, something is
linked to something else, and I just am unable to notice it.

Many thanks in advance for helping me spot my silliness.


-- 
Puneet Kishor

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to