1 -- 2 -- Patricia Fasel 3 -- Los Alamos National Laboratory 4 -- 1990 August 5 -- 6 module Utils (xsectInterp, genRand) where 7 8 import GamtebType 9 import Consts 10 import InitTable 11 import Array((!))--1.3 12 13 -- linear interpolation to get cross sections as f(erg) 14 15 xsectInterp :: Energy -> (Indx, Probability) 16 xsectInterp e = 17 (eIndx, (pComp, pPair, pPhot, (pComp+pPair+pPhot))) 18 where 19 logE = log e 20 eIndx = findIndx 1 21 where 22 findIndx i | (i < numLev) && (logE > ergs!i) = 23 findIndx (i+1) 24 findIndx i = i 25 i = (if (eIndx < 2) then 2 else eIndx) 26 f = (logE - ergs!(i-1)) / (ergs!i - ergs!(i-1)) 27 pComp = exp (xComp!(i-1) + f*(xComp!i - xComp!(i-1))) 28 pPair = exp (xPair!(i-1) + f*(xPair!i - xPair!(i-1))) 29 pPhot = exp (xPhot!(i-1) + f*(xPhot!i - xPhot!(i-1))) 30 31 32 -- random number generator from seed 33 34 genRand :: Random -> (Random, Random) 35 genRand seed = 36 (r1/65599, r2/71123) 37 where 38 r1 = (314557*seed + 2711) `fiRem` 65599 39 r2 = (2711*seed + 314557) `fiRem` 71123 40 x `fiRem` m = x - fromIntegral ((truncate x `div` m) * m)