program aug12 implicit none interface subroutine display(n,f) integer,dimension(:)::n character(*)::f end subroutine logical function ok(n) integer,dimension(:)::n end function subroutine reverse(x,y) integer,dimension(:),intent(in)::x integer,dimension(:),intent(out)::y end subroutine end interface integer,dimension(4)::x,xr integer,dimension(6:8)::y,yr integer,dimension(2,3)::z integer::i,j character(23)::form = '(x,a2,"(",i2,") = ",i2)' print*,"Initialize x" do j = 1,4 x(j) = j end do print* do j = 1,4 print form,"x",j,x(j) end do print* print*,"Display x" print* call display(x,form) print* if (ok(x)) then print*,"x is ok" else print*,"x is not ok" end if print* print*,"xr = Reverse x" print* call reverse(x,xr); do j = 1,4 print form,"xr",j,xr(j) end do print* print*,"Display xr" print* call display(xr,form) print* print*,"Initialize y" do j = 6,8 y(j) = j+10 end do y(7) = -1 print* do j = 6,8 print form,"y",j,y(j) end do print* print*,"Display y" print* call display(y,form) print* if (ok(y)) then print*,"y is ok" else print*,"y is not ok" end if print* print*,"yr = Reverse y" call reverse(y,yr); print* do j = 6,8 print form,"yr",j,yr(j) end do print* print*,"Display yr" print* call display(yr,form) read*,((z(i,j),j = 1,3), i = 1,2) print* print*,"Read z and write z" print'(6i3)',((z(i,j),i = 1,2), j = 1,3) end program subroutine display(a,form) implicit none integer,dimension(:)::a character(*)::form integer::i do i = 1,size(a) print form,"a",i,a(i) ! print*,"a(",i,") =",a(i) end do end subroutine logical function ok(a) ! output condition: ok = all entries of a are non-negative implicit none integer,dimension(:)::a logical::ok_so_far integer::i ok_so_far = .true. do i = 1,size(a) if (a(i) < 0) ok_so_far = .false. end do ok = ok_so_far end function subroutine reverse(x,y) ! input condition: size(x) = size(y) integer,dimension(:),intent(in)::x integer,dimension(:),intent(out)::y integer::i do i = 1,size(x) y(i) = x(size(x)+1-i) end do end subroutine