The Fortran Perspective

When you write Fortran code, ordinarily you will work in the Fortran perspective. When you create a new Fortran project (as described above), the wizard will ask if you want to switch to the Fortran perspective, or you can do it manually by clicking Window > Open Perspective > Other... and selecting Fortran from the list. For more information on perspectives, click on Help > Help Contents in Eclipse, and navigate to Workbench User Guide > Concepts > Perspectives. Perspectives are also covered in the Eclipse tutorial, which can be found in Workbench User Guide > Getting started > Basic tutorial. In particular, note that you can add views to a perspective by clicking Window > Show View > Other... and selecting a new view from the Show View dialog. You can also reset the current perspective to its original layout: From the menu bar, choose Window > Reset Perspective. By default, the Fortran perspective contains a central area for editing code, as well as the following views:

For more information on the Make Targets view, click on Help > Help Contents in Eclipse, and navigate to C/C++ Development User Guide > Reference > C/C++ Views and Editors > Make Targets view.

The Fortran Projects View

The Fortran Projects view displays project files in a tree structure. In this view you can do the following:

Files can be opened by double-clicking on the filename or by right-clicking on the file and choosing "Open With" from the context menu. Most other actions are performed by right-clicking on the file and choosing an action from the context menu. The Fortran projects view is similar to the C/C++ Projects View. For more information on the Fortran Projects view, refer to the documentation on the C/C++ Projects view by clicking on Help > Help Contents in Eclipse and navigating to C/C++ Development User Guide > Reference > C/C++ Views and Editors > C/C++ Projects view.

Configuring Content Types: Free vs. Fixed Form

Photran supports both fixed-form and free-form Fortran code. Each source form has its own editor.

Fixed form is an older form designed for punch cards. It is more common in Fortran 77 and earlier programs, although it is still part of Fortran 2003. In fixed form, a "c", "C", "*", or "!" in column 1 indicates a comment; columns 1 through 5 are used for a statement label; a character in column 6 indicates a continuation line; and program statements are contained in columns 7 through 72. Anything after column 72 is ignored.

Photran uses filename extensions to determine whether a file is in fixed- or free-form. By default, .f, .fix, .for, .fpp, and .ftn are assumed to be in fixed source form, while .f03, .f95, .f90, and .f77 are assumed to be in free source form. Additional extensions can be added to this list by changing the Eclipse Content Type preferences. For more information on configuring content types, click on Help > Help Contents in Eclipse and navigate to Workbench User Guide > Reference > Preferences > Content Types.

Using the Fortran editor and Fortran perspective

Selecting free vs. fixed form

Free Form Fortran Editor
Photran has different editors for free- and fixed-form files. The free-form editor is pictured above. The fixed-form editor has vertical bars delineating column six and marking the right-hand side of column 72; it is pictured below. When you double-click on a file in the Fortran Projects view, Photran will open it in either the free- or fixed-form editor according to its filename extension. (See the previous section on how to customize this.) You can explicitly choose whether to open a file in the free-form or fixed-form editor by right-clicking on the file in the Fortran Projects view and selecting either Open With > Fortran Editor (Fixed Form) or Open With > Fortran Editor (Free Form). Opening free-form code in the fixed-form editor (or vice versa) will result in a watermark reading "Warning: Content Type Mismatch" being displayed in the upper right corner of the editor. Do not ignore the "Warning: Content Type Mismatch" watermark. Photran always uses the content type of the file to populate the Outline view and to operate the features described in the Advanced Features Manual. So if you are editing a fixed form file but this watermark is being displayed, Photran thinks it is a free form file. You MUST change the content types in the Eclipse preferences, as described in the previous section, for the Outline view to display and for any of the advanced features to work.
Fixed Form Fortran Editor

Outline view

Outline View
When a Fortran file is open in the Fortran editor, the Outline view shows an outline of the structural elements of that file: subprograms, main programs, modules, derived types, etc. The Outline view notes the content type of the file (free form or fixed form); it will also note when there is an error in the code. To add the Outline view to the current perspective go to Window > Show View > Other... > General > Outline.
Outline Error

Overview of the Fortran editors

The free form and fixed form editors generally support the same features. The main features to note are the horizontal ruler at the top of the editor, code folding, and smart syntactic highlighting. The horizontal ruler measures the width of the editor in characters: There is either a symbol (-/+) or number for each column in the editor. A plus sign (+) is shown every fifth character, and every tenth character is numbered. It is also possible to turn on the print margin (gray vertical line) in the 80th column; this is discussed further below in the section titled "Configuring the Editor."

Editor Ruler
Code folding is also supported in the free form editor, but turning on code folding will disable the horizontal ruler; how to do this is described below as well. When folding is turned on, a minus sign (-) will be displayed in the left margin of the editor next to each program, function, subroutine, etc.; clicking on the minus sign will temporarily collapse the display of that entity to a single line.
Editor Folding
The editors also support smart syntactic highlighting. As you write programs in Fortran, you will notice that different colors are applied to comments, identifiers, intrinsics, keywords, and strings to make code more readable. It is possible to change the colors for each of the previously mentioned code components in the Fortran editor preferences (this is discussed in the section "Configuring the Editor," below). Often, the editor can even distinguish between, for example, the keyword "if" and a variable named "if." However, it is not perfect; it uses a faster, but less reliable, heuristic than the actual Fortran parser that drives the Outline view and all of the Advanced Features.

Comment/uncomment

Photran can comment or uncomment a block of Fortran statements, placing an exclamation point (!) before the statements or removing it, respectively. Select the statements in the Fortran editor. Then right-click the selection, and choose Comment/Uncomment from the context menu.

Setting bookmarks

Bookmarks are an Eclipse feature which allows you to mark important lines in a file and then quickly jump to those lines using the Bookmarks view. To set a bookmark, right-click the grey bar on the left side of the editor at the line where the bookmark should be located and select "Add Bookmark..." from the popup menu. A bookmark can also be placed on a line by locating the cursor on the line, going to Edit > Add Bookmark... in the menu bar. Type in the desired name for the bookmark in the dialog box and click OK. A blue bookmark will show up in the grey bar on the left side of the editor. Bookmarks can then be viewed in the Bookmarks view (Window > Show View > Other..., select Bookmarks in the General folder).

Go to line (Ctrl+L)

The "Go To Line..." feature allows you to jump to a specific line number in a file when it is open in a Fortran editor. In the menu bar, go to Navigate > Go To Line... (or press the hotkey, Ctrl+L on Windows/Linux or Command+L on Mac) to open the Go To Line dialog box. Typing in the line you wish to navigate to, and clickg OK. The cursor will be moved to the beginning of the specified line.

Configuring The Editor

Selecting horizontal ruler vs. folding

Fortran editors can either display the horizontal ruler, or they can have code folding enabled, but not both. To determine which will be enabled, go to Window > Preferences in the menu bar. Expand Fortran and select Editor. Check the appropriate box(es) to enable folding in the free-form and/or fixed-form Fortran editor.

Setting colors for syntax highlighting

The colors for Fortran syntax highlighting can be modified in the Fortran editor preferences. To modify the color settings, go to Window > Preferences in the menu bar. Expand Fortran and select Editor. The color choosers for Comments, Identifiers, Intrinsics, Keywords, and Strings are available on this page.

Showing the print margin

Editors can optionally display a gray vertical bar at a specified column; generally, this is set in column 80 to act as a visual "print margin." To enable display of the print margin, go to Window > Preferences in the menu bar. Under General, expand Editors, and select Text Editors. Check the box for "Show print margin". Optionally, you can also change the column in which the print margin will be displayed. Click Apply and the print margin should now display in the editor.

Setting fixed-form line length

In fixed form, Fortran specifies that anything past column 72 (default) is a comment. However, that can be changed to a value other than 72. To change the length of the line, go to Window > Preferences in the menu bar. Under Fortran, select Editor. Change the value of field labeled "Fixed-form line length" to the desired length of the line. Note that the accepted range for the length of the line is 72-999 inclusive.

Converting tabs to spaces

To enable conversion of tabs to spaces, go to Window > Preferences in the menu bar. Under General, expand Editors, and select Text Editors. Check the box for "Insert spaces for tabs" to have Eclipse automatically convert Tabs to spaces. Note that this will only apply to new tabs that you type; it will not change your existing files.

It is easy to replace tabs with spaces in an existing file, as long as the tabs all occur at the beginning of a line. (For tabs in the middle of a line, this won't work quite right.) (1) Move the cursor to the beginning of the file; (2) click on Edit > Find/Replace...; (3) in the Find box, type "\t" (without the quotes); (4) in the Replace With box, type 4 or 8 spaces (each tab character will be replaced with exactly what you type, so if you type four spaces, each tab character will be replaced with four spaces); (5) select Search: Forward and Scope: All; (6) check the "regular expression" box; and (7) click Replace All. This will replace every tab character with spaces.

Show whitespace

Whitespace characters can be displayed by going to Window > Preferences. Under General > Editors > Text Editors, check the box next to "Show whitespace characters" and click Apply. Spaces, tabs, and newlines will now be shown as light gray double-angle quotes (»), dots (·), and paragraph symbols (¶), respectively.

Set Font

Photran uses the same font as the basic Eclipse text editor. To change it, click on Window > Preferences in the menu bar. Under General, expand Appearance, and select Colors and Fonts. In the list on the right, select Text Font. Click the "Change..." button to change the font.

Show line numbers

Line numbers can be displayed in the editor in the Text Editor preferences page. Go to Window > Preferences. Under General > Editors > Text Editors, check the box "Show line numbers" and click Apply.