FORTran Print Statement Examples

In the realm of programming, particularly in the field of scientific computing, Fortran remains a powerful and widely-used language. One of its fundamental aspects is the ability to output data, which is achieved through print statements. Let's delve into the world of Fortran print statements, exploring their syntax, various formats, and providing practical examples.

an image of a form that has been printed out
an image of a form that has been printed out

Before we dive into the specifics, it's essential to understand that Fortran print statements are used to display output on the console or a file. They are a crucial component in debugging, data visualization, and communicating results to users.

a black and white poster with two different types of writing on it's sides
a black and white poster with two different types of writing on it's sides

Understanding Fortran Print Statements

At the heart of Fortran print statements lies the WRITE statement. It's the primary tool for outputting data. The basic syntax of a Fortran print statement is as follows:

an invoice form is shown with lines and numbers
an invoice form is shown with lines and numbers

WRITE (unit, fmt) var

Here, 'unit' represents the output destination (like 6 for the standard output, or a file unit), 'fmt' is the format string that controls the output's appearance, and 'var' is the variable you want to print.

Professional Personal Financial Statement Template Free
Professional Personal Financial Statement Template Free

Format Strings in Fortran Print Statements

Format strings are pivotal in determining how your output looks. They consist of a combination of explicit and implied format specifications. Explicit format specifications start with an 'I', 'F', or 'E' for integer, real, or exponential format, respectively. Implied format specifications, on the other hand, are based on the type of the variable being printed.

Let's explore this with an example. Consider the following Fortran code snippet:

Thematic Statement Examples - MS Office Documents
Thematic Statement Examples - MS Office Documents

PROGRAM PrintExample REAL :: x = 3.14159 WRITE(*,*) 'The value of Pi is: ', x END PROGRAM

In this example, '*' is the default format for real numbers, so 'x' will be printed in its default format. The '*' also indicates that the output will be written to the standard output (unit 6).

Control Specifiers in Fortran Print Statements

Transmittal Letter Examples
Transmittal Letter Examples

Control specifiers are used to control the output's appearance further. They include 'T' for tab, 'X' for space, and '+' for sign. For instance, the following code:

PROGRAM PrintExample INTEGER :: i = 123 WRITE(*, '(I3)') i END PROGRAM

Statement of Retained Earnings Example
Statement of Retained Earnings Example
Statement of Account Sample and Template
Statement of Account Sample and Template
Statement Templates | Free Word Templates
Statement Templates | Free Word Templates
an invoice form with the words statement written on it, and two lines that are
an invoice form with the words statement written on it, and two lines that are
Quotation Template | Quote Form | Price Quote | MS Excel | Google Sheets | Job
Quotation Template | Quote Form | Price Quote | MS Excel | Google Sheets | Job
Free Statement of Financial Position Template & Example
Free Statement of Financial Position Template & Example
17 Personal Financial Statement Templates and Forms (Word, Excel, PDF)
17 Personal Financial Statement Templates and Forms (Word, Excel, PDF)
FREE 13+ Method Statement Samples & Templates in PDF, Word
FREE 13+ Method Statement Samples & Templates in PDF, Word
Free Request for Information Templates
Free Request for Information Templates
Daisy Blake
Daisy Blake
Statement Of Service Army Example Active Duty Statement Of Service Military Trust Letter, Statement Of Service Template, Simple Service Level Agreement Template, Military Support Letter, Army Certificate Of Service Document, Us Army Retirement Documents, Military Letter Template, Military Service Document, Sample Service Level Agreement
Statement Of Service Army Example Active Duty Statement Of Service Military Trust Letter, Statement Of Service Template, Simple Service Level Agreement Template, Military Support Letter, Army Certificate Of Service Document, Us Army Retirement Documents, Military Letter Template, Military Service Document, Sample Service Level Agreement
an invoice form with the words, my business and it's receipt
an invoice form with the words, my business and it's receipt
an article from the future of tax
an article from the future of tax
Affidavit Form - My Word Templates
Affidavit Form - My Word Templates
Transes Template # 2 | by roceroaubrey
Transes Template # 2 | by roceroaubrey
Sample ULTIMATE DISCLOSURE Template » Forms 2026
Sample ULTIMATE DISCLOSURE Template » Forms 2026
Free Word Templates
Free Word Templates
Resume Personal Statements Examples Contemporary Best 20 Personal Brand Statement Examples Id...
Resume Personal Statements Examples Contemporary Best 20 Personal Brand Statement Examples Id...
Free Customer Statement of Account Template & Sample
Free Customer Statement of Account Template & Sample
50 Professional Witness Statement Forms & Templates ᐅ TemplateLab
50 Professional Witness Statement Forms & Templates ᐅ TemplateLab

will print '123' with a width of 3 characters, padding with spaces if necessary.

Advanced Fortran Print Statements

Fortran print statements can also handle arrays and complex numbers. For arrays, you can use the '(' and ')' to specify the range of elements to print. For complex numbers, Fortran automatically prints the real and imaginary parts.

Printing Arrays in Fortran

To print an array, you can use the following syntax:

WRITE(*,*) arr(1:5)

This will print the first five elements of the array 'arr'.

Printing Complex Numbers in Fortran

When printing a complex number, Fortran automatically prints the real and imaginary parts. Here's an example:

PROGRAM PrintExample COMPLEX :: c = (1.0, 2.0) WRITE(*,*) c END PROGRAM

This will output '1.000000 2.000000', showing both the real and imaginary parts.

In conclusion, Fortran print statements are a powerful tool for outputting data in a controlled and formatted manner. Whether you're printing a single variable or an array of complex numbers, Fortran's WRITE statement, combined with format strings and control specifiers, provides the flexibility to meet your output needs. Happy coding!