1 | SUBROUTINE SOBSEQ(N,X)
|
---|
2 |
|
---|
3 | C-----------------------------------------------------------------------
|
---|
4 | C SOB(OL) SEQ(UENCE)
|
---|
5 | C
|
---|
6 | C SOBOL QUASI RANDOM NUMBER GENERATOR
|
---|
7 | C REFERENCE : NUMERICAL RECIPES, W.H. PRESS ET AL.,
|
---|
8 | C CAMBRIDGE UNIVERSITY PRESS, 1992 ISBN 0 521 43064 X
|
---|
9 | C THIS SUBROUTINE IS CALLED FROM SELCOR
|
---|
10 | C-----------------------------------------------------------------------
|
---|
11 |
|
---|
12 | INTEGER N,MAXBIT,MAXDIM
|
---|
13 | REAL X(*),FAC
|
---|
14 | PARAMETER (MAXBIT=30,MAXDIM=6)
|
---|
15 | INTEGER I,IM,IN,IPP,J,K,L,IP(MAXDIM),IU(MAXDIM,MAXBIT),
|
---|
16 | * IV(MAXBIT*MAXDIM),IX(MAXDIM),MDEG(MAXDIM)
|
---|
17 | SAVE IP,MDEG,IX,IV,IN,FAC
|
---|
18 | EQUIVALENCE (IV,IU)
|
---|
19 | DATA IP /0,1,1,2,1,4/, MDEG /1,2,3,3,4,4/, IX /6*0/
|
---|
20 | DATA IV /6*1,3,1,3,3,1,1,5,7,7,3,3,5,15,11,5,15,13,9,156*0/
|
---|
21 | C-----------------------------------------------------------------------
|
---|
22 |
|
---|
23 | IF (N.LT.0) THEN
|
---|
24 | DO 14 K=1,MAXDIM
|
---|
25 | DO 11 J=1,MDEG(K)
|
---|
26 | IU(K,J)=IU(K,J)*2**(MAXBIT-J)
|
---|
27 | 11 CONTINUE
|
---|
28 | DO 13 J=MDEG(K)+1,MAXBIT
|
---|
29 | IPP=IP(K)
|
---|
30 | I=IU(K,J-MDEG(K))
|
---|
31 | I=IEOR(I,I/2**MDEG(K))
|
---|
32 | DO 12 L=MDEG(K)-1,1,-1
|
---|
33 | IF(IAND(IPP,1).NE.0)I=IEOR(I,IU(K,J-L))
|
---|
34 | IPP=IPP/2
|
---|
35 | 12 CONTINUE
|
---|
36 | IU(K,J)=I
|
---|
37 | 13 CONTINUE
|
---|
38 | 14 CONTINUE
|
---|
39 | FAC=1./2.**MAXBIT
|
---|
40 | IN=0
|
---|
41 | ELSE
|
---|
42 | IM=IN
|
---|
43 | DO 15 J=1,MAXBIT
|
---|
44 | IF(IAND(IM,1).EQ.0)GOTO 1
|
---|
45 | IM=IM/2
|
---|
46 | 15 CONTINUE
|
---|
47 | PAUSE 'MAXBIT TOO SMALL IN SOBSEQ'
|
---|
48 | 1 IM=(J-1)*MAXDIM
|
---|
49 | DO 16 K=1,MIN(N,MAXDIM)
|
---|
50 | IX(K)=IEOR(IX(K),IV(IM+K))
|
---|
51 | X(K)=IX(K)*FAC
|
---|
52 | 16 CONTINUE
|
---|
53 | IN=IN+1
|
---|
54 | ENDIF
|
---|
55 | RETURN
|
---|
56 | END
|
---|