# Configuring Source Forms and Filename Extensions

Photran supports both fixed-form and free-form Fortran code. Photran also supports C preprocessor directives, such as #define, #ifdef, #include, __FILE__, and __LINE__ in Fortran code.

> 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. (Although column 72 is specified in the Fortran standard, most compilers allow you to change this to permit longer lines; Photran allows you to change it as well, as described in the next section.)

Photran uses filename extensions to determine whether a file is in fixed- or free-form and whether or not it is C-preprocessed. The default filename extensions are as follows.

Filename Extensions | Source Form/Preprocessing
.f, .fix, .for, .fpp, .ftn .F, .F77, .FIX, .FOR, .FTN, .FPP, .fpp | Fixed source form
.f08, .f03, .f95, .f90 | Free source form with INCLUDE lines
.F08, .F03, .F95, .F90 | Free source form with C preprocessor directives

## Configuring Source Form/Filename Extension Associations

The filename extensions listed above are the defaults for new Fortran projects. To change them:

1. In the Fortran Projects view, right-click on a project, and choose Properties.
2. In the tree on the left, navigate to Fortran General > Source Form.
3. For each filename extension(s) you want to change, select the appropriate source form from the dropdown box.
4. Click OK to close the dialog box.

## Adding Additional Filename Extensions

Additional filename extensions can be added by changing the Eclipse Content Type preferences.

1. Click on Window > Preferences... (Eclipse > Preferences... on Mac OS X).
   1. In the "Content types:" tree in the right pane, navigate to Text > Fortran Source File.
2. Click the Add... button.
3. To make all files with a ".fre" filename extension be recognized as Fortran source code, enter *.fre in the dialog. You can also specify individual filenames by omitting the *. prefix; for example, entering old-fortran-code.txt will make any file named old-fortran-code.txt be recognized as Fortran source code, but not other .txt files.
4. Click OK to close the dialogs.

For more information on configuring content types, click on Help > Help Contents in Eclipse and navigate to Workbench User Guide > Reference > Preferences > Content Types.

# Configuring Fixed Form Line Width

While free source form allows lines to be arbitrarily long, in fixed form, there is a predetermined maximum line width. Often, this is 72 characters (i.e., anything after column 72 is ignored and treated as a comment), although most compilers allow you to change this to permit longer lines. Photran allows you to change it as well. To change the maximum line width in fixed form sources...

1. Open the workbench preferences. On Windows or Linux, click Window > Preferences; on Mac OS X, click Eclipse > Preferences.
2. Expand the Fortran category, and choose Editor.
3. Change the value of the field labeled "fixed form line length." The value must be at least 72.

If you have any fixed form editors open, close and reopen them; notice that the rightmost, gray vertical bar has been moved to the column indicated, and the parser (which constructs the Outline view) has adjusted accordingly. NOTE: This is a workspace-wide preference: It affects all fixed form files in the workspace. It is not currently possible to adjust this setting per project or per file.

# 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:

- The Fortran Projects view displays your project(s) and any files and folders in it.
- The Problems view will show errors from your Fortran compiler, if Photran can recognize them. (This requires configuring an error parser, described elsewhere in this manual.)
- The Console view shows the output from your Fortran compiler. When you run your Fortran program, its output is also displayed in the Console view.
- The Fortran Declaration view is described in the Photran Advanced Features manual.
- The Outline view shows the high-level structure of your program, i.e., the subprograms, modules, derived types, etc. comprising it.
- The Make Targets view allows you to quickly run make on a particular target defined in a custom Makefile.

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:

- Open files in the Fortran editor
- Manage existing files (cut, paste, delete, move or rename)
- Create new projects, files, or folders
- Import or Export files and projects
- Browse the high-level structures in Fortran files
- Open projects in a new window
- Perform some multi-file refactorings (such as Introduce Implicit None; see the Photran Advanced Features Manual)

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.

# Using the Fortran editor and Fortran perspective

## 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.

## Overview of the Fortran editor

The Fortran editor includes a number of features. The main features to note are the horizontal ruler at the top of the editor, code folding, and syntax 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."

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.
The editors also support syntax 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. Search for the font you want.

### 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.

### Code Templates

Code templates are used to make coding faster and easier. After typing the first letter of whatever you are typing, press Ctrl+Space and a list of choices will appear. Go to Windows > Preferences > Fortran > Templates to manage which templates you want available.