replying to my own email...

On Thu, Nov 4, 2010 at 6:42 PM, P Kishor <[email protected]> wrote:
> (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.
>

There is something going on beyond my understanding here. I was able
to solve the above by calculating the selection mask only once,
however, if I calculate the selection mask more than once in the same
code call, it seems to produce a wrong mask the second time. I even
create brand new variables, even a different sub. No matter. It is as
if something is connected to something else, and the subsequent runs
are affected by the first run.

The problem is solved by taking a different approach, but I would sure
like to understand what is going on.


> Many thanks in advance for helping me spot my silliness.
>
>
> --
> Puneet Kishor
>



-- 
Puneet Kishor http://www.punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
-----------------------------------------------------------------------
Assertions are politics; backing up assertions with evidence is science
=======================================================================

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

Reply via email to