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을 배열로 선언하지 않았다고 추측한다. (이 프로그램에서와 같은 변수가 아닐 것이다 - 이것이 완전한 프로그램이라면 (끝은 없다)) 링커가 함수라고 생각한다. . – francescalus
매우 유감스럽게 생각합니다.이 게시물의 코드를 편집 할 때 서브 루틴의 표준 편차를 추가했습니다. 다시 한번 보실래요? –
* 내가 뭘 잘못하고 있니? * 21 세기에 Fortran 코드를'implicit none '없이 쓰고있다. 내가 여기에 반복적으로 글을 쓰고있는 것을 보았을 때,'암묵적인 사람 없음 '이없는 포트란에서 프로그래밍하는 모든 사람들은 고통을받을 자격이 있습니다. –