PROGRAM square_sum
  IMPLICIT NONE
  REAL :: sq_sum, number
  INTEGER :: st

  OPEN (11, FILE = 'square.dat', STATUS="OLD", IOSTAT=st)
  IF ( st /= 0 ) THEN
     WRITE(0,*) "Error read opening file 'square.dat'"
     STOP "Error end"
  ENDIF
  OPEN (22, FILE = 'square.ris', STATUS="REPLACE", DELIM="quote", IOSTAT=st)
  IF ( st /= 0 ) THEN
     WRITE(0,*) "Error write opening file 'square.ris'"
     STOP "Error end"
  ENDIF
  sq_sum = 0.0
  DO 
!    READ (11, '(F6.2)', IOSTAT=st) number
    READ (11, *, IOSTAT=st) number
    IF ( st /= 0 ) THEN
       WRITE(0,*) "Error reading file 'square.dat'"
       EXIT
    ENDIF
    WRITE (22,*) 'number = ', number
    IF (number == 0.0) EXIT
    IF (number <  0.0) CYCLE
    sq_sum = sq_sum + SQRT(number) 
    WRITE (22,*) 'square_sum =', sq_sum
  END DO
  WRITE (22,*) ''
  WRITE (22,*) 'The solution is:'
  WRITE (22,*) sq_sum
  STOP "Nice end"
END PROGRAM square_sum
