1#!/usr/bin/perl 2# 3 4 use FileHandle; 5 my $i=1; 6 my $j=1; 7 8 $r[$i][$j] = 1; 9 10 11 $firstcall = 1; 12 13 # Open op5dat.for 14 open(IN,"op5dat.for") || die "Sorry, I couldn't open op5dat.for\n"; 15 open(OUT,">op5dat") || die "Sorry, I couldn't open op5dat.\n"; 16 autoflush OUT 1; 17 # Write to the file... 18 printf OUT "#========================================================================\n"; 19 printf OUT "# R and S data ported from diehard and put into C-style matrix form\n"; 20 printf OUT "#========================================================================\n"; 21 # ...and also output to console, just for fun. 22 printf "#========================================================================\n"; 23 printf "# R and S data ported from diehard and put into C-style matrix form\n"; 24 printf "#========================================================================\n"; 25 26 # Initialize the table (read in the whole thing in order) 27 nextrs(); 28 for($i=0;$i<60;$i++) { 29 for($j=$i;$j<60;$j++){ 30 $r[$i][$j] = nextrs(); 31 $r[$j][$i] = $r[$i][$j]; 32 } 33 } 34 35 print OUT "static int r[60][60] = {\n"; 36 for($i=0;$i<60;$i++) { 37 print OUT " {"; 38 for($j=0;$j<59;$j++){ 39 printf OUT (" %10d,",$r[$i][$j]); 40 } 41 if($i<59){ 42 printf OUT (" %10d},\n",$r[$i][59]); 43 } else { 44 printf OUT (" %10d}\n",$r[$i][59]); 45 } 46 } 47 print OUT "};\n"; 48 49 for($i=0;$i<60;$i++) { 50 for($j=$i;$j<60;$j++){ 51 $s[$i][$j] = nextrs(); 52 $s[$j][$i] = $s[$i][$j]; 53 } 54 } 55 56 print OUT "static int s[60][60] = {\n"; 57 for($i=0;$i<60;$i++) { 58 print OUT " {"; 59 for($j=0;$j<59;$j++){ 60 printf OUT (" %10d,",$s[$i][$j]); 61 } 62 if($i<59){ 63 printf OUT (" %10d},\n",$r[$i][59]); 64 } else { 65 printf OUT (" %10d}\n",$r[$i][59]); 66 } 67 } 68 print OUT "};\n"; 69 70 exit; 71 72 73sub nextrs { 74 if($firstcall == 1){ 75 my $irs = 0; 76 my $jrs; 77 while(<IN>){ 78 chop; 79 @field = split(/\s+/,$_); 80 $fields = @field; 81 for($jrs=1;$jrs<$fields;$jrs++){ 82 $rs[$irs] = $field[$jrs]; 83 $irs++; 84 } 85 } 86 # print "# Read in $irs values\n"; 87 $irs = 0; 88 $firstcall = 0; 89 return; 90 } 91 92 return $rs[$irs++]; 93 94} 95 96