Imagine we have 3 functions which call each other: func1(u,Y,is_D) calls func2, func2 calls func3. and all of them have the same OPTIONAL vars.
Manipulations with optional vars are performed only in func3. The question is next: Can I pass variables without checking present or not. Can checking be performed only at the last function func3? in compiler ifort it works. BUT I want to understand is it standard or not? Will it work for other compilers Fortran 90, since in a cluster users have to works with a provided compiler?
The second question is can I check present and value of optional variables, for example in next form: IF(PRESENT(is_D) .AND. is_D.EQ.1). How I understand after checking of first subcondition if it is TRUE it will check next subcondition and it will work, But if it is FALSE, will it stop checking next statements? Is there any standards?
FUNCTION func1 (u1, is_D, u2) RESULT(res)
IMPLICIT NONE
REAL (pr), DIMENSION (N,M),INTENT(IN) :: u1
REAL (pr), DIMENSION (N,M),INTENT(IN), OPTIONAL :: u2
REAL (pr), DIMENSION (N) :: res
INTEGER, OPTIONAL :: is_D
res= func2(u1,is_D,u2)
END FUNCTION func1
FUNCTION func2 (u1, is_D, u2) RESULT(res)
IMPLICIT NONE
REAL (pr), DIMENSION (N,M),INTENT(IN) :: u1
REAL (pr), DIMENSION (N,M),INTENT(IN), OPTIONAL :: u2
REAL (pr), DIMENSION (N) :: res
INTEGER, OPTIONAL :: is_D
res = func3(u1,is_D,u2) +func3(u1+1,is_D,u2)
END FUNCTION func2
FUNCTION func3 (u1, is_D, u2) RESULT(res)
IMPLICIT NONE
REAL (pr), DIMENSION (N,M),INTENT(IN) :: u1
REAL (pr), DIMENSION (N,M),INTENT(IN), OPTIONAL :: u2
REAL (pr), DIMENSION (N) :: res
INTEGER, OPTIONAL :: is_D
IF (present(is_D).AND. PRESENT(u2)) THEN
res = SUM (u2, DIM=2)
ELSE
res = SUM (u1,DIM=2)
END IF
END FUNCTION func3
Aucun commentaire:
Enregistrer un commentaire