[Info-vax] Architecture specific code in VMS Fortran
Steven Schweda
sms.antinode at gmail.com
Sat Oct 1 17:46:23 EDT 2011
On Oct 1, 11:56 am, Tom Wade <nos... at tomwade.eu> wrote:
> I've checked out the HP Fortran manuals for compiler directives in code that can select based on the
> architecture (VAX/Alpha/IA64). It seems the CDEC$ IF DEFINED stuff is the way to go, but although
> it describes how to define and test variables, I can't see a list of predefined variables such as
> the current architecture. I want to do something like
>
> CDEC$ IF DEFINED (VAX)
>
> <code to be compiled only if on VAX>
> CDEC$ ENDIF
>
> Any small examples ?
I haven't done much with Fortran since it was FORTRAN, so
I know nothing, but ...
Hmmm. Never thought about it. I see nothing in the HELP
about any predefined anything, so I'd guess that you'd need
to specify something on the FORTRAN command line which would
have the desired effect.
Hmmm. CC has /DEFINE, but FORTRAN seems to have no direct
equivalent. /D_LINES can inject one bit worth of information
into the code, but I see no obvious way to combine a D-line
with a CDEC$-line, so it appears useless in this situation.
Perhaps one could use CC /PREPROCESS_ONLY [/DEFINE] to
preprocess Fortran code which contains C-preprocessor
directives. At a long-dead job, we wrote our own
preprocessor which used "C$$" comment/directives to bracket
conditional code:
alp $ sea [...]*.f* "c$$"
[...]
C$$ VMS
C$$ VMS
C$$ APOLLO
C$$ APOLLO
C$$ SUN/ULTRIX
C$$ SUN/ULTRIX
[...]
In a VMS-only environment, one could scatter
architecture-specific files into architecture-specific
directories, and then use a command like "FORTRAN /INCLUDE =
arch-specific-directory" to select whence a directive like
INCLUDE 'arch.for'
would find an architecture-specific "arch.for".
Another possibility would be explicitly to specify an
appropriate architecture-specific file in the FORTRAN
command. For example:
alp $ type arch_alpha.for, arch_ia64.for, arch_vax.for
CDEC$ define my_alpha
ALP$DKC0:[SMS.ITRC]arch_ia64.for;1
CDEC$ define my_ia64
ALP$DKC0:[SMS.ITRC]arch_vax.for;1
CDEC$ define my_vax
alp $ fort arch_ia64.for+ arch_test2.for /obje = arch_test2
alp $ link arch_test2
alp $ run arch_test2
ARCH = IA64
Here's the program:
alp $ type arch_test2.for
program arch_test2
character* 8 ARCH
CDEC$ if defined( my_ALPHA)
parameter (ARCH = "Alpha")
CDEC$ else if defined( my_IA64)
parameter (ARCH = "IA64")
CDEC$ else if defined( my_VAX)
parameter (ARCH = "VAX")
CDEC$ else
parameter (ARCH = "Unknown")
CDEC$ endif
type *, "ARCH = ", ARCH
end
Naturally, without the architecture-specific preface:
alp $ fort arch_test2.for /obje = arch_test2
alp $ link arch_test2
alp $ run arch_test2
ARCH = Unknown
Interestingly, despite the documentation, that test
program is called "arch_test2" because the original
"arch_test" did something interesting:
alp $ type arch_test.for
program arch_test
character* 8 ARCH
CDEC$ if defined( ALPHA)
parameter (ARCH = "Alpha")
CDEC$ else if defined( IA64)
parameter (ARCH = "IA64")
CDEC$ else if defined( VAX)
parameter (ARCH = "VAX")
CDEC$ else
parameter (ARCH = "Unknown")
CDEC$ endif
type *, "ARCH = ", ARCH
end
alp $ fort arch_test
alp $ link arch_test
alp $ run arch_test
ARCH = Alpha
This suggests that there may be some useful (but poorly
documented) capability hidden away in this stuff. I don't
seem to have an IA64 Fortran compiler kit (and, as a
lowly-peon hobbyist, access to one is not very convenient),
and I'm too lazy to fire up a VAX to test this, so I can only
guess at what might happen elsewhere, but there does seem to
be some hope. As usual, many things are possible, and
everything's complicated. (And, sometimes, experiment can be
more informative than reading.)
More information about the Info-vax
mailing list