Ticket #7378: fteqs.pro

File fteqs.pro, 1012 bytes (added by Peter Peterson, 7 years ago)
Line 
1pro fteqs,q,int,r,ft,lorch=lorch
2
3; FT of int(Q)  -> ft(r) the meaning of Q and r may be reversed ; actually it calculates  sum i(Q) sin(Qr)/(Qr) Q^2 dQ
4
5if (not var_defined(lorch)) then lorch=0
6
7dq=q(1)-q(0)
8; Q or r is assumed to be equidistant
9
10int1=int*q^2
11; multiply with Q^2 beforehand
12
13nq=n_elements(q)
14if n_elements(r) eq 0 then r=(dindgen(nq))*!pi/max(q) ; if r is undefined, define it.
15
16nr=n_elements(r)
17ft=dblarr(nr)
18; define ft as a double precision vector
19
20if (lorch eq 0) then begin&for i=0,nr-1 do begin&x=q*r(i)& ft(i)=total(int1*j0(x)) &end&end
21
22if (lorch ne 0) then begin&for i=0,nr-1 do begin&x=q*r(i)& ft(i)=total(int1*j0(x)*j0(!pi*q/max(q))) &end&end
23
24; do the summation
25
26ft=ft*dq
27; multiply with dQ afterwards
28return
29end
30
31function j0,x
32; this function calculates sin(x)/x, avoiding division by zero (sin(0)/0=1)
33
34y=x
35w=where(x gt 1e-20,n)
36if n gt 0 then y(w)=sin(x(w))/x(w)
37w=where(x lt 1e-20,n)
38if n gt 0 then y(w)=1.d0
39return,y
40end
41
42
43
44
45
46
47
48