FortranForm

FortranForm[expr]

prints as a Fortran language version of expr.

Details

  • Standard arithmetic functions and certain control structures are translated.
  • When an input evaluates to FortranForm[expr], FortranForm does not appear in the output. »
  • The width of output lines must be set explicitly by giving the option PageWidth->n for the relevant output stream.
  • SetOptions[$Output,PageWidth->72] uses a line width of 72 characters for standard Wolfram Language output.
  • No declarations are generated.

Examples

open allclose all

Basic Examples  (1)

A Fortran language version of a polynomial:

A mixed numeric and symbolic expression:

Scope  (1)

Fortran formatting for an arbitrary function:

A composite power:

Applications  (1)

Compute terms of the analytic Hessian for a multivariate function for use in Fortran code:

Properties & Relations  (2)

When an input evaluates to FortranForm[expr], FortranForm does not appear in the output:

Out is assigned the value x2, not FortranForm[x^2]:

FortranForm formats expressions like Fortran code:

CForm formats expressions like C code:

Possible Issues  (2)

Additional Fortran function definitions may be needed to run the code:

Even when an output omits FortranForm from the top level, it is not stripped from subexpressions:

The output does not have FortranForm in it:

However, the variable e does have FortranForm in it, which may affect subsequent evaluations:

The product is not evaluated due to the intervening FortranForm:

Assign variables first and then apply FortranForm to the result to maintain computability:

Wolfram Research (1988), FortranForm, Wolfram Language function, https://reference.wolfram.com/language/ref/FortranForm.html.

Text

Wolfram Research (1988), FortranForm, Wolfram Language function, https://reference.wolfram.com/language/ref/FortranForm.html.

CMS

Wolfram Language. 1988. "FortranForm." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/FortranForm.html.

APA

Wolfram Language. (1988). FortranForm. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FortranForm.html

BibTeX

@misc{reference.wolfram_2023_fortranform, author="Wolfram Research", title="{FortranForm}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/FortranForm.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_fortranform, organization={Wolfram Research}, title={FortranForm}, year={1988}, url={https://reference.wolfram.com/language/ref/FortranForm.html}, note=[Accessed: 19-March-2024 ]}