Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. May 5, 2014 #1

    Hepth

    User Avatar
    Gold Member

    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 Im 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 wouldnt be ugly.

    I really really want to avoid passing all these variables to another function.
     
  2. jcsd
  3. May 5, 2014 #2

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    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.
     
  4. May 5, 2014 #3

    Hepth

    User Avatar
    Gold Member

    Thanks, for some reason I couldn't find that by searching what I wanted. Thats exactly it.
     
  5. May 5, 2014 #4

    jtbell

    User Avatar

    Staff: Mentor

    Note that every time you change the "included" file, you have to recompile the program.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran 77 [F77] : Code in external file without subroutine?
Loading...