Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
70
Task/Call-a-function/Fortran/call-a-function-1.f
Normal file
70
Task/Call-a-function/Fortran/call-a-function-1.f
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
program main
|
||||
implicit none
|
||||
integer :: a
|
||||
integer :: f, g
|
||||
logical :: lresult
|
||||
interface
|
||||
integer function h(a,b,c)
|
||||
integer :: a, b
|
||||
integer, optional :: c
|
||||
end function
|
||||
end interface
|
||||
write(*,*) 'no arguments: ', f()
|
||||
write(*,*) '-----------------'
|
||||
write(*,*) 'fixed arguments: ', g(5,8,lresult)
|
||||
write(*,*) '-----------------'
|
||||
write(*,*) 'optional arguments: ', h(5,8), h(5,8,4)
|
||||
write(*,*) '-----------------'
|
||||
write(*,*) 'function with variable arguments: Does not apply!'
|
||||
write(*,*) 'An option is to pass arrays of variable lengths.'
|
||||
write(*,*) '-----------------'
|
||||
write(*,*) 'named arguments: ', h(c=4,b=8,a=5)
|
||||
write(*,*) '-----------------'
|
||||
write(*,*) 'function in statement context: Does not apply!'
|
||||
write(*,*) '-----------------'
|
||||
write(*,*) 'Fortran passes memory location of variables as arguments.'
|
||||
write(*,*) 'So an argument can hold the return value.'
|
||||
write(*,*) 'function result: ', g(5,8,lresult) , ' function successful? ', lresult
|
||||
write(*,*) '-----------------'
|
||||
write(*,*) 'Distinguish between built-in and user-defined functions: Does not apply!'
|
||||
write(*,*) '-----------------'
|
||||
write(*,*) 'Calling a subroutine: '
|
||||
a = 30
|
||||
call sub(a)
|
||||
write(*,*) 'Function call: ', f()
|
||||
write(*,*) '-----------------'
|
||||
write(*,*) 'All variables are passed as pointers.'
|
||||
write(*,*) 'Problems can arise if instead of sub(a), one uses sub(10).'
|
||||
write(*,*) '-----------------'
|
||||
end program
|
||||
|
||||
!no argument
|
||||
integer function f()
|
||||
f = 10
|
||||
end function
|
||||
|
||||
!fixed number of arguments
|
||||
integer function g(a, b, lresult)
|
||||
integer :: a, b
|
||||
logical :: lresult
|
||||
g = a+b
|
||||
lresult = .TRUE.
|
||||
end function
|
||||
|
||||
!optional arguments
|
||||
integer function h(a, b, c)
|
||||
integer :: a, b
|
||||
integer, optional :: c
|
||||
|
||||
h = a+b
|
||||
if(present(c)) then
|
||||
h = h+10*c
|
||||
end if
|
||||
end function
|
||||
|
||||
!subroutine
|
||||
subroutine sub(a)
|
||||
integer :: a
|
||||
a = a*100
|
||||
write(*,*) 'Output of subroutine: ', a
|
||||
end subroutine
|
||||
4
Task/Call-a-function/Fortran/call-a-function-2.f
Normal file
4
Task/Call-a-function/Fortran/call-a-function-2.f
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
REAL this,that
|
||||
DIST(X,Y,Z) = SQRT(X**2 + Y**2 + Z**2) + this/that !One arithmetic statement, possibly lengthy.
|
||||
...
|
||||
D = 3 + DIST(X1 - X2,YDIFF,SQRT(ZD2)) !Invoke local function DIST.
|
||||
2
Task/Call-a-function/Fortran/call-a-function-3.f
Normal file
2
Task/Call-a-function/Fortran/call-a-function-3.f
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
H = A + B
|
||||
IF (blah) H = 3*H - 7
|
||||
25
Task/Call-a-function/Fortran/call-a-function-4.f
Normal file
25
Task/Call-a-function/Fortran/call-a-function-4.f
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
REAL FUNCTION INTG8(F,A,B,DX) !Integrate function F.
|
||||
EXTERNAL F !Some function of one parameter.
|
||||
REAL A,B !Bounds.
|
||||
REAL DX !Step.
|
||||
INTEGER N !A counter.
|
||||
INTG8 = F(A) + F(B) !Get the ends exactly.
|
||||
N = (B - A)/DX !Truncates. Ignore A + N*DX = B chances.
|
||||
DO I = 1,N !Step along the interior.
|
||||
INTG8 = INTG8 + F(A + I*DX) !Evaluate the function.
|
||||
END DO !On to the next.
|
||||
INTG8 = INTG8/(N + 2)*(B - A) !Average value times interval width.
|
||||
END FUNCTION INTG8 !This is not a good calculation!
|
||||
|
||||
FUNCTION TRIAL(X) !Some user-written function.
|
||||
REAL X
|
||||
TRIAL = 1 + X !This will do.
|
||||
END FUNCTION TRIAL !Not the name of a library function.
|
||||
|
||||
PROGRAM POKE
|
||||
INTRINSIC SIN !Thus, not an (undeclared) ordinary variable.
|
||||
EXTERNAL TRIAL !Likewise, but also, not an intrinsic function.
|
||||
REAL INTG8 !Don't look for the result in an integer place.
|
||||
WRITE (6,*) "Result=",INTG8(SIN, 0.0,8*ATAN(1.0),0.01)
|
||||
WRITE (6,*) "Linear=",INTG8(TRIAL,0.0,1.0, 0.01)
|
||||
END
|
||||
5
Task/Call-a-function/Fortran/call-a-function-5.f
Normal file
5
Task/Call-a-function/Fortran/call-a-function-5.f
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
TYPE MIXED
|
||||
CHARACTER*12 NAME
|
||||
INTEGER STUFF
|
||||
END TYPE MIXED
|
||||
TYPE(MIXED) LOTS(12000)
|
||||
Loading…
Add table
Add a link
Reference in a new issue