Help with Fortran90: Reading a File

  • Context: Fortran 
  • Thread starter Thread starter ne_237
  • Start date Start date
  • Tags Tags
    Fortran90
Click For Summary

Discussion Overview

The discussion revolves around challenges faced by participants in reading and writing files using Fortran90. The scope includes technical explanations and problem-solving related to file input/output operations in Fortran90.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant expresses difficulty in reading a mixed file of numbers and characters, seeking a method to format the output into two columns.
  • Another participant suggests that Fortran is not ideal for this type of problem and proposes using Python instead, questioning the necessity of using Fortran.
  • A participant insists on solving the problem specifically with Fortran90, indicating a constraint on the programming language used.
  • There is a separate issue raised regarding writing arrays to a file, with a participant seeking advice on formatting output as a matrix.
  • A suggestion is made to use specific Fortran syntax to write the entire row of a matrix to a file, with variations depending on the number of columns.
  • Another participant confirms that the suggested syntax works for them, sharing their experience with a specific Fortran compiler.

Areas of Agreement / Disagreement

Participants express differing views on the suitability of Fortran for the tasks at hand, with some advocating for its use while others suggest alternative languages like Python. The discussion on writing arrays also shows varying approaches, but there is some agreement on the syntax for outputting rows.

Contextual Notes

Participants do not reach a consensus on the best approach for reading and writing files in Fortran90, and there are unresolved questions regarding the formatting of output and handling of specific data types.

ne_237
Messages
9
Reaction score
0
Hi All
I have a problem in the work with Fortran90. I have a file that don't have any idea for read it. It consiste of number and character.For example it includes as below
1 15193r 8 9r 4 6 74r,...
I want to write these numbers in 2 columns. For example
1 15193
8 9
4 0
6 74
terms with r show the number of iteratin and number ( that after it doesn't exist term with r) shows that this number has no iteration. Please help me.

Thanks a lot.
 
Technology news on Phys.org
Honestly Fortran is one of the worst languages for that type of problem. It would probably be quicker to do it in Python, even if you had to teach yourself the basics of Python first.

Do you have any other languages available?
 
Thanks Uart.But I had to solve this problem with Fortran90.
 
I have a problem in write arrays also.How I do write rows and columns in file as matrix.
For example I use this program:
do i=1,10
write(12,*)(x(i,j),j=1,20)
end do
but in file only 4columns are showed and 20columns are breaked.Can anyone help me?
Thanks a lot.
 
Last edited:
Hi ne 237

If the matrix only has 20 columns then try using to following

write(12,*) x(i,:)

If it's got more than 20 (but you only want to output the first 20) try

write(12,*) x(i,1:20)
 
Thanks a lot Uart for reply
But I want to the output will be as below:
1 2 2 3 2 3 4 3 5 3 5 3 6 4 5 8 9 45 65 14
...
...
...
that is 20columns (or more in other program)write in different rows.
 
Yeah that's how it works for me (you still need the outer for loop of course).

do i=1,10
write(12,*) x(i,:)
end do

I'm using the freeware gnu fortran compiler "g95" and the above code correctly writes the matrix, whole row per line, to an output text file.
 
Thank you very much.
 

Similar threads

  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 5 ·
Replies
5
Views
9K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 18 ·
Replies
18
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K