| 82 |  | Kfindrow(r, rem) : if(rem-Knaz(r)+.5, Kfindrow(r+1, rem-Knaz(r)), r); | 
| 83 |  | Krow = if(Kbin-(Kmax-.5), 0, Kfindrow(1, Kbin)); | 
| 84 |  | Kcol = Kbin - Kaccum(Krow-1); | 
| 85 | < | Kazi = 360*DEGREE * (Kcol + .5 - x2) / Knaz(Krow); | 
| 85 | > | Kazi = 360*DEGREE * (Kcol + (.5 - x2)) / Knaz(Krow); | 
| 86 |  | Kpol = DEGREE * (x1*Kpola(Krow) + (1-x1)*Kpola(Krow-1)); | 
| 87 |  | sin_kpol = sin(Kpol); | 
| 88 |  | Dx = -cos(Kazi)*sin_kpol; | 
| 89 |  | Dy = sin(Kazi)*sin_kpol; | 
| 90 |  | Dz = sqrt(1 - sin_kpol*sin_kpol); | 
| 91 | + | Komega = 2*PI*if(Kbin-.5, | 
| 92 | + | (cos(Kpola(Krow-1)*DEGREE) - cos(Kpola(Krow)*DEGREE))/Knaz(Krow), | 
| 93 | + | 1 - cos(Kpola(1)*DEGREE)); | 
| 94 |  | '; | 
| 95 |  | # Compute Klems bin from exiting ray direction | 
| 96 |  | my $kcal = ' | 
| 243 |  | q{-e 'Kbin=$1;x1=rand(1.21*recno+2.75);x2=rand(-3.55*recno-7.57)' } . | 
| 244 |  | q{-e '$1=xp;$2=yp;$3=zp;$4=Dx;$5=Dy;$6=Dz' } . | 
| 245 |  | "| rtcontrib -h -ff -n $nproc -c $nsamp -e '$kcal' -b kbin -bn $ndiv " . | 
| 246 | < | "-m $modnm -w -ab 4 -lw 1e-5 $octree " . | 
| 247 | < | q{| rcalc -if3 -e '$1=0.265*$1+0.670*$2+0.065*$3'}; | 
| 246 | > | "-m $modnm -w -ab 5 -ad 700 -lw 3e-6 $octree " . | 
| 247 | > | "| rcalc -e 'x1:.5;x2:.5;$tcal' -e 'Kbin=floor((recno-1)/$ndiv)' " . | 
| 248 | > | q{-if3 -e '$1=(0.265*$1+0.670*$2+0.065*$3)/(Komega*Dz)'}; | 
| 249 |  | # Output XML epilogue | 
| 250 |  | print | 
| 251 |  | '               </ScatteringData> |