- #1
shyvir3108
- 2
- 0
Homework Statement
I want to read only specific lines from a file using fortran code.
Homework Equations
Fortran code
The Attempt at a Solution
I have a dummy.txt file wrote
7
5
6
4
5
6
9
10
14
19
I want read only values between lines 5 to lines10. But when I use print statement, the value that produce is 0 in all lines. Can you advice what is wrong with my codes?
Below is my codes:
********************************************
Fortran:
subroutine average
implicit none
integer, parameter :: t1 = 5 , t2 = 10
real :: sumEz
real,dimension(2000) :: n1
integer :: i,t
real :: sum
sum = 0.0
sumEz = sum
open(2, file = 'add.txt', form='formatted')
open(unit = 12 , file = 'dummy.txt', status = 'old', action = 'read')
do i = t1,t2
read(12,*) n1(i)
print *, i,'n1(i)=',n1(i)
sumEz = sumEz + n1(i)**2
write (2,*)sumEz
end do
close (2)
close(12)
end subroutines
**********************************************
Result:
5 n1(i)= 0.00000000
6 n1(i)= 0.00000000
7 n1(i)= 0.00000000
8 n1(i)= 0.00000000
9 n1(i)= 0.00000000
10 n1(i)= 0.00000000
Last edited by a moderator: