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

A Query on MODULES

smanoj
Beginner
489 Views
Hi,

I have a query reqarding the MODULES in Intel Fortran 9.1. I have a set of C functions, which need to be called from Fortran so I provided the wrappers andthese behaves well. Now I am adding the MODULE INTERFACES for these wrappers.

For a specific functionI have a difficutly in defining the INTERFACE in the MODULE. One of the arguments of the functions can be scalar or can be a array. As by default Fortran takes the pointer it doesnt matter whether I send a address of a scalar or a address of an array. How can I resolve this in MODULE.

Example code:
MODULE TEST

INTERFACE

INTEGER (KIND=4) FUNCTION IDS_GETREAL (iSpot1,gdsName,nbr,rVar,maxNbr)

INTEGER (KIND=4) iSpot1
CHARACTER(LEN=*) gdsName
INTEGER (KIND=4) NBR
REAL (KIND=4) rVar---------------------- or REAL (KIND=4) rVar(*)
INTEGER (KIND=4) maxNbr
END FUNCTION IDS_GETREAL
END INTERFACE

END MODULETEST

In this function, the variable rVar can be a scalar or an array. If Idefine it as REAL (KIND=4)rVar, itgives the type mismatch errorIf I send anarray.

Is there is anywaythat I can overload the declartionin the Module.

Regards,
Manoj

0 Kudos
4 Replies
eos_pengwern
Beginner
489 Views
Quoting - smanoj
Hi,

I have a query reqarding the MODULES in Intel Fortran 9.1. I have a set of C functions, which need to be called from Fortran so I provided the wrappers andthese behaves well. Now I am adding the MODULE INTERFACES for these wrappers.

For a specific functionI have a difficutly in defining the INTERFACE in the MODULE. One of the arguments of the functions can be scalar or can be a array. As by default Fortran takes the pointer it doesnt matter whether I send a address of a scalar or a address of an array. How can I resolve this in MODULE.

Example code:
MODULE TEST

INTERFACE

INTEGER (KIND=4) FUNCTION IDS_GETREAL (iSpot1,gdsName,nbr,rVar,maxNbr)

INTEGER (KIND=4) iSpot1
CHARACTER(LEN=*) gdsName
INTEGER (KIND=4) NBR
REAL (KIND=4) rVar---------------------- or REAL (KIND=4) rVar(*)
INTEGER (KIND=4) maxNbr
END FUNCTION IDS_GETREAL
END INTERFACE

END MODULETEST

In this function, the variable rVar can be a scalar or an array. If Idefine it as REAL (KIND=4)rVar, itgives the type mismatch errorIf I send anarray.

Is there is anywaythat I can overload the declartionin the Module.

Regards,
Manoj


Is IDS_GETREAL an 'elemental' function? Usually, this is the only type of Fortran function that can take a scalar or an array equally happily (or else, how does the function find out what it has been sent?).

If it is an elemental function, then obviously the interface definition should say so.

Stephen.
0 Kudos
Steven_L_Intel1
Employee
489 Views
Elemental would require that all the arguments be either scalars or arrays. What you want instead is a generic interface with some fancy aliasing so that they go to the same routine. I suggest this:

[plain]INTERFACE IDS_GETREAL

       INTEGER (KIND=4) FUNCTION IDS_GETREAL_S (iSpot1,gdsName,nbr,rVar,maxNbr)
!DEC$ ATTRIBUTES DECORATE,ALIAS:"IDS_GETREAL" :: IDS_GETREAL_S

            INTEGER  (KIND=4) iSpot1
            CHARACTER(LEN=*) gdsName
            INTEGER  (KIND=4) NBR
            REAL     (KIND=4) rVar 
            INTEGER  (KIND=4) maxNbr
       END FUNCTION IDS_GETREAL_S

       INTEGER (KIND=4) FUNCTION IDS_GETREAL_A (iSpot1,gdsName,nbr,rVar,maxNbr)
!DEC$ ATTRIBUTES DECORATE,ALIAS:"IDS_GETREAL" :: IDS_GETREAL_A

            INTEGER  (KIND=4) iSpot1
            CHARACTER(LEN=*) gdsName
            INTEGER  (KIND=4) NBR
            REAL     (KIND=4) rVar(*)
            INTEGER  (KIND=4) maxNbr
       END FUNCTION IDS_GETREAL_A

END INTERFACE IDS_GETREAL[/plain]
The compiler will select the correct interface.
0 Kudos
smanoj
Beginner
489 Views
Elemental would require that all the arguments be either scalars or arrays. What you want instead is a generic interface with some fancy aliasing so that they go to the same routine. I suggest this:

[plain]INTERFACE IDS_GETREAL

       INTEGER (KIND=4) FUNCTION IDS_GETREAL_S (iSpot1,gdsName,nbr,rVar,maxNbr)
!DEC$ ATTRIBUTES DECORATE,ALIAS:"IDS_GETREAL" :: IDS_GETREAL_S

            INTEGER  (KIND=4) iSpot1
            CHARACTER(LEN=*) gdsName
            INTEGER  (KIND=4) NBR
            REAL     (KIND=4) rVar 
            INTEGER  (KIND=4) maxNbr
       END FUNCTION IDS_GETREAL_S

       INTEGER (KIND=4) FUNCTION IDS_GETREAL_A (iSpot1,gdsName,nbr,rVar,maxNbr)
!DEC$ ATTRIBUTES DECORATE,ALIAS:"IDS_GETREAL" :: IDS_GETREAL_A

            INTEGER  (KIND=4) iSpot1
            CHARACTER(LEN=*) gdsName
            INTEGER  (KIND=4) NBR
            REAL     (KIND=4) rVar(*)
            INTEGER  (KIND=4) maxNbr
       END FUNCTION IDS_GETREAL_A

END INTERFACE IDS_GETREAL[/plain]
The compiler will select the correct interface.

Hi Steve,

Thank you very much , I had implemented it.

Regards,
Manoj
0 Kudos
Steven_L_Intel1
Employee
489 Views
A correction - ELEMENTAL would require that all the arguments be scalars. Calling an elemental routine with array argument(s) is implicitly calling the scalar routine in a loop, once for each element.
0 Kudos
Reply