File: file_31.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 (39 lines) | stat: -rw-r--r-- 981 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
program file_31
    use iso_fortran_env, only: int16
    integer(int16), allocatable :: d(:,:)
    integer(int16), allocatable :: a(:)
    integer :: i, ios, s, j

    allocate(d(3,3))
    allocate(a(3))

    ! open a file and read data into the array
    open(unit=s, file='file_31_data.txt', status='old', action='read', iostat=ios)
    if (ios /= 0) then
        print *, "Error opening file"
        stop
    end if
    read(s, *, iostat=ios) a
    if (ios /= 0) then
        print *, "Error reading data"
        stop
    end if
    do i = 1, 3
        do j = 1, 3
            read(s, *, iostat=ios) d(i, j)
            if (ios /= 0) then
                print *, "Error reading data"
                stop
            end if
        end do
    end do
    close(s)
    print *, "Loaded data:"
    do i = 1, 2
        print *, d(i, :)
    end do
    print *, sum(d)
    if ( sum(d) /= 1440 ) error stop
    print *, sum(a)
    if ( sum(a) /= 60 ) error stop
end program file_31