我使用的是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