Fortran compiler#
- class sage.misc.inline_fortran.InlineFortran(globals=None)#
Bases:
object
- add_library(s)#
- add_library_path(s)#
- eval(x, globals=None, locals=None)#
Compile fortran code
x
and adds the functions in it toglobals
.INPUT:
x
– Fortran codeglobals
– a dict to which to add the functions from the fortran modulelocals
– ignored
EXAMPLES:
sage: # needs numpy sage: code = ''' ....: C FILE: FIB1.F ....: SUBROUTINE FIB(A,N) ....: C ....: C CALCULATE FIRST N FIBONACCI NUMBERS ....: C ....: INTEGER N ....: REAL*8 A(N) ....: DO I=1,N ....: IF (I.EQ.1) THEN ....: A(I) = 0.0D0 ....: ELSEIF (I.EQ.2) THEN ....: A(I) = 1.0D0 ....: ELSE ....: A(I) = A(I-1) + A(I-2) ....: ENDIF ....: ENDDO ....: END ....: C END FILE FIB1.F ....: ''' sage: fortran(code, globals()) sage: import numpy sage: a = numpy.array(range(10), dtype=float) sage: fib(a, 10) sage: a array([ 0., 1., 1., 2., 3., 5., 8., 13., 21., 34.])