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
If d1 is defined you don't declare the nc2 and dx2 module variables, but they are still referenced in sub2?
When d1 is defined, sub2 is invalid (uses undefined variables). Conditionalize it out. Jim Dempsey
Blog: The Parallel Void
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?
ifort supports #ifdef ... #endif with /fpp option. Don't know if that's what you mean by "any other way."
conditional calling the subroutines
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