Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: pball
First of all are there any Fortran programmers out there?
If so I'd like some help with reading data from a file and then using it in a program.
I have a txt file with numbers in it, one per line. I would like to be able to read that into an array. I've been teaching myself Fortran and found an example where there is a do loop which will read each line until there are no lines left to read from the file.
I wasn't able to copy that and make it work. So any help would be appreciated.
P.S. I'm only learning Fortran since my engineering company has some stuff in it and me being the co-op, I have to add stuff and make it work.

"I wasn't able to copy that and make it work."
Maybe not a great example.
=====================================
If at first you don't succeed, you're about average.M2

I guess your right but I'm thinking it's more the read statement that was used.
I think I might have found somthing to help out. Tomorrow at work I'm gonna have to try and format the the list to be inputed and then use format for the reading part too.
best guess i have

Yay I got it on my own. I just had to format the file i was inputting and the read statement that was reading the file.
My input file is made using this format
write (7,fmt='(1x, I12)') p
which places the 1's digit in the 12th column.This read statement will read the first 100 lines and store them in an array called ar
do 110 i= 1, 100
read(unit=1,fmt='(1x, I12)', end=150) ar(i)
110 continue
150 continueIf only I could figure out batch scripting this easy.
Now I just have to make the rest of the program work.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |