Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

PTP/photran/documentation/photran7advanced

You are here: PTP > Photran > Documentation > Photran 7.0 Advanced Features

Photran 7.0 Advanced Features

Contents

Introduction

Photran 7.0 includes a number of sophisticated features that are designed to make it easier to write, modify, search, and maintain Fortran code. These include content assist, which can "auto-complete" variable and function names as you type; a declaration view, which can show the leading comments for the selected variable or procedure; Fortran Search, which allows you to find declarations and references to modules, variables, procedures, etc.; and refactorings, which change your source code to improve its design while preserving its behavior.

Enabling Advanced Features

In order to use any of the advanced features described in this document, you must specifically enable them as described below. After you do this, Photran will index your project; that is, it will build a database of what modules, subprograms, etc. are declared in every file in your project. This information will be updated incrementally every time you save a file. Although this process is usually reasonably fast, it may become disruptive when working on very large projects, so it has been disabled by default. Note that the first time your project is indexed, it may take a while, because Photran must analyze every file in your project; after that, it will only index files that have changed (and files that depend on a file that has changed), so it will generally be much faster.

How to Enable Advanced Features

  1. Right-click on your project in the Fortran Projects view
  2. Click on Properties
  3. Expand Fortran General in the list on the left, and click on Analysis/Refactoring (see screenshot below)
  4. Check the "Enable Fortran analysis/refactoring" check box
  5. If you want to enable content assist, the Fortran Declaration view, etc., check those boxes as well
  6. You may also want to set module and include paths at this point (see below)
  7. Click OK

Setting Module and Include Paths

If your source code contains INCLUDE lines or USE lines referencing modules in other files, Photran needs to know where to look in order to find these. It will not figure this out automatically. For each project in which you plan to use refactoring support,

  1. Right-click on your project's folder in the Fortran Projects view
  2. Click on Properties
  3. Expand Fortran General in the list on the left, and click on Analysis/Refactoring
  4. List the folders in which Photran should search for INCLUDE files and modules when refactoring. They will be searched in order from the first folder listed to the last. Subfolders are not searched automatically; you must include them explicitly.
  5. Click OK
Photran-refac-properties.png

Advanced Features and C Preprocessed Code

Starting with Photran 6, C preprocessor directives are supported in Fortran code, as described in the Photran User's Guide. While most of the advanced features described in this manual can handle C preprocessed code, refactorings currently cannot. If you attempt to refactor C preprocessed code, you will receive an error message.

Advanced Editing Features

Content Assist

As you are typing a Fortran program, content assist pops up a list of the subprograms, variables, intrinsics, etc. that are in scope. It is invoked by pressing Ctrl+Space. As you start typing a name, the list is refined based on what you have typed; you can then use the arrow keys to choose from the list and press Enter to complete the definition. Content assist is useful when you don't remember the exact name of a function, or when a function has a long name and you don't want to type all of it. An example is shown below.

To use content assist, you will need to open the project properties, switch to the Fortran Analysis/Refactoring category, and check the "Enable Fortran content assist (Ctrl+space)" box. You will need to close and re-open any Fortran editors before you can start using content assist, however.

Fortran Content Assist

Fortran Declaration View

The Fortran Declaration view displays the statement where a variable, program, or subprogram is declared. If you place the text editor cursor within (or highlight) a variable name or the name of a subroutine in a CALL statement, the Fortran Declaration view will then display the actual declaration. For variables, the declaration view displays the variable declaration as well as a comment regarding the type of variable and other information, such as dimension information for an array as shown in the example below. For subprograms, it displays the FUNCTION or SUBROUTINE statement, including any comments that precede it.

Fortran Declaration View

Hover Tips

Hover tips display the same text as the Fortran Declaration view (described above); however, they display it in a popup window when the mouse cursor is hovered over an identifier.

Fortran hover tips are enabled in a project's analysis/refactoring properties. To turn them on or off, check the box labeled "Enable Fortran Hover Tips" in the project properties under Fortran General > Analysis/Refactoring. (Note that Analysis/Refactoring must also be enabled.)

Fortran Hover Tips

Search and Navigation

Open Declaration

The Open Declaration command allows you to quickly find the declaration of a particular variable or subprogram. In the Fortran editor, click on (or select) an identifier. Then either

  • click on the Navigate menu, and select Open Declaration, or
  • right-click on the identifier, and, and select Open Declaration, or
  • press the F3 key on your keyboard.

This feature is particularly useful when the declaration is in another file. For example, if your program contains a CALL statement which invokes a subroutine imported from a module in another file, invoking Open Declaration on the subroutine name in the CALL statement will open the module in a new editor, and the cursor will be located on the declaration of that subroutine.

Fortran Search

Fortran Search is a syntax-aware, multi-file search tool. Unlike textual searches, Fortran Search "understands" Fortran programs. It is used to search for a particular type of declaration (e.g., only modules, or only subroutines), or it can find all of the uses of a particular variable or subroutine. It also allows to you to limit the scope of the search (e.g., it can search every file in the workspace, or just a particular project).

In order to use Fortran Search, click on the Search menu and select Fortran...

OpenSearch.jpg

This will open the Eclipse Search dialog, and the Fortran tab will be active. There, you can specify several things:

  • The Search for frame allows you to specify whether it should search for subroutines, functions, modules, variables, etc.
  • The Scope frame allows you to specify what file(s) will be searched.
  • The Limit to frame allows you to specify whether you want to find declarations, references, or both.
SearchDeclarations.jpg
Notice that only the declarations of variables/functions were found. Also note the use of the wild-card character(?) in the search box

Wildcards

Wildcards are special symbols used for pattern matching. For more information, click on Help > Help Contents in Eclipse, and navigate to Workbench User Guide > Reference > User interface information > Search.

  • * - represents any number of any symbols. For example, a search for *d would match bad, rescued, d, assembled, etc.
  • ? - represents any one single character. For example, a search for ?ad would match bad, mad, sad, dad, zad, etc.

Regular expressions are an even more advanced pattern matching languages. For more information, click on Help > Help Contents in Eclipse and navigating to Workbench User Guide > Getting started > Basic tutorial > Searching

Refactoring

Introduction

What is Refactoring?

Refactorings are changes to a program that improve its internal design but do not change its behavior. These include minor, coding style changes (like using IMPLICIT NONE statements), code readability improvements (like replacing a variable named N with one called NUM_POINTS), performance improvements (like interchanging loops under certain conditions), and even larger-scale design changes (like moving a procedure from one module to another).

Although these types of changes can be done by hand, making them is often tedious and error-prone. Photran automates many such refactorings. For example, the Refactor > Rename command can automatically locate the declaration(s) and uses of a particular subroutine, and change its name in all of those locations. It is "smart," too; if there is a subroutine named d and a variable named d in a different context, it won't confuse the two. Moreover, before making such a change, Photran will attempt to verify that the change is safe to make. For example, a subroutine A cannot be renamed to B if there is already a variable named B in a context where that subroutine is called.

For more information on refactoring, see M. Fowler, Refactoring: Improving the Design of Existing Code, Addison-Wesley, 1999.

Refactoring in Photran

Most refactorings can be accessed via the Refactor menu in the menu bar, as described below. However, the most common refactorings also have hotkeys (e.g., Alt+Shift+R for Rename; hotkeys are listed in the Refactoring menu next to each command). Also, most refactorings can be accessed by right-clicking in an editor and choosing Refactor from the popup menu.

Some refactorings (such as Introduce Implicit None and Replace Obsolete Operators) can be applied to several files at once. As described below, this involves selecting one or more files in the Fortran Projects view, then right-clicking on any of the selected filenames and choosing Refactor from the popup menu.

  • Clicking on a filename in the Fortran Projects view selects that file (and only that file).
  • Ctrl+click (Command+click on Mac OS X) can be used to select or deselect additional files.
  • To select a range of files, click on one filename, and Shift+click on a later filename; those files and all of the files in between will be selected as well.

Caution: Photran can only refactor free-format Fortran source code. It is not possible to refactor fixed-form code. Make sure that only free-form Fortran files are selected. The Refactor menu may not be available if any of the files are fixed-form or non-Fortran files.

Rename

  • Description: Rename is essentially a "smart" search and replace: It allows you to change the name of a variable, subprogram, etc. It correctly observes scoping and shadowing rules can also rename subprograms and module entities across files.
  • Applies To:
    1. Local variables1,2
    2. Subprograms3 (including external and interface declarations)
    3. Derived types
    4. Module entities (variables and subprograms)
    5. Main programs
    6. Namelists
    7. Common blocks
    8. Block data subprograms
  • Operation:
    1. Click on the name of a local variable, subprogram, etc.
    2. Click Refactor > Rename... The Rename dialog will appear.
      Rename dialog
    3. Enter a new name for the variable/subprogram/etc.
    4. If you are renaming an external subprogram or a subprogram declared in an interface block, you may want to (un)check the box labeled Match external subprograms with interfaces and external declarations. If this is checked, the refactoring will attempt to find all external subprograms, EXTERNAL statements, and subprogram declarations in INTERFACE blocks that have the given name, and they will all be renamed.
    5. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Simple example of the Rename refactoring

1. Dummy subprogram arguments cannot be renamed
2. Components of derived types cannot be renamed
3. Intrinsic subprograms and type-bound procedures (Fortran 2003) cannot be renamed

Extract Procedure

  • Description: Extract Procedure removes a sequence of statements from a procedure, places them into a new subroutine, and replaces the original statements with a call to that subroutine. Any local variables used by those statements will be passed as parameters to the new procedure. This refactoring is generally used to make long procedures shorter.
  • Applies To: A sequence of one or more action statements inside a procedure or main program.
  • Operation:
    1. Select a sequence of one or more action statements in the editor. Be sure to include the newline following the last statement in the selection.
    2. Click Refactor > Extract Procedure... The Extract Procedure dialog will appear.
      Extract Procedure dialog
    3. Enter a name for the new procedure that will be created.
    4. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Simple example of the Extract Procedure refactoring

Extract Local Variable

  • Description: Extract Local Variable removes a subexpression from a larger expression and assigns that subexpression to a local variable, replacing the original subexpression with a reference to that variable. This refactoring is usually used to eliminate duplicated subexpressions or to introduce explanatory variable names into complex expressions.
  • Caveats: The refactoring will only be allowed to proceed if extracting the subexpression will preserve the associativity and precedence of the original expression. This refactoring assumes that the extracted expression has no side effects; it does not check whether moving the computation of the extracted expression will change the behavior of the program.
  • Operation:
    1. Select an expression in the editor.
    2. Click Refactor > Extract Local Variable... The Extract Local Variable dialog will appear.
    3. Enter the type and name for the new local variable that will be created.
    4. Click Preview to see what changes will be made, then click OK to apply them.

Subprogram Refactorings

Add Subroutine Parameter

  • Description: This refactoring will add a parameter to a subroutine.
  • Applies To: A subroutine.
  • Operation:
    1. Select the subroutine name or subroutine statement
    2. Click Refactoring > Subprogram > Add Subroutine Parameter (or press Shift+Alt+P)
    3. Use the input page to choose the type, intent, and name of the parameter.
    4. Type in numbers for the default value and position.
    5. Click preview to view the changes without applying, or OK to apply the changes.
  • Example:
    Example of Add Subroutine Parameter refactoring.

Permute Subprogram Arguments

  • Description: This refactoring will change the order of the arguments to a subroutine and adjust all call sites accordingly.
  • Applies To: All files calling the selected subroutine.
  • Operation:
    1. Select the subroutine name or subroutine statement
    2. Click Refactoring > Subprogram > Change Subroutine Signature.
    3. Use the input page's up and down buttons to rearrange the order of the arguments for the subroutine.
    4. Click preview to view the changes without applying, or OK to apply the changes.
  • Example:
    Example of Change Subroutine Signature refactoring.

Safe Delete

  • Description: This refactoring will remove all Internal Subprograms from a given Host. The refactoring fails if there are any references to the subprogram.
  • Applies To: A file.
  • Operation:
    1. Select the subroutine name or subroutine statement to remove
    2. Click Refactoring > Subprogram > Safe Delete
    3. Click preview to view the changes without applying, or OK to apply the changes.
  • Example:
    Example of the Safe-Delete Internal Subprograms refactoring.

Module Refactorings

Make Private Entity Public

  • Description: Changes a module variable or subprogram from PRIVATE to PUBLIC visibility, and checks that it won't conflict with any existing name where that module is USEd.
  • Applies To: Variables, subroutines, functions.
  • Does Not Apply To: Intrinsics, Externals, Interfaces.
  • Operation:
    1. Select the name of the private entity you wish to make public.
    2. Choose Refactor > Module > Make Private Entity Public.
    3. Click Preview to see what changes will be made, then click OK to apply them.
  • Example
    Example of make private entity public refactoring.

Example 2 of make private entity public refactoring.

Encapsulate Variable

  • Description: Encapsulate variable creates getter and setter methods for the selected variable in the module where it is defined and changes variable's visibility to private. It also replaces all uses of that variable in all files to use getter and setter method calls1.
  • Applies To:
    1. Variables defined in the module.
    2. Variables of all basic as well as user-defined types
  • Does Not Apply To:
    1. Arrays
    2. Variables that are not defined in a module
    3. Parameters (i.e. integer, parameter :: CANNOT_ENCAPSULATE)
    4. Pointers (i.e. real, pointer :: CANNOT_ENCAPSULATE)
    5. Targes (i.e. integer, target :: CANNOT_ENCAPSULATE)
  • Operation:
    1. Click on or select the name of variable you want to encapsulate.
    2. Click Refactor > Module > Encapsulate Variable. The Encapsulate Variable dialog will appear.
      Getter and setter name menu for encapsulating variable temp
    3. Enter names for getter and setter methods. You will be warned if the names that you want to assign to your getter and setter methods will be conflicting with some other identifier in any of the involved files.
    4. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Simple example of Encapsulate Variable refactoringtemp
               
    Simple example of Encapsulate Variable refactoringtemp

1. If a variable is used as a parameter to a function/subroutine call, and that function changes the value of the variable as a side-effect, that change will not be preserved.

Use Statement Refactorings

Add ONLY Clause to USE Statement

  • Description: Creates a list of the symbols that are being used from a module, and adds it to the USE statement.
  • Applies To: All modules containing public definitions.
  • Does not apply to: Empty modules or modules with only private entities.
  • Operation:
    1. Select the name of the module in the USE statement you wish to add an ONLY clause to.
    2. Choose Refactor > Use Statement > Add Only Clause to Use Statement.
    3. Select which module entities you wish to include in the ONLY list. Any entities in an existing ONLY list will already be selected and can be deselected to be removed.
      Add ONLY to USE dialog
    4. Click Preview to see what changes will be made, then click OK to apply them.
  • Example
    Example of Add ONLY clause to USE statement refactoring.

Minimize ONLY List

  • Description: Deletes symbols that are not being used from the ONLY list in a USE statement.
  • Applies To: USE statements with an ONLY clause.
  • Operation:
    1. Select the name of the module in the USE statement you wish to minimize the ONLY list for.
    2. Choose Refactor > > Use Statement > Minimize Only List.
    3. Click Preview to see what changes will be made, then click OK to apply them.
  • Example
    Example of Minimize ONLY list refactoring.

Common Block Refactorings

Make Common Block Variable Names Consistent

  • Description: Fortran allows different definitions of a COMMON block to give the same variable different names. This is confusing. This refactoring gives the variables the same names in all definitions of the COMMON block.
  • Applies To: All COMMON blocks with a valid name.
  • Does not apply to: COMMON blocks with a NULL name.
  • Operation:
    1. Select the name of the COMMON block in the editor which you wish to make variable names consistent for.
    2. Choose Refactor > Common Block > Make Common Block Variable Names Consistent.
    3. Enter the new names which you wish to give the COMMON variables. The default new names are the original names in the selected block with "_common" appended.
      Make common var names consistent dialog
    4. Click Preview to see what changes will be made, then click OK to apply them.
  • Example
    Example of Make COMMON variable names consistent refactoring.
    Example of Make COMMON variable names consistent refactoring.

Move Saved Variables to Common Block

  • Description: Move Saved Variables to Common Block creates a common block for all "saved" variables of a subprogram. Declarations of these variables in the subprogram are transformed such that they are no longer "saved". The generated common block is declared both in the main PROGRAM and in the affected subprogram. Variables placed in the common block are renamed such that they do not conflict or shadow other variables. The current implementation assumes that the subprogram is in the CONTAINS section of the PROGRAM.
  • Applies To: Subprograms.
  • Operation:
    1. Click on the declaration statement of a subprogram.
    2. Click Refactor > Common Block > Move Saved Variables to Common Block.
    3. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Example of the Introduce Implicit None refactoring

Loop Refactorings

Interchange Loops

  • Description: Swaps inner and outer loops of the selected nested do-loop1. This refactoring merely switches the inner and outer do-headers. It will not make any changes to the body of the loop.
  • Applies To: Selected nested do-loop
  • Operation:
    1. Select the nested loops you wish to interchange
    2. Click Refactor > Do Loop > Interchange Loops. The Interchange loops dialog will appear.
    3. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Simple example of Interchange Loops refactoring

1. In order for refactoring to work correctly, there must be no statements before the second loop. If such statements exist, correctness of the refactoring is not guaranteed.

Fuse Loops

  • Description: Takes two do-loops, normalizes their bounds, and finally puts the loop bodies in a single do-loop.
  • Applies To: Find the two do-loops you want to fuse, and select only the first one1. If there are any statements in between the two loops, the statements will remain after the fused do-loop. In order for the loops to be compatible, the loops need to have the same number of iterations (the bounds do not need to be the same, just the number of times the body of the loop is accessed).
  • Operation:
    1. Select the first do-loop to be fused.
    2. Click Refactor > Do Loop > Fuse Loops.
    3. Click Preview to see a comparison view of the changes made, and OK to apply the changes.
  • Example:
    Example of Loop Fusion with loops of different bounds

1. The refactoring will find the next listed do-loop in your code (even with other lines of code in between them).

Reverse Loop

  • Description: Takes an incrementing or decrementing loop, swaps the lower and upper bounds, and negates the step.
  • Applies To: Selected do-loop
  • Operation:
    1. Select full do-loop or do-loop header
    2. Click Refactor > Do Loop > Reverse Loop.
    3. Click Preview to see a comparison view of the changes made, and OK to apply the changes.
  • Example:
    Example of Reverse Loop Refactoring

Tile Loop

  • Description: This refactoring takes a double nested do-loop, and creates a nested do-loop with four levels of depth. Instead of iterating through a two dimensional array (for example) by going through each row, it will loop over smaller tile blocks
  • Applies To: A double nested do-loop where both step values are 1.
  • Inputs:
    • Tile Size: The size of the accessing block or tile. So, if the tile size is 3, an array will be accessed in 3x3 blocks.
    • Tile Offset: Adjusts where the blocks start (all the data will always be covered no matter where it starts).
  • Operation:
    1. Select the whole nested do-loop, or the header of the top nested do-loop.
    2. Click Refactoring > Do Loop > Tile Loop.
    3. Enter a tile step and tile offset, then click preview to view changes, or OK to apply changes.
  • Example:
    Example of loop tiling with a tile size of 20 and a tile offset of 5.

Unroll Loop

  • Description: Takes the selected do-loop and either completely or partially unrolls it. This will also optionally include a conditional statement to make sure the loop stays in bounds.
  • Applies To: A do-loop that doesn't contain labels, and never writes to the index variable (Ex: read(*,*) indexVar)
  • Operation:
    1. Select the loop to unroll (or just the header).
    2. Click Refactoring > Do Loop > Unroll Loop.
    3. Select either the number of times you would like to unroll the loop, or check the "Complete unrolling" box. Uncheck the "Include bounds checking" box if you don't want a conditional statement to ensure proper loop bounds in numbered loop unrolling.
    4. Click Preview to see the changes this refactoring will make, and OK to make the changes.
  • Example(Numbered):
    Preview of unrolling a loop four times including a bounds check
  • Example(Complete):
    Preview of completely unrolling a loop

Refactorings to Remove Obsolete Language Features

Remove Arithmetic If

  • Description: This refactoring will remove all arithmetic if statements, a feature that became obsolete in Fortran 90, from a single file or all the files in a project.
  • Applies To: A project or file.
  • Operation:
    1. Select the project or file with arithmetic if statements to remove.
    2. Click Refactoring > Obsolete Language Features > Remove Arithmetic If Statements
    3. Click preview to view the changes without applying, or OK to apply the changes.
  • Example:
    Example of the Remove Arithmetic If Statement refactoring.

Remove Assigned Goto

  • Description: This refactoring will remove all assigned goto statements and replace them with case blocks.
  • Applies To: All assigned goto statements.
  • Operation:
    1. Click Refactoring > > Obsolete Language Features > Remove Assigned Goto.
    2. Choose Yes if you want to add a default case, otherwise choose No.
    3. Click preview to view the changes without applying, or OK to apply the changes.
  • Example:
    Example of the Remove Arithmetic If Statement refactoring.

Remove Branch to End If

  • Description: Removes the branch to END IF statements. The GOTO statements carry outbranching. Branching to end if is replaced with branching to CONTINUE statement that immediately follows the END IF statement.
  • Applies To: Selected end if statement
  • Operation:
    1. Select an end if statement with a statement label
    2. Click Refactor > Obsolete Language Features > Remove Branch to End If
    3. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Simple example of Remove Branch to End If refactoring

Replace Character* with Character(len=)

  • Description: Replaces character*n declaration with character(len=n) declaration.
  • Applies To: All character declarations
  • Operation:
    1. Select one of the character declaration statements
    2. Click Refactor > Obsolete Language Features > Replace Character* with Character(len=)... The Replace Character* with Character(len=) will appear.
    3. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Simple example of Replace Character* with Character (len=) refactoring

Remove Computed Goto

  • Description: Replaces computed goto statement with select case statement
  • Applies To: Selected computed goto statement
  • Operation:
    1. Select the computed goto statement you wish to remove
    2. Click Refactor > Obsolete Language Features > Remove Computed Goto. The Remove Computed Goto dialog will appear.
    3. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Simple example of Remove Computed Goto refactoring

Replace Obsolete Operators

  • Description: Replace Obsolete Operators replaces all uses of old-style comparison operators (such as .LT. and .EQ.) with their newer equivalents (symbols such as < and ==). and adds explicit declarations for all variables that were previously declared implicitly.
  • Applies To: All uses of the following operators in one or more files: .LT. .LE. .EQ. .NE. .GT. .GE.
  • Operation:
    1. This is a multiple-file refactoring.
      • To Replace Obsolete Operators in a single file, open the file in the editor and choose Refactor > Obsolete Language Features > Replace Obsolete Operators from the menu bar.
      • To Replace Obsolete Operators in multiple files, select the files in the Fortran Projects view, right-click on any of the selected filenames, and choose Refactor > Obsolete Language Features > Replace Obsolete Operators from the popup menu.
    2. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Example of the Replace Obsolete Operators refactoring

Replace Old-Style Do Loops

  • Description: Replaces old-style do loops with the modern style of do loops
  • Applies To: All old-style do loops
  • Operation:
    1. Click Refactor > Obsolete Language Features > Remove Old-Style Do Loops.
    2. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Simple example of Remove Old-Style Do Loop refactoring

Remove Pause Statement

  • Description: Replaces pause statement with empty print and read statements
  • Applies To: Selected pause statement
  • Operation:
    1. Select the pause statement you wish to remove
    2. Click Refactor > Obsolete Language Features > Remove Pause Statement.
    3. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Simple example of Remove Pause Statement refactoring

Remove Real/Double Precision Loop Counter

  • Description: Transforms a do or do while loop with control to a do or do while loop without control.
  • Applies To: Selected loop
  • Operation:
    1. Select the loop you wish to transform
    2. Click Refactor > Obsolete Language Features > Remove Real/Double Precision Loop Counter.
    3. Choose either do loop or do while loop.
    4. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Simple example of Remove Real/Double Precision Loop Counter refactoring

Refactorings to Improve Coding Style

Add Identifier to End Statement

  • Description: This refactoring will add the program/subprogram name to an end statement.
  • Applies To: A file or project.
  • Operation:
    1. Select the file or project.
    2. Click Refactoring > Coding Style > Add Identifier to End Statement
    3. Click preview to view the changes without applying, or OK to apply the changes.
  • Example:
    Example of Add Identifier to END statement refactoring.

Change Keyword Case

  • Description: Makes all applicable keywords the same case throughout the selected Fortran program files.
  • Applies To: All keywords except those listed below.
  • Does not apply to:
    1. Identifiers
    2. All constants except for integer constants and real constants
  • Operation:
    1. This is a multiple-file refactoring.
      • To Change Keyword Case in a single file, open the file in the editor and choose Refactor > Coding Style > Change Keyword Case from the menu bar.
      • To Introduce Implicit None in multiple files, select the files in the Fortran Projects view, right-click on any of the selected filenames, and choose Refactor > Coding Style > Change Keyword Case from the popup menu.
    2. Select Upper or Lower Case
      Canonicalize keyword capitalization dialog.
    3. Click Preview to see what changes will be made, then click OK to apply them.
  • Example
    Example of Canonicalize Keyword Capitalization refactoring.

Convert Between If Statement and If Construct

  • Description: Converts a simple if statement to an if construct with a then block and possible else block.
  • Applies To: Selected if statement.
  • Operation:
    1. Refactor > Coding Style > Convert Between If Statement and If Construct
    2. Select whether or not you want an empty else block.
    3. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Example of the Convert Between If Statement and If Construct refactoring

Convert Data Statement to Parameter Statements

  • Description: When a variable declared in a DATA statement is intended to be a constant, Data to Parameter can be used to change it to a variable with the PARAMETER attribute. Using the PARAMETER attribute makes it more clear which variables are constants and which ones are not; it can also result in performance gains, since it may allow an optimizing compiler to replace some variable accesses with the constant value.
  • Applies To: All main programs, subprograms, and modules in one or more files.
  • Operation:
    1. This is a multiple-file refactoring.
      • To transform variables declared as data in variables declared with parameter attribute in a single file, open the file in the editor and choose Refactor > Coding Style > Convert Data Statement to Parameter Statements from the menu bar.
      • To transform variables declared as data in variables declared with parameter attribute in multiple files, select the files in the Fortran Projects view, right-click on any of the selected filenames, and choose Refactor > Coding Style > Convert Data Statement to Parameter Statements from the popup menu.
    2. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Example of the Data To Parameter refactoring

Introduce Implicit None

  • Description: Adds IMPLICIT NONE statements to a file and adds explicit declarations for all variables that were previously declared implicitly.
  • Applies To: All main programs, subprograms, and modules in one or more files.
  • Operation:
    1. This is a multiple-file refactoring.
      • To Introduce Implicit None in a single file, open the file in the editor and choose Refactor > Coding Style > Introduce Implicit None from the menu bar.
      • To Introduce Implicit None in multiple files, select the files in the Fortran Projects view, right-click on any of the selected filenames, and choose Refactor > Coding Style > Introduce Implicit None from the popup menu.
    2. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Example of the Introduce Implicit None refactoring

Make Save Attributes Explicit

  • Description: Makes Save Attributes Explicit.
  • Applies To: The entire program.
  • Operation:
    1. Refactor > Coding Style > Make Save Attributes Explicit
    2. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Example of the Make Save Attributes Explicit refactoring

Remove Unreferenced Labels

  • Description: Removes any unreferenced labels.
  • Applies To: All unreferenced labels.
  • Operation:
    1. Refactor > Coding Style > Remove Unreferenced Labels
    2. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Example of the Remove Unreferenced Labels refactoring

Remove Unused Local Variables

  • Description: Remove Unused Variables removes declarations of local variables that are never used.
  • Applies To: All main programs, subprograms, and modules in one or more files.
  • Operation:
    1. This is a multiple-file refactoring.
      • To Remove Unused Variables in a single file, open the file in the editor and choose Refactor > Coding Style > Remove Unused Local Variables from the menu bar.
      • To Remove Unused Variables in multiple files, select the files in the Fortran Projects view, right-click on any of the selected filenames, and choose Refactor > Coding Style > Remove Unused Local Variables from the popup menu.
    2. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Example of the Remove Unused Variables refactoring

Standardize Statements

  • Description: Standardize Statements rewrites all variables declarations, so that
    • there is only one variable declaration per line, and
    • every variable declaration contains a double colon (::).
    This is intended to make the code more readable.
  • Applies To: All main programs, subprograms, and modules in one or more files.
  • Operation:
    1. This is a multiple-file refactoring.
      • To Standardize Statements in a single file, open the file in the editor and choose Refactor > Coding Style > Standardize Statements from the menu bar.
      • To Standardize Statements in multiple files, select the files in the Fortran Projects view, right-click on any of the selected filenames, and choose Refactor > Coding Style > Standardize Statements from the popup menu.
    2. Click Preview to see what changes will be made, then click OK to apply them.
  • Example:
    Example of the Standardize Statements refactoring

Debugging

These refactorings are used to debug your program.

Highlight Variable Accesses

  • Description: Creates a file of your code where the variables are highlighted according to whether they are read or write variables.
  • Applies To: The entire program.
  • Operation:
    1. Refactor > Debugging > Highlight Variable Accesses
  • Example:
    Example of the Highlight Variable Accesses refactoring

Display Symbol Table for Current File

  • Description: Creates file with a list of all the variables. Lists the name and type of variable and the line where the variable was declared.
  • Applies To: The entire program.
  • Operation:
    1. Refactor > Debugging > Display Symbol Table for Current File
  • Example:
    Example of the Display Symbol Table for Current File refactoring

Find All Declarations in Scope

  • Description: Gives a list of all the declarations that are in the scope of the line you're on.
  • Operation:
    1. Refactor > Debugging > Find All Declarations in Scope
    2. You will see a list of all the variables that are in scope. You can type in a variable to see if it is in scope.
  • Example:
    Example of the Find All Declarations in Scope refactoring

Select Enclosing Scope

  • Description: Highlights the entire range of source text corresponding to a token’s enclosing ScopingNode.
  • Operation:
    1. Click on a token in the editor.
    2. Refactor > Debugging > Select Enclosing Scope

Display Error/Warning Log

  • Description: Creates file with a log of errors and warnings.
  • Operation:
    1. Refactor > Debugging > Display Error/Warning Log

Resolve Interface Binding

  • Description: Resolves all interface binding.
  • Operation:
    1. Refactor > Debugging > Resolve Interface Binding

Find Matching Interface Declarations

  • Description: Finds matching interface declaration for an identifier in a subprogram declaration.
  • Operation:
    1. Refactor > Debugging > Find Matching Interface Declarations

Display Binder Statistics

  • Description: Creates file with a list of average and maximum times for ReferenceCollider, ModuleLoader, etc.
  • Operation:
    1. Refactor > Debugging > Display Binder Statistics
  • Example:
    Example of the Display Binder Statistics refactoring

    Reset Binder Statistics

    • Description: Resets the Binder Statistics. If you Display Binder Statistics, there will be no data under Average Times.
    • Operation:
      1. Refactor > Debugging > Reset Binder Statistic

    Display Database Statistics

    • Description: Creates file with stats on how many times methods such as getIncomingEdgesTo, getAnnotation, and isOutOfDate have been called.
    • Operation:
      1. Refactor > Debugging > Display Database Statistics
    • Example:
      Example of the Display Database Statistics refactoring

    Reset Database Statistics

    • Description: Resets the Database Statistics. If you Display Database Statistics, there will be no data.
    • Operation:
      1. Refactor > Debugging > Reset Database Statistic

    Display Database

    • Description: Creates file with database statistics on dependencies, edges, and modification stamps.
    • Operation:
      1. Refactor > Debugging > Display Database
    • Example:
      Example of the Display Database refactoring

    Display Edge Model of Current File

    • Description: Creates file that has info on all of the edges.
    • Operation:
      1. Refactor > Debugging > Display Edge Model of Current File
    • Example:
      Example of the Display Edge Model of Current File refactoring

    Ensure Database is Up-to-Date

    • Description: Makes sure that the database is up-to-date.
    • Operation:
      1. Refactor > Debugging > Ensure Database is Up-to-Date

    Clear and Rebuild Database

    • Description: Clears and rebuilds the database.
    • Operation:
      1. Refactor > Debugging > Clear and Rebuild Database

    Browse VPG Database

    • Description: Allows you to view all edges, dependencies, and annotations for all files.
    • Operation:
      1. Refactor > Debugging > Browse VPG Database
      2. Select a file and switch between edges, dependencies, and annotations on the right side of the box.
    • Example:
      Example of the Browse VPG Database refactoring

    Not Yet Available

    The following refactorings have been submitted but are not yet included in Photran.

    Add Use Of Named Entities

    • Description: This refactoring adds the statement use M, only: ... to another module, if a similar statement does not already exist. It fails if this will result in a naming conflict, the introduction of circular dependencies between modules, or if a statement use M already exists but renames any named entities.
    • Applies To: A list of named entities.
    • Operation:
      1. Move your cursor to the module you want to "use".
      2. Click Refactoring > Add Use Of Named Entities to Modules.
      3. Select the named entities you would like to use, and the module you want to use them in.
      4. Click preview to view the changes, and OK to apply the changes.
    • Example:
      Example of the Add Use Stmt refactoring.

      Move Module Entities

      • Description: This refactoring moves a set of named entities from one module to another, and updates all use statements that reference these modules.
      • Applies To: A list of named entities.
      • Operation:
        1. Move your cursor to the module with the entities you would like to move.
        2. Click Refactoring > Move Module Entities.
        3. Select the named entities you would like to move, and the module you want to move them to.
        4. Click preview to view the changes, and OK to apply the changes.
      • Example:
        Move Module Entities example.


        Change Subroutine to Function

        • Description: This refactoring will change a subroutine to a function. The refactoring fails if there are no intent out arguments.
        • Applies To: A file.
        • Operation:
          1. Select the subroutine name or subroutine statement that needs to be changed to a function
          2. Click Refactoring > Change Subroutine To Function.
          3. Click preview to view the changes without applying, or OK to apply the changes.
        • Example:
          Example of Change Subroutine to Function refactoring.

        Convert Specification Statement to Declaration Attribute

        TODO

        Toggle End Name

        TODO

        Standardize Input Output Format

        TODO

Back to the top