For Programmers: Free Programming Magazines  


Home > Archive > Fortran > August 2007 > Q: Are there pre-defined macro symbols available to determine what compiler is being









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Q: Are there pre-defined macro symbols available to determine what compiler is being
James Tursa

2007-08-24, 4:23 am

I have a MATLAB engine source file that is intended to be part of a
user library. Part of the start-up will be to get the FORTRAN program
current working directory with the getcwd() call and then pass that on
to the MATLAB engine so that it is pointed to the same directory as
the FORTRAN program. Problem is, getcwd() is not implemented the same
way on every compiler. For the two compilers I have access to, Compaq
VF 6.1 includes getcwd() in the module named DFPORT which is in the
library file DFPORT.LIB. On the Intel 9.1 compiler, getcwd() is in
the module named IFPORT in the library file (something else I forget
at the moment). So I have to place the burden on the user of telling
my code what compiler is being used. I prefer this to maintaining
multiple versions of my library code for various compilers. For
example, the user code would be:
----------------------------------------------------------
#define INTEL91

program myprog
use MATLABmodule

call mOpen

(blah blah blah other code)

end program myprog
------------------------------------------------------------
and my module source code would be:
------------------------------------------------------------
#include "fintrf.h"
module MATLABmodule

mwPointer :: MATLABengine = 0
logical :: MATLABisClosed = .true.

contains

subroutine mOpen
#ifdef COMPAQ61
use DFPORT
#elif INTEL91
use IFPORT
#endif
implicit none
!-FUN
mwPointer engOpen
!-LOC
#if defined( COMPAQ61 ) || defined( INTEL91 )
integer*4 result, k, n
character*260 cwd
#endif
!-----
if( MATLABisClosed ) then
MATLABengine = engOpen(' ')
if( MATLABengine == 0 ) then
write(*,*) '*** ERROR *** MATLAB engine will not open'
else
MATLABisClosed = .false.
#if defined( COMPAQ61 ) || defined( INTEL91 )
result = getcwd(cwd)
if( result == 0 ) then
n = 1
do k=260,1,-1
if( cwd(k:k) /= ' ' ) then
n = k
exit
endif
enddo
k = engEvalString(MATLABengine, "cd '"//cwd(1:n)//"'")
else
write(*,*) '*** ERROR *** Unable to get working dir'
endif
#endif
endif
endif
return

end function

end module
------------------------------------------------------------
Q1: Is there a way to detect, in the pre-processor with a #ifdef or
some other way, which compiler is being used without forcing the user
to define something to tell me? i.e., are there any pre-defined macro
symbols that I can test for to tell me what compiler is being used?
That way I wouldn't have to rely on the user to set something
correctly, and it makes the user code a little more portable.

Q2: Also, for users out there with other compilers, I am curious to
know what module and library file is the getcwd() routine contained in
for your compiler?

James Tursa

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com