Re: Pre-processor-like Capability? [message #6416 is a reply to message #6405] |
Thu, 13 June 1996 00:00   |
dave
Messages: 31 Registered: February 1994
|
Member |
|
|
>>>> > "Bruce" == Bruce E Thomason <brucet@hsonline.net> writes:
Bruce> Does anyone know of a IDL/PV-Wave capability that is
Bruce> analogous to C's preprocessor?
Bruce> I am particularly interested in efficiently establishing
Bruce> symbolic references (in the coding process) to constant
Bruce> values for use across many routines (as #define does w/ the
Bruce> C pre-processor), but to have these values efficiently
Bruce> accessed at run-time.
I create small functions at the beginning of the source that return the
desired values:
FUNCTION magic_number
return 'boing'
END
PRO whatever, x, y, z
. . .
IF a NE magic_number THEN BEGIN
print, "Bad Magic"
return, 0
ENDIF
. . .
END
This is portable, can be included in one source file, and used in
another, and is almost as simple as a #define. It's a good idea to
use a FORWARD_FUNCTION declaration to declare all such functions at
the beginning of a procedure, in case the definition is in another
file.
Performace won't suffer unless your code is highly looped, in which
case you chould probably be linking in a C for FORTRAN module anyway.
Good luck,
David.
--
David Fenyes University of Texas Medical School
dave@msrad72.med.uth.tmc.edu Dept. of Radiology
|
|
|