Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Name conflict in Module

anishtain4
Beginner
1,598 Views
I have two subroutine in a module that both have one varibale, i. in one of them I want this be a integer and in another one this should be unite imaginary, but when I define it different types it says that this name has been defined in this file with another data type! I used another names to proceed my work but I would like to know how should I compensate with this?

another problem I have is that when I define functions after "end module" and want to call them into other functions or subroutines, visual studio recognize them as array and says they have not been defined! what should I do about this?
0 Kudos
7 Replies
jimdempseyatthecove
Honored Contributor III
1,598 Views
Can you reduce the module and subroutines to a simple case that exhibits the symptions. Then post the code?
With this code at hand, we can then either see the problem or compile and experience the problem.

Jim
0 Kudos
anishtain4
Beginner
1,598 Views
[bash]REAL(8) FUNCTION NDD_F(XI,F,X,n) !NEWTON DIVIDED DIFFERENCE_FORWARD
  IMPLICIT NONE
  REAL,INTENT(IN)	::XI(:),F(:),X
  INTEGER		::N
END FUNCTION

FUNCTION CONV(F,G,N)    !CONVOLUTION
  IMPLICIT NONE
  REAL,INTENT(IN)   ::F(N),G(N),N
END FUNCTION

SUBROUTINE FFT2(F,N)  !FFT FOR A POWER OF TWO
  F(I,:)= FS(B2D(RD2B(I,DECIMINATION)),:)
END SUBROUTINE

INTEGER FUNCTION RD2B(DEC,N)  !DECIMAL TO REVERSE BINARY
  IMPLICIT NONE
	INTEGER,INTENT(IN)	::DEC,N
	INTEGER							::I,DEC_D
	REAL								::EP
	RD2B		= 0
	DEC_D		= DEC
	EP			= 1E-5
	DO I=N,1,-1
		RD2B	= RD2B+MOD(DEC_D,2)*10**(I-1)
		DEC_D	= INT(DEC_D/2)
	END DO
END FUNCTION

INTEGER FUNCTION B2D(BIN) !BINARY TO DECIMAL
  IMPLICIT NONE
	INTEGER,INTENT(IN)	::BIN
	INTEGER							::I,N,BIN_D
	REAL								::EP
	B2D		= 0
	EP		= 1E-5
	BIN_D	= BIN
	N=INT(LOG10(EP+REAL(BIN_D)))+1
	DO I=1,N
		B2D = B2D+2**(I-1)*MOD(BIN_D,10**I)/10**(I-1)
	END DO
END FUNCTION[/bash]
In ndd_f I have defined N as an integer, but in conv I want to define N as a real (I know in this case that can be integer I may want to use this as wave number which is not always integer) and it says names conflict. These are all after "contains" in a module.

other problem is with the FFT2 and B2D and RD2B, when I put the later two functions after end module a syntax error appears in FFT which says they are not defined variables! I'm not sure if the pasted code helps you, but all of the code is a little bit long for here.
0 Kudos
DavidWhite
Valued Contributor II
1,598 Views


FUNCTION CONV(F,G,N) !CONVOLUTION

IMPLICIT NONE

REAL,INTENT(IN) ::F(N),G(N),N

END FUNCTION

The issue is not that you have the same name, but that you are trying to declare two arrays F and G with a real argument for the size. In the declarations for F(N) and G(N), the size of the arrays, "N" must be integer.

David

0 Kudos
mecej4
Honored Contributor III
1,598 Views
You have to use integers for array dimensions, but you can do the following:
[fortran]REAL,INTENT(IN)   :: N, F(FLOOR(N)),G(FLOOR(N)) 
[/fortran]
0 Kudos
anishtain4
Beginner
1,598 Views
Thanks david and mecej.
But one other question remained unanswered yet. if I wan to define a function after end module of a module file how should make fortran understand that it is a function not a variable?

Another question raised, is there anyway other than sending in N or using UBOUND() frequently to determine dimension of helping arrays in subroutine or functions?

To define a function we can write:
integer function test()
end function
or we can write:
function test()
integer::test(4)
end function
Is there any possibility that we use first form and define a function whos output is an array?
0 Kudos
DavidWhite
Valued Contributor II
1,598 Views
You can define arrays which are passed as arguments as, e.g.

REAL,DIMENSION(*) :: X

X will take whatever size it is in the calling program.

My uderstanding on function returns is that you can only return a scalar (at least it was when I learned Fortran 30 years ago).

I would normally pass back arrays as arguments, and normally use subroutine calls:

Subroutine Test (XIN, XOUT)
REAL, DIMENSION(*), INTENT(IN) :: XIN
REAL, DIMENSION(*), INTENT(OUT) :: XOUT

This also avoids the need todefine fucntion type, as in your example.

Regards,


David



0 Kudos
Steven_L_Intel1
Employee
1,598 Views
You can now return arrays, but an explicit interface to the function must be visible to the caller.
0 Kudos
Reply