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

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 2K views
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.
 
Physics 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