codegen - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Libraries and Packages : Deprecated Packages and Commands : Deprecated commands : codegen/fortran(deprecated)

codegen

  

fortran

  

generate Fortran code

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

fortran(s);

fortran(s, options);

Parameters

s

-

expression, array of expressions, or list of equations

Description

• 

Important: The codegen[fortran] command has been deprecated.  Use the superseding command CodeGeneration[Fortran] instead. See CodeGeneration for information on translation to other languages.

• 

The codegen[fortran] function generates Fortran 77 code for evaluating the input. The input s must be a single algebraic expression, an array of algebraic expressions, a list of equations of the form name = algebraic that is understood to mean a sequence of assignment statements, or a Maple procedure. If the array is not named, then the name unknown is used. For help on translating Maple procedures into Fortran, see codegen/fortran/procedure . The fortran command takes the following optional arguments for controlling the output.

• 

The filename option: By default the output is sent to standard output. An optional argument of the form filename = "foo" can be used to direct the output to the file foo. The output will be appended to the file.

• 

The optimized option: If the keyword optimized is specified as an optional argument, common subexpression optimization is performed. The result is a sequence of assignment statements in which temporary values are stored in local variables beginning with the letter t. The global names t0, t1, t2, ... are reserved for use by fortran for this purpose. The input to the optimizer must satisfy certain conditions.  See codegen/optimize for more information.

• 

The digits option: Non-floating point constants, such as integers, rationals, and symbols such as Pi, are converted using evalf to floating point constants where necessary; for example, as arguments to real functions such as sqrt. By default, the number of digits used is 7 for single precision, and 16 for double precision.  This can be set to n digits by specifying an optional argument digits = n.

• 

The precision option: If the optional argument precision=single or precision=double is given, this specifies whether floating-point constants are to be output in E (single precision) or D (double precision) notation, respectively.  It also specifies how function names are to be translated.  The default is single precision if the mode=single or mode=complex option is provided and double precision otherwise.

• 

The mode option.  The mapping of functions names from Maple to Fortran can be controlled by providing the optional argument mode=t, where t is one of single, double, generic or complex.  If the mode option is not given, the default is mode=generic. For example, the natural logarithm function (ln or log in Maple) is translated as follows

mode          translation

single        alog

double        dlog

complex       clog

generic       log

• 

The renaming of functions, such as arctan in Maple to atan in Fortran, is done by the function `codegen/fortran/function_name`. You can change how functions are renamed. For example,

codegen/fortran/function_namearctan,1,doubledatan

codegen/fortran/function_namearctan,2,singleatan2

• 

In translating arrays (Maple vectors and matrices and other arrays), the fortran function does not reindex the arrays to the 1-based indexing that Fortran requires.  Since Maple vectors and matrices are indexed from 1, this is not a problem.  If you have an array indexed from 0 or something else, you have to convert it to 1-based indexing first.  This can easily be done by using the convert function.  See the help page for convert[array]. If the array contains unassigned entries, the value output in the Fortran code is the string undefined.

• 

The Fortran language has a continuation line limit of 19 lines which, if exceeded, results in an error during compilation. For large expressions that exceed this limit, the fortran routine will automatically break up the expression. The global names s0, s1, s2, ... are reserved for use by fortran for this purpose.

• 

The function fortran produces Fortran code as a side-effect and returns NULL as the function value. Therefore, the ditto commands % and %% will not recall the output from the fortran command.

• 

The command with(codegen,fortran) allows the use of the abbreviated form of this command.

Examples

Important: The codegen[fortran] command has been deprecated.  Use the superseding command CodeGeneration[Fortran] instead.

withcodegen,fortran:

f12x+3x22x3+x4

f:=x42x3+3x22x+1

(1)

fortranf

      t0 = x**4-2*x**3+3*x**2-2*x+1

fortranf,optimized

      t1 = x**2
      t2 = t1**2
      t7 = -2*t1*x+3*t1+t2-2*x+1

fortranconvertf,horner,x

      t0 = 1+(-2+(3+(-2+x)*x)*x)*x

fπlnx22lnx22

f:=πlnx22lnx22

(2)

fortranf

      t0 = 0.3141592653589793D1*log(x**2)-sqrt(2.D0)*log(x**2)**2

fortranf,optimized

      t1 = x**2
      t2 = log(t1)
      t4 = sqrt(2.D0)
      t5 = t2**2
      t7 = 0.3141592653589793D1*t2-t4*t5

fortrans=x2,t=lns,r=πt2s2,precision=single

      s = x**2
      t = log(s)
      r = 0.3141593E1*t-sqrt(2.E0)*s**2

Aarray1..2,1..2,symmetric:

A1,1logx:A1,21logx:

printA

lnx1lnx1lnx`?`2,2

(3)

fortranA,mode=single

      A(1,1) = alog(x)
      A(1,2) = 1-alog(x)
      A(2,1) = 1-alog(x)
      A(2,2) = 0.E0

fortranA,optimized,mode=double

      t1 = dlog(x)
      t2 = 1-t1
      A(1,1) = t1
      A(1,2) = t2
      A(2,1) = t2
      A(2,2) = (0.D0/0.D0)

fconvert12x+3x22x3+x4,horner

f:=1+2+3+2+xxxx

(4)

funapplyf,x

f:=x→1+2+3+2+xxxx

(5)

fortranf

c The options were    : operatorarrow
      doubleprecision function f(x)
      doubleprecision x

        f = 1+(-2+(3+(-2+x)*x)*x)*x
        return
      end

See Also

codegen

codegen,fortran,procedure(deprecated)

CodeGeneration

CodeGeneration[Fortran]

Writing Efficient Code

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam