Fortran

Guide To Learn

Core elements of Fortran

Writing to files on disk: A minimal note-taking app

You now know how to read from standard input and write to standard output. You also know how to format the data for pretty printing, or for reading specially formatted records. Sooner or later, you’ll need to read data from and write data to files on disk. In this section, we’ll implement a minimal, yet […]

Format statements in legacy Fortran code

If you find yourself working with a legacy Fortran program or library for some time, you’ll eventually run into labeled format statements that look like this: ❶ Refers to the format statement via a numbered label ❷ Label and format statement Here, the format string is specified not with a character variable or string literal, but with an integer […]

Formatting strings, broken down

If you’re familiar with any C-style language, you’ve likely had some experience with formatting numbers and text there. In Python, for example, if you wanted to display the number pi as “3.14,” you’d type ‘%4.2f’ % pi–four characters total, two of which are used for the fractional part, with the character f denoting a floating-point number. This is part of the […]

Designing the aircraft dashboard

Fortran’s formatting rules are quite tedious, so let’s learn them by tackling a practical problem. Consider the following scenario. You’re an aircraft flight instruments engineer, and you’re tasked with implementing the on-screen display of several key parameters related to the aircraft’s in-flight state. The design team has instructed you to display only certain parameters and […]

Formatting numbers and text

In this section, you’ll learn how to explicitly format numbers and text for output to screen or files on disk. You’ve probably noticed that in most cases when we used print or write statements to display values on the screen, they produced output with somewhat awkward formatting and wide empty spaces between values. For example, in the previous section, […]

Standard input, output, and error

If you’ve done any programming before picking up this book, you’ve likely heard of standard input (stdin), output (stdout), and error (stderr). They’re collectively known as standard streams and were introduced in the early days of the Unix operating system to allow easier interaction with the local file system and hardware, such as keyboards, printers, and, later, screens. […]

Reading and writing multiple variables at once

While implementing a simple echo program in the previous subsection, we accidentally stumbled on list-directed I/O, which allows you to read or write multiple variables on the same line. It’s called list-directed because of its functionality to consume and emit an arbitrary list of variables. For example, if you input a character string, an integer, and a […]

Your first I/O: Input from the keyboard and output to the screen

So far, we’ve read data and written it to screen and/or files in almost every chapter in this book. For brevity, and to stay focused on other features of the language, I only briefly mentioned what we did and why, so I haven’t explained in much detail about how it works. Before we jump into […]

Scroll to top