File: read_01.f90

package info (click to toggle)
lfortran 0.60.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,412 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 37; javascript: 15
file content (70 lines) | stat: -rw-r--r-- 1,414 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
program read_01
    character(len=2), target :: str = "42"
 
    character(len=2) :: c
    integer :: i32
    integer(8) :: i64
    real :: f32
    real(8) :: f64
    integer, save, dimension(3) :: i32_arr_size3 = [-1,-1,-1]
    character(20) :: key
 
    character(5) :: val
    character(len=:), allocatable :: al_val

    character(len=:), allocatable :: al_str
    character(len=:), pointer :: str_ptr

    read(str, *) c
    print *, c
    if (c /= "42") error stop
 
    read(str, *) i32
    print *, i32
    if (i32 /= 42) error stop

    read(str, *) i64
    print *, i64
    if (i64 /= 42) error stop
 
    read(str, *) f32
    print *, f32
    if (f32 /= 42.0) error stop

    read(str, *) f64
    print *, f64
    if (f64 /= 42.0) error stop

    allocate(character(len=2) :: al_str)

    val = "ab"

    read(val, *) al_str
    print *, al_str
    if (al_str /= "ab") error stop

    allocate(character(len=2) :: al_val)

    str = "cd"

    read(str, *) al_val
    print *, al_val
    if (al_val /= "cd") error stop

    print *, str
    str = "72"
    key = "int_read"
    select case(key)
        case ("int_read")
            read(str, *) i32
        case ("int_arr_size3_read")
            read(str, *) i32_arr_size3
    end select
    print *, i32
    if (i32 /= 72) error stop
    str = "20"
    str_ptr => str
    read(str_ptr, *) i32
    print *, i32
    if (i32 /= 20) error stop
end program