3 Replies - 2755 Views - Last Post: 16 November 2009 - 04:06 PM Rate Topic: -----

#1 henryl   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 12-May 06

Problem with READ Sentence in FORTRAN

Posted 07 October 2009 - 11:11 AM

OPEN(21,FILE='bank150_m2.bcs.s2c')
READ(21,'(A)')header
READ(21,'(A)')header
READ(21,'(A)')header
DO i=1,nbedim+1
  READ(21,*,END=11)node(i),amp(i),phase(i)
  nnodes=i
END DO
WRITE(*,*)'Error in reading input boundary condition file ... ',  &
	'The number of entries exceeds NBEDIM'
STOP
11   CLOSE(21)
 


This a file I have to read in Fortran 90. The open part is pretty clear, but I have problems understanding the READ sentence. Specifically what this sentence does, with a third parameter included (END=11). Can someone please, explain to me how this piece of code works?

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with READ Sentence in FORTRAN

#2 crazy_prog   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-November 09

Re: Problem with READ Sentence in FORTRAN

Posted 05 November 2009 - 12:48 PM

END = s -> end-of-file specifier

where s is the statement label of an executable statement that appears in the same program unit as the end-of-file specifier.

If a READ statement contains an end-of-file specifier and the processor encounters an end-of-file condition and no error condition during execution of the statement:

1) execution of the READ statement terminates,
2) if the READ statement contains an input/output status specifier ( 12.7), the variable or array element ios becomes defined with a processor-dependent negative integer value, and execution continues with the statement labeled s .
Was This Post Helpful? 0
  • +
  • -

#3 kcc9999   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-November 09

Re: Problem with READ Sentence in FORTRAN

Posted 16 November 2009 - 03:58 PM

View Posthenryl, on 7 Oct, 2009 - 10:11 AM, said:

OPEN(21,FILE='bank150_m2.bcs.s2c')
READ(21,'(A)')header
READ(21,'(A)')header
READ(21,'(A)')header
DO i=1,nbedim+1
  READ(21,*,END=11)node(i),amp(i),phase(i)
  nnodes=i
END DO
WRITE(*,*)'Error in reading input boundary condition file ... ',  &
	'The number of entries exceeds NBEDIM'
STOP
11   CLOSE(21)
 


This a file I have to read in Fortran 90. The open part is pretty clear, but I have problems understanding the READ sentence. Specifically what this sentence does, with a third parameter included (END=11). Can someone please, explain to me how this piece of code works?

Was This Post Helpful? 0
  • +
  • -

#4 kcc9999   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-November 09

Re: Problem with READ Sentence in FORTRAN

Posted 16 November 2009 - 04:06 PM

View Posthenryl, on 7 Oct, 2009 - 10:11 AM, said:

OPEN(21,FILE='bank150_m2.bcs.s2c')
READ(21,'(A)')header
READ(21,'(A)')header
READ(21,'(A)')header
DO i=1,nbedim+1
  READ(21,*,END=11)node(i),amp(i),phase(i)
  nnodes=i
END DO
WRITE(*,*)'Error in reading input boundary condition file ... ',  &
	'The number of entries exceeds NBEDIM'
STOP
11   CLOSE(21)
 


This a file I have to read in Fortran 90. The open part is pretty clear, but I have problems understanding the READ sentence. Specifically what this sentence does, with a third parameter included (END=11). Can someone please, explain to me how this piece of code works?



Sorry - I screwed that last post up.
Crazy_Prog is correct but specifically to this code - when the read statement reaches the end of the file denoted by unit 21, the program will jump to the statement that says "11 CLOSE(21)" . Sorry for the last post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1