Running a Fortran 77 program in a C++ enviorment/program

In summary, the student is trying to write a C++ program that will run a fortran77 program and change the input file.
  • #1
lordentropy
6
0
I hope someone out there can help me out on this one. I have intermediate C++ experience, just a working level knowledge, however my prof. threw me a project to work on and where I am at now I have no experience with.

So this is what's up, I have a massive fortran 77 program...that does some heavy, calculations with a but load of data which can take days to execute on a supercomputer. However, I was told not to mess with the fortran77 program even though most of the code is 'homegrown' and there are extensive libraries out now that can take away pages of code.

So my task is to vary the input file this program is running off of, run the fortran program and get the output files and loop it over again at another interval.

So some how I need to run this fortran program within a C++ program that I am going to write, more to the point inside a loop that will change the input file, run fortran, get output files...rename output files to match interval it was intially ran at, and change interval and do it all over again.

How in the hell do you run a fortran77 program within a C++ program?
 
Technology news on Phys.org
  • #2
If the fortran code is already compiled (so you have "something.exe" sat in your working directory) then you could try something like:

#include <stdlib.h>
...
system("something.exe");
...

If you want to run fortran code in c++ then there is a wrapper, called "f2c" (I think you just need a header file, "f2c.h"). I've never used this so I have no idea how it works... but I hope this helps.
 
  • #3
Yes that helps, I figured it had to be something like that but I had no clue where to look, I figured as for simplistically and efficiency I should just run the executable within the C++ program, b/c well my next task after I write this piece of serial code...is to parallelize the loop and I thought it would be better for me and the program to just run the executable.
Thanks much
 

1. Can I use C++ libraries in my Fortran 77 program?

Yes, it is possible to use C++ libraries in your Fortran 77 program. However, some modifications may be necessary to ensure compatibility between the two languages.

2. How do I call a Fortran 77 subroutine from my C++ program?

You can call a Fortran 77 subroutine from your C++ program by using the "extern C" declaration in your C++ code. This will ensure that the C++ compiler recognizes the Fortran subroutine and allows you to call it.

3. What is the best way to pass data between Fortran 77 and C++?

The best way to pass data between Fortran 77 and C++ depends on the specific needs of your program. One option is to use common blocks, which allow for shared data between the two languages. Another option is to use the ISO C Binding feature in Fortran, which allows for interoperability with C data types.

4. Can I mix Fortran 77 and C++ code in the same source file?

Yes, it is possible to mix Fortran 77 and C++ code in the same source file. However, you will need to use the "extern C" declaration for the C++ code and make sure the Fortran code is compiled correctly.

5. Is it possible to debug a Fortran 77 program running in a C++ environment?

Yes, it is possible to debug a Fortran 77 program running in a C++ environment. You can use a debugger that supports both languages, or you can use a separate debugger for each language and coordinate breakpoints between them.

Similar threads

  • Programming and Computer Science
Replies
22
Views
872
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
2
Replies
37
Views
3K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
4
Views
501
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
32
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
Back
Top