Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

It worked but not completely

Status
Not open for further replies.

vibhava

Programmer
Apr 20, 2008
19
US
hi,
yesterday i got a suggestion about writing column data (post named" help in reading and writing column data" Following the tip i got i looked for the previous article and i thin ki found one which was good for me. but i am still having small problem:
the code i used is exactly the same as shown in the thread:
program main
! MAXCOL is 1 more than the max expected
parameter (MAXCOL = 10, INFILE = 5)
integer info(MAXCOL)
character*80 line
integer row, col
open (INFILE, file='C:\WAMView\bnz\GlobalInputs\samsur2.txt')
row = 0
10 continue
row = row + 1
!
! Read the line containing the data
read (INFILE, '(A)', end=30) line
!
! Read the data from the line
read (line, *, err=20, end=20) (info(col), col = 1, MAXCOL, 1)
20 continue
!
! we stop at one more that what was there so subtract 1
col = col - 1
!
! print what we got
write (*, *) (info(i), i = 1, col, 1)
goto 10
30 continue
close (INFILE)
stop
end

THE INPUT FILE LOOKS LIKE

10 10 10 10 10 10 10 10 10 10
20 20 20 20 20
25 25 25 25 25 25 25
30 30 40


The output file looks like this

10 10 10 10 10 10
10 10 10 10
20 20 20 20 20 10
10 10 10 10
25 25 25 25 25 25
25 10 10 10
30 30 40 25 25 25
25 10 10 10

The problem is that after line 1 in input file (which was the longest line) for rest of the line empty spaces were filled by 10
I am wondering what to do. I tried almost whole day (i know its easy and should not take this long but i have just started writing codes in FORTRAN) but couldn't find the problem.
Please help me

Vibhava
 
The input file should be in this format. The program you've listed will take data in this format.

10 20 30 40
10 20 30 40
10 20 30 10
10 20 10 05
10 20 05
10
10
10
10
10
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top