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

conditional calling the subroutines

wally_w_
Beginner
1,216 Views

 Hi all 

      I am trying to compile a test program pasted below, using the conditional compilation directive.

      But it failed,  Could anyone tell me where wrong is the program?

  

Module param
!DEC$ IF DEFINED (d1)
integer,parameter :: nc1 = 10
real*8 dx1
!DEC$ ELSE
integer,parameter :: nc1 = 10
integer,parameter :: nc2 = 10
real*8 dx1
real*8 dx2
!DEC$ ENDIF
end module

program main
use param
implicit none
!DEC$ IF DEFINED (d1)
call sub1
!DEC$ ELSE
call sub1
call sub2
!DEC$ ENDIF
end program

subroutine sub1
use param
implicit none
dx1 = 1.d0/ nc1
end subroutine

subroutine sub2
use param
implicit none
dx2 = 1.d0/ nc2
end subroutine

0 Kudos
4 Replies
IanH
Honored Contributor III
1,216 Views
If d1 is defined you don't declare the nc2 and dx2 module variables, but they are still referenced in sub2?
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,216 Views
When d1 is defined, sub2 is invalid (uses undefined variables). Conditionalize it out. Jim Dempsey
0 Kudos
wally_w_
Beginner
1,216 Views
Dear all, Thank you for your early reply. As you said, I modified this test program as follows: !DEC$ IF DEFINED (d1) subroutine sub1 use param implicit none dx1 = 1.d0/ nc1 end subroutine !DEC$ END IF !DEC$ IF DEFINED (d2) subroutine sub2 use param implicit none dx2 = 1.d0/ nc2 end subroutine !DEC$ END IF Is there any other way to do so?
0 Kudos
TimP
Honored Contributor III
1,216 Views
ifort supports #ifdef ... #endif with /fpp option. Don't know if that's what you mean by "any other way."
0 Kudos
Reply