! ------------------------------------------------- ! Broken program 2 ! ! Associates a pointer to a random portion of table. ! The length pf the portion is printed by a subroutine ! in a module. ! ! This program contains mistakes! ! ------------------------------------- module precision integer,parameter:: dp=kind(1.d0) end module precision module printparts use precision contains subroutine printparts(part) real(dp):: pointer:: part ! in case part is not pointing to anything if(.not. associated(part)) return print*,'array section has length ',size(part) write(*,'(f0.5)') part end subroutine printparts end module printparts program vika2 use precision use printpart implicit none integer, parameter:: n=100 integer:: i real(dp):, ponter:: part real(dp),target:: table(n) real(dp):: rand ! ! fill a random table ! call random_number(table) ! ! pick a random portion of the table to point to ! do i = 1, 200 ! start index, random point between [1,n] call random_number(rand) k0 = int(n*rand) ! end index, random point between [1:n] k1 = int(n*rand) if(k1>k0) then ! index pair (k0,k1) can be used to get a portion of table part => table(k0:k1) end if ! print out the part of the table that "part" points to call printpart(part) end do end program vika2