IMPLICIT DOUBLE PRECISION(A-H, O-Z) DIMENSION x(1000000), v(1000000),w(1000000), xr(1000000), x1(1000000) COMMON /c1/ n, n1 COMMON /c2/ phi, r1, r, t COMMON /c3/ e1, h, pi COMMON /c4/ al, p1, a COMMON /c5/ q, y,f ! Output files !OPEN(12, FILE='27f.txt', STATUS='UNKNOWN') ! Parameters N = 1001 n1 = n * 1 NRUN = 150000 H = 0.01D0 t = 0.0D0 pi = 4 * atan(1.0D0) c1 = -pi c2 = pi rang = c2 - c1 c3 = -0.1D0 c4 = 0.1D0 ran = c3 - c4 a = 1.0D0 w0 = 0.00D0 f = 2.00D0 q = 5.0D0 y =2.0D0 al=0.0D0 ! loren wsum=0.0D0 do m1=1,n1,1 call random_number(xr(m1)) w(m1)=w0+a*tan(2*pi*(xr(m1) - 0.25d0)) wsum=wsum+w(m1) ! g(m1)=a/(pi*(((w(m1)-w0)**2)+(a**2))) end do !******************************* !**************************** !********************************************* !DO e1=0,8,0.050D0 e1=1.85D0 fr=0.0d0 t=0.0d0 ! Initialization do m1 = 1, n1, 1 if (m1 .eq. (n + 1) / 2) then x(m1) = 0.0D0 elseif (m1 .eq. 1) then x(m1) = -pi else x(m1) = x(m1 - 1) + rang / (n - 1) end if call random_number(v(m1)) v(m1) = v(m1) * (2.0D0 * pi) - pi end do do i = 1, NRUN csum=0.0d0 ssum=0.0d0 do m1=1,n,1 csum=csum+cos(x(m1)) ssum=ssum+sin(x(m1)) end do cs=csum/real(n) ss=ssum/real(n) r1=sqrt((cs**2)+(ss**2)) phi=atan(ss/cs) if (cs .lt. 0) THEN phi=phi+pi end if t = t + h CALL RK4(x, v, h, w) !******************************** if(i .gt. 90000)then fr=fr+r1 !******************************** end if end do !****************(end time loop)************* fr=fr/(nrun-90000) ! WRITE(12,*)e1,fr WRITE(*,*)E1,FR !********************************************** ! !******************* !END DO STOP END PROGRAM ! ! SUBROUTINE RK4(X, V, H, W) IMPLICIT DOUBLE PRECISION(A-H, O-Z) DIMENSION X(1000000), V(1000000), W(1000000) COMMON /c1/ n, N1 DIMENSION TEMP_X(1000000), TEMP_V(1000000) DIMENSION AK11(1000000), AK12(1000000), AK13(1000000), AK14(1000000) DIMENSION AK21(1000000), AK22(1000000), AK23(1000000), AK24(1000000) DIMENSION PRIME_X(1000000), PRIME_V(1000000) ! DO I = 1, N1 TEMP_X(I) = X(I) TEMP_V(I) = V(I) END DO ! CALL DERIVE(X, V, PRIME_X, PRIME_V, W) DO I = 1, N1 AK11(I) = H * PRIME_X(I) AK21(I) = H * PRIME_V(I) TEMP_X(I) = X(I) + AK11(I)/ 2.0D0 TEMP_V(I) = V(I) + AK21(I) / 2.0D0 END DO ! CALL DERIVE(X, V, PRIME_X, PRIME_V, W) DO I = 1, N1 AK12(I) = H * PRIME_X(I) AK22(I) = H * PRIME_V(I) TEMP_X(I) = X(I) + AK12(I) / 2.0D0 TEMP_V(I) = V(I) + AK22(I) / 2.0D0 END DO ! CALL DERIVE(X, V, PRIME_X, PRIME_V, W) DO I = 1, N1 AK13(I) = H * PRIME_X(I) AK23(I) = H * PRIME_V(I) TEMP_X(I) = X(I) + AK13(I) / 2.0D0 TEMP_V(I) = V(I) + AK23(I) / 2.0D0 END DO ! CALL DERIVE(X, V, PRIME_X, PRIME_V, W) DO I = 1, N1 AK14(I) = H * PRIME_X(I) AK24(I) = H * PRIME_V(I) X(I)=X(I)+1.0d0/6.0D0*(AK11(I)+2.0D0*(AK12(I)+AK13(I))+AK14(I)) V(I)=V(I)+1.0d0/6.0D0*(AK21(I)+2.0D0*(AK22(I)+AK23(I))+AK24(I)) END DO END SUBROUTINE RK4 SUBROUTINE DERIVE(X, V, PRIME_X, PRIME_V, W) IMPLICIT DOUBLE PRECISION(A-H, O-Z) DIMENSION X(1000000), V(1000000), PRIME_X(1000000), PRIME_V(1000000), W(1000000) COMMON /c1/ n, N1 COMMON /c2/ phi, r1, r, t COMMON /c3/ e1, e2, h, pi COMMON /c4/ al, p1, a COMMON /c5/ q, y, f DO M1 = 1, N1 PRIME_X(M1) = V(M1) PRIME_V(M1) = (W(M1) + ((1.0D0+(q*(r1**f)))*e1 * r1 * SIN(phi - X(M1) + al)) - V(M1))/y END DO END SUBROUTINE DERIVE
Write, Run & Share Fortran code online using OneCompiler's Fortran online compiler for free. It's one of the robust, feature-rich online compilers for Fortran language, running on the latest version 7. Getting started with the OneCompiler's Fortran compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Fortran
and start coding.
OneCompiler's Fortran online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Fortran program which takes name as input and prints hello message with your name.
program hello
character :: name*30
read *, name
print *, "Hello ", name
end program hello
Fortran language was initially developed for scientific calculations by IBM in 1957. It has a number of in-built functions to perform mathematical calculations and is ideal for applications which has more mathematical calculations.
Data type | Description | Usage |
---|---|---|
Integer | To store integer variables | integer :: x |
Real | To store float values | real :: x |
Complex | To store complex numbers | complex :: x,y |
Logical | To store boolean values True or false | logical :: x=.True. , logical :: x = .FALSE. |
Character | To store characters and strings | character :: x |
Variable is a name given to the storage area in order to manipulate them in our programs.
data type :: variable_name
Array is a collection of similar data which is stored in continuous memory addresses.
data-type, dimension (x,y) :: array-name
integer, dimension(3,3) :: cube
Do is used to execute a set of statement(s) iteratively when a given condition is true and the loop variable must be an integer.
do i = start, stop [,step]
! code
end do
Do-While is used to execute a set of statement(s) iteratively when a given condition is true.
do while (condition)
!Code
end do
If is used to execute a set of statements based on a condition.
if (logical-expression) then
!Code
end if
If is used to execute a set of statements based on a condition and execute another set of statements present in else block, if condition specified in If block fails.
if (logical-expression) then
!code when the condition is true
else
!code when the condition fails
end if
Case is similar to switch in C language.
[name:] select case (regular-expression)
case (value1)
! code for value 1
... case (value2)
! code for value 2
...
case default
! default code
...
end select [name]