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

Click For Summary
Injecting external code into a Fortran 77 program without using subroutines or functions is a topic of interest for those looking to streamline their code. The discussion highlights the desire to separate lines of code into an external file while allowing them to be evaluated inline, maintaining access to local variables. Standard Fortran 77 offers the INCLUDE statement, which can be used to incorporate external files directly into the main code. This method allows for better organization and automation, especially when working with numerous variables. However, it is important to note that any changes made to the included file necessitate recompiling the entire program. The use of the C preprocessor is also mentioned as a potential tool for more complex code management, although its relation to Mathematica remains unclear.
Hepth
Science Advisor
Gold Member
Messages
457
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 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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

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
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 59 ·
2
Replies
59
Views
11K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 14 ·
Replies
14
Views
2K