Fortran 77 [F77] : Code in external file without subroutine?

Click For Summary

Discussion Overview

The discussion revolves around the possibility of including external code in Fortran 77 without using subroutines or function calls, specifically focusing on the use of an external file to hide code while maintaining access to local variables.

Discussion Character

  • Technical explanation, Conceptual clarification, Debate/contested

Main Points Raised

  • One participant inquires about injecting external code into a separate file to be evaluated inline, without using a procedure or function call, while accessing local variables.
  • Another participant mentions the standard Fortran 77 INCLUDE statement as a potential solution for including external code.
  • A later reply notes that changes to the included file require recompilation of the program.
  • One participant expresses gratitude for the information about the INCLUDE statement, indicating it was previously overlooked.

Areas of Agreement / Disagreement

Participants appear to agree on the use of the INCLUDE statement as a method for including external code, but the implications of using it, such as the need for recompilation, are acknowledged without further consensus on the best approach.

Contextual Notes

The discussion does not resolve the potential limitations or implications of using the INCLUDE statement in relation to the specific needs of the original inquiry, such as integration with Mathematica.

Hepth
Science Advisor
Gold Member
Messages
458
Reaction score
40
I have some F77 code and I am wondering if it is possible to inject external code into a separate file and call it without it being a subroutine, and placed into the code. An example would be :

a = 1 + 1
b = a + 1
c = b + a
a = c + b
d = 4 + a


and I want to take lines 3 and 4 and put them into somewhere else, say another file so I have

a = 1 + 1
b = a + 1
(externalfile.f)
d = 4 + a

and it has the same result.

So basically just HIDING code into another file, such that it will be evaluated inline without using a procedure or function call to it. It just uses the local variables that are in use.


The reason I do this is that I have a LOT of variables for a few results, and I am using the FortranForm from Mathematica. But it would be MUCH easier to automate this for changes if I can just export the code to a file and never really look at it, and then my main file wouldn't be ugly.

I really really want to avoid passing all these variables to another function.
 
Technology news on Phys.org
Standard fortran 77 has an INCLUDE statement:

INCLUDE 'filename'

Most fortran 77 compilers have an option to use the C preprocessor (which can do more than just #include, of course).

I've no idea how this relates to Mathematica.
 
  • Like
Likes   Reactions: 1 person
Thanks, for some reason I couldn't find that by searching what I wanted. Thats exactly it.
 
Note that every time you change the "included" file, you have to recompile the program.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 14 ·
Replies
14
Views
2K