Fortran - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


CodeGeneration

  

Fortran

  

translate Maple code to Fortran code

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

Fortran(x, cgopts)

Parameters

x

-

expression, list, rtable, procedure, or module

cgopts

-

(optional) one or more CodeGeneration options

Description

• 

The Fortran command translates Maple code to Fortran 77 code.

  

- If the parameter x is an algebraic expression, then a Fortran statement assigning the expression to a variable is generated.

  

- If x is a list, rtable or Maple Array of algebraic expressions, then a sequence of Fortran statements assigning the elements to a Fortran array is produced.  Only the initialized elements of the rtable or Maple Array are translated.

  

- If x is a list of equations nm=expr where nm is a name and expr is an algebraic expression, this is understood to mean a sequence of assignment statements.  In this case, the equivalent sequence of Fortran assignment statements is generated.

  

- If x is a procedure, then either a Fortran function or a subroutine is generated.

  

- If x is a module, then a Fortran program is generated, as described on the FortranDetails help page.

• 

The parameter cgopts may include one or more CodeGeneration options, as described in CodeGenerationOptions. The limitvariablelength=false option, available for this command only, allows you to use names longer than 6 characters.  By default, such names are automatically replaced because they do not comply with the Fortran 77 standard.

• 

For more information about how the CodeGeneration package translates Maple code to other languages, see Translation Details. For more information about translation to Fortran in particular, see FortranDetails.

Examples

See CodeGenerationOptions for a description of the options used in the following examples.

withCodeGeneration:

Translate a simple expression and assign to the name "w" in the target code.

Fortranx+yz2xz,resultname=w

      w = -2 * x * z + y * z + x

Translate a list and assign to an array with name "w" in the target code.

Fortranx,2y,5,z,resultname=w

      w(1,1) = x
      w(1,2) = 2 * y
      w(2,1) = 5
      w(2,2) = z

Translate a computation sequence.  Optimize the input first.

css=1.0+x,t=lnsexpx,r=expx+xt:

Fortrancs,optimize

      s = 0.10D1 + x
      t1 = log(s)
      t2 = exp(-x)
      t = t2 * t1
      r = x * t + t2

Declare that x is a float and y is an integer.  Return the result in a string.

sFortranx+y+1,declare=x::float,y::integer,output=string

s cg = x + dble(y) + 0.1D1

(1)

Translate a procedure.  Assume that all untyped variables have type integer.

f := proc(x, y, z) return x*y-y*z+x*z; end proc:

Fortranf,defaulttype=integer

      integer function f (x, y, z)
        integer x
        integer y
        integer z
        f = y * x - y * z + x * z
        return
      end

Translate a procedure containing an implicit return.  A new variable is created to hold the return value.

f := proc(n)
    local x, i;
    x := 0.0;
    for i to n do
        x := x + i;
    end do;
end proc:

Fortranf

      doubleprecision function f (n)
        integer n
        doubleprecision x
        integer i
        doubleprecision cgret
        x = 0.0D0
        do 100, i = 1, n, 1
          x = x + dble(i)
          cgret = x
100     continue
        f = cgret
        return
      end

Translate a procedure accepting an Array as a parameter.

f := proc(x::Array(numeric, 5..7))
    return x[5]+x[6]+x[7];
end proc:

Fortranf

      doubleprecision function f (x)
        doubleprecision x(5:7)
        f = x(5) + x(6) + x(7)
        return
      end

Translate a module with one exported and one local procedure.

m := module() export p; local q;
    p := proc(x,y) if y>0 then trunc(x); else ceil(x); end if; end proc:
    q := proc(x) sin(x)^2 end proc:
end module:

Fortranm,resultname=t0

      doubleprecision function q (x)
        doubleprecision x
        q = sin(x) ** 2
        return
      end

      integer function p (x, y)
        doubleprecision x
        integer y
        if (0 .lt. y) then
          p = int(aint(x))
          return
        else
          p = int(ceil(x))
          return
        end if
      end

      program m
      end

Translate a procedure with no return value, containing an output statement.

f := proc(N)
    printf("%d is a Number.\n", N);
end proc:

Fortranf

      subroutine f (N)
        doubleprecision N
        print *, N, ' is a Number.'
      end

Use names longer than 6 characters with the limitvariablelength option.

p:=proc() local longvar: end proc;

pproclocallongvar;end proc

(2)

Fortranp

      subroutine p
        doubleprecision cg
      end

Fortranp,limitvariablelength=false

      subroutine p
        doubleprecision longvar
      end

See Also

CodeGeneration

CodeGenerationOptions

FortranDetails

Translation Details