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