【发布时间】:2014-04-04 22:26:45
【问题描述】:
所以我已经构建了我的程序,但是我一遍又一遍地说同样的话:
benchmark.f90(17): error #6451: A dummy argument name is required in this context. [N]
INTEGER, intent (in) :: N
------------------------^
benchmark.f90(18): error #6420: This array name is invalid in this context. [A]
REAL, intent (out), DIMENSION (N), allocatable :: a
--------------------------------------------------^
benchmark.f90(18): error #6646: ALLOCATABLE or POINTER attribute dictates a deferred-shape-array [A]
REAL, intent (out), DIMENSION (N), allocatable :: a
--------------------------------------------------^
benchmark.f90(17): error #6219: This variable, used in a specification expression, must be a dummy argument, a COMMON block object, or an object accessible through host or use association [N]
INTEGER, intent (in) :: N
------------------------^
benchmark.f90(26): error #6219: This variable, used in a specification expression, must be a dummy argument, a COMMON block object, or an object accessible through host or use association [N]
REAL, INTENT(in out), DIMENSION(N) :: a
----------------------------------^
benchmark.f90(48): error #6420: This array name is invalid in this context. [A]
real, intent (in out), DIMENSION(N) :: a
--------------------------------------------^
benchmark.f90(48): error #6219: This variable, used in a specification expression, must be a dummy argument, a COMMON block object, or an object accessible through host or use association [N]
real, intent (in out), DIMENSION(N) :: a
所以我的数组和维度显然有问题,但由于我对可分配数组缺乏了解,我很难过。我已经包含了程序和子例程,希望有人可以轻松发现我的问题。
PROGRAM BENCHMARK
implicit none
integer :: N
REAL, Dimension(N), Allocatable :: a
write(6,*)'please enter size of array'
read(5,*) N
call randfunc(N,a)
call bubblesort(a,a)
call binarysearch(a,a)
deallocate (a)
END PROGRAM BENCHMARK
SUBROUTINE randfunc
implicit none
INTEGER, intent (in) :: N
REAL, intent (out), DIMENSION (N), allocatable :: a
Allocate(a(1:N))
CALL random_number(a)
a = a*5.0
write(6,*)'this should be the randomly generated array', a
END SUBROUTINE
SUBROUTINE bubblesort(a)
REAL, INTENT(in out), DIMENSION(N) :: a
REAL :: temp
INTEGER :: i, j
LOGICAL :: swapped = .TRUE.
DO j = SIZE(a)-1, 1, -1
swapped = .FALSE.
DO i = 1, j
IF (a(i) > a(i+1)) THEN
temp = a(i)
a(i) = a(i+1)
a(i+1) = temp
swapped = .TRUE.
END IF
END DO
IF (.NOT. swapped) EXIT
END DO
END SUBROUTINE
SUBROUTINE binarysearch
REAL, intent (in out), DIMENSION(N) :: a
INTEGER :: ran, start, finish, mid
INTEGER :: i, N, val
i = 1
do i = 1, N
READ(*,*) a(i)
end do
write(6,*) 'Enter Value'
read(5,*) val
start = 1
finish = N
ran = finish - start
mid = (start + finish) /2
do while( a(mid) /= val .and. ran > 0)
if (val > a(mid)) then
start = mid + 1
else
finish = mid - 1
end if
ran = finish - start
mid = (start + finish)/2
end do
if( a(mid) /= val) then
write(*,*) val, 'NOT FOUND'
else
write(*,*) 'VALUE AT' , mid
end if
END SUBROUTINE
【问题讨论】:
标签: arrays sorting random binary fortran