home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / fortran / 4264 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.2 KB  |  43 lines

  1. Path: sparky!uunet!destroyer!cs.ubc.ca!unixg.ubc.ca!sitka.triumf.ca!morgan
  2. From: morgan@sitka.triumf.ca (Morgan Burke)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: Multiple includes
  5. Date: 11 Nov 1992 00:58:35 GMT
  6. Organization: TRIUMF, Vancouver BC
  7. Lines: 30
  8. Distribution: world
  9. Message-ID: <1dplrrINNg7t@iskut.ucs.ubc.ca>
  10. References: <1dotfaINN4a1@alnitak.usc.edu>
  11. NNTP-Posting-Host: sitka.triumf.ca
  12.  
  13. In article <1dotfaINN4a1@alnitak.usc.edu>, olaf@alnitak.usc.edu (Olaf Meeuwissen) writes:
  14. |> Is there a way to include files conditionally?  
  15. |> I mean, only include it if it is not included already.
  16.  
  17. If your f77 compiler uses cpp, you can use the #include statement
  18. instead of the Fortran INCLUDE.  Then, inside the include file, use
  19. #define and #ifndef, for example:
  20.  
  21. C  dim.h
  22. #ifndef INCLUDE_DIM
  23.       INTEGER dim
  24.       PARAMETER ( dim = 10 )
  25. #endif
  26. #define INCLUDE_DIM
  27. C  end of dim.h
  28.  
  29. The file will be included more than once, but the contents will only be 
  30. present the first time it is included.
  31.  
  32. Of course, if you are going to use cpp anyway, you could always just do:
  33.  
  34. C  dim.h
  35. #define DIM 10
  36. C  end of dim.h
  37.  
  38. and then declare all your arrays with dimension DIM.  It won't matter if
  39. this file is included more than once.
  40.  
  41. -- Morgan Burke (morgan@reg.triumf.ca)
  42.  
  43.