Fortran 90 Program for Processing Output Files | Looping Through File Names

  • Fortran
  • Thread starter jd1828
  • Start date
  • Tags
    Fortran
In summary, the speaker is trying to write a program in Fortran 90 to process multiple output files with similar names. They want the program to loop through each file, changing the name by adding a letter to the end each time it reads the file. Another person suggests defining a new character variable with an editing suffix to accomplish this.
  • #1
jd1828
44
0
Im trying to write a program in fortran 90 to process some output files that i have. Here is the problem I am having. All of the output files are named file.datA, file.datB,...ect. I set the variable "file" to equal file.dat. I want the program to run through a loop and each time change the name of "file". Basically I need to add A-Z on the end each time it reads the file.
 
Technology news on Phys.org
  • #2
jd1828 said:
Im trying to write a program in fortran 90 to process some output files that i have. Here is the problem I am having. All of the output files are named file.datA, file.datB,...ect. I set the variable "file" to equal file.dat. I want the program to run through a loop and each time change the name of "file". Basically I need to add A-Z on the end each time it reads the file.

... wonder if you could do it simply by defining a new character variable by trimming (using TRIM and some "editing suffix" in between, like // to ditch spaces etc.) 2 other chars together, and using the new one in the loop as the filename.
 
  • #3


Hello,

Thank you for sharing your problem with writing a Fortran 90 program to process output files. It seems like you are facing a challenge in looping through file names. I would be happy to provide some guidance on how to approach this problem.

Firstly, it is important to understand that in Fortran 90, file names are treated as character strings. This means that you can manipulate them using string operations such as concatenation, slicing, and indexing. With this in mind, we can devise a solution to your problem.

One approach is to use a DO loop to iterate through the alphabets A-Z and use the string concatenation operator // to append them to the file name. For example, your loop could look something like this:

DO i = 1, 26
file = "file.dat" // CHAR(i+64)
! code to process the file
END DO

In this loop, the variable "i" takes the values from 1 to 26, and CHAR(i+64) converts the integer value to its corresponding ASCII character. This way, in each iteration, the file name will be updated with a different alphabet at the end.

Another approach is to use the intrinsic function "TRIM" to remove the trailing spaces from the file name and then append the alphabets. For instance, your loop could look like this:

DO i = 1, 26
file = TRIM(file) // CHAR(i+64)
! code to process the file
END DO

This approach eliminates the need to specify the file name in quotes, making it more flexible.

I hope these suggestions help you in solving your problem. Please let me know if you have any further questions or need clarification on any of the above. Best of luck with your program!
 

1. What is Fortran 90?

Fortran 90 is a high-level programming language used primarily for scientific and engineering applications. It is an updated version of the Fortran programming language, with added features and improvements.

2. Why do I need help with Fortran 90?

Fortran 90 can be a complex language, especially for those who are new to programming. It requires a strong understanding of programming concepts and syntax, and it may take some time and practice to become proficient.

3. Where can I find resources for learning Fortran 90?

There are many online resources available for learning Fortran 90, such as tutorials, forums, and online courses. You can also find books and manuals on Fortran 90 at your local library or bookstore.

4. Can I use Fortran 90 for any type of programming?

Fortran 90 is primarily used for scientific and engineering applications, but it can also be used for general purpose programming. However, there may be other programming languages that are better suited for certain tasks.

5. How can I get help with specific Fortran 90 problems?

If you are having trouble with a specific Fortran 90 program or project, there are many online forums and communities where you can ask for help and receive guidance from experienced Fortran programmers. You can also consult with a programming tutor or seek assistance from your colleagues or classmates.

Similar threads

  • Programming and Computer Science
Replies
16
Views
3K
  • Programming and Computer Science
Replies
22
Views
907
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
4
Views
588
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
3
Replies
75
Views
4K
Back
Top