Advertisement
cd62131

CacheCalculation

Jul 27th, 2014
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.77 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use feature 'say';
  5. use Math::Trig;
  6. my $file = 'datatest.dat';
  7. open my $in, '<', $file or die "File Not Found\n";
  8. my @aa = ();
  9. my @bb = ();
  10. my @cc = ();
  11. my @dd = ();
  12. my $i = 0;
  13. while(<$in>){
  14.   my @data = split;
  15.   my $ra = deg2rad $data[0]; #radに変換
  16.   my $dec = deg2rad $data[1];
  17.   $aa[$i] = cos $dec;
  18.   $bb[$i] = sin $ra;
  19.   $cc[$i] = cos $ra;
  20.   $dd[$i] = sin $dec;
  21.   $i++;
  22. }
  23. close($in);
  24. my $size = scalar @aa;
  25. for ($i = 0; $i < $size; $i++) {
  26.   for (my $j = $i + 1; $j < $size; $j++) {
  27.     my $theta = rad2deg(
  28.       sqrt(
  29.         ($aa[$i] * $bb[$i] - $aa[$j] * $bb[$j]) ** 2 +
  30.         ($aa[$i] * $cc[$i] - $aa[$j] * $cc[$j]) ** 2 +
  31.         ($dd[$i] - $dd[$j]) ** 2
  32.       )
  33.     );
  34.     say $theta;
  35.   }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement