How to read files while running fortran program?

Click For Summary

Discussion Overview

The discussion revolves around the process of reading input files while running a Fortran simulation program on Linux. Participants explore the requirements for file input and the methods to link or reference these files during execution.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • Naomi inquires about the meaning of needing to read several input files for a Fortran simulation and how to accomplish this.
  • jtbell provides a link to a resource that may help with understanding file reading in Fortran.
  • Naomi clarifies that she is not looking to read files within the program itself but is unsure about linking to the files when running the program.
  • Another participant explains that "link" has a specific meaning in compiled languages and suggests that the program needs to open and read the files, indicating that the file names could be hardcoded, taken as input, or passed via the command line.
  • Naomi later reports that she resolved her issue by including the file as < file.txt > in the command line when running the program.

Areas of Agreement / Disagreement

The discussion appears to have a resolution with Naomi successfully figuring out how to read the files, but there is no consensus on the initial understanding of linking files versus reading them during program execution.

Contextual Notes

Participants did not provide specific details about the source code or the exact requirements for file input, leaving some assumptions and dependencies on definitions unresolved.

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.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K