Fortran

Guide To Learn

Opening files in read-only or write-only mode

Sooner or later, you’ll run across files that are meant to be used as read-only; for example, important satellite data that shouldn’t be overwritten. Similarly, some files will be useful only in write-only mode, such as the quick notes that we’ve been working on in this section. Fortran allows you to open a file in […]

Opening a file and writing to it

The first step involves getting the filename as a command-line argument, opening the file for writing, and allowing the user to write into it. To implement this is relatively straightforward but will require quite a few new language elements. Let’s take a look at the complete program first, as shown in the following listing. Listing […]

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, […]

Scroll to top