!     Last change:  X     2 Dec 2004    1:56 pm
PROGRAM how_to_read
!Demonstrates basic format for reading data in from a file

   IMPLICIT NONE
   INTEGER :: i=1, n
   REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: seq_in, seq_out

   OPEN(3,FILE='trial_in.dat',STATUS='UNKNOWN')
   READ(3,*) n
   WRITE(*,*) 'n=', n
   ALLOCATE (seq_in(n), seq_out(n))

   DO
      READ (3,*) seq_in(i)
      WRITE(*,*) i, seq_in(i)
      IF (i==n) EXIT
      i=i+1
    END DO

   CLOSE (3)

   seq_out=2.0*seq_in

   OPEN (2,FILE='trial_out.dat',STATUS='REPLACE')
   WRITE (2,*) n
   DO i = 1,n
      WRITE (2,*) seq_in(i), seq_out(i)
   END DO
   CLOSE (2)

   DEALLOCATE (seq_in, seq_out)

   STOP
END PROGRAM how_to_read

