Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Case selection problem

rus_nur
Beginner
561 Views
I need function, which will be dependent from some real parameter and also
can be determinated from some integer, like that:
Function SomeFunction (A, b)
A: real(8), b- integer (type of function)
My problem is that I couldn`t make it with case selection.
Looks like:
Case(I) then i=1
SomeFunction=A*2
Case(I) then i=2
SomeFunction=exp(A)
Help me please.
0 Kudos
1 Reply
meistrv
Beginner
561 Views
I have tried it and it works for me. My code is:

PROGRAM casee

INTERFACE
REAL*8 FUNCTION Funkce(A,b)
REAL*8 A
INTEGER b
END FUNCTION
END INTERFACE

REAL*8 A,res
INTEGER b, ii

A=2.3D0
DO 5 ii=1,5
res=Funkce(A,ii)
WRITE (*,'(a,F10.5)') 'Result = ',res
5 CONTINUE
STOP
END

REAL*8 FUNCTION Funkce(A,b)

REAL*8 A
INTEGER b

SELECT CASE (b)

CASE(1)
Funkce=3*A+2.1
CASE(2)
Funkce=A**2+9
CASE(3)
Funkce=exp(A)
CASE(4)
Funkce=sin(A)
CASE(5)
Funkce=abs(A)
END SELECT

RETURN
END FUNCTION
0 Kudos
Reply