這可能非常簡單,但編譯我的小Fortran程序時出現錯誤。 (文件是.f90)這是固定還是自由行長度的問題?這似乎是我可以從Google搜索中收集到的所有信息。名稱中無效的Fortran 90
這裏的程序:
program array
integer :: k, n, i, j, h, f, AllocateStatus
real*8, dimension(:, :, :), allocatable :: a
character, parameter :: "fname"
k = 5
n = 5
h = 1
allocate(a(n,k,h), stat = AllocateStatus)
if (AllocateStatus /= 0) stop "*** Not enough memory ***"
a(1,:,:) = 5
a(2,:,:) = 6
call writeArray(7,a,"testOutput")
deallocate(a)
end program array
subroutine writeArray(f,array,fname)
implicit none
integer :: f, i, j, k, n
character, parameter :: "fname"
real*8, dimension(:, :, :), allocatable :: array
open(unit = f, file="fname")
do, i=1,n
do, j=1,k
write(7,"(F5.2)") array(i,j,:)
if (j==k) write(7,"(A1)") "X"
enddo
enddo
!write(7,"(I5)") size(a)
close(f)
end subroutine writeArray
而且錯誤:
test.f90:4.29:
character, parameter :: "fname"
1
Error: Invalid character in name at (1)
test.f90:24.26:
character, parameter :: "fname"
1
Error: Invalid character in name at (1)
test.f90:21.35:
subroutine writeArray(f,array,fname)
1
Error: Symbol 'fname' at (1) has no IMPLICIT type
謝謝,我已經明白了!你一直很有幫助! – whatsherface
並感謝您爲陣列添加「大小」功能。我當然希望使它更通用,並試圖找到它的語法。 :) – whatsherface