Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
17
Task/Loops-Break/Fortran/loops-break-1.f
Normal file
17
Task/Loops-Break/Fortran/loops-break-1.f
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
program Example
|
||||
implicit none
|
||||
|
||||
real :: r
|
||||
integer :: a, b
|
||||
|
||||
do
|
||||
call random_number(r)
|
||||
a = int(r * 20)
|
||||
write(*,*) a
|
||||
if (a == 10) exit
|
||||
call random_number(r)
|
||||
b = int(r * 20)
|
||||
write(*,*) b
|
||||
end do
|
||||
|
||||
end program Example
|
||||
69
Task/Loops-Break/Fortran/loops-break-2.f
Normal file
69
Task/Loops-Break/Fortran/loops-break-2.f
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
PROGRAM LOOPBREAK
|
||||
INTEGER I, RNDINT
|
||||
|
||||
C It doesn't matter what number you put here.
|
||||
CALL SDRAND(123)
|
||||
|
||||
C Because FORTRAN 77 semantically lacks many loop structures, we
|
||||
C have to use GOTO statements to do the same thing.
|
||||
10 CONTINUE
|
||||
C Print a random number.
|
||||
I = RNDINT(0, 19)
|
||||
WRITE (*,*) I
|
||||
|
||||
C If the random number is ten, break (i.e. skip to after the end
|
||||
C of the "loop").
|
||||
IF (I .EQ. 10) GOTO 20
|
||||
|
||||
C Otherwise, print a second random number.
|
||||
I = RNDINT(0, 19)
|
||||
WRITE (*,*) I
|
||||
|
||||
C This is the end of our "loop," meaning we jump back to the
|
||||
C beginning again.
|
||||
GOTO 10
|
||||
|
||||
20 CONTINUE
|
||||
|
||||
STOP
|
||||
END
|
||||
|
||||
C FORTRAN 77 does not come with a random number generator, but it
|
||||
C is easy enough to type "fortran 77 random number generator" into your
|
||||
C preferred search engine and to copy and paste what you find. The
|
||||
C following code is a slightly-modified version of:
|
||||
C
|
||||
C http://www.tat.physik.uni-tuebingen.de/
|
||||
C ~kley/lehre/ftn77/tutorial/subprograms.html
|
||||
SUBROUTINE SDRAND (IRSEED)
|
||||
COMMON /SEED/ UTSEED, IRFRST
|
||||
UTSEED = IRSEED
|
||||
IRFRST = 0
|
||||
RETURN
|
||||
END
|
||||
INTEGER FUNCTION RNDINT (IFROM, ITO)
|
||||
INTEGER IFROM, ITO
|
||||
PARAMETER (MPLIER=16807, MODLUS=2147483647, &
|
||||
& MOBYMP=127773, MOMDMP=2836)
|
||||
COMMON /SEED/ UTSEED, IRFRST
|
||||
INTEGER HVLUE, LVLUE, TESTV, NEXTN
|
||||
SAVE NEXTN
|
||||
IF (IRFRST .EQ. 0) THEN
|
||||
NEXTN = UTSEED
|
||||
IRFRST = 1
|
||||
ENDIF
|
||||
HVLUE = NEXTN / MOBYMP
|
||||
LVLUE = MOD(NEXTN, MOBYMP)
|
||||
TESTV = MPLIER*LVLUE - MOMDMP*HVLUE
|
||||
IF (TESTV .GT. 0) THEN
|
||||
NEXTN = TESTV
|
||||
ELSE
|
||||
NEXTN = TESTV + MODLUS
|
||||
ENDIF
|
||||
IF (NEXTN .GE. 0) THEN
|
||||
RNDINT = MOD(MOD(NEXTN, MODLUS), ITO - IFROM + 1) + IFROM
|
||||
ELSE
|
||||
RNDINT = MOD(MOD(NEXTN, MODLUS), ITO - IFROM + 1) + ITO + 1
|
||||
ENDIF
|
||||
RETURN
|
||||
END
|
||||
31
Task/Loops-Break/Fortran/loops-break-3.f
Normal file
31
Task/Loops-Break/Fortran/loops-break-3.f
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
SUBROUTINE RANDU(IX,IY,YFL)
|
||||
Copied from the IBM1130 Scientific Subroutines Package (1130-CM-02X): Programmer's Manual, page 60.
|
||||
CAUTION! This routine's 32-bit variant is reviled by Prof. Knuth and many others for good reason!
|
||||
IY = IX*899
|
||||
IF (IY) 5,6,6
|
||||
5 IY = IY + 32767 + 1
|
||||
6 YFL = IY
|
||||
YFL = YFL/32767.
|
||||
END
|
||||
|
||||
FUNCTION IR19(IX)
|
||||
CALL RANDU(IX,IY,YFL)
|
||||
IX = IY
|
||||
I = YFL*20
|
||||
IF (I - 20) 12,11,11
|
||||
11 I = 19
|
||||
12 IR19 = I
|
||||
END
|
||||
|
||||
IX = 1
|
||||
Commence the loop.
|
||||
10 I = IR19(IX)
|
||||
WRITE (6,11) I
|
||||
11 FORMAT (I3)
|
||||
IF (I - 10) 12,20,12
|
||||
12 I = IR19(IX)
|
||||
WRITE (6,11) I
|
||||
GO TO 10
|
||||
Cease.
|
||||
20 CONTINUE
|
||||
END
|
||||
Loading…
Add table
Add a link
Reference in a new issue