598
|
1 #!/usr/bin/perl
|
|
2
|
|
3 # fix Cerium xml normal vector
|
|
4
|
|
5 my $i = -1;
|
|
6 my (@x,@y,@z);
|
|
7 my @cord;
|
|
8 my $fix = 1;
|
|
9
|
|
10 sub v {
|
|
11 print "$x[0] $y[0] $z[0]\n";
|
|
12 print "$x[1] $y[1] $z[1]\n";
|
|
13 print "$x[2] $y[2] $z[2]\n";
|
|
14 }
|
|
15
|
|
16 sub outer {
|
|
17 my ($ax,$ay,$az) = (
|
|
18 $x[1]-$x[0],
|
|
19 $y[1]-$y[0],
|
|
20 $z[1]-$z[0],
|
|
21 );
|
|
22 my ($bx,$by,$bz) = (
|
|
23 $x[2]-$x[0],
|
|
24 $y[2]-$y[0],
|
|
25 $z[2]-$z[0],
|
|
26 );
|
|
27 my ($ox,$oy,$oz) = (
|
|
28 $ay*$bz - $az*$by,
|
|
29 -$ax*$bz + $az*$bx,
|
|
30 $ax*$by - $ay*$bx,
|
|
31 );
|
|
32 my($r) = sqrt($ox*$ox+$oy*$oy+$oz*$oz);
|
|
33 ($ox,$oy,$oz) = ($ox/$r,$oy/$r,$oz/$r);
|
|
34 push(@cord, [$ox,$oy,$oz]);
|
|
35 # print " $ox $oy $oz\n";
|
|
36 }
|
|
37
|
|
38 while(<>) {
|
|
39 if (! $fix) {
|
|
40 if (/<sur/) {
|
|
41 print;
|
|
42 next;
|
|
43 }
|
|
44 }
|
|
45 if (/<normal/) {
|
|
46 $i= -2;
|
|
47 print if ($fix);
|
|
48 next;
|
|
49 }
|
|
50 if (/<\/normal/) {
|
|
51 $i = -1;
|
|
52 print if ($fix);
|
|
53 next;
|
|
54 }
|
|
55 if ( $i < -1) {
|
|
56 if ($i== -4) {
|
|
57 my $cord = shift(@cord);
|
|
58 if ($fix) {
|
|
59 print " $cord->[0] $cord->[1] $cord->[2] \n";
|
|
60 print " $cord->[0] $cord->[1] $cord->[2] \n";
|
|
61 print " $cord->[0] $cord->[1] $cord->[2] \n";
|
|
62 } else {
|
|
63 print "outer $i $cord->[0] $cord->[1] $cord->[2] \n";
|
|
64 print ;
|
|
65 }
|
|
66 $i = -2;
|
|
67 } else {
|
|
68 $i--;
|
|
69 }
|
|
70 next;
|
|
71 }
|
|
72 print if ($fix);
|
|
73 if (/<\/coord/) {
|
|
74 $i = -1;
|
|
75 next;
|
|
76 }
|
|
77 if (/<coord/) {
|
|
78 @cord = ();
|
|
79 $i=0;
|
|
80 next;
|
|
81 }
|
|
82 if ($i<0) {
|
|
83 next;
|
|
84 }
|
|
85 if (/([-]*[.\d]+)\s+([-]*[.\d]+)\s+([-]*[.\d]+)/) {
|
|
86 ($x[$i],$y[$i],$z[$i]) = ($1,$2,$3);
|
|
87 # print "$i $_";
|
|
88 if ($i==2) {
|
|
89 &outer;
|
|
90 $i = 0;
|
|
91 next;
|
|
92 }
|
|
93 $i++;
|
|
94 } else {
|
|
95 $i = -1;
|
|
96 }
|
|
97 }
|
|
98
|
|
99 # end
|