Fortran: reading the data from file

  • #1
4
0
Hello, I have data in file and I want to read the data into variable in fortran to save memory caculation. I want to know: When I open file inputdata, whether fortran have any notices about the way it read data into variables? (like mathematica: each open file, we just read in the order anyway)
 

Answers and Replies

  • #2
13,044
6,928
You can find examples via google.

Here's a tutorial on it:

http://www.math.hawaii.edu/~hile/fortran/fort7.htm

It also depends on the type of input file like if its a text file or a binary file file access would be somewhat different
or if it was a netcdf file where you'd need to use netcdf apis to read/write to it.
 
  • #3
4
0
Thanks. In case, I have the data file like:
1 2 3 4 5
6 7 8 9 10
4 5 1 5 8
9 6 3 2 1
7 4 2 1 13
and I want to create the coeff A of equations system
A= 1 2 3 5
4 5 1 8
9 6 3 1
Whether or not I can take these data from the file by statement?
 
  • #4
35,236
7,056
Thanks. In case, I have the data file like:
1 2 3 4 5
6 7 8 9 10
4 5 1 5 8
9 6 3 2 1
7 4 2 1 13
and I want to create the coeff A of equations system
A= 1 2 3 5
4 5 1 8
9 6 3 1
Whether or not I can take these data from the file by statement?
Yes, this is pretty straightforward to do. What have you tried so far? You shouldn't expect us to write the code for you, though.
 
Last edited:
  • #5
4
0
Yes, this is pretty straightforward to do. What have you tried so far? You shouldn't expect us to write the code for you, though.
No. I mean I am a new one in programing. So many concept in fortran I dont Know.
I just want to know whether it can do that or not and How to do that. In my code, [A]= [1]+[2]+[3]+[4] so many matrices so that I try to find more about reading array data from file on webs.
 
Last edited by a moderator:
  • #6
35,236
7,056
Thanks. In case, I have the data file like:
1 2 3 4 5
6 7 8 9 10
4 5 1 5 8
9 6 3 2 1
7 4 2 1 13
and I want to create the coeff A of equations system
A= 1 2 3 5
4 5 1 8
9 6 3 1
Whether or not I can take these data from the file by statement?
It's not clear to me what you're trying to do. From what you show above, the pattern appears to be
1. Read in the contents of a row, and store the 1st, 2nd, 3rd, and 5th item in the array, skipping the 4th item.
2. Skip the next row.
3. Repeat steps 1 and 2.

However, the numbers you show in your array A don't follow this pattern when you get to the 4th row. Is that a mistake?
 
  • #7
4
0
I want to solve the equation system by fortran and Laplack subroutine. And the first thing to do is create the matrix coeff A. I think
It's not clear to me what you're trying to do. From what you show above, the pattern appears to be
1. Read in the contents of a row, and store the 1st, 2nd, 3rd, and 5th item in the array, skipping the 4th item.
2. Skip the next row.
3. Repeat steps 1 and 2.

However, the numbers you show in your array A don't follow this pattern when you get to the 4th row. Is that a mistake?
Thank. To be clear, my problem is solve equations system
https://drive.google.com/file/d/0BwK2cNv1sXawbWx6N21LQXMtME0/view?usp=sharing [Broken]
By the way, Can you give me a example about statement: skip the row while reading data from file and read the any rows from input file?
Thanks a lot.
 

Attachments

  • 1.jpg
    1.jpg
    51.6 KB · Views: 424
Last edited by a moderator:
  • #8
jtbell
Mentor
15,809
4,063
Can you give me a example about statement: skip the row while reading data from file

A read() statement normally reads one line from the file. To skip a line, simply use a read() statement that does not list any input variables:

Fortran:
      read (ifile, *)
 

Related Threads on Fortran: reading the data from file

Replies
1
Views
7K
Replies
2
Views
29K
Replies
5
Views
18K
Replies
5
Views
4K
Replies
2
Views
787
  • Last Post
Replies
5
Views
3K
  • Last Post
Replies
4
Views
2K
Replies
1
Views
5K
Replies
6
Views
9K
Top