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

AI Thread Summary
To run a Fortran 77 program within a C++ environment, one approach is to use the system command to execute the compiled Fortran executable directly from C++. The user aims to create a loop in C++ that modifies the input file for the Fortran program, executes it, retrieves the output files, and renames them based on the interval of execution. Another option mentioned is using a wrapper like "f2c" to facilitate the integration, although the user is unfamiliar with its implementation. The focus remains on maintaining the original Fortran code while efficiently managing input and output through C++. The discussion highlights the importance of leveraging existing executables for performance and simplicity in the task.
lordentropy
Messages
5
Reaction score
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
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.
 
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
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
2
Views
770
Replies
8
Views
4K
Replies
6
Views
3K
Replies
1
Views
3K
Replies
3
Views
2K
Back
Top