(j3.2006) derived types with type parameters are different

Bill Long longb
Mon Jul 28 12:44:17 EDT 2008



Robert Corbett wrote:
> Aleksandar Donev wrote:
>   
>> On Friday 25 July 2008 09:44, Bill Long wrote:
>>
>>     
>>> The feature is a pain to implement, so resistance to
>>> doing it over a different way will be very high.
>>>       
>> But what way does Cray do---you seemed unsure of the actual answer? Can Robert 
>> please prepare two examples (one KIND, one non-KIND), including the mentioned 
>> generic interface, and see if Cray and IBM actually do the same thing?
>> Aleks
>>     
>
> Here are three programs that can be used to test how
> bounds expressions affect type equivalence.
> Different bounds expressions can be substituted for
> those in the derived types.
>
> Bob Corbett
>
>
> -----------------------------------------------------------------
>
>        MODULE M1
>          INTERFACE S
>            SUBROUTINE S1(X)
>              TYPE T(N)
>                INTEGER, KIND :: N
>                SEQUENCE
>                REAL A(N+N)
>              END TYPE
>              TYPE(T(2)) :: X
>            END SUBROUTINE
>          END INTERFACE
>          TYPE T(N)
>            INTEGER, KIND :: N
>            SEQUENCE
>            REAL A(N+N)
>          END TYPE
>          TYPE(T(2)) :: X
>        END
>
>        MODULE M2
>          INTERFACE S
>            SUBROUTINE S2(X)
>              TYPE T(N)
>                INTEGER, KIND :: N
>                SEQUENCE
>                REAL A(2*N)
>              END TYPE
>              TYPE(T(2)) :: X
>            END SUBROUTINE
>          END INTERFACE
>          TYPE T(N)
>            INTEGER, KIND :: N
>            SEQUENCE
>            REAL A(2*N)
>          END TYPE
>          TYPE(T(2)) :: X
>        END
>
>        SUBROUTINE S1(X)
>          TYPE T(N)
>            INTEGER, KIND :: N
>            SEQUENCE
>            REAL A(N+N)
>          END TYPE
>          TYPE(T(2)) :: X
>          PRINT *, 'CALLED S1'
>        END
>
>        SUBROUTINE S2(X)
>          TYPE T(N)
>            INTEGER, KIND :: N
>            SEQUENCE
>            REAL A(2*N)
>          END TYPE
>          TYPE(T(2)) :: X
>          PRINT *, 'CALLED S2'
>        END
>
>        PROGRAM MAIN
>          USE M1, ONLY: S, X
>          USE M2, ONLY: S, Y=>X
>          CALL S(X)
>          CALL S(Y)
>        END
>   

This one compiled and output:

CALLED S1
CALLED S2


> ------------------------------------------------------------------------
>
>        MODULE M1
>          INTERFACE S
>            SUBROUTINE S1(X, M)
>              TYPE T(N)
>                INTEGER :: N
>   

This is a syntax error.  The ",kind" or ",len" are not optional syntax, 
assuming this is intended to be a type parameter declaration.  If not, 
then the statements are out of order - component declarations come after 
SEQUENCE.

Same error repeated several times below.
>                SEQUENCE
>                REAL A(N+N)
>              END TYPE
>              TYPE(T(M)) :: X
>            END SUBROUTINE
>          END INTERFACE
>          TYPE T(N)
>            INTEGER :: N
>            SEQUENCE
>            REAL A(N+N)
>          END TYPE
>          TYPE(T(2)) :: X
>        END
>
>        MODULE M2
>          INTERFACE S
>            SUBROUTINE S2(X, M)
>              TYPE T(N)
>                INTEGER :: N
>                SEQUENCE
>                REAL A(2*N)
>              END TYPE
>              TYPE(T(M)) :: X
>            END SUBROUTINE
>          END INTERFACE
>          TYPE T(N)
>            INTEGER :: N
>            SEQUENCE
>            REAL A(2*N)
>          END TYPE
>          TYPE(T(2)) :: X
>        END
>
>        SUBROUTINE S1(X, M)
>          TYPE T(N)
>            INTEGER :: N
>            SEQUENCE
>            REAL A(N+N)
>          END TYPE
>          TYPE(T(M)) :: X
>          PRINT *, 'CALLED S1'
>        END
>
>        SUBROUTINE S2(X, M)
>          TYPE T(N)
>            INTEGER, KIND :: N
>            SEQUENCE
>            REAL A(2*N)
>          END TYPE
>          TYPE(T(M)) :: X
>   

This is an error. The type parameter for T is a KIND type parameter, and 
thus M must be a named constant here.  But it is a dummy argument.

>          PRINT *, 'CALLED S2'
>        END
>
>        PROGRAM MAIN
>          USE M1, ONLY: S, X
>          USE M2, ONLY: S, Y=>X
>          CALL S(X, 2)
>          CALL S(Y, 2)
>        END
>   

Because of all the errors, the code above did not compile - no output.

> ------------------------------------------------------------------------------
>
>        MODULE M1
>          TYPE T(N)
>            INTEGER :: N
>   

Similar error to above.
>            SEQUENCE
>              REAL A(N+N)
>          END TYPE
>          TYPE(T(2)) :: X
>        END
>
>        MODULE M2
>          TYPE T(N)
>            INTEGER :: N
>            SEQUENCE
>              REAL A(2*N)
>          END TYPE
>          TYPE(T(2)) :: X
>        END
>
>        PROGRAM MAIN
>          USE M1, ONLY: X
>          USE M2, ONLY: Y
>   

There is no Y in module M2.

>          X%A = 0.0
>          Y = X
>          PRINT *, X, Y
>        END
>   

Because of errors, this one did not compile.  No output.

Cheers,
Bill

> --------------------------------------------------------------------------------------
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3
>   

-- 
Bill Long                                   longb at cray.com
Fortran Technical Support    &              voice: 651-605-9024
Bioinformatics Software Development         fax:   651-605-9142
Cray Inc., 1340 Mendota Heights Rd., Mendota Heights, MN, 55120

            




More information about the J3 mailing list