Changes between Version 14 and Version 15 of HowTo/FortranStandards
- Timestamp:
- 2013-04-26T18:12:22+02:00 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
HowTo/FortranStandards
v14 v15 1 1 = Fortran style guide = 2 3 [[BR]] 4 2 5 3 6 = Introduction = … … 25 28 = Interfaces = 26 29 27 Existing structure and interactions between module and subroutines and how to improve it 30 ''Existing structure and interactions between module and subroutines and how to improve it'' 31 32 [[BR]] 28 33 29 34 1) For function/suroutine calls, there should only be five arguments per line. … … 42 47 = Clarity = 43 48 44 Layout of code for clarity to the reader, reminder about the commenting style and ensuring interaction with the documentation compiler (dOxygen) 49 ''Layout of code for clarity to the reader, reminder about the commenting style and ensuring interaction with the documentation compiler (dOxygen)'' 45 50 46 2) Related to point one, in the variable declaration of the subroutine, it's nice to have 51 [[BR]] 52 53 (1) Related to point one, in the variable declaration of the subroutine, it's nice to have 47 54 all the variables which are passed to/from to be in the same order as they are listed. 48 55 {{{ … … 74 81 }}} 75 82 76 3) '''Comment at end of loop:''' If there is a loop within a loop (nested loop), or a lengthy single loop, it is helpful to repeat the loop instructions as a comment next to the END statement, as so: 83 [[BR]] 84 85 (2) '''Comment at end of loop:''' If there is a loop within a loop (nested loop), or a lengthy single loop, it is helpful to repeat the loop instructions as a comment next to the END statement, as so: 77 86 78 87 {{{ … … 92 101 }}} 93 102 94 3) '''Equations:''' Use brackets to improve readability (even though addition and subtraction are treated ahead of division and multiplication, it is easier for the reader to scan the equations if this is made explicit). Also, if the equation runs over several lines, try to break the expression at a close bracket or an addition/subtraction. 103 [[BR]] 104 105 (3) '''Equations:''' Use brackets to improve readability (even though addition and subtraction are treated ahead of division and multiplication, it is easier for the reader to scan the equations if this is made explicit). Also, if the equation runs over several lines, try to break the expression at a close bracket or an addition/subtraction. 95 106 96 107 e.g. '''a = (b * i) + (c / n)''' is easier to read than '''a = b * i + c / n''' 97 108 98 4) '''Line length:''' Although the maximum line length of Fortran90 is 132 characters, keep your code to less than 80 characters per line - this preserves the formatting for those who work with small terminal windows on their computer and when producing a printout. 109 [[BR]] 99 110 100 5) '''Use of space:''' Always indent the code within conditional statements or loops, but don't use tabs, as the formatting will not be preserved across platforms. 111 112 (4) '''Line length:''' Although the maximum line length of Fortran90 is 132 characters, keep your code to less than 80 characters per line - this preserves the formatting for those who work with small terminal windows on their computer and when producing a printout. 113 114 [[BR]] 115 116 (5) '''Use of space:''' Always indent the code within conditional statements or loops, but don't use tabs, as the formatting will not be preserved across platforms. 117 118 [[BR]] 101 119 102 120 ---- … … 107 125 Choosing where and when to define particular variables; portability between compilers; allocation/de-allocation of arrays etc. 108 126 109 127 [[BR]] 110 128 111 129 ---- 112 130 113 131 [[BR]] 114 = Speed optimisation =132 = Debugging and speed optimisation = 115 133 116 guidelines for making loops more efficient, eliminating dead code 134 ''guidelines for making loops more efficient, eliminating dead code'' 117 135 136 [[BR]] 137 138 (1) ''''bavard' (chatterbox!):''' is an externalised parameter that can be used to determine the nature of WRITE statements in the code for monitoring and debugging. It is proposed that for the trunk code a uniform set of parameters is used to control the size of the output text files as appropriate to the task in hand. 139 140 For example: 141 142 '''IF''' bavard '''EQUALS''' 0 then no output 143 144 '''IF''' bavard '''=>''' 1 then parameters used are reported 145 146 '''IF''' bavard '''=>''' 2 then entering and leaving subroutines are reported 147