Ticket #7378: creategr.pro

File creategr.pro, 8.8 KB (added by Peter Peterson, 7 years ago)
Line 
1pro creategr,a,b,sq,gr,q,hydrogen=hydrogen,rho=rho,sigma=sigma,interactive=interactive,qminpla=qminpla,qmaxpla=qmaxpla,d1=d1,qmaxft=qmaxft,scannr=scannr,qualstring=qualstring,backfile=backfile,usehq=usehq,sbs=sbs,sb2=sb2,l=l,maxr=maxr,ignq=ignq,lowfit=lowfit,normf=normf,help=help,displq=displq,disply=disply,packfrac=packfrac,comment=comment,nlowfit=nlowfit,error=error
2
3if not var_defined(hydrogen) then hydrogen=0
4if not var_defined(rho) then rho=0.02205
5if not var_defined(sigma) then sigma=10.631
6if not var_defined(interactive) then interactive=1
7if not var_defined(qmaxft) then qmaxft=!pi*10
8if not var_defined(qminpla) then qminpla=5
9if not var_defined(qmaxpla) then qmaxpla=50
10if not var_defined(d1) then d1=0.627
11if not var_defined(scannr) then scannr=9999
12if not var_defined(backfile) then backfile='backpdf.dat'
13if not var_defined(usehq) then usehq=0
14if not var_defined(sbs) then sbs=(4.1491+2*5.803)^2
15if not var_defined(sb2) then sb2=4.1491^2+2*5.803^2
16if not var_defined(l) then l=[1,20]
17if not var_defined(maxr) then maxr=20
18if not var_defined(ignq) then ignq=7
19if not var_defined(q) then q=findgen(2500)*.02
20if not var_defined(normf) then normf='normdatapdf.dat'
21if not var_defined(help) then help=0
22if not var_defined(displq) then displq=[min(q),max(q)]
23if not var_defined(packfrac) then packfrac=1.
24if not var_defined(qualstring) then qualstring=''
25if not var_defined(comment) then comment='You may note Qmax, background, normalization,mask etc. here'
26if not var_defined(lowfit) then lowfit=0
27if not var_defined(nlowfit) then nlowfit=10
28if help eq 1 then begin
29print,'USAGE: creategr,a,b,sq,gr,q,hydrogen=hydrogen,rho=rho,sigma=sigma,interactive=interactive,qminpla=qminpla,d1=d1,qmaxft=qmaxft,scannr=scannr,backfile=backfile,usehq=usehq,sbs=sbs,sb2=sb2,l=l,maxr=maxr,ignq=ignq,normf=normf,help=help,displq=displq,disply=disply,packfrac=packfrac,comment=comment,lowfit=lowfit'
30print,'a: a variable for scan to be FT (input)'
31print,'b: b variable for scan to be FT (input)'
32print,'sq: S(Q) (ouput)'
33print,'gr: g(r) with Lorch (output)'
34print,' q: (input) Q, default findgen(2500)*.02'
35print,'hydrogen =1/2 (try a hydrogen Placzek, 2 is preferred) =0 (no Hydrogen Placzek)
36print,' rho: density in molecules /A^3, default=0.02205 silica glass'
37print,'interactive=0 no plots'
38print,' qminpla (default=5A^-1) minimum Q to fit a Polynomial as self scattering background'
39print,' qmaxpla (default=50A^-1) maximum Q to fit a Polynomial as self scattering background'
40print,' d1 = diameter of the sample in cm (default = 0.627, a quarter inch)'
41print,' qmaxft: maximum Q for FT (default= 10 x pi)'
42print,'scannr scannr used for output files'
43print,'backfile= name of the backgroundfile created with makeback'
44print,'usehq=1 use high Q behavior for normalization, =0 use absolute normalization'
45print,'sbs= (sum of b)^2 default sbs=(4.1491+2*5.803)^2 (SiO2)'
46print,'sb2= (sum of b^2) default sb2=4.1491^2+2*5.803^2 (SiO2)'
47print,'l= [1,20] display range of the FT'
48print,'maxr=20 maximum r where FT is calculated'
49print,'ignq=5 minimum Q values to be ignored'
50print,'lowfit: (default 0) if lowfit=1 then a polynomial is used to extrapolate to Q->0'
51print,' normf: default normf=-normdatapdf.dat- normalization file generated withcreanorm'
52print,'qualstring : string to be added to file names for better identification, default: no strings attached'
53print,'packfrac: (default 1.) packing fraction of the sample'
54print,'comment: contains a string that is written int the output file proceeded by #, e.g. Qmax can be noted here'
55return
56end
57
58qign=ignq
59; define material constants for Vanadium
60rhovana=0.0722 ;density Vanadium uc/A^3
61sigmavana=5.08 ;elastic scattering cross section
62d1vana=0.627 ; diameter of our standard vanadium bar
63
64;read normalization file
65openr,1,normf,err=err
66close,1
67if err ne 0 then begin
68print,err,'no normalization file'
69stop
70return
71end
72restore,normf
73
74;read  background file
75openr,1,backfile,err=err
76close,1
77if err ne 0 then begin
78print,err,'no background file'
79return
80end
81restore,backfile
82
83normall=normpdf(0,*)+normpdf(1,*)+normpdf(2,*)+normpdf(3,*)+normpdf(4,*)+normpdf(5,*)
84normall=reform(normall)
85
86smb=a-aback ;sample minus background
87smb(where (normall gt 0))=smb(where (normall gt 0))/normall(where (normall gt 0)) ;normalize the data to vanadium
88if var_defined(error) and var_defined(ebacka) then begin
89 esmb=sqrt(error^2+ebacka^2)
90esmb(where (normall gt 0))=esmb(where (normall gt 0))/normall(where (normall gt 0))
91endif
92if lowfit then begin             ;extrapoation to Q->0
93res=poly_fit(q(qign:qign+nlowfit)^2,smb(qign:qign+nlowfit),2)
94if interactive then begin
95plot,q(0:qign+nlowfit*3),smb(0:qign+nlowfit*3),ps=2,title='Extrapolation to Q->0',xtit='Q/A!e-1'
96oplot,q(qign:qign+nlowfit*3),smb(qign:qign+nlowfit),ps=2,color=255
97oplot,q(0:qign+nlowfit),poly(q(0:qign+nlowfit)^2,res)
98oplot,q(0:qign+nlowfit*3),q(0:qign+nlowfit*3)*0+mean(smb(qign:qign+nlowfit))
99prtc
100end
101smb(0:qign)=poly(q(0:qign)^2,res)
102end
103if not lowfit then begin
104smb(0:qign)=mean(smb(qign:qign+nlowfit))
105if interactive then begin
106plot,q(0:qign+nlowfit*3),smb(0:qign+nlowfit*3),ps=2,title='Extrapolation to Q->0',xtit='Q/A!e-1'
107oplot,q(0:qign+nlowfit*3),q(0:qign+nlowfit*3)*0+mean(smb(qign:qign+nlowfit))
108prtc
109end
110end
111
112if n_elements(smb) ne 2500 then print,' Careful. This does not appear to be a standard file'
113
114; Placzek "correction"
115
116if (hydrogen eq 0) then respla=poly_fit(q(fr(q,qminpla):fr(q,qmaxpla))^2,smb(fr(q,qminpla):fr(q,qmaxpla)),2)
117if (hydrogen eq 2) then begin
118aa=[10,6,.5,6.,.1]
119respla=curvefit(q(fr(q,qminpla):fr(q,qmaxpla)),smb(fr(q,qminpla):fr(q,qmaxpla)),q(fr(q,qminpla):fr(q,qmaxpla))+0+1,aa,funct='pseudovoigt',/noder)
120pseudovoigt,q,aa,pla
121end
122
123if interactive then begin ; plot the fitted polynomial/ pseudovoigt
124if not var_defined(disply) then disply=[min(smb),max(smb)]
125plot,q,smb,xra=displq,yra=disply,ytit='Normalized intensity',xtit='Q/A!e-1'
126oplot,q,q*0+rho*sigma*d1^2/(rhovana*sigmavana*d1vana^2)*packfrac,color=255,th=3,li=2
127if hydrogen eq 0 then oplot,q,poly(q^2,respla),color=255
128if hydrogen eq 2 then oplot,q,pla,color=255
129prtc
130endif
131bsmb=b-bback
132bsmb(where (normpdf gt 0))=bsmb(where (normpdf gt 0))/normpdf(where (normpdf gt 0))
133if hydrogen eq -1 then sq=smb-rho*sigma*d1^2/(rhovana*sigmavana*d1vana^2)*packfrac
134if hydrogen eq 0 then sq=smb-poly(q^2,respla)
135if hydrogen eq 2 then sq=smb-pla
136
137
138; define S(Q) either by high Q normalization or by absolute normalization
139
140if usehq and hydrogen eq 0 then begin
141sq=sq/poly(max(q)^2,respla);*rhovana*sigmavana/rho/sigma
142if var_defined(error) and var_defined(ebacka) then esq=esmb/poly(max(q)^2,respla)
143endif
144if usehq and hydrogen eq 2 then begin
145sq=sq/pla(fr(q,49));*rhovana*sigmavana/rho/sigma
146if var_defined(error) and var_defined(ebacka) then esq=esmb/pla(fr(q,49))
147endif
148if not usehq then begin
149sq=sq/rho/sigma/d1^2*rhovana*sigmavana*d1vana^2/packfrac
150if var_defined(error) and var_defined(ebacka) then esq=esmb/rho/sigma/d1^2*rhovana*sigmavana*d1vana^2/packfrac
151endif
152if interactive then begin
153plot,q,sq,ytit='A (S(Q)-1)',xtit='Q/ A!e-1',chars=2
154prtc
155endif
156
157if hydrogen eq 1 then begin
158hplazcek,q,b,normpdf,pla
159if interactive then begin
160plot,q,smb
161oplot,q,pla,color=255
162prtc
163endif
164endif
165;;;sq=smb-pla
166;;;stop
167nr=maxr/.01
168
169fteqs,q(0:fr(q,qmaxft)),sq,rr,ft
170fteqs,q(0:fr(q,qmaxft)),sq,findgen(nr)*.01,ft1
171fteqs,q(0:fr(q,qmaxft)),sq,findgen(nr)*.01,ftl,l=1
172
173f1=rho*sigma/rhovana/sigmavana*d1^2/d1vana^2
174ft=ft/2/!pi^2/rho/sbs*sb2/packfrac
175ft1=ft1/2/!pi^2/rho/sbs*sb2/packfrac
176ftl=ftl/2/!pi^2/rho/sbs*sb2/packfrac
177if interactive then begin
178plot,findgen(nr)*.01,ft1,xra=[l(0),l(1)],ytit='g(r)-1',xtit='r/A',chars=2
179oplot,findgen(nr)*.01,ftl,color=255,th=2
180oplot,rr,ft,ps=2
181prtc
182plot,findgen(nr)*.01,ft1*findgen(nr)*.01,xra=[1,maxr],ytit='PDF = r (g(r)-1)/A',xtit='r/A',chars=2
183oplot,findgen(nr)*.01,ftl*findgen(nr)*.01,color=255,th=2
184oplot,rr,ft*rr,ps=2
185prtc
186endif
187if scannr gt 9999 and scannr le 99999 then astring=string(scannr,format='(i5)')
188if scannr gt 999 and scannr le 9999 then astring=string(scannr,format='(i4)')
189if scannr gt 99 and  scannr le 999 then astring=string(scannr,format='(i3)')
190if scannr gt 9 and  scannr le 99 then astring=string(scannr,format='(i2)')
191if scannr lt 10 then astring=string(scannr,format='(i)')
192wstd,findgen(nr)*.01,ft1,'NOM_'+astring+qualstring+'ftf.dat',comment=comment
193wstd,findgen(nr)*.01,ft1*findgen(nr)*.01,'NOM_'+astring+qualstring+'ftfrgr.dat',comment=comment
194wstd,findgen(nr)*.01,ft1*findgen(nr)*.01,'NOM_'+astring+qualstring+'ftfrgr.gr',comment=comment
195wstd,findgen(nr)*.01,ftl,'NOM_'+astring+qualstring+'ftl.dat',comment=comment
196wstd,findgen(nr)*.01,ftl*findgen(nr)*.01,'NOM_'+astring+qualstring+'ftlrgr.gr',comment=comment
197wstd,rr,ft,'NOM_'+astring+qualstring+'ftnat.dat',comment=comment
198if (not var_defined(error)) or (not var_defined(ebacka)) then wstd,q,sq,'NOM_'+astring+qualstring+'SQ.dat',comment=comment
199if var_defined(error) and var_defined(ebacka) then wstd,q,[[reform(sq)],[reform(esq)]],'NOM_'+astring+qualstring+'SQ.dat',comment=comment,nz=3
200
201
202gr=ftl
203
204return
205end
206