Fortran How to read files while running fortran program?

AI Thread Summary
To run a Fortran simulation on Linux, it is essential to understand how to read the required input files as specified in the User's Manual. The program must open and read these files, which can be done by either hardcoding the file names in the source code, taking them as input at runtime, or passing them via the command line. The term "link" is not applicable in this context, as it refers to a different aspect of compiled programming. The user resolved their issue by including the input file directly in the command line using the syntax "< file.txt >" when executing the program.
ngendler
Messages
20
Reaction score
0
Hi,

I am trying to run a simulation written mostly in Fortran on Linux. The User's Manual says that "To run a simulation one needs to read several input files." Then, it lists a bunch of files. I was wondering what it means by that and how I "read" the files?

Thanks in advance,

Naomi
 
Technology news on Phys.org
@jtbell, thank you but no. I'm not trying read files within the program. The program is all completely written. But now when I run it, I think I need to link to those files or something, I'm not sure.
 
ngendler said:
@jtbell, thank you but no. I'm not trying read files within the program. The program is all completely written. But now when I run it, I think I need to link to those files or something, I'm not sure.
"Link" has a very specific meaning in compiled programming languages such as Fortran, and is not applicable in your case. Your program needs to open the files and read from them, as described in the link that jtbell provided.

Your program needs to know the names of the files that it will be getting input from. The names of these files could be hardcoded in strings in the program, taken as input at run time, or passed on the command line when the program begins running. Without seeing the source code of your program, we can't say what you need to do to run it.
 
Nevermind, I figured it out. I just included the file as < file.txt > in the command line where I ran the program.
 
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
8
Views
1K
Replies
2
Views
773
Replies
5
Views
5K
Replies
17
Views
6K
Replies
12
Views
3K
Replies
5
Views
2K
Replies
2
Views
3K
Replies
1
Views
3K
Back
Top