主题:求救
为什么一个function连续调用两次,在参数一样的情况下而结果不一样啊
module typedef
implicit none
type sor
real:: T
real:: SS
end type
end module
!module fun
! implicit none
!contains
function SSS(A,N)
implicit none
real::SSS
integer,intent(in)::N
integer::m
real,intent(in)::A(N)
real::temp
SSS=0.0
do m=1,N
temp=temp+A(m)
end do
temp=temp/N
!SSS=A+N
do m=1,N
SSS=SSS+(A(m)-temp)*(A(m)-temp)
end do
return
end function
!end module
program datapro
use typedef
implicit none
!use fun
!real,external::SSS
interface
function SSS(A,N)
implicit none
integer::N
real::A(N)
real::SSS
end function
end interface
character(len=15):: inputfilename="1.txt"
integer,parameter:: inputfileid=50
logical :: alive
integer,parameter::max=100
integer::error
type(sor)::ww(max)
!real,allocatable::SI(:),SI_order(:)
integer::i=1,j,N
real::temp,temp2
!,S,A(8)
inquire(file=inputfilename,exist=alive) !
if(.not. alive) then
write(*,*)trim(inputfilename)," doesn't exist"
stop
end if
open(unit=inputfileid,file=inputfilename,position='rewind')
do while(.true.)
read(inputfileid,"(F6.3,5xF7.4)",iostat=error)ww(i) !
if (error/=0) exit
i=i+1
end do
close(inputfileid)
write(*,*)ww(1:i-1)%SS,i-1
temp=SSS(ww%SS,i-1)
write(*,*)ww(1:i-1)%T,i-1
temp2=SSS(ww%SS,i-1)
!N=i-1
!A=ww(1:8)%SS
! do i=1,N
! temp=temp+A(i)
! end do
! temp=temp/N
! do i=1,N
! S=S+(A(i)-temp)*(A(i)-temp)
! end do
write(*,*)'无变点',temp,i,temp,temp2,temp2,SSS(ww%SS,i-1)
stop
end
module typedef
implicit none
type sor
real:: T
real:: SS
end type
end module
!module fun
! implicit none
!contains
function SSS(A,N)
implicit none
real::SSS
integer,intent(in)::N
integer::m
real,intent(in)::A(N)
real::temp
SSS=0.0
do m=1,N
temp=temp+A(m)
end do
temp=temp/N
!SSS=A+N
do m=1,N
SSS=SSS+(A(m)-temp)*(A(m)-temp)
end do
return
end function
!end module
program datapro
use typedef
implicit none
!use fun
!real,external::SSS
interface
function SSS(A,N)
implicit none
integer::N
real::A(N)
real::SSS
end function
end interface
character(len=15):: inputfilename="1.txt"
integer,parameter:: inputfileid=50
logical :: alive
integer,parameter::max=100
integer::error
type(sor)::ww(max)
!real,allocatable::SI(:),SI_order(:)
integer::i=1,j,N
real::temp,temp2
!,S,A(8)
inquire(file=inputfilename,exist=alive) !
if(.not. alive) then
write(*,*)trim(inputfilename)," doesn't exist"
stop
end if
open(unit=inputfileid,file=inputfilename,position='rewind')
do while(.true.)
read(inputfileid,"(F6.3,5xF7.4)",iostat=error)ww(i) !
if (error/=0) exit
i=i+1
end do
close(inputfileid)
write(*,*)ww(1:i-1)%SS,i-1
temp=SSS(ww%SS,i-1)
write(*,*)ww(1:i-1)%T,i-1
temp2=SSS(ww%SS,i-1)
!N=i-1
!A=ww(1:8)%SS
! do i=1,N
! temp=temp+A(i)
! end do
! temp=temp/N
! do i=1,N
! S=S+(A(i)-temp)*(A(i)-temp)
! end do
write(*,*)'无变点',temp,i,temp,temp2,temp2,SSS(ww%SS,i-1)
stop
end