Home

Photran 7.0 User's Guide pdf version

image

Contents

1. Remove Unreterenced labels o Changes to be performed a pr v Y Remove Unreferenced Labels Me A File foo SABA Original Source Refactored Source doi 1 9 doi 1 9 250 print 1 print i END DO END DO lil do i 1 9 do i 1 9 300 print i print i END DO END DO LE r GI ry Figure 3 36 3 8 REFACTORINGS TO IMPROVE CODING STYLE TT Remove Unused Variables e Description Remove Unused Variables removes declarations of local va riables that are never used e Applies To All main programs subprograms and modules in one or more files e 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 Remove Unused 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 Remove Unused Variables from the popup menu 2 Click Preview to see what changes will be made then click OK to apply them e Example Example of the Remove Unused Variables refactoring Changes to be performed ec gt Figure 3 37 78 CHAPTER 3 REFACTORING Standardize Statements e Description Standardize Statements rewrites all variables declarations so that there is only one variable declaration per line and every var
2. FF private 90 SAGA Original Source Refactored Source 4 integer private optional pri 4 integer private optional real hi 5 real hi 6 private hi HH 6 public hi 7 7 o intrinsic hello 2 intrinsic hello E external goodbye 9 external goodbye 1 private hello 1 private hello 11contains licontains 2 subroutine hello 12 subroutine hello private 13 private 4 Mi r 4 m Figure 3 5 Example 2 of make private entity public refactoring Encapsulate variable e Description Encapsulate variable creates getter and setter methods for the selected variable in the module where it is defined and changes varia ble s visibility to private It also replaces all uses of that variable in all files to use getter and setter method calls1 e Applies To 1 Variables defined in the module 2 Variables of all basic as well as user defined types e 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 e Operation 1 Click on or select the name of variable you want to encapsulate 2 Click Refactor Encapsulate Variable The Encapsulate Variable dialog will appear Getter and setter name menu for encapsulating variable temp 3 3 MODULE REFACTORINGS 49 ISnio Extract Procedure Extract selected
3. 9 evel t E j 1 9 USING THE FORTRAN EDITOR AND FORTRAN PERSPECTIVI21 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 ge nerally 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 Un der 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
4. external change_c common a h Toggle Breakpoint Disable Breakpoint Breakpoint Properties Morel a Joona 30 to Annotation Ctri 1 Add Bookmark lo h Add Task vV Show Quick Diff Ctrl Shift Q Show Line Numbers Preferences b 2 3 c 4 5 print a b c When you switch to the Debug perspective the breakpoints you set will be listed in the Breakpoints view For more information on debugging click on Help Help Contents in Eclipse and navigate to C C Development User Guide Tasks Running and de bugging projects Debugging Known Run Debug Issues 1 13 COMPILER SPECIFIC PROBLEMS 29 When using Cygwin in Windows debugging a program can result in a cannot find gcc source error as described in Bug 280492 Note that this error does not have an effect on the running of the program The program will still run correctly in Debug mode 1 13 Compiler specific problems G95 In debug mode using the step button to step through the code line by line sometimes jumps leapfrog effect around in the source code editor view For example pressing F6 step after a breakpoint several times might sometimes result in a jump to line 1 and stepping again will return to the correct line in the code gFortran No known issues Intel Fortran Compiler No known issues IBM XLF No known issues 1 14 Advanced Features Photran 7 0 includes a number of sophisticated features that are designed t
5. s mirror at gtlib gatech edu is generally quite fast and reliable for example 2 Add the Cygwin directories to your Windows PATH Under Windows XP the process is as follows a Make sure you are logged in under an administrator account b Open the Control Panel c Double click the System icon d Switch to the Advanced tab e Click the Environment Variables button f Under System Variables find the variable Path in the list and click on it g Click Edit h At the end of the Variable Value text add i Click OK click OK click OK and close the Control Panel j Close and re open Photran Windows should now search Additional Instructions for Mac OS X Users If you install gfortran on Mac OS X it may be installed in usr local bin which is not by default on the PATH If you are launching Eclipse from a Terminal the PATH can be set by modifying etc paths However if you are launching Eclipse from the Finder by double clicking on it or the Dock then the PATH is not obtained from the shell or etc paths Instead it s obtained 1 4 GETTING STARTED 9 from MacOSX environment plist The format of the environment plist file is as follows change the path appropriately If you create or edit this file you will need to log out or reboot before the changes will take effect lt xml version 1 0 encoding UTF 8 gt lt DOCTYPE plist PUBLIC Apple Computer DTD PLIST
6. cing 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 e Caveats The refactoring will only be allowed to proceed if extracting the subexpression will preserve the associativity and precedence of the ori ginal 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 e Operation 1 Select an expression in the editor 2 Click Refactor Extract Local Variable The Extract Local Varia ble 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 44 CHAPTER 3 REFACTORING 3 2 Subprogram Refactorings Add Subroutine Parameter e Description This refactoring will add a parameter to a subroutine e Applies To A subroutine e 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 e Example E Add Sub
7. d e amp contains type t Cf amp subroutine s complex Ch implicit none type t integer n end type Kn opaco 3 3 3 0 3 3 h G 4 lend subroutine end program end subroutine end program Figure 3 34 3 8 REFACTORINGS TO IMPROVE CODING STYLE 75 Make Save Attributes Explicit e Description Makes Save Attributes Explicit e Applies To The entire program e 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 e Example Example of the Make Save Attributes Explicit refactoring Make Save Attributes Explicit Changes to be performed amp F Y Y 43 Make Save Attributes Explicit B Brile foo SABA Original Source Refactored Source subroutine sub subroutine sub IE integer counter 0 HF integer SAVE counter 0 IF counter counter 1 counter counter 1 a print counter print counter end subroutine end subroutine Figure 3 35 76 CHAPTER 3 REFACTORING Remove Unreferenced Labels e Description Removes any unreferenced labels e Applies To All unreferenced labels e Operation 1 Refactor Coding Style Remove Unreferenced Labels 2 Click Preview to see what changes will be made then click OK to apply them e Example Example of the Remove Unreferenced Labels refactoring
8. 1 0 EN http www apple com DTDs PropertyList 1 0 dtd gt lt plist version 1 0 gt lt dict gt lt key gt PATH lt key gt lt string gt usr local mpi bin usr local bin bin sbin usr bin usr sbin sbin usr sbin Developer Tools usr texbin Users greg bin lt string gt lt dict gt lt plist gt 1 4 Getting Started Photran is an integrated development environment and refactoring tool for Fortran 77 90 95 and 2003 It includes an editor with smart syntax high lighting a GUI debugger CVS support Makefile based compilation error mes sage recognition for many common Fortran compilers Fortran language based search and code navigation content assist a Fortran declaration view and many refactorings including popular refactorings such as Rename and Extract Procedure as well as Fortran specific refactorings like Introduce Implicit None Photran is based on Eclipse and some of its components are reused from the Eclipse C C Development Tools CDT Throughout this documentation you will see references to relevant parts of the Eclipse and CDT documentation which can be accessed by clicking on the Help menu inside Photran Eclipse and clicking Help Contents If you have never used Eclipse before please work through the Eclipse Workbench tutorial before attempting to use Photran Click on Help Help Contents in Eclipse and navigate to Workbench User Guide Getting started Basic tutorial This will intro
9. 22 Operators f90 LoopTest F Operators f90 SABA Original Source Refactored Source if 1 Tt 2 and 3 le 4 if 1 lt 2 and 3 lt 4 amp or 5 une 6 amp or 5 26 amp print print lend program lend program 2 7 Figure 3 26 Replace Old Style Do Loops e Description Replaces old style do loops with the modern style of do loops e Applies To All old style do loops e 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 e Example Simple example of Remove Old Style Do Loop refactoring 3 7 REFACTORINGS TO REMOVE OBSOLETE LANGUAGE Replace Old Style Do Loops a a Changes to be performed LDL Py Y Y Replace Old Style Do Loops FF File f9o Sa ZA Original Source Refactored Source T a o BOF 1 9 HH doi i 9 250 print 1 _ 250 print i END DO do 300 1 1 9 El 300 print i drsi S o 300 print i 3l END DO E E Figure 3 27 Remove Pause Statement e Description Replaces pause statement with empty print and read state ments e Applies To Selected pause statement e Operation 1 Select the pause statement you wish to remove 2 Click Refactor Obsolete Language Features Remove Pause Sta tement 3 Click Preview to see what chan
10. Date Te Le_Data_To_Parameter 82 9 512457 y d3 10 17 comment 3 1 27 API 27 snd m4 values have been modified they are not parameters Figure 3 33 74 CHAPTER 3 REFACTORING Introduce Implicit None e Description Adds IMPLICIT NONE statements to a file and adds expli cit declarations for all variables that were previously declared implicitly e Applies To All main programs subprograms and modules in one or more files e 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 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 Introduce Implicit None from the popup menu 2 Click Preview to see what changes will be made then click OK to apply them e Example Example of the Introduce Implicit None refactoring ano Introduce Implicit None Changes to be performed LL Flr M v amp Introduce Implicit None mM 2 crazyimplicits f90 org eclipse photran samples src implicits 3 E crazyimplicits f90 BABA Original Source Refactored Source program p program p a 3 implicit none d 4 real a stop real d contains a 3 subroutine s d 4 implicit integer a c g stop real
11. Error Parser for Lahey Fujitsu Fortran 7 1 Photran Error Parser for NAG Fortran Photran Error Parser for PGI Fortran Photran Error Parser for Intel Fortran 8 1 Recognizing Executables Binary Parsers In order to run execute your Fortran application you will need to tell Eclipse which Binary Parser s to use for your project This can be done in the project properties Right click project Properties Fortran Build Settings Binary Parsers Tab Which binary parser you want to use will depend on the operating system environment you are working in For example the default choice is the Elf Parser which is for Linux environments Windows users would need to deselect the Elf Parser and select the PE Windows Parser and or the Cygwin PE Parser Mac users should choose the Mach O parser 1 12 RUNNING AND DEBUGGING FORTRAN PROGRAMS Properties for fortranCommon type filter text Resource Builders C C Build C C General a Fortran Build Discovery options Environment Settings Tool chain editor Variables Fortran General Project References Run Debug Settings Task Repository Task Tags Validation Settings Configuration Debug Manage Configurations Tool Settings Build Steps T Build Artifact Binary parser Binary Parsers 3 Error Parsers Y PE Windows Parser Y Cygwin PE Parser Elf Parser Mach O Parser HP UX SOM Parser GN
12. Fortran Projects view a Fortran project will have an F icon while a C C project will have a C icon To convert an existing C C project to a Fortran project 1 2 1 7 Switch to the Fortran perspective In the Fortran Projects view right click on the project you want to con vert and select Convert to Fortran Project from the pop up menu The project should now have an F icon in the Fortran Projects view ES LSThis_is_a C project be 15 This_is_a_Fortran_project Upgrading Projects Created with Earlier Versions of Photran There are three major changes in Photran 6 that affect users of previous ver sions of Photran 1 Projects must be converted to Fortran projects In the past Photran would treat C projects and Fortran projects similarly In fact in Photran 4 and earlier versions Photran s new project wizard actually created C projects But in Photran 6 many of Photran s features will only be available after a project is converted to a Fortran project Every Fortran project is a C project too so CDT s features will still work on the project Learn how to convert projects Project properties must be reset Photran 6 uses a new mechanism for storing project properties Unfortunately this means that the project properties for old projects must be re created This includes enabling analysis refactoring and setting include paths and module paths Source form settings must be
13. Window Preferences Under General Editors Text Editors check the box next to Show whi tespace 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 Colors and Fonts Qr ge v Y General Colors and Fonts any character any string Vv Appearance Colors and Fonts Label Decoratior Capabilities A aiin b la cvs Compare Patch gt fe Debug Content Types bile ave v Editors b Text Compare Keys A b G View and Editor Folders v Network Connectior Perspectives Search v Security v Startup and Shutdc Web Browser D Workspace Ant C C Fortran gt Help Install Update Description Java Plug in Development Run Debug Preview No preview available Y Y V YY YY YY Team Restore Defaults Apply 1 9 USING THE FORTRAN EDITOR AND FORTRAN PERSPECTIVE3 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 y J v General V e a a a a a A d D A
14. 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 16 CHAPTER 1 INSTALLING PHOTRAN 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 perspec tive 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 ma nually 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 gt Other and selecting a new view from the Show View dialog You can also reset the current perspective to its origina
15. 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 e 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 e Applies To Local variables1 2 Subprograms3 including external and interface declarations Derived types Module entities variables and subprograms Main programs Namelists Common blocks o NI non A 0 N e Block data subprograms e 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 3 1 INTRODUCTION 41 F Match external subprograms with interfaces and external declarations Preview gt 4 Cancel 3 ox 4 If you are renaming an external subprogram or a subprogram de clared in an interface block you may want to un check the box labeled Match external subprograms with interfaces
16. it to the file cdt master 7 0 0 12010xxxxxxxx zip that you downloa ded above CHAPTER 1 INSTALLING PHOTRAN Click OK to close the Add Site dialog This will return you to the Install dialog Expand CDT Main Features and check the box next to Eclipse C C Development Tools Click on the Next button Click the Finish button and agree to the license to complete the installa tion After CDT is installed you will be asked to restart Eclipse You may then proceed to install Photran To install Photran start Eclipse then 10 Click on Help Install New Software Click on the Add button Click on the Archive button Point it to the file ptp master 4 0 0 12010xxxxxxxx zip that you down loaded above Click OK to close the Add Site dialog This will return you to the Install dialog Expand Fortran Development Tools Photran and check the boxes next to Photran End User Runtime and Rephraser Engine End User Runtime the latter is a supporting component If you are running Linux and have the Intel Fortran Compiler installed or if you are on a Macintosh and have the IBM XL Fortran compiler installed expand Fortran Compiler Support and select the appropriate compiler Note that you cannot install Intel Fortran compiler support unless you are running Linux Click on the Next button If you get an error me
17. 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 2 Right click on your project s folder in the Fortran Projects view Click on Properties Expand Fortran General in the list on the left and click on Analy sis Refactoring 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 Click OK 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 2 2 ADVANCED EDITING FEATURES 33 aoe Properties for MyProject type filter text Analysis Refactoring Sy Ov v Resource To enable Open Declaration Find All References the Fortran Declaration Builders view content assist and refactoring in Fortran programs check the following box A program database index will be updated every time C C Build a Fortran file is created or saved gt C C General 7 gt i mM Enable Fortran ana
18. the IBM XL Fortran compiler installed expand Fortran Compiler Support and select the appropriate compiler Note that you cannot install Intel Fortran compiler support unless you are running Linux 8 Click on the Next button 9 If you get an error message see below for troubleshooting information 10 Click the Finish button and agree to the license to complete the installa tion Troubleshooting Eclipse s installer gives notoriously cryptic error messages which unfortuna tely are out of Photran s control Some of the more common ones are below If you run into a different error message and cannot resolve it please ask for help on the Photran mailing list Problem You receive the following error message during installation Cannot complete the install because one or more required items could not be found Missing requirement 125xxxxxxxxxx 0 0 0 125xxxxxxxxxx requires org eclipse photran intel feature group 5 0 0 xxxx but it could not be found Solution You are attempting to install support for the Intel Fortran com piler but you are not running Linux Go back in the installation wizard and uncheck Linux Intel R Fortran Compiler Support Problem You receive the following error message during installation Cannot complete the install because one or more required items could not be found Software being installed Photran End User Runtime 7 0 x xxxxxxxxxxxx org eclipse photran feature group 7
19. to a value other than 72 To change the length of the line go to Window Preferences in the menu bar Under For tran 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 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 22 CHAPTER 1 INSTALLING PHOTRAN 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
20. unroll or just the header 2 Click Refactoring Loop Unrolling 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 e Example Numbered G a ie oe Changes to be performed l a 4 Loop Unrolling EF test4 f90 test4 E testa 190 sagal Refactored Source Figure 3 18 Preview of unrolling a loop four times including a bounds check e Example Complete 3 6 LOOP REFACTORING 59 Loop Unrolling lala Es Changes to be performed a Y 63 Loop Unrolling EF test4 f90 test4 I testa t90 Figure 3 19 Preview of completely unrolling a loop Tile Loop e 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 e Applies To A double nested do loop where both step values are 1 e Inputs o 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 o Tile Offset Adjusts where the
21. 0 x xxxxxxxxxxxx Missing requirement Photran VPG CDT Interface Plug in 7 0 x xxxxxxxxxxxx org eclipse photran cdtinterface vpg 7 0 X XXXXXXXXxxxx requires bundle org eclipse cdt core 0 0 0 but it could not be found Cannot satisfy dependency From Photran End User Runtime 7 0 X XXXxxxxxxxxx org eclipse photran feature group 7 0 x xxxxxxxxxxxx To org eclipse photran cdtinterface vpg 7 0 x xxxxxxxxxxxx 8 CHAPTER 1 INSTALLING PHOTRAN Solution You do not have CDT 7 0 installed and it couldn t be down loaded and installed automatically Try installing CDT 7 0 first then retry installing Photran Additional Instructions for Windows Users To compile and run Fortran programs in Photran you will need to have a Fortran compiler and make utility installed gfortran and GNU Make are com monly used and free Most Linux Unix distributions include these Under Windows you will need to install Cygwin 3 which optionally includes gfor tran and GNU Make or MinGW 4 and put them on your Windows PATH Instructions for Cygwin 1 Install Cygwin the defaults are mostly OK but you will need to expli citly tell it to include the Devel packages at least gcc4 fortran gdb and make when the installer asks you to select what packages to ins tall If gcc4 fortran is not listed under the Devel packages you may have chosen a bad mirror restart the Cygwin installation and choose a different mirror instead Georgia Tech
22. Any entities in an existing ONLY list will already be selected and can be deselected to be removed Add ONLY to USE dialog 2 Add ONLY clause to USE statement lala 2 Select the module entities to add to the ONLY clause onlytest El help_common3 Click OK to add the ONLY clause to the selected USE statement To see what changes will be made click Preview Preview gt Cancel 4 Figure 3 9 4 Click Preview to see what changes will be made then click OK to apply them e Example see figure 3 10 3 4 USE STATEMENT REFACTORINGS 51 73 Add ONLY clause to USE statement EEE Changes to be performed tolg 7 amp Add ONLY clause to USE statement E testl 90 addOnlyTest F test1 f90 AAA Original Source Refactored Source 3use module3 3use module3 only onlytest a 4use module4 only help_common4 4use module4 only help_common4 Simplicit none Simplicit none Bl 7common block a b c mem r f t 7common block a b c mem r f Sinteger a Sinteger a 9real b 9real b 10double precision c 10double precision c 12integer r f t 12integer r f t mas 5b 4 6 fc 2 3 4 m Figure 3 10 Example of Add ONLY clause to USE statement refactoring Minimize ONLY List e Description Deletes symbols that are not being used from the ONLY list in a USE statement e Applies To USE statements with an ONLY clause e Operation 1 Select t
23. 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 Analy sis Refactoring see screenshot fig 2 3 4 Check the Enable Fortran analysis refactoring check box 31 32 CHAPTER 2 INTRODUCTION If you want to enable content assist the Fortran Declaration view etc check those boxes as well You may also want to set module and include paths at this point see fig 2 3 Click OK Setting Module and Include Paths If your source code contains INCLUDE lines or USE lines referencing modules in
24. Extensions Source Form Preprocessing f fix for fpp ftn F F77 FIX FOR FTN FPP fpp Fixed source form f08 f03 95 90 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 Pro perties 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 8 WRITING CODE 15 en Properties for FreeFormParserBugs type filter text Source Form Pr Hr v gt Resource Builders The list of Fortran filename extensions is determined C C Build by the workspace wide content type settings C C General Fortran Build Fortran General Source form filename associations File Name Extension Source Form Analysis Refactoring F Fixed Form INCLUDE lines ignored Export Settings Paths and Symbols F03 Free Form C Prepr
25. Lists the name and type of variable and the line where the variable was declared Applies To The entire program e Operation Refactor Debugging Display Symbol Table for Current File e Example Example of the Display Symbol Table for Current File refac toring 3 9 DEBUGGING 81 Find All Declarations in Scope e Description Gives a list of all the declarations that are in the scope of the line you re on e Operation Refactor Debugging Find All Declarations in Scope 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 e Example Example of the Find All Declarations in Scope refactoring 82 CHAPTER 3 REFACTORING Select Enclosing Scope e Description Highlights the entire range of source text corresponding to a token s enclosing ScopingNode e Operation Click on a token in the editor Refactor Debugging Select Enclosing Scope 3 9 DEBUGGING Display Error Warning Log e Description Creates file with a log of errors and warnings e Operation Refactor Debugging Display Error Warning Log 83 84 CHAPTER 3 REFACTORING Resolve Interface Binding e Description Resolves all interface binding e Operation Refactor Debugging Resolve Interface Binding 3 9 DEBUGGING 85 Find Matching Interface Declarations e Description Finds matching interface declaration for an identifier in a subprogram declaration e Operation Re
26. Photran 7 0 User s Guide pdf version Mariano M ndez September 28 2011 Contents Contents 1 Installing Photran 1 1 Prerelease installation instructions 1 2 System Requirements 1 3 Installation Procedure o e lA Getting Started neteco e wi ee ee a RO ae ON aE 1 5 Starting a New Project o e 1 6 Converting C C Projects to Fortran Projects 1 7 Upgrading Projects Created with Earlier Versions of Photran 1 8 Writing Code oa e lc e en ee S e 1 9 Using the Fortran editor and Fortran perspective 1 10 Compiling Fortran Programs 1 11 Building Projects vomitar haa a a E 1 12 Running and Debugging Fortran Programs 1 13 Compiler specific problems 1 14 Advanced Features o e e eee 1 15 Troubleshooting e e Introduction 2 1 Enabling Advanced Features o 2 2 Advanced Editing Features o 2 3 Search and Navigation o e Refactoring Sole Mtro Chis rce tt e an Gah A de a 3 2 Subprogram Refactorings o a 3 3 Module Refactorings o e e 3 4 Use Statement Refactorings o 3 5 Common Block RefactoringS 3 6 Loop Refactoring e e 3 7 Refactorings to Remove Obsolete Language Features 3 8
27. Refactorings to Improve Coding Style 3 9 Debugging ti ny ct e ee Oe wa as td e 3 10 Not Yet Available o 31 31 33 35 Chapter 1 Installing Photran 1 1 Prerelease installation instructions Prerelease versions of Photran 7 0 must be installed as follows The insta lation instructions in subsequent sections are currently incorrect and will be updated prior to the 7 0 release 1 Download the latest release candidate build of the Eclipse 3 6 SDK or Platform Runtime Binary 3 6RC1 from http download eclipse org eclipse downloads drops S 3 6RC1 201005131500 Download the latest release candidate build of CDT 7 0 from http download eclipse org tools cdt builds 7 0 0 index html Download the latest release candidate build of PTP 4 0 from http wiki eclipse org PTP builds 4 0 0 this includes Photran 7 0 To start Eclipse 1 On Windows unzip the file eclipse xxxxx zip that you downloaded above into a directory of your choice and launch eclipse exe You may need to run it with administrator privileges On Linux or Mac OS X untar the file eclipse xxxxx tar gz that you down loaded above and launch the eclipse binary Before you can install Photran into Eclipse you will need to install CDT To install CDT 1 2 3 4 Click on Help Install New Software Click on the Add button Click on the Archive button Point
28. U Elf Parser E AIX XCOFF32 Parser Move Up Move Down tir ic New Go Into Index Copy Paste Delete Move Import Export Refresh Run As Validate Team 1 12 Open in New Window Exclude from build Build Configurations Make targets Build Project Clean Project Remove from Context Rename Close Project Debug As Convert To Compare With Restore from Local History PDE Tools Properties File Edit Refactor Navigate Search Run Project Window Help amp Br Br O rQ Arr Ctrl Alt Shift Down E 1 Local C C Application E 2 Local Fortran Application Run Configurations 5 6 e6 G BE Outline 23 IB lt Free Form Source gt hello F x e GO arn ntime EclipseApplicationitest Debugltestexe 7 17 09 1031 A Fem oe Make Target 5 PARLO Running and Debugging Fortran Programs To run a Fortran application right click the project in the Fortran Projects view and click Run As Local Fortran Application This will build and run the Fortran application and output will be printed to the console Remember if you are using a custom makefile the makefile will need to be written correctly for the project to be built If you want to manage the run configuration for example if you want to pass comma
29. Unix systems include these details on installing them in Windows and Mac are below 1 3 Installation Procedure Installing on a Machine With Internet Access To install Photran start Eclipse then 1 Click on Help Install New Software 2 Click on the Add button 3 In the Location field type http download eclipse org tools ptp releases helios 4 Click OK to close the Add Site dialog This will return you to the Install dialog b 5 Expand Fortran Development Tools Photran and check the box next to Photran End User Runtime 6 CHAPTER 1 INSTALLING PHOTRAN 6 If you are running Linux and have the Intel Fortran Compiler installed or if you are on a Macintosh and have the IBM XL Fortran compiler installed expand Fortran Compiler Support and select the appropriate compiler Note that you cannot install Intel Fortran compiler support unless you are running Linux 7 Click on the Next button 8 If you get an error message see below for troubleshooting information 9 Click the Finish button and agree to the license to complete the installa tion Installing on a Machine Without Internet Access You will the following files If you do not have CDT installed you will need to download the latest 7 0 x CDT master update archive from http download eclipse org tools cdt releases helios This should be a file named cdt master 7 0 x zip for some value of x To install Photr
30. _common appended Make common var names consis tent dialog 4 Click Preview to see what changes will be made then click OK to apply them e Example Example of Make COMMON variable names consistent refac toring 3 5 COMMON BLOCK REFACTORINGS 53 3 Make COMMON variable names consistent lala x J Original Name New Name c c_ common la d_common e e common Preview gt Cancel 3 Make COMMON variable names consistent ii ole x anges to be performe th ch formed 3 Y Make COMMON variable names consistent 71 22 common f90 commonStuff eP moreCommon f90 commonstuff a common f90 aa 4 al Original Source Refactored Source common common c d e common2 f g common common c_common d_common complex c complex c_ common dimension c 3 dimension c common 3 double precision d e f g h Y double precision d e f g double precision d double precision d_common double precision e double precision e_common il double precision f double precision f double precision g double precision g E double precision h double precision h a 1 a 1 b 2 3 b 2 3 c 4 5 c_common 4 5 be Figure 3 12 Move Saved Variables to Common Block e 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 transf
31. am test 2 impLicit none integer a 0 4 callos 5 end progr w a Local variable integer a srl 2 hi Subroutine a pring world Subroutine 3 end subraabs Intrinsic 19 achar Intrinsic 11 subroutin acos Intrinsic jee print adjust Intrinsic a adjustr Intrinsic aimag Intrinsic aint Intrinsic AA 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 Declaration View The Fortran Declaration view displays the statement where a variable pro gram 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 state ment 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 sub programs it displays the FUNCTION or SUBROUTINE statement including any comments that precede it ia morecommon 0 a common a b integer a real poh common common d e common2 f g common3 h complex c dimension c 3 double precisi double
32. an you will need the latest PTP update site archive from http wiki eclipse org PTP builds 4 0 0 This should be a file named ptp master 4 0 0 I2010xxxxxxxx zip If you do not have CDT installed start Eclipse then 1 Click on Help Install New Software 2 Click on the Add button 3 Click on the Archive button 4 Point it to the file cdt master 7 0 x zip 5 Click OK to close the Add Site dialog This will return you to the Install dialog 6 Expand CDT Main Features and check the box next to Eclipse C C Development Tools 7 Click on the Next button 8 Click the Finish button and agree to the license to complete the installa tion 9 After CDT is installed you will be asked to restart Eclipse You may then proceed to install Photran To install Photran start Eclipse then 1 Click on Help Install New Software 2 Click on the Add button 3 Click on the Archive button 1 3 INSTALLATION PROCEDURE 7 4 Point it to the file ptp master 4 0 0 12010xxxxxxxx zip 5 Click OK to close the Add Site dialog This will return you to the Install dialog 6 Expand Fortran Development Tools Photran and check the boxes next to Photran End User Runtime and Rephraser Engine End User Runtime the latter is a supporting component 7 If you are running Linux and have the Intel Fortran Compiler installed or if you are on a Macintosh and have
33. 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 e Example Changes to be performed Y M wv amp Rename mM R F RenameEx f90 A ea Original Source Ey Refactored Source print twice n print two_times n end program end program o Returns the value that is twice n integer function two_times n O a v Returns the value that is twice n integer function twice n integer intent in n twice 2 n end function twice integer intentin n two_times 2 n end function two_times Preview gt Cancel ok gt 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 A2 CHAPTER 3 REFACTORING Extract Procedure e 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 proce
34. ar pea go 0 107 20 30 40 pn select case n E ase 1 got se 2 goto 20 case 3 go to 30 case 4 go to 40 end select lt Back J __ok cn Figure 3 25 Simple example of Remove Computed Goto refactoring Replace Obsolete Operators e Description Replace Obsolete Operators replaces all uses of old style comparison operators such as LT and EQ with their newer equiva lents symbols such as and and adds explicit declarations for all variables that were previously declared implicitly e Applies To All uses of the following operators in one or more files LT LE EQ NE GT GE e 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 gt Replace Obsolete Operators from the popup menu 2 Click Preview to see what changes will be made then click OK to apply them e Example Example of the Replace Obsolete Operators refactoring 66 CHAPTER 3 REFACTORING BOQ ss Replace Obsolete Operators Changes to be performed x mM w Replace Obsolete Operators mM
35. below Click File New File Call it Makefile Click Finish Create a Makefile similar to the one shown below Again we assume you are familiar with the structure of a Makefile You cannot simply copy and paste this example because the gfortran and rm lines must start with a tab not spaces The g switch instructs gfortran to include debugging symbols in the generated executable so that it can be debugged later The o switch tells it what to name the generated executable Click Project Clean then click OK Open the Console view and make sure make ran OK and compiled your program In the Fortran Projects view expand the Binaries entry and click on your executable e g hello exe x86le Click Run Run As Local Fortran Application Choose GDB Debugger Cygwin GDB Debugger if you re under Win dows Check the Console view and make sure Hello World appeared hello f90 program hello print Hello World end program Makefile You MUST replace the spaces beginning the gfortran and rm lines with a tab character all gfortran o hello exe g hello f90 clean rm f hello exe 1 6 1 6 CONVERTING C C PROJECTS TO FORTRAN PROJECTS 13 Converting C C Projects to Fortran Projects Every Fortran project is also a C project so CDT s functionality will work as expected on Fortran projects However a C C is not a Fortran project until it has been explicitly converted In the
36. blocks start all the data will always be covered no matter where it starts e Operation 1 Select the whole nested do loop or the header of the top nested do loop 2 Click Refactoring Loop Tiling 3 Enter a tile step and tile offset then click preview to view changes or OK to apply changes 4 e Example 60 CHAPTER 3 REFACTORING Figure 3 20 Example of loop tiling with a tile size of 20 and a tile offset of 5 3 7 Refactorings to Remove Obsolete Language Features Remove Arithmetic If Statements e 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 e Applies To A project or file e Operation 1 Select the project or file with arithmetic if statements to remove 2 Click Refactoring Obsolete Language Features Remove Arithme tic If Statements 3 Click preview to view the changes without applying or OK to apply the changes e Example 3 7 REFACTORINGS TO REMOVE OBSOLETE LANGUAGE FEATURES 61 ir YoY Remove Arithmetic If Statements Changes to be performed UAE Mv amp Remove Arithmetic If Statements Y 25 iftest f90 if test E iftest f90 AAA Original Source Refactored Source program iftest program iftest integer x 2 integer x 2 TF GO 10 20 30 if x lt 0 then goto 10 10 print x
37. chain from the toolchain list you may need to first uncheck the Show project types check box at the bottom of the win dow before you can see this Click Next Click on Advanced Settings Expand C C Build in the list on the left and click on Settings ao ND al Click on the Binary Parsers tab Check the appropriate parsers for your platform If you are using Windows check PE Windows Parser and or Cygwin PE Parser if you are using Linux check Elf Parser if you are using Mac check Mach O parser 9 Click on the Error Parsers tab Check the error parser s for the Fortran compiler s you will use 10 Click OK 11 Click Finish 12 Click File New Source File 13 Call it hello f90 click Finish 14 Type the standard Hello World program shown below and click File gt Save 15 Open the Console view and make sure make ran OK and compiled your program 16 In the Fortran Projects view expand the Binaries entry and click on your executable e g HelloFortran exe x86le 1 5 STARTING A NEW PROJECT 11 17 Run Run As Run Local Fortran Application 18 Choose GDB Debugger Cygwin GDB Debugger if you re under Win dows 19 Check the Console view and make sure Hello World appeared hello f90 program hello print Hello World end program Starting a Project with a Hand Written Makefile The following is a typical procedure for starting a new
38. code to a subroutine named Preview gt C Cancel 3 Ea Figure 3 6 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 e Example see figure 3 7 and 3 8 Gua CES Figure 3 7 Simple example of Encapsulate Variable refactoring 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 50 CHAPTER 3 REFACTORING Figure 3 8 Another simple example of Encapsulate Variable refactoring 3 4 Use Statement Refactorings Add ONLY Clause to USE Statement e Description Creates a list of the symbols that are being used from a module and adds it to the USE statement e Applies To All modules containing public definitions e Does not apply to Empty modules or modules with only private entities e Operation 1 Select the name of the module in the USE statement you wish to add an ONLY clause to 2 Choose Refactor Add ONLY clause to USE statement 3 Select which module entities you wish to include in the ONLY list
39. duce you to Eclipse concepts such as perspectives and views such terminology will be used throughout this manual 1 5 Starting a New Project One of the advantages or disadvantages of using Photran is that it does not include a Fortran compiler Instead it uses make to compile Fortran programs This allows you to use any Fortran compiler you want but it also means that a Makefile must be written which tells the make program how to compile your Fortran program e For small simple projects Photran can auto generate a Makefile which will use the GNU Fortran compiler gfortran e For more complex projects you can write a custom Makefile 10 CHAPTER 1 INSTALLING PHOTRAN For more information on project types click on Help Help Contents in Eclipse and navigate to C C Development User Guide Concepts CDT Projects Starting a Project with an Auto Generated Makefile The following is a typical procedure for starting a new project using an auto generated Makefile Your system must have the GNU Fortran gfortran compi ler installed for this procedure to work To make sure that gfortran is installed you can open a command prompt Windows or terminal window Linux Mac and type gfortran without the quotes it should respond with gfortran no input files 1 Click File New Fortran Project 2 Call it HelloFortran 3 Choose Executable Gnu Fortran from the project type list 4 Choose GCC Tool
40. dures shorter e Applies To A sequence of one or more action statements inside a proce dure or main program e 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 ANO Extract Procedure Extract selected code to a subroutine named subroutine Preview gt C Cancel ca 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 e Example WAN Extract Procedure Changes to be performed LDL M v amp Extract Procedure M LD ExtractExample f90 LoopTest P ExtractExample f90 BAA Original Source program ExtractExample real array 5 Refactored Source program ExtractExample F real array 5 array 50000 4000 300 20 17 call subroutineCarray print array end program print array O contains subroutine subroutine array implicit none real array 5 array 50000 4000 300 20 1 end subroutine end program 3 1 INTRODUCTION 43 Extract Local Variable e Description Extract Local Variable removes a subexpression from a lar ger expression and assigns that subexpression to a local variable repla
41. e gi implicit none do 1 1 10 2 print Mji end do do 1 0 4 1 do 3 21 25 1 print 18241 print 1 3 print 1 1 21 end do end do integer i end program test end program test Figure 3 16 Example of Loop Fusion with loops of different bounds Reverse Loop e Description Takes an incrementing or decrementing loop swaps the lo wer and upper bounds and negates the step e Applies To Selected do loop e Operation 1 Select full do loop or do loop header 2 Click Refactor Reverse Loop 3 Click Preview to see a comparison view of the changes made and OK to apply the changes e Example Changes to be performed 4 17163 Reverse Loop Unchecked EF test 90 test E testa 90 Original Source Refactored Source implicit none implicit none integer i integer i do i 1 10 2 do 1 10 1 2 print i print i end do end do end program test end program test ae a Gee Figure 3 17 Example of Reverse Loop Refactoring 58 CHAPTER 3 REFACTORING Unroll Loop e 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 e Applies To A do loop that doesn t contain labels and never writes to the index variable Ex read indexVar e Operation 1 Select the loop to
42. e Import or Export files and projects e Browse the high level structures in Fortran files e Open projects in a new window e 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 1 9 Using the Fortran editor and Fortran perspective Outline View F hello f90 E commonTest 90 E common f90 3 G BE Outline 8 _ Make Targets 7 5 1 4 8 pia xo v pe ser N HEB lt Free Form Source gt implicit none Y main gt change_c o E external changeab common a b integer a r real ni b common common c d e common2 f g common3 h complex c dimension c 3 double precision d e f g h double precision double precision double precision double precision double precision rane a ez 18 CHAPTER 1 INSTALLING PHOTRAN When a Fortran file is open in the For
43. efactored Source pao CONTINUE PRINT j j ifl 2 print i 2 a m a T oo Figure 3 32 3 8 REFACTORINGS TO IMPROVE CODING STYLE 73 Convert Data Statement to Parameter Statements e 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 e Applies To All main programs subprograms and modules in one or more files e 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 Data To Parameter 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 filena mes and choose Refactor Data To Parameter from the popup menu 2 Click Preview to see what changes will be made then click OK to apply them e Example Example of the Data To Parameter refactoring Changes to be pertormes 4 v M
44. efactorings to Improve Coding Style Add Identifier to End Statement e Description This refactoring will add the program subprogram name to an end statement e Applies To A file or project e 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 e Example Example of Add Identifier to END statement refactoring _ Fortran identifiertest identifier f90 Eclipse SDK CHAPTER 3 REFACTORING Changes to be performed M Y 4 Add Identifier to END E identifier 90 28 3a Original Source Refactored Source module testmodule module testmodule integer xfromtestmodule integer xfromtestmodule 19 en HHen e testmodule o function testfunction A function testfunction A integer intent in A integer intent in A testfunction 4 _ _ testfunction 4 A 20 end A comment after the end 20 end function testfunction A comment after the end m program fortrantest program fortrantest print Main program print Main program contains contains integer function testfunction A integer function testfunction A integer intent in A integer intent in A testfunction 4 _ ___testfunction 4 30 end function 30 end function testfunction O subrout
45. estsub 1 2 200 200 F 31054 call testsub 1 2 200 200 D 4 F 3 200 print hello world y E 14 end program testoptional 200 print hello world end program testoptional 16 subroutine testsub A B C D E F I lt lt lt lt lt 9 1 _ integer optional C Subroutine testsub A B D E F C lt lt lt lt lt integer optional E integer optional C character 3 D integer optional E end subroutine character 3 D end subroutine Cancel Figure 3 2 46 CHAPTER 3 REFACTORING Safe Delete e Description This refactoring will remove all Internal Subprograms from a given Host The refactoring fails if there are any references to the subprogram e Applies To A file e 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 e Example see figure 3 3 Safe Delete Non Generic Internal Subprogram Changes to be performed 4 Y Safe Delete Non Generic Internal Subprogram TEF test 190 TestProject F test f90 Original Source Refactored Source integer i j program test implicit none integer i j k end program test end program test Figure 3 3 Example of the Safe Delete Internal Subprograms refactoring 3 3 MODULE REFACTORINGS AT 3 3 Module Refactor
46. factor Debugging Find Matching Interface Declarations 86 CHAPTER 3 REFACTORING Display Binder Statistics e Description Creates file with a list of average and maximum times for ReferenceCollider ModuleLoader etc e Operation Refactor Debugging Display Binder Statistics e Example Example of the Display Binder Statistics refactoring 3 9 DEBUGGING 87 Reset Binder Statistics Description Resets the Binder Statistics If you Display Binder Statis tics there will be no data under Average Times Operation Refactor Debugging Reset Binder Statistic Display Data base Statistics Description Creates file with stats on how many times methods such as getIncomingEdgesTo getAnnotation and isOutOfDate have been called Operation Refactor Debugging Display Database Statistics Example Example of the Display Database Statistics refactoring 88 CHAPTER 3 REFACTORING Reset Database Statistics e Description Resets the Database Statistics If you Display Database Statistics there will be no data e Operation Refactor Debugging Reset Database Statistic 3 9 DEBUGGING 89 Display Database e Description Creates file with database statistics on dependencies edges and modification stamps e Operation Refactor Debugging Display Database e Example Example of the Display Database refactoring 90 CHAPTER 3 REFACTORING Display Edge Model of Current File e Description Creates
47. file that has info on all of the edges e Operation Refactor Debugging Display Edge Model of Current File e Example Example of the Display Edge Model of Current File refactoring 3 9 DEBUGGING Ensure Database is Up to Date e Description Makes sure that the database is up to date e Operation Refactor Debugging Ensure Database is Up to Date 91 92 CHAPTER 3 REFACTORING Clear and Rebuild Database e Description Clears and rebuilds the database e Operation Refactor Debugging Clear and Rebuild Database 3 9 DEBUGGING 93 Browse VPG Database e Description Allows you to view all edges dependencies and annotations for all files e Operation Refactor Debugging Browse VPG Database Select a file and switch between edges dependencies and annotations on the right side of the box e Example Example of the Browse VPG Database refactoring 94 CHAPTER 3 REFACTORING 3 10 Not Yet Available The following refactorings have been submitted but are not yet included in Photran Add Use Of Named Entities e Description This refactoring adds the statement use M only to anot her 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 e Applies To A list of named entities e Operation Move your cursor to the modu
48. g eclipse photran sam GQ sre fixed form Text iced G stc fortran and c References Pp filer G sre gaussian eliminati gt e integer blah adb G src language features aa 69 src line fitting gt sre modules src scoping GG src implicits 1 call add temp variable blah E src implicits 2 temp 5 k variable E 29 src implicits 3 src common contains G sre cray pointers subroutine add a b c 2 gt stc variable encapsulation integer result Ex gt settings result atb c Gy sre fortran2003 print result Gy src liebmann 1 eoshift A ne saa Gy stc liebmann 2 arrays Ey gt stc liebmann 3 loops cvsignore 11 fonction mult x y z integer res res x y z _ E gt liebmann 90 14 EAS y cctprnject tt end function mult Ey gt cproject 16 P project 1 2 4 t This will open the Eclipse Search dialog and the Fortran tab will be active There you can specify several things e The Search for frame allows you to specify whether it should search for subroutines functions modules variables etc e The Scope frame allows you to specify what file s will be searched e The Limit to frame allows you to specify whether you want to find de clarations references or both Fortran org eclipse photran sampl variable encapsulation main f90 Eclipse Platform Run Pi Hr O Q P B Ov Wh 97e eros 5 Navigator 6 a modulel f90 E main490 53 E file
49. ges will be made then click OK to apply them e Example Simple example of Remove Pause Statement refactoring 68 CHAPTER 3 REFACTORING G Remove Pause Statement oix Changes to be performed Dd ey Y Y Remove Pause Statement Mel Me ars za Original Source Refactored Source e ME print memorize these numbers 4 8 15 16 23 42 pause E print memorize these numbers 4 8 15 16 23 42 PRINT 17 READ 5 Figure 3 28 Remove Real Double Precision Loop Counter e Description Transforms a do or do while loop with control to a do or do while loop without control e Applies To Selected loop e 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 e Example Simple example of Remove Real Double Precision Loop Coun ter refactoring 3 8 REFACTORINGS TO IMPROVE CODING STYLE 69 Remove Real Double Precision Loop Counter ol ix f arenes to be performed 2 Ge Y Y Remove Real Double Precision Loop Counter E File f9o Aga original Source Refactored Source Gomi S sn E J j 1 end do do j 1 i AE i gt 10 THEN E J Figure 3 29 3 8 R
50. gt Help gt Install Update Java b Plug in Development gt Run Debug gt Team CHAPTER 1 Preferences Templates Create edit or remove templates INSTALLING PHOTRAN Name Context Description Auto Inse Y allocate Fortran Y ALLOCAT Fortran Y call Fortran Y CALL Fortran cA deallocat Fortran M DEALLO Fortran Y do while Fortran Y DO WHIL Fortran Allocate statement Allocate statement Call statement low Call statement upi Deallocate statemi Deallocate statemi Do while construct Do while construct on on on Re on on on on Import on GI E sth Preview Restore Defaults Apply 1 10 Compiling Fortran Programs To compile a project Photran generally executes whatever make command is on your system path On most systems this will invoke GNU Make As noted above when you create a project you can decide if Photran will auto generate a Makefile that uses GNU Fortran Intel Fortran or IBM XL Fortran or you can elect to hand write your own Makefile To use an automatically generated Makefile choose Executable Gnu For tran on XYZ from the Project type menu where XYZ is your platform Windows Linux or Mac OS X There are similar options available for Intel Fortran and IBM XL Fortran To create a project using a custom Makefile in the project type selection box expand the Makefile Projec
51. he name of the module in the USE statement you wish to minimize the ONLY list for 2 Choose Refactor Minimized ONLY list for Selected module 3 Click Preview to see what changes will be made then click OK to apply them e Example see figure 3 11 3 Minimize ONLY List Wlej x Changes to be performed glp Y amp Minimize ONLY List Y amp test2 f90 minOnlyListTest F test2 f90 SAQA Original Source Refactored Source lprogram test2 iprogram test2 use module only i helper 2 use module only helper implicit none implicit none call helper call helper 5end program test2 Send program test2 lt Back OK Cancel Figure 3 11 Example of Minimize ONLY list refactoring 3 5 Common Block Refactorings Make COMMON Variable Names Consistent e 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 e Operation 1 Select the name of the COMMON block in the editor which you wish to make variable names consistent for 2 Choose Refactor Make COMMON Variable Names Consistent form the menu bar 3 Enter the new names which you wish to give the COMMON varia bles The default new names are the original names in the selected block with
52. iable declaration contains a double colon This is intended to make the code more readable e Applies To All main programs subprograms and modules in one or more files e Operation 1 This is a multiple file refactoring To Standardize Statements in a single file open the file in the editor and choose Refactor 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 Standardize Statements from the popup menu 2 Click Preview to see what changes will be made then click OK to apply them e Example Example of the Standardize Statements refactoring ja Original Source Refactored Source program exanplo Standardize Statenents program exanple Standardize Statements el types Figure 3 38 3 9 DEBUGGING 79 3 9 Debugging These refactorings are used to debug your program Highlight Variable Accesses e Description Creates a file of your code where the variables are highligh ted according to whether they are read or write variables e Applies To The entire program e Operation Refactor Debugging Highlight Variable Accesses e Example Example of the Highlight Variable Accesses refactoring 80 CHAPTER 3 REFACTORING Display Symbol Table for Current File e Description Creates file with a list of all the variables
53. ine do_stuff subroutine do_stuff print Hip print Hil 4 end subroutine 40 end subroutine do_stuff end end program fortrantest subroutine do_stuff subroutine do_stuff _ Print Hi print Hi O 50 end 50 end subroutine do_stuff Figure 3 30 Change Keyword Case e Description Makes all applicable keywords the same case throughout the selected Fortran program files e Applies To All keywords except those listed below e Does not apply to 1 Identifiers 2 All constants except for integer constants and real constants e Operation 1 This is a multiple file refactoring To Change Keyword Case in a single file open the file in the edi tor and choose Refactor Canonicalize Keyword Capitalization 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 3 8 REFACTORINGS TO IMPROVE CODING STYLE 71 filenames and choose Refactor Change Keyword Case from the popup menu 2 Select Upper or Lower Case Canonicalize keyword capitalization dia log Cononicalae Keng Contant alaj z T Change keywords to Lower Case Upper Case Click OK to change the case of all keywords in the selected files To see what changes will be made click Preview 3 Click Preview to see what changes will be made then click OK to apply them e Example Exa
54. ings Make Private Entity Public e 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 Make Private Entity Public 3 Click Preview to see what changes will be made then click OK to apply them Example see figure 3 4 and 3 5 2 Make Private Entity Public loja x y Changes to be performed De p Y amp Make Private Entity Public 7 2 private 90 makePrivPubTest F private f90 AAA Original Source Refactored Source 4 integer private optional priv blah 4 integer private optional real hi 5 integer public optional priv private hi 6 real hi 0 7 private hi intrinsic hello 2 Mio external goodbye 9 intrinsic hello 5 1 private hello 0 external goodbye iicontains 11 private hello subroutine hello 12contains private 13 subroutine hello end subroutine 14 private end snhrontina m r 4 Figure 3 4 Example of make private entity public refactoring 48 CHAPTER 3 REFACTORING S Make Private Entity Public oo ae a Changes to be performed slg a 7 amp Make Private Entity Public 182 privatef90 makePrivPubTest
55. is negative else if x 0 then goto 40 goto 20 20 print x is zero else goto 40 goto 30 30 print x is positive end if 40 print end transmission 10 print x is negative ri goto 40 end nronram iftest 2 nrint x is zernl bd lt Back Cancel C Figure 3 21 Example of the Remove Arithmetic If Statement refactoring Remove Assigned Goto e Description This refactoring will remove all assigned goto statements and replace them with case blocks e Applies To All assigned goto statements e 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 e Example Example of the Remove Arithmetic If Statement refactoring 62 CHAPTER 3 REFACTORING Changes to be performed amp F B Y M amp Remove Assigned Goto Me File f90 MyProject 1 File fao S52 4a Original Source Refactored Source eal i j a real i j i 100 ASSIGN 100 to i E select case 1 goto 1 case 100 goto 100 100 print 100 case default stop Unknown label ASSIGN 200 to j end select goto j 100 print 100 200 print 200 j 200 select case j case 200 goto 200 case default stop Unknown Label end select g zes C C mM Figure 3 22 Remove Branch to End If e Description Rem
56. l 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 e The Fortran Projects view displays your project s and any files and folders in it e The Problems view will show errors from your Fortran compiler if Pho tran can recognize them This requires configuring an error parser des cribed elsewhere in this manual e 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 e The Fortran Declaration view is described in the Photran Advanced Fea tures manual e The Outline view shows the high level structure of your program i e the subprograms modules derived types etc comprising it e 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 Con tents in Eclipse and navigate to C C Development User Guide Reference gt C C Views and Editors Make Targets view 1 9 USING THE FORTRAN EDITOR AND FORTRAN PERSPECTIVEL7 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 e Manage existing files cut paste delete move or rename e Create new projects files or folders
57. lace Character with Character len will appear 3 Click Preview to see what changes will be made then click OK to apply them e Example 64 CHAPTER 3 REFACTORING Changes to be performed D F Y Y 83 Replace Character with Character len MIE File f90 MyProject P File f90 Laaa Original Source Refactored Source character 7 name Location character Len 7 name character 11 occupation character Len 7 location character middle_initial character Len 11 occupation character Len 1 middle_initial Y lt Back Cancel Figure 3 24 Simple example of Replace Character with Character len refactoring Remove Computed Goto e Description Replaces computed goto statement with select case state ment e Applies To Selected computed goto statement e 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 e Example 3 7 REFACTORINGS TO REMOVE OBSOLETE LANGUAGE FEATURES 65 Remove Computed Goto aren x Changes to be performed Lol 4 7 amp Remove Computed Goto 117 main190 ComputedGoToExample ES Refactored Source n Enter n from the kt read n Enter n from tH Will this disappear Will this disappe
58. le you want to use Click Refactoring Add Use Of Named Entities to Modules Select the named entities you would like to use and the module you want to use them in Click preview to view the changes and OK to apply the changes e Example Example of the Add Use Stmt refactoring Move Module Entities e Description This refactoring moves a set of named entities from one module to another and updates all use statements that reference these modules e Applies To A list of named entities e Operation Move your cursor to the module with the entities you would like to move Click Refactoring Move Module Entities Select the na med entities you would like to move and the module you want to move them to Click preview to view the changes and OK to apply the changes e Example Move Module Entities example Change Subroutine to Function e Description This refactoring will change a subroutine to a function The refactoring fails if there are no intent out arguments e Applies To A file e Operation Select the subroutine name or subroutine statement that needs to be changed to a function Click Refactoring Change Subroutine To Function Click preview to view the changes without applying or OK to apply the changes 3 10 NOT YET AVAILABLE e Example Example of Change Subroutine to Function refactoring Convert Specification Statement to Declaration Attribute TODO Toggle End Name TODO Standardize Input Outp
59. lysis refactoring Fortran Build w Fortran General mM Enable Fortran Declaration view Analysis Refactoring mM Enable Fortran content assist Ctrl Space Paths and symbols mM Enable Fortran Hover tips Project References Run Debug Settings gt Task Repository The following specify the paths searched for modules and INCLUDE files during analysis and refactoring Task Tags These MAY BE DIFFERENT from the settings used by Validation your compiler to build your project Folders to be searched for modules in order of preference MyProject Ne Remove Up Down e air Folders to be searched for INCLUDE files in order of preference MyProject include New Remove Up Down gt Restore Defaults Apply Figure 2 1 Enable Fortran analysis refactoring 2 2 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 34 CHAPTER 2 INTRODUCTION name and you don t want to type all of it An example is shown below oe A eageescGeracpeeecTor ab 1 progr
60. mple of Change Keyword Case refactoring Canonicalize Keyword Capitalization a Changes to be performed CEE a Y amp Canonicalize Keyword Capitalization Y eP common f90 commonStuff 7 hello f90 test F common f90 AA ea Original Source Refactored Source PROGRAM main program main a USE moreCommon use moreCommon IMPLICIT NONE implicit none 0 a EXTERNAL change c external change c 10 AS DIOR 30 COMMON a b common a b INTEGER a HA integer a REAL TH real z b a oO COMMON common c d e common2 f common common c d e common2 i E PS complex c A Aima Figure 3 31 72 CHAPTER 3 REFACTORING Convert Between If Statement and If Construct e Description Converts a simple if statement to an if construct with a then block and possible else block e Applies To Selected if statement e 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 e Example Example of the Convert Between If Statement and If Construct refactoring qa Convert Between If Statement and If Construct On px Changes to be performed a gt lv Y Convert Between If Statement and If Construct j Y So a File f90 SA GA Original Source R
61. n 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 39 40 CHAPTER 3 REFACTORING 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 e Clicking on a filename in the Fortran Projects view selects that file and only that file e Ctrl click Command click on Mac OS X can be used to select or deselect additional files e To select a range of
62. nd line arguments to your Fortran application or set certain 28 CHAPTER 1 INSTALLING PHOTRAN environment variables right click on the project in the Fortran Projects view click Run As Run Configurations Create a new launch configuration under Fortran Local Application or edit an existing one and modify the settings as needed Debugging programs works similarly except you can choose Debug As Lo cal Fortran Application or Debug Configurations from the context menu Running and debugging Fortran applications is similar to running and de bugging C C applications For more information on running and debugging binary applications click on Help Help Contents in Eclipse and navigate to C C Development User Guide Tasks Running and debugging projects 10 Setting Breakpoints There are two ways to set breakpoints in the editor The easiest way to set a breakpoint in the editor is to double click in the left margin gray vertical bar on the line at which you wish to set the breakpoint A blue dot will appear in the margin on the line where the breakpoint is set Double clicking again at the same location will remove the breakpoint You can also set a breakpoint by right clicking in the left margin on the line where you wish to set the breakpoint and clicking Toggle Breakpoint The blue dot indicating the breakpoint will appear or disappear if already set in the left margin of the editor F hello f90
63. nd module moreCommon lt n m oc Preview gt gun Okuma Figure 3 13 Example of Make COMMON variable names consistent refacto ring e Example 3 6 LOOP REFACTORING E Move Saved Variables to Global Common Block IES Changes to be performed amp lp F test f90 e A Original Source Refactored Source Es PROGRAM MyProg PROGRAM MyProg 2 CALL MySub CONTAINS SUBROUTINE MySub AE ie Be COMMON MySub c REAL SAVE i r IN CALL MySub SAVE 3 Mi CONTAINS M END SUBROUTINE MySub NM SUBROUTINE MySub END PROGRAM NyProg COMMON HiySub comoni i 3601 j xxxi 1000 ll INTEGER L e E T UJ REAL r_xxx1 END SUBROUTINE MySub END PROGRAM MyProg z Lal Bal E pa Figure 3 14 3 6 Loop Refactoring Interchange loops e 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 e Applies To Selected nested do loop e Operation 1 Select the nested loops you wish to interchange 2 Click Refactor Interchange Loops The Interchange loops dialog will appear 3 Click Preview to see what changes will be made then click OK to apply them e Example 1 In order for refactoring to work correctly there must be no state ments before
64. o make it easier to write modify search and maintain Fortran code These in clude 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 refac torings which change your source code to improve its design while preserving its behavior 1 15 Troubleshooting If you are experiencing problems installing or working with Photran please review the FAQ 11 If you don t find an answer there please join the Pho tran mailing list 12 a large number of users as well as Photran s develo pers monitor that list and they are generally eager to help Retrieved from http wiki eclipse org PTP photran documentation photran7 Chapter 2 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 refac torings which change your source code to improve its design while preserving its behavior 2 1
65. ocessed Source Form F08 Free Form C Preprocessed gt Project Facets Project References 2 77 Fixed Form INCLUDE lines ignored ES n Run Debug Settings F90 Free Form C Preprocessed y Server v Cancel GED 2 Cancel a In the Content types tree in the right pane navigate to Text gt 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 Con tents in Eclipse and navigate to Workbench User Guide Reference Prefe rences 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 gt Preferences on Mac OS X
66. ogram function subroutine etc clicking on the minus sign will temporarily collapse the display of that entity to a single line 1 9 USING THE FORTRAN EDITOR AND FORTRAN PERSPECTIVEL9 F common f90 F moreCommon f90 23 module moreCommon implicit none integer blah private blah contains subroutine change ab 0 subroutine stuff end module moreCommon The editors also support syntax highlighting As you write programs in For tran 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 character len 1 function char_at self index result return Pons clas
67. ormed 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 e Applies To Subprograms e Operation 1 Click on the declaration statement of a subprogram 2 Click Refactor Move Saved Variables to Common Block 3 Click Preview to see what changes will be made then click OK to apply them 54 CHAPTER 3 REFACTORING 2 Make COMMON variable names consistent lola z J Changes to be performed DL lp V Make COMMON variable names consistent Y 25 common f90 commonstuff W e moreCommon f90 commonStuff F moreCommon f90 2a 4a Original Source Refactored Source end subroutine subroutine stuff end subroutine subroutine stuff common common c d e complex c dimension c 3 complex c_common dimension c common 3 common common c_common d_com Y double precision d e 1 double precision d e TL double precision d double precision d_common double precision e double precision e common print Stuff end subroutine stuff end module moreCommon e print Stuff end subroutine stuff e
68. output from your Fortran compiler including any error messages will be displayed in the Console view However for many compilers Photran can recognize error messages placing the problem description in the Problems view and marking the corresponding line in the source file with a red X icon To do this you must have the correct error parsers selected in your Fortran project s build settings To modify these settings right click on your Fortran project go to Properties Fortran Build Settings and select the Error Parsers tab A list of error parsers is displayed select the one s corresponding to the Fortran compiler s you are using and click OK 3 Properties for fortranCommon 2 pS type filter text Settings ay vv Resource Builders C C Build Configuration Debug y Manage Configurations C C General Fortran Build Discovery options Tool Settings Build Steps pg Build Artifact Binary Parsers Error Parsers Environment Settings Y CDT GNU Make Error Parser Tool chain editor Y Photran Error Parser for GNU Fortran gfortran Variables Y CDT GNU C C Error Parser Fortran General Y CDT GNU Linker Error Parser Project References Y CDT GNU Assembler Error Parser Check all Run Debug Settings E CDT Visual C Error Parser Task Repository Photran Error Parser for Absoft Fortran Uncheck all Task a Photran Error Parser for G95 Fortran a Photran
69. oves 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 e Applies To Selected end if statement e 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 e Example Simple example of Remove Branch to End If refactoring 3 7 REFACTORINGS TO REMOVE OBSOLETE LANGUAGE G Remove Branch to En ALEME a x Changes to be performed DL ee y MI amp Remove Branch to End If Statement me We File foo Sa ZA Original Source Refactored Source T DO 20 i 1 10 DO 20 i 1 10 IF MOD i 2 eq 0 THEN IF MOD i 2 eq 0 THEI GOTO 10 KH GOTO 20 END IF END IF j i j j i IF j ge 100 THEN IF j ge 100 THEN j i j j j j 10 END IF 4 END IF 20 CONTINUE 20 CONTINUE PRINT ji j PRINT j j Ves mo Figure 3 23 Replace Character with Character len e Description Replaces character n declaration with character len n de claration e Applies To All character declarations e Operation 1 Select one of the character declaration statements 2 Click Refactor Obsolete Language Features Replace Character with Character len The Rep
70. ppearance Capabilities Compare Patch Content Types Editors File Associations b Text Editors Keys Network Connectior Perspectives Search Security Startup and Shutde Web Browser D workspace Ant C C Fortran Help Install Update Java Plug in Development Run Debug Team Text Editors See Colors and Fonts to configure the font Undo history size Displayed tab width O Insert spaces for tabs Highlight current line O Show print margin Show range indicator O Show whitespace characters Show affordance in hover on how to make it sticky When mouse moyed into hover Enrich after delay Enable drag and drop of text Warn before editing a denved file Smart caret positioning at line start and end Appearance color options Line number foreground Current line highlight Color Print margin Find scope Selection foreground color Selection background color Background color Foreground color _Hyperlink 3 More colors can be configured on the Colors and Fonts preference page Restore Defaults 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 D General D Ant D CCF Y Fortran CDT Integration Editor Templates
71. precision double precision double precision f double precision double precision d e f g h ya m a 1 b 2 3 c 4 5 print a b c call change ab call stuff print Now the first two variables below should have garbage values print and the third should be 5 6 nrint a h e Problems El Console Fortran Declaration 3 Local variable complex 3 complex c 2 3 SEARCH AND NAVIGATION 35 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 1 program test 2 implicit none integer a 0 call hi 5 end progr 6 subroutine hi prints Hello 8 subrouti subroutine hi 9 subroutin 1 print 11 end sub Press F2 for focus 13 subroutine wor Ld print WORLD 15 end subroutine 16 2 3 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 ei
72. project using a hand written Makefile The following example uses the GNU Fortran gfortran compiler but any Fortran compiler can be used instead We will assume that you are familiar with how to write a Makefile If not there are plenty of resources on the Web including a tutorial from an introductory Computer Science course at UIUC 5 and another from the University of Hawaii 6 and of course you can always read the entire manual for GNU Make 7 1 Click File New Fortran Project 2 Call it HelloFortran 3 Expand Makefile project in the project type list it has a folder icon and choose Empty Project 4 Select Other Toolchain in the toolchain list in the right hand co lumn and click Next 5 Click on Advanced Settings 6 Expand C C Build in the list on the left and click on Settings 7 Click on the Binary Parsers tab Check the appropriate parsers for your platform Tf you are using Windows check PE Windows Parser and or Cygwin PE Parser if you are using Linux check Elf Parser if you are using Mac check Mach O parser 8 Click on the Error Parsers tab Check the error parser s for the Fortran compiler s you will use 9 Click OK 12 11 12 13 14 15 16 17 18 19 20 21 22 23 24 CHAPTER 1 INSTALLING PHOTRAN Click Finish Click File New Source File Call it hello f90 Click Finish Type the standard Hello World program shown
73. rds are special symbols used for pattern matching For more informa tion click on Help Help Contents in Eclipse and navigate to Workbench User Guide Reference User interface information Search e represents any number of any symbols For example a search for d would match bad rescued d assembled etc e 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 Chapter 3 Refactoring 3 1 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 i
74. routine Parameter Ebe Changes to be performed D FG te Y Y amp Add Subroutine Parameter BFile f90 SAA Original Source Refactored Source module BFile module BFile 2 limplicit none limplicit none contains contains i subroutine sub i subroutine sub newName integer intent in newName end subroutine end subroutine end module BFile end module BFile G X Figure 3 1 Example of Add Subroutine Parameter refactoring 3 2 SUBPROGRAM REFACTORINGS 45 Permute Subprogram Arguments e Description This refactoring will change the order of the arguments to a subroutine and adjust all call sites accordingly e Applies To All files calling the selected subroutine e Operation 1 2 Select the subroutine name or subroutine statement Click Refactoring Subprogram Change Subroutine Signature Use the input page s up and down buttons to rearrange the order of the arguments for the subroutine Click preview to view the changes without applying or OK to apply the changes e Example Example of Change Subroutine Signature refactoring a a Change Subroutine Signature Changes to be performed 2 elp Mv 23 Change Subroutine Signature M 5 subroutinesig f90 changesigtest F subroutinesig f90 SAQA Original Source Refactored Source f T end interface call testsub 1 2 200 200 3 4 5 6 call testsub 1 2 200 200 4 5 6 3 zi call t
75. s string intent in self oo a gp E a A ty result return Open Declaration F3 Show In CREW gt string string Cut X Copy C Paste V Probl Comment Uncomment roble Shift Right 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 20 CHAPTER 1 INSTALLING PHOTRAN 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 Numbers and Punctuation E
76. set for the project Previous versions of Photran used Eclipse s workspace wide settings to distinguish free and fixed form files In Photran 6 each project has its own settings that determine which filename extensions correspond to free and fixed source form and which files contain C preprocessor directives Learn about source form settings 14 CHAPTER 1 INSTALLING PHOTRAN 1 8 Writing Code 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
77. ssage see below for troubleshooting information Click the Finish button and agree to the license to complete the installa tion 1 2 SYSTEM REQUIREMENTS 5 1 2 System Requirements To install Photran 6 0 You must have Eclipse 3 6 Helios installed 1 You should have the C C Development Tools CDT 7 0 installed If you do not a If you downloaded Eclipse from eclipse org and you will be following the instructions below for Installing on a Machine With Internet Access then CDT should be installed automatically when you ins tall Photran b Otherwise CDT probably will not be installed automatically You will need to install CDT manually Follow the instructions below for Installing on a Machine Without Internet Access You should also follow these instructions if you did not download Eclipse from eclipse org e g if you installed it from a Linux distribution like Ubuntu 2 Eclipse must be running on a Java 1 5 or later Java Virtual Machine JVM To get reasonable performance we recommend Sun s JVM 1 or IBM s J9 2 OpenJDK the default JVM on newer versions Fedora Linux also works well although GNU Classpath the default JVM on older versions of Fedora is generally too slow to be useful 3 If you want to compile and build Fortran applications you must have a make program such as GNU Make and a Fortran compiler such as gfortran the GNU Fortran compiler in your system path Many Linux
78. t 490 _ ER PERE 3 eS gt org eclipse photran samples dev e Program main indow Help By E Fortran Proj 92 8 sre fixed form OS ES Fortran Search U Java Search Plug in Search E ste fortran and c AS at external filel arch pattern G src gaussian elimination re aan E ad E Regular expression aca gt integer blah dB 6 src language features o A C any string any character amp wae 1Some comment Sea limitto gt ste s ee BSAA REE Y Common block Y Function All occurrences E ste scoping Eii GQ sre implicits 1 Gail Gad tens cr T Subroutine Y Module Declarations ste implicits 2 A Variable Program References E stc implicits 3 stc common aro eee oa subroutine add a b c 2 ste cray pointers aria Workspace Selected resources Enclosing projects gt sre variable encapsulation integer result Gy gt settings result a b c Working set Choose Gy src fortran2003 print result Gy sre liebmann 1 eoshift e subrost ie add Gy src liebmann 2 arrays i ae iman T kop function malt x y 2 ea integer res Moo res x y z 2 gt lebmanns60 11 ap es G coca a ee end function mult gt cproject D project 12 2 3 SEARCH AND NAVIGATION 37 Notice that only the declarations of variables functions were found Also note the use of the wild card character in the search box Wildcards Wildca
79. t folder and select Empty Project 1 11 BUILDING PROJECTS 25 3 Fortran Project loa x Fortran Project lt gt Create a Fortran project of the selected type Project name Fortran test Y Use default location C Users Kurt Hendle dev workspace Fortran test Browse default Project type Toolchains gt Executable GCC Tool Chain Empty Project Hello World C Project 6 Hello World ANSI C Project gt Shared Library gt Static Library Executable Gnu Fortran Executable Gnu Fortran on MacOS X Makefile project Empty Project Hello World C Project Show project types and toolchains only if they are supported on the platform 1 11 Building Projects Compiling Fortran projects is identical to compiling C C Projects For more information on building projects click on Help Help Contents in Eclipse and navigate to C C Development User Guide Concepts Build gt Building C C Projects 8 Setting Make Targets Setting make targets for Fortran programs is also identical to setting make targets for C C programs For more information on make targets click on Help Help Contents in Eclipse and navigate to C C Development User Guide Tasks Building projects Creating a make target 9 26 CHAPTER 1 INSTALLING PHOTRAN Marking Error Messages from Your Fortran Compiler Error Parsers When you build compile your Fortran program the
80. the second loop If such statements exist correctness of the refactoring is not guaranteed 55 56 CHAPTER 3 REFACTORING 3 Interchange Loops ss 215 js Changes to be performed selg 4 1183 Interchange Loops 7 2 liebmann f30 org eclipse photran samples src liebmann 3 loops ol jelta 0 0 a abs next i j prev i j a ha Figure 3 15 Simple example of Interchange Loops refactoring Fuse Loops e Description Takes two do loops normalizes their bounds and finally puts the loop bodies in a single do loop e Applies To Find the two do loops you want to fuse and select only the first onel 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 e Operation 1 Select the first do loop to be fused 2 Click Refactor Loop Fusion 3 Click Preview to see a comparison view of the changes made and OK to apply the changes e Example 1 The refactoring will find the next listed do loop in your code even with other lines of code in between them 3 6 LOOP REFACTORING 97 Changes to be performed a 7183 Loop Fusion EF test 90 testa E tests t00 Original Source I integer si Refactored Sourc
81. ther e click on the Navigate menu and select Open Declaration or e right click on the identifier and and select Open Declaration or e 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 36 CHAPTER 2 INTRODUCTION 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 Fortran org eclipse photran samples src variable encapsulation main f90 Eclipse Platform File Edit Refactor Navigate Search Run Project Window Help gt A 4 Search Ctrl H 6 Ryi ov iB if ee o le T Fortran Proj 23 5 Navi i E file1 f90 E fixedForm f a a A SP CIC I Fortran E gt or
82. tran 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 gt Other gt General Outline DZ Outline 23 _ Make Targets ww e ZF Syntax error Unexpected identifier c 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 IF hello 90 3 program hello implicit none print Hello end program hello 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 pr
83. ut Format TODO 95

Download Pdf Manuals

image

Related Search

Related Contents

Steckerladegerät »UNI 3AS«-Set  User Manual for Business Approver  Cisco MR26  Xerox Phaser 7100 User's Manual  Manuel d`utilisation de MyVisit  GsmSuite User Manual english  Epson 3LCD Product Specifications  Nokia 1208 77g  Clauses communes aux deux lots - Coeur Entre-Deux-Mers    

Copyright © All rights reserved.
Failed to retrieve file