Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This is easily the most helpful website I've ever used, and this is the best forum with the quickest response time bar none...."

Geography

Where in the world do Tek-Tips members come from?

Reading table input from a .txt fileHelpful Member! 

bobbydrake (TechnicalUser)
12 Jun 12 4:34
dear all,
i have this problem inputing data. i have this following data:
index i j value
1 1 2 2
2 1 3 10
3 2 3 10
4 2 4 5
5 3 4 6
i need this data to read it in fortran and make it as a matrix a(i,j).
'i' mean the row of a matrix a, and 'j' column of matrix a.
example, from index 1, it has to be a(1,2)=2
from the given data it will produces matrix:
a=
0 2 10 0
0 0 10 5
0 0 0 6
0 0 0 0

would you help me through this? :) many thanks before.
FJacq (Programmer)
12 Jun 12 5:33
Please, show us your program, especially how you read your array and how you print it.

François Jacq

Helpful Member!  melmacianalf (TechnicalUser)
12 Jun 12 5:39
Try something like this

CODE --> Fortran

program read_table
implicit none
integer, parameter :: size_matrix = 4
integer :: stat
integer :: i, j, ind, val
integer :: matrix(size_matrix, size_matrix)

open(unit=100, file='input.dat')

matrix = 0
do
read(100,*,iostat=stat) ind, i, j, val
if (stat .ne. 0) exit
matrix(i,j) = val
enddo

do i = 1, size_matrix
print *, matrix(i,:)
enddo

close(100)

end program read_table
bobbydrake (TechnicalUser)
12 Jun 12 6:03
thx a million mel!
it works for me, :)

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close