1
SUBROUTINE vegas(region,ndim,fxn,init,ncall,itmx,nprn,tgral,sd,
3
INTEGER init,itmx,ncall,ndim,nprn,NDMX,MXDIM
4
REAL tgral,chi2a,sd,region(2*ndim),fxn,ALPH,TINY
5
PARAMETER (ALPH=1.5,NDMX=50,MXDIM=10,TINY=1.e-30)
7
CU USES fxn,xran1,rebin
8
INTEGER i,idum,it,j,k,mds,nd,ndo,ng,npg,ia(MXDIM),kg(MXDIM)
9
REAL calls,dv2g,dxg,f,f2,f2b,fb,rc,ti,tsi,wgt,xjac,xn,xnd,xo,
10
*d(NDMX,MXDIM),di(NDMX,MXDIM),dt(MXDIM),dx(MXDIM),r(NDMX),x(MXDIM),
11
*xi(NDMX,MXDIM),xin(NDMX),xran1,rndn
13
DOUBLE PRECISION schi,si,swgt
14
DATA idum/1/ ! DOES NOT AFFECT PREVIOUS SETTINGS
20
COMMON /VEGAS_PAR1/NG,NDIM1
21
COMMON /VEGAS_PAR2/region1,xi,xnd,dx
23
SAVE ! make variables static
25
if(init.le.0)then !enter here on a cold start
37
if (init.le.1)then !enter here to inherit the grid but not the answers
43
if (init.le.2)then !enter here to inherit the grid and the answers
47
if(mds.ne.0)then !setup for stratification
48
ng=(ncall/2.+0.25)**(1./ndim) !number of calls per dimension
50
if((2*ng-NDMX).ge.0)then
60
cfax: returns the actual number of calls
63
dv2g=(calls*dxg**ndim)**2/npg/npg/(npg-1.)
67
c WRITE (*,*) 'NG,NDIM,K ',NG,NDIM,K
68
c WRITE (*,*) 'NPG,CALLS,NCALL ',NPG,CALLS,NCALL
69
c WRITE (*,*) 'ND,DXG ',ND,DXG
71
dx(j)=region(j+ndim)-region(j)
74
c-- do the binning if necessary
80
call rebin(ndo/xnd,nd,r,xin,xi(1,j))
84
if(nprn.ge.0) write(*,200) ndim,calls,it,itmx,nprn,ALPH,mds,nd
88
c if init>=3 it enters here
106
cfax: avoid random numbers exactly equal to 0. or 1.
108
if(rndn.eq.1e0.or.rndn.eq.0e0) goto 303
109
xn=(kg(j)-rndn)*dxg+1.
110
c write(*,*) k,kg(j),xn
111
ia(j)=max(min(int(xn),NDMX),1)
113
xo=xi(ia(j),j)-xi(ia(j)-1,j)
114
rc=xi(ia(j)-1,j)+(xn-ia(j))*xo
119
x(j)=region(j)+rc*dx(j)
127
di(ia(j),j)=di(ia(j),j)+f
128
if(mds.ge.0) d(ia(j),j)=d(ia(j),j)+f2
132
f2b=(f2b-fb)*(f2b+fb)
133
if (f2b.le.0.) f2b=TINY
138
d(ia(j),j)=d(ia(j),j)+f2b
141
c this is just a counter: total number of points thrown is ng**ndim
143
kg(k)=mod(kg(k),ng)+1
144
if(kg(k).ne.1) goto 10
147
c all points for this iteration have been thrown.
148
c now it calculates the results for this iteration
149
c and the cumulative result,chi^2
153
si=si+dble(wgt)*dble(ti)
154
schi=schi+dble(wgt)*dble(ti)**2
157
chi2a=max((schi-si*tgral)/(it-.99d0),0.d0)
161
write(*,201) it,ti,tsi
164
write(*,202) j,(xi(i,j),di(i,j),i=1+nprn/2,nd,nprn)
169
c refines the grid after the iteration
186
c-- slow down the evolution
190
if(d(i,j).lt.TINY) d(i,j)=TINY
191
r(i)=((1.-d(i,j)/dt(j))/(log(dt(j))-log(d(i,j))))**ALPH
194
call rebin(rc/xnd,nd,r,xin,xi(1,j))
197
28 continue !main iteration loop
203
200 FORMAT(/' input param. for vegas: ndim=',i3,' calls=',
204
*f8.0/24x,' it=',i5,' itmx=',i5/24x,' nprn=',i3,' alph=',
205
*f5.2/24x,' mds=',i3,' nd=',i4/)
206
c200 FORMAT(/' input parameters for vegas: ndim=',i3,' ncall=',
207
c *f8.0/28x,' it=',i5,' itmx=',i5/28x,' nprn=',i3,' alph=',
208
c *f5.2/28x,' mds=',i3,' nd=',i4/(30x,'xl(',i2,')= ',g11.4,' xu(',
210
201 FORMAT(' iter. no.',I3,': ','integral =',g14.7,' +/- ',g9.2)
211
c201 FORMAT(/' iteration no.',I3,': ','integral =',g14.7,'+/- ',g9.2/
212
c *' all iterations: integral =',g14.7,'+/- ',g9.2,' chi**2/it',
214
202 FORMAT(/' data for axis ',I2/' X delta i ',
215
*' x delta i ',' x delta i ',/(1x,
216
*f7.5,1x,g11.4,5x,f7.5,1x,g11.4,5x,f7.5,1x,g11.4))
222
SUBROUTINE rebin(rc,nd,r,xin,xi)
225
REAL rc,r(NDMX),xi(NDMX),xin(NDMX)
240
xin(i)=xn-(xn-xo)*dr/r(k)