Can You Loop Numbers and Write an Output File in Fortran?

  • Context: Fortran 
  • Thread starter Thread starter ƒ(x) → ∞
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary
SUMMARY

This discussion addresses looping through a set of numbers in Fortran and writing output to a file. The provided code snippet demonstrates how to loop from 1 to 52 using a nested loop structure, where 'n' represents the number of iterations. Additionally, it suggests parsing characters and concatenating them into a single string before writing to a file, rather than writing each character individually. This approach enhances efficiency in file output operations.

PREREQUISITES
  • Fortran programming language fundamentals
  • Understanding of loops and control structures in Fortran
  • File I/O operations in Fortran
  • String manipulation techniques in Fortran
NEXT STEPS
  • Explore Fortran DO loops and their applications
  • Learn about Fortran file handling and output methods
  • Investigate character parsing and string concatenation in Fortran
  • Study best practices for efficient file writing in Fortran
USEFUL FOR

This discussion is beneficial for Fortran developers, programmers interested in file handling, and anyone looking to enhance their skills in looping constructs and output operations in Fortran.

ƒ(x) → ∞
Messages
24
Reaction score
0
Is it possible to loop a set of numbers?

For example I wish to run a set of number 1,2,3,4,5...52 but when we get to 52 I wish to go back to 1 and start looping again.

How do write an output file in Fortran?

I have opened a file and moved each character so that each letter has moved for example d to e...x to y... How could I write this new series of characters to a file
 
Technology news on Phys.org
Not sure what you mean by "run" a set of numbers. If you just wish to print them, then something easy enough like this should work:
Code:
do i=1,n !-- number of times you wish you loop
 do j=1,52
    write(6,*) j
 end do
end do

As far as the second question, you might be best parsing each character in a line, and then concatenating them all to one text string and writing that entire line to file (rather than character by character).
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 19 ·
Replies
19
Views
7K