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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with indexing in FORTRAN77

Status
Not open for further replies.

dazedandconfusedinnc

Technical User
Jun 10, 2009
3
US
I am fairly new to FORTRAN and am self taught. I just got a new compiler and am having an indexing (I think) issue with 77. Here is the piece of code:

DO n=1,12
READ(10,2007) md(n)
2007 FORMAT(F3.0)

WRITE(11,2008) md(1)
2008 FORMAT(F4.0)

END DO

I am trying to get the 1st value in the array to output, but instead I get the 1st value printed 11 times. If I put it after the 'END DO' then I it prints 0. If anyone could help it would be greatly appreciated.
 
Hi

Put the write statement outside the do loop. Increase the length in the format statement from F3.0 to F12.0. That may help. Are you sure that the value of md(1) is not 0? I also guess that you are reading from some file and writing into another file:

program test
real*4 md(12)
open(10,file='in.txt',status='old')
open(11,file='out.txt,status='unknown')
do n=1,12
read(10,2007,end=99) md(n)
2007 format(f12.0)
enddo
99 continue
write(11,2008) md(1)
2008 format(f12.3)
end
 
That worked...thanks! I think part of my problem is less than complete understanding of how the 'continue' function works.
 
continue is just a dummy statement. Very useful for labels. Note that it is completely different from continue in languages like C/C++/Java/php/C#.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top