Hi
I'd like to use module to pass data between procedures.
In the following, subroutine FCN is an argument of subroutine CDGRD
which calculates gradient (IMSL). I have comment those statements
related to IMSL.
module shared_data
implicit none
save
real,dimension(2) :: y
end module shared_data
module A
contains
!C
SUBROUTINE FCN (N, X, F)
use shared_data
INTEGER N
REAL X(N), F
!C
F = y(1)*X(1) +y(2)*x(1)- 3.*X(2)
!C
RETURN
END SUBROUTINE FCN
end module A
!module B
!contains
!subroutine mm(XC,XSCALE,GC,N)
!use A
!INTEGER I, N, NOUT
!real :: EPSFCN
!REAL,dimension(N) :: GC, XC, XSCALE
!!C Set function noise.
!EPSFCN = 0.
!CALL CDGRD (FCN, N, XC, XSCALE, EPSFCN, GC)
!CALL UMACH (2, NOUT)
!WRITE (NOUT,99999) (GC(I),I=1,N)
!99999 FORMAT (' The gradient is', 2F8.2, /)
!END subroutine mm
!end module B
program main
!use B
use shared_data
!integer,parameter :: N=2
!C Initialization.
!REAL,dimension(N) :: XC=(/1.,2./), XSCALE=(/1.,1./);
!The gradient
!REAL,dimension(N) :: GC
real,dimension(2) :: y
y=(/-2.,-1./);
!do i=1,2
! xc(1)=(i-1)*0.5;
!do j=1,2
! xc(2)=(j-1)*1.;
!call mm(XC,XSCALE,GC,N)
!enddo;enddo
end
after compiled by CVF6.6c:
Error: The attributes of this name conflict with those made accessible
by a USE statement. [Y]
y=(/-2.,-1./);
^
Error: The shapes of the array expressions do not conform. [Y]
I know I have declared twice: one in main program and the other in
module (module shared_data).
How to pass y array to FCN? please note that FCN can have only three
arguments.
thank you in advance.
Mike


|