C MAIN PROGRAM FOR LOGARITHMIC SPIRAL GENERATION C ALGORITHM/PROGRAM BY SK MISHRA, DEPT. OF ECONOMICS, NEHU,SHILLONG COMMON /RNDM/IU,IV DIMENSION X(200),Y(200),THETA(200),ANGLE(200),R(200) C ---------------------------------------- C NOW WE GENERATE THE DATA WRITE(*,*)'INPUT THE SAMPLE SIZE = NPOINTS' READ(*,*) NPOINTS N=NPOINTS !RENAMING NPOINTS AS N WRITE(*,*)'INPUT HIGHEST ANGLE (UPTO 360 FOR K=0, UPTO 720 FOR K=1 *, UPTO 1080 FOR K=2, ETC' READ(*,*) HANG C GENERATION OF ANGLES IN DEGREES WRITE(*,*)'INPUT RANDOM NUMBER SEED' READ(*,*) IU DO 1 I=1,N CALL RANDOM(RAND) THETA(I)=HANG*RAND 1 CONTINUE C CONVERSION OF ANGLES INTO RADIANS : PI=4*ATAN(1.0) FACT=4.0*ATAN(1.0)/180.0 DO 2 I=1,N ANGLE(I)=THETA(I)*FACT 2 CONTINUE WRITE(*,*)'FEED A AND B IN R=A*EXP(B*THETA) : LOGARITHMIC SPIRAL' READ(*,*) A,B C CX AND CY DISPLACE CENTER OF SPIRAL (0,0) BY CX AND CY WRITE(*,*)'DISPLACEMENT OF X -- CX ?' READ(*,*)CX WRITE(*,*)'DISPLACEMENT OF Y -- CY ?' READ(*,*)CY C GENERATION OF X AND Y DO 3 I=1,N R(I)=A*EXP(B*ANGLE(I)) X(I)=R(I)*COS(ANGLE(I)) Y(I)=R(I)*SIN(ANGLE(I)) 3 CONTINUE C WE SAVE DATA X AND Y IN 'XYDAT' FILE OPEN(7,FILE='XYDAT') WRITE(7,*) N C INTRODUCING DISPLACEMENT TO X BY CX AND TO Y BY CY DO 33 I=1,N call normal(rand) X(I)=X(I)+CX+RAND*1 call normal(rand) Y(I)=Y(I)+CY+RAND*1 WRITE(7,*) X(I),Y(I) 33 CONTINUE CLOSE(7) WRITE(*,*)'SPIRAL DATA GENERATED AND SAVED IN FILE NAMED XYDAT' write(*,*)'program ends' END C ----------------------------------------------------------------- SUBROUTINE NORMAL(R) C PROGRAM TO GENERATE N(0,1) FROM RECTANGULAR RANDOM NUMBERS C IT USES BOX-MULLER VARIATE TRANSFORMATION FOR THIS PURPOSE. C ----------------------------------------------------------------- C ----- BOX-MULLER METHOD BY GEP BOX AND ME MULLER (1958) --------- C BOX, G. E. P. AND MULLER, M. E. "A NOTE ON THE GENERATION OF C RANDOM NORMAL DEVIATES." ANN. MATH. STAT. 29, 610-611, 1958. C IF U1 AND U2 ARE UNIFORMLY DISTRIBUTED RANDOM NUMBERS (0,1), C THEN X=[(-2*LN(U1))**.5]*(COS(2*PI*U2) IS N(0,1) C ALSO, X=[(-2*LN(U1))**.5]*(SIN(2*PI*U2) IS N(0,1) C PI = 4*ARCTAN(1.0)= 3.1415926535897932384626433832795 C 2*PI = 6.283185307179586476925286766559 C ----------------------------------------------------------------- COMMON /RNDM/IU,IV INTEGER IU,IV C ----------------------------------------------------------------- CALL RANDOM(RAND) ! INVOKES RANDOM TO GENERATE UNIFORM RAND [0, 1] U1=RAND ! U1 IS UNIFORMLY DISTRIBUTED [0, 1] CALL RANDOM(RAND) ! INVOKES RANDOM TO GENERATE UNIFORM RAND [0, 1] U2=RAND ! U1 IS UNIFORMLY DISTRIBUTED [0, 1] R=SQRT(-2.D0*ALOG(U1)) R=R*COS(U2*6.28318531) RETURN END SUBROUTINE RANDOM(RAND) COMMON /RNDM/IU,IV IV=IU*65539 IF(IV.LT.0) THEN IV=IV+2147483647+1 ENDIF RAND=IV IU=IV RAND=RAND*0.4656613E-09 RETURN END