Fortran 90/95 Code That Allows A Function To Return An Array

I am not sure why I like the idea of a function returning an array over having a subroutine with an output array but I do. So this is how you do it:

program arrayeqns
    interface
        function eqns(q)
            real :: eqns(6), q(6)
        end function
    end interface
    call rk4(q)
end program

function eqns(q)
    real :: eqns(6), q(6)
    eqns(1) = q(4)
    eqns(2) = q(5)
    eqns(3) = q(6)
    eqns(4) = 0.
    eqns(5) = 0.
    eqns(6) = -9.8
    return
end function eqns

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>