home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / maths / plplot / plplot_2 / src / stubf / fmacs.m4 next >
Encoding:
Text File  |  1994-07-12  |  6.3 KB  |  214 lines

  1. divert(-1)dnl
  2. #============================================================================!
  3. # fmacs.m4
  4. # Some utility macros for Fortran m4 hacking.
  5. # Maurice J. LeBrun
  6. # IFS, University of Texas at Austin
  7. # Mar 24, 1994
  8. #
  9. # Some notes:
  10. #
  11. # I always use upper case for macro constants.  Utility macros are
  12. # typically lower case, so you must be careful of namespace collisions
  13. # with these (few) and the builtin m4 macros.  In particular, the m4
  14. # "include" command will take precedence over the fortran one (common
  15. # fortran extension), so its best to use the m4 include instead.  Or, you
  16. # can protect it using quoting characters.
  17. #
  18. # The default m4 quoting characters: `', are changed to {}, since (a)
  19. # these don't conflict with anything in Fortran (unlike the forward
  20. # quote, which is needed for strings), and (b) they are easier to see.
  21. # Some people also like to use [].
  22. #
  23. # The text (comments) in this file are discarded by the divert().
  24. #
  25. # At the end of the file the comment introducer is changed to a "*".
  26. #
  27. # $Id: fmacs.m4,v 1.3 1994/07/12 19:21:32 mjl Exp $
  28. # $Log: fmacs.m4,v $
  29. # Revision 1.3  1994/07/12  19:21:32  mjl
  30. # Fixed type definitions to help generated text stay within 72 columns.
  31. #
  32. # Revision 1.2  1994/03/30  08:28:56  mjl
  33. # Fixed broken macro definition.
  34. #
  35. # Revision 1.1  1994/03/30  07:29:39  mjl
  36. # Moved fortran interface files up one level -- no longer separate single
  37. # and double precision files.  Implemented m4 expansion of REAL into either
  38. # real*4 or real*8 depending on configure settings, for portable builds
  39. # of either the single or double precision library without copying files.
  40. # Files with .fm4 suffix must be run through m4 to become normal fortran
  41. # files.
  42. #
  43. #============================================================================#
  44.  
  45. changequote({,})
  46.  
  47. ifdef({INCLUDED_FMACS},,{
  48.     define(INCLUDED_FMACS, 1)
  49.  
  50. #============================================================================#
  51. # Some new macro primitives.
  52.  
  53.     define(TRUE, 1)
  54.     define(YES, 1)
  55.     define(ON, 1)
  56.  
  57.     define(FALSE, 0)
  58.     define(NO, 0)
  59.     define(OFF, 0)
  60.  
  61.     define(if_true, {ifelse($1,TRUE, {$2},{$3})})
  62.     define(if_false,{ifelse($1,FALSE,{$2},{$3})})
  63.  
  64. # AND, OR, and CMP macros for logical operations with macros.
  65. # Each expands to only TRUE or FALSE, and accept only two arguments (at 
  66. # present).  Example usage:
  67. #
  68. #    if_true(OR(FOO, BAR), { ... })
  69. #
  70. # will expand the given code if FOO or BAR are defined to TRUE.
  71.  
  72.     define(AND, {if_true($1, if_true({$2}, TRUE, FALSE), FALSE)})
  73.     define(OR,  {if_true($1, TRUE, if_true({$2}, TRUE, FALSE))})
  74.     define(CMP, {ifelse($1, {$2}, TRUE, FALSE)})
  75.  
  76. # Null macro (for easily discarding sections of code!)
  77.  
  78.     define(ignore,)
  79.  
  80. # undef()    alias for undefine
  81. # ifndef()    if-not-defined -- reverses action of ifdef.
  82. # cdefine()    Conditional define -- only define if not already defined.
  83. # cexpand()    Conditional expand -- expands argument if it is a macro.
  84.  
  85.     define(undef,  {undefine({$1})})
  86.     define(ifndef, {ifdef({$1},{$3},{$2})})
  87.     define(cdefine,{ifndef({$1},{define({$1},{$2})})})
  88.     define(cexpand,{ifdef({$1},{$1})})
  89.  
  90. # getstring returns its arg as a string 
  91.  
  92.     define(getstring,{'{$1}'})
  93.  
  94. # concat -- concatenates arguments to make a single token
  95.  
  96.     define(concat, {ifelse($1,,,{$1{}concat(shift($*))})})
  97.  
  98. # Macro do
  99. # Generates a do-loop like set of source code lines (}unrolls} loop).
  100. # NOTE: you must be very careful about extra spaces when using this macro.
  101. #
  102. # Example code illustrating macro_do:
  103. # Preliminary definitions:
  104. #
  105. #    define(terma,{ a$1 })
  106. #    define(termb,{ b$1 })
  107. #    define(termc,{ c$1$2 })
  108. #
  109. # The code:
  110. #
  111. #    macro_do({MD_I},1,3,
  112. #    {
  113. #        macro_do({MD_J},1,2,
  114. #        {
  115. #        termc(MD_I,MD_J) = terma(MD_I)*termb(MD_J);
  116. #        })
  117. #    })
  118. #
  119. # Output (sans blank lines) :
  120. #
  121. #         c11  =  a1 * b1 ;
  122. #         c12  =  a1 * b2 ;
  123. #         c21  =  a2 * b1 ;
  124. #         c22  =  a2 * b2 ;
  125. #         c31  =  a3 * b1 ;
  126. #         c32  =  a3 * b2 ;
  127. #----------------------------------------------------------------------------#
  128.  
  129.     define(macro_do,
  130.       {define({$1},$2)$4{}ifelse($1,$3,,{macro_do({$1},eval($2+1),$3,{$4})})})
  131.  
  132. #----------------------------------------------------------------------------#
  133. # Define some system macros
  134.  
  135.     define(if_aix,    {ifelse(SYSTEM,AIX, {$1},{$2})})
  136.     define(if_dgux,    {ifelse(SYSTEM,DGUX,{$1},{$2})})
  137.     define(if_sysv,    {ifelse(SYSTEM,SYSV,{$1},{$2})})
  138.     define(if_bsd,    {ifelse(SYSTEM,BSD, {$1},{$2})})
  139.     define(if_unicos,    {ifelse(SYSTEM,UNICOS,{$1},{$2})})
  140.     define(if_sunos,    {ifelse(SYSTEM,SUNOS,{$1},{$2})})
  141.     define(if_ultrix,    {ifelse(SYSTEM,ULTRIX,{$1},{$2})})
  142.     define(if_hpux,    {ifelse(SYSTEM,HPUX,{$1},{$2})})
  143.     define(if_linux,    {ifelse(SYSTEM,Linux,{$1},{$2})})
  144.     define(if_sx,    {ifelse(SYSTEM,SX,{$1},{$2})})
  145.  
  146. #----------------------------------------------------------------------------#
  147. # Define the implicit_none macro.  
  148. #
  149. # Default
  150. # Implicit character almost as good as implicit none.
  151.  
  152.     define(implicit_none, {implicit character(a-z)})
  153.  
  154. # "implicit undefined" is used in many "f77" compatible compilers
  155.  
  156.     if_sunos({
  157.     define({implicit_none}, {implicit undefined(a-z)})
  158.     })
  159.  
  160.     if_aix({
  161.     define({implicit_none}, {implicit undefined(a-z)})
  162.     })
  163.  
  164. # "implicit none" is F90 and Mil Std...
  165.  
  166.     if_sx({
  167.     define({implicit_none}, {implicit none})
  168.     })
  169.  
  170.     if_unicos({
  171.     define({implicit_none}, {implicit none})
  172.     })
  173.  
  174.     if_hpux({
  175.     define({implicit_none}, {implicit none})
  176.     })
  177.  
  178. #----------------------------------------------------------------------------#
  179. # Define REAL according to the desired floating point precision.  The
  180. # compiler should AT LEAST support automatic promotion of constants via a
  181. # command line flag.  Most can promote variables as well, but this way is
  182. # a bit more portable.
  183.  
  184.     define(if_dbl,    {ifdef({DOUBLE}, {$1},{$2})})
  185.  
  186. # There should be a better way..
  187.  
  188.   if_unicos({
  189.     define(REAL,        {real})
  190.     define(COMPLEX,        {complex})
  191.     define(IMPLICIT_REAL,    {implicit real(a-h,o-z)})
  192.     define(DREAL,        {real})
  193.     define(IMAG,        {aimag {} ifelse({$*},,,{($*)})})
  194.   },{
  195.     define(IMAG,        {imag {} ifelse({$*},,,{($*)})})
  196.     if_dbl({
  197.     define(REAL,        {real*8})
  198.     define(COMPLEX,        {complex*16})
  199.     define(IMPLICIT_REAL,    {implicit real*8(a-h,o-z)})
  200.     define(DREAL,        {real*16})
  201.     },{
  202.     define(REAL,        {real*4})
  203.     define(COMPLEX,        {complex*8})
  204.     define(IMPLICIT_REAL,    {implicit real*4(a-h,o-z)})
  205.     define(DREAL,        {real*8})
  206.     })
  207.   })
  208.  
  209. #============================================================================#
  210.  
  211. })
  212. changecom(*)
  213. divert(0)dnl
  214.