Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Using MODULEs in Fortran 90/95

  1. Jan 6, 2014 #1
    Hi!
    I require help in writing a code where I want to put FUNCTION definitions in one module and INTERFACEs to the functions (as I use assumed-shape arrays in the functions) in another. But I get multiple errors when trying to compile. Could anyone assist me in solving this problem? Please see program below. Thanks in advance.
    Code (Text):

    MODULE qwer
        CONTAINS
        PURE FUNCTION BMatVect(ShapeFuncDeriv,JacobiInv)
            IMPLICIT NONE
           Real, Intent(IN) :: JacobiInv(:,:),ShapeFuncDeriv(:,:)
           Real::BMatVect(size(ShapeFuncDeriv,1),size(ShapeFuncDeriv,2))
            BMatVect = Matmul(JacobiInv, ShapeFuncDeriv)
        END FUNCTION BMatVect
    END MODULE qwer

    MODULE ty
        USE qwer
        INTERFACE BMatVect_function
            PURE FUNCTION BMatVect(ShapeFuncDeriv,JacobiInv)
             IMPLICIT NONE
           Real, Intent(IN) :: JacobiInv(:,:),ShapeFuncDeriv(:,:)
           Real::BMatVect(size(ShapeFuncDeriv,1),size(ShapeFuncDeriv,2))
            END FUNCTION BMatVect
        END INTERFACE BMatVect_function
    END MODULE ty

    PROGRAM MyTest
        USE ty
        IMPLICIT NONE
        REAL :: A(2,2) = reshape((/1,1,1,1/),(/2,2/)), &
                       B(2,4) = reshape((/-0.5,-0.5,0.5,0.0,0.0,0.0,0.0,0.5/),(/2,4/)), &
                   C(2,4)
        C = BMatVect (B, A)
        PRINT*, C(1,:)
        PRINT*, C(2,:)
    END PROGRAM MyTest
     
     
    Last edited: Jan 6, 2014
  2. jcsd
  3. Jan 6, 2014 #2

    jedishrfu

    Staff: Mentor

    What FORTRAN are you using?

    Have you tried adding a 'use qwer' in the program? Not sure if thats the problem but maybe you can't nest things.

    http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlf101l.doc%2Fxlflr%2Fmodproc.htm [Broken]

    Lastly, can you change your use of the spoiler tag to the the code tag? The spoiler is used for hints and makes your program listing flicker on and off with mouse movement.

    Some more best practice comments on module usage:

    http://stackoverflow.com/questions/...-modules-subroutines-and-functions-in-fortran
     
    Last edited by a moderator: May 6, 2017
  4. Jan 6, 2014 #3
    Some compilers don't like you putting actual numbers in arrays which haven't been defined as a fixed size. I would try doing something with declaration of in quer by removing the 1 and 2 when determining array size.
    Also, as good practice only use the modules that that sub/function/program requires, ideally with 'only' statements for robustness. Some compilers get confused if there are multiple routes to variables etc through different modules. This will also assist should decided to vectorise your code.
     
  5. Jan 6, 2014 #4
    jedishrfu, Thanks a lot for the link to Stackoverflow! It helped. It turns out that when you use MODULE the interface is being generated automatically, so the program knows it. Ergo, the problem was in my second MODULE 'ty' with explicit INTERFACE. I got rid of it. Now everything runs smoothly. Thanks again!:thumbs:

    P.S.: I already use CODE tag. If you mean vice versa, SPOILER tag doesn't hide anything for me.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Using MODULEs in Fortran 90/95
Loading...