我使用的是Mac,並試圖編譯使用gfortran編譯器計算給定樣本的平均值和標準偏差一個非常簡單的Fortran代碼。代碼如下:Fortran數組名不接受架構X86_64
C This is a fortran program for calculation the average, standard deviation
C and standard error of a given set of data.
C Created by Ömer Faruk BODUR - 12 October 2014
PROGRAM AvDevErr
character(len=1) choise
character(len=50) path
real ave,x,std
real, DIMENSION(30) :: array1
integer h
write(*,*)'Do you want to enter your data manually ?
&Press "y" for yes or "n" for No then submit your choise by
&pressing Enter:'
read(*,*)choise
if(choise.eq.'y') then
sum1=0.0
icount=0
sum2=0.0
write(*,*)'Please enter the values to be used when calculating
&the average, standard deviation and standard error. When finished,
&enter 0 then press Enter:'
read(*,*)x
1 if(x.ne.0) then
sum=sum+x
icount=icount+1
read(*,*)x
go to 1
endif
endif
ave=sum/real(icount)
if(choise.eq.'n') then
sum=0.0
icount=0
j=1
write(*,*)'Enter the name of your data file'
read(*,5)path
5 format(a10)
write(*,*)'Enter the number of data to be used in your file: '
read(*,*)ndata
open(10,FILE=path,status='old')
write(*,*)'The data in your file to be used is below: '
do 14 i=1,ndata
read(10,7,END=99)array1(i)
write(*,*)array1(i)
7 format(f4.2)
sum=sum+array1(i)
icount=icount+1
14 enddo
ave=sum/real(ndata)
99 endif
write(*,*)'The sum of the data is: ',sum
write(*,*)'The number of data used is: ',ndata
write(*,*)'the average of the data set is= ',ave
call stdeviation(ndata,ave)
write(*,*)'The standard deviation is: ',std
stop
end program AvDevErr
subroutine stdeviation(ndata,ave)
do 19 i=1,ndata
sum2=sum2 + (array1(i)-ave)**2
19 enddo
std=sqrt(sum2/real(ndata-1))
return
end
但是,我得到低於引用我的數組名如下錯誤:
Undefined symbols for architecture x86_64:
"_array1_", referenced from:
_stdeviation_ in ccHYprZn.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
我在做什麼錯?
有一件事沒有顯示我們'stdeviation'代碼負責的錯誤。我想你還沒有宣佈'array1'作爲數組在那裏(不,這將是相同的變量在這個程序 - 如果這是完整的程序[有沒有'end']),因此鏈接認爲它是一個功能。 – francescalus 2014-10-12 11:37:41
非常抱歉。我通過添加子程序stdeviation編輯了這篇文章中的代碼。你能再看看嗎? – 2014-10-12 11:41:22
*我做錯了什麼?*您正在編寫21世紀的Fortran代碼而沒有「隱含的無」。當我發現自己在這裏重複編寫SO時,任何在Fortran中編程而沒有「隱含」的編程人員都不應該承受所有的痛苦。 – 2014-10-12 11:42:59