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|
The filename extensions listed above are the defaults for new Fortran projects. To change them:
Additional filename extensions can be added 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.
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...
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.
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 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.
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."
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
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 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.