File: file_40.f90

package info (click to toggle)
lfortran 0.60.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,416 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 38; javascript: 15
file content (36 lines) | stat: -rw-r--r-- 834 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
program file_40
   implicit none
   integer           :: i
   real              :: r

   open(10, file="data.txt", status="replace", form="formatted")
   write(10,'(A)') "1  2"    ! INTEGER field (I4)
   write(10,'(A)') "3 . 5"   ! REAL field (F5.1)
   close(10)

   open(10, file="data.txt", form="formatted", blank="null")

   read(10,'(I4)') i
   read(10,'(F5.1)') r

   close(10)
   print *, "INTEGER  :", i     ! -> 12
   print *, "REAL     :", r     ! -> 3.5

   if ( i /= 12) error stop
   if ( r /= 3.5) error stop

   open(10, file="data.txt", form="formatted", blank="zero")

   read(10,'(I4)') i
   read(10,'(F5.1)') r

   close(10)

   print *, "INTEGER  :", i     ! -> 1002
   print *, "REAL     :", r     ! -> 3.5   (same result)

   if ( i /= 1002) error stop
   if ( abs(r-30.0499992) > 1e-6 ) error stop

end program