9 |
|
my $windoz = ($^O eq "MSWin32" or $^O eq "MSWin64"); |
10 |
|
use File::Temp qw/ :mktemp /; |
11 |
|
sub userror { |
12 |
< |
print STDERR "Usage: iso2klems [-t][-W][-s \"x=string;y=string\"] [input.dat]\n"; |
12 |
> |
print STDERR "Usage: iso2klems [-t][-f \"x=string;y=string\"][-u unit] [input.dat]\n"; |
13 |
|
exit 1; |
14 |
|
} |
15 |
|
my ($td,$rmtmp,$cmd); |
29 |
|
while ($#ARGV >= 0) { |
30 |
|
if ("$ARGV[0]" eq "-t") { |
31 |
|
$reverse = ! $reverse; |
32 |
< |
} elsif ("$ARGV[0]" eq "-s") { |
32 |
> |
} elsif ("$ARGV[0]" =~ /^-[fs]$/) { |
33 |
|
$wrapper .= " -f \"$ARGV[1]\""; |
34 |
|
shift @ARGV; |
35 |
+ |
} elsif ("$ARGV[0]" eq "-u") { |
36 |
+ |
$wrapper .= " -u $ARGV[1]"; |
37 |
+ |
shift @ARGV; |
38 |
|
} elsif ("$ARGV[0]" =~ /^-./) { |
39 |
|
userror(); |
40 |
|
} else { |
48 |
|
die "Invalid input data, requires 5 columns\n" if ( $? ); |
49 |
|
open (MYFH, ">> $funcfile"); |
50 |
|
print MYFH "DEG : PI/180;\n"; |
51 |
< |
print MYFH "and(a,b) : if(a,b,a);\n"; |
51 |
> |
print MYFH "sq(x) : x*x;\n"; |
52 |
|
print MYFH "eq(a,b) : min(a-b+1e-5,b-a+1e-5);\n"; |
53 |
|
print MYFH "rtheta(i) : select(i,5,15,25,35,45,55,65,75,90);\n"; |
54 |
|
print MYFH "nphis(i) : select(i,1,8,16,20,24,24,24,16,12);\n"; |
55 |
|
print MYFH "tdeg1(tb) : if(tb-1.5, (rtheta(tb)+rtheta(tb-1))/2, 0);\n"; |
56 |
< |
print MYFH "omega1(tb) : 2*PI*if(tb-1.5, (cos(rtheta(tb-1)*DEG)-cos(rtheta(tb)*DEG))/nphis(tb),"; |
57 |
< |
print MYFH "\t(1 - cos(rtheta(1)*DEG)));\n"; |
56 |
> |
print MYFH "omega1(tb) : PI*if(tb-1.5, (sq(cos(rtheta(tb-1)*DEG))-sq(cos(rtheta(tb)*DEG)))/nphis(tb),"; |
57 |
> |
print MYFH "\t(1 - sq(cos(rtheta(1)*DEG))));\n"; |
58 |
|
print MYFH "tbin(b,cnt) : if(nphis(b)-cnt-.5, b, tbin(b+1,cnt-nphis(b)));\n"; |
59 |
|
print MYFH "tdeg(b) : tdeg1(tbin(1,b-1));\n"; |
60 |
|
print MYFH "omega(b) : omega1(tbin(1,b-1));\n"; |
65 |
|
if ($windoz) { |
66 |
|
$cmd = qq{cnt $nsamps } . |
67 |
|
qq{| rcalc -f $funcfile -w -e "tdeg=180/$nsamps*(\$1+.5);abs(x):if(x,x,-x)" } . |
68 |
< |
qq{-e "theta=tdeg*DEG;ifact=2*PI*abs(cos(theta))*sin(theta)" } . |
68 |
> |
qq{-e "theta=tdeg*DEG;ifact=PI*PI*abs(cos(theta))*sin(theta)" } . |
69 |
|
q{-e "$1=ifact*Tdiff(tdeg);$2=ifact*Rdiff(tdeg)" } . |
70 |
|
qq{| total -$hsamps -m}; |
71 |
|
} else { |
72 |
|
$cmd = qq{cnt $nsamps } . |
73 |
|
qq{| rcalc -f $funcfile -w -e 'tdeg=180/$nsamps*(\$1+.5);abs(x):if(x,x,-x)' } . |
74 |
< |
qq{-e 'theta=tdeg*DEG;ifact=2*PI*abs(cos(theta))*sin(theta)' } . |
74 |
> |
qq{-e 'theta=tdeg*DEG;ifact=PI*PI*abs(cos(theta))*sin(theta)' } . |
75 |
|
q{-e '$1=ifact*Tdiff(tdeg);$2=ifact*Rdiff(tdeg)' -od } . |
76 |
|
qq{| total -id2 -$hsamps -m}; |
77 |
|
} |
91 |
|
qq{-e "Rd1=if($h2h[1]-.001,Rdiff(tideg)*Rdiff(tsdeg)/$h2h[1],0)" } . |
92 |
|
qq{-e "Td2=if($h2h[2]-.001,Tdiff(180-tideg)*Tdiff(180-tsdeg)/$h2h[2],0)" } . |
93 |
|
qq{-e "Rd2=if($h2h[3]-.001,Rdiff(180-tideg)*Rdiff(180-tsdeg)/$h2h[3],0)" } . |
94 |
< |
qq{-e "\$1=if(Tspec(0),if(diag,Tspec(tideg)/om,Td1*corr),Td1)" } . |
95 |
< |
qq{-e "\$2=if(Rspec(0),if(diag,Rspec(tideg)/om,Rd1*corr),Rd1)" } . |
96 |
< |
qq{-e "\$3=if(Tspec(180),if(diag,Tspec(180-tideg)/om,Td2*corr),Td2)" } . |
97 |
< |
qq{-e "\$4=if(Rspec(180),if(diag,Rspec(180-tideg)/om,Rd2*corr),Rd2)" }; |
94 |
> |
q{-e "$1=if(Tspec(0),if(diag,Tspec(tideg)/om,Td1*corr),Td1)" } . |
95 |
> |
q{-e "$2=if(Rspec(0),if(diag,Rspec(tideg)/om,Rd1*corr),Rd1)" } . |
96 |
> |
q{-e "$3=if(Tspec(180),if(diag,Tspec(180-tideg)/om,Td2*corr),Td2)" } . |
97 |
> |
q{-e "$4=if(Rspec(180),if(diag,Rspec(180-tideg)/om,Rd2*corr),Rd2)" }; |
98 |
|
} else { |
99 |
|
$cmd = qq{cnt 145 145 } . |
100 |
|
qq{| rcalc -f $funcfile } . |
103 |
|
qq{-e 'Rd1=if($h2h[1]-.001,Rdiff(tideg)*Rdiff(tsdeg)/$h2h[1],0)' } . |
104 |
|
qq{-e 'Td2=if($h2h[2]-.001,Tdiff(180-tideg)*Tdiff(180-tsdeg)/$h2h[2],0)' } . |
105 |
|
qq{-e 'Rd2=if($h2h[3]-.001,Rdiff(180-tideg)*Rdiff(180-tsdeg)/$h2h[3],0)' } . |
106 |
< |
qq{-e '\$1=if(Tspec(0),if(diag,Tspec(tideg)/om,Td1*corr),Td1)' } . |
107 |
< |
qq{-e '\$2=if(Rspec(0),if(diag,Rspec(tideg)/om,Rd1*corr),Rd1)' } . |
108 |
< |
qq{-e '\$3=if(Tspec(180),if(diag,Tspec(180-tideg)/om,Td2*corr),Td2)' } . |
109 |
< |
qq{-e '\$4=if(Rspec(180),if(diag,Rspec(180-tideg)/om,Rd2*corr),Rd2)' }; |
106 |
> |
q{-e '$1=if(Tspec(0),if(diag,Tspec(tideg)/om,Td1*corr),Td1)' } . |
107 |
> |
q{-e '$2=if(Rspec(0),if(diag,Rspec(tideg)/om,Rd1*corr),Rd1)' } . |
108 |
> |
q{-e '$3=if(Tspec(180),if(diag,Tspec(180-tideg)/om,Td2*corr),Td2)' } . |
109 |
> |
q{-e '$4=if(Rspec(180),if(diag,Rspec(180-tideg)/om,Rd2*corr),Rd2)' }; |
110 |
|
} |
111 |
|
system qq{$cmd | rsplit "-t " $TK1dataf $RK1dataf $TK2dataf $RK2dataf}; |
112 |
|
die "Error running rcalc or rsplit" if ( $? ); |