#!/usr/bin/perl

#    poincare.pl, slices rossler into poincare sections with rotating slice

#    Copyright (C) 2010 Timothy Jones

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.



use Math::Trig;
open(IN,"all.dat");
@filearray=<IN>;
$num=@filearray;

$a=0.432;
$b=2.0;
$c=4.0;
$da=(2*pi/700);

#Fixed Points
$x0=($c - sqrt($c*$c - 4*$a*$b))/2;
$y0=-($c - sqrt($c*$c - 4*$a*$b))/(2*$a);

for($i=0; $i<$num; $i++){
    @line=split(/\s+/,$filearray[$i]);
    $x=$line[0];
    $y=$line[1];
    $z=$line[2];
    $ttheta=atan2(abs($y-$y0),abs($x-$x0));

    if($y>$y0 && $x>$x0){$theta=$ttheta;}
    if($y>$y0 && $x<$x0){$theta=(pi/2 - $ttheta)+ pi/2;}
    if($y<$y0 && $x<$x0){$theta=$ttheta + pi;}
    if($y<$y0 && $x>$x0){$theta=(pi/2 - $ttheta) + 3*pi/2;}

#    print "$theta\n";

    for($a=0; $a<700; $a++)
         {
   	   $min=((2*pi)/700)*($a);
           $max=((2*pi)/700)*($a+1);
           if($theta < $max && $theta > $min)
                       {
		   $num=1000+$a;
		   $file=$num.".dat";
                   $radius=sqrt($x*$x + $y*$y);
                   open(OUT, ">>$file");
                   print OUT "$radius $z $min \n";
                       }
         }  

	
 
}

  

