| 261 | [[BR]] |
| 262 | = Some things found in the Prism Coding standard that seem like good ideas = |
| 263 | |
| 264 | These could be useful. Even if some of them are already widely used, it's sometimes nice to make them explicit. |
| 265 | |
| 266 | (1) Try to keep non-header lines to 80 characters or less, although this is not a hard limit. |
| 267 | (2) Put Fortran keywords and intrinsic functions in all uppercase letters. |
| 268 | (3) Do not use tab characters, as a mix of tab characters and spaces makes for terrible formatting portability. As noted above, tab in emacs is fine, since it actually uses spaces. |
| 269 | (4) Five arguments per line as a soft guideline for subroutine and function calls/declaration (soft guideline meaning it's not the end of the world if sometimes four or six are used). |
| 270 | (5) Include IMPLICIT NONE in module declarations. |
| 271 | (6) Always use INTENT statements for arguments. |
| 272 | (7) Never use "magic numbers", i.e. hard-coded numbers that cannot be traced to a literature formula. Externalization helps a lot with this. |
| 273 | (8) Be mindful of loop ordering for best memory access (performance). In other words, |
| 274 | |
| 275 | {{{ |
| 276 | |
| 277 | DO k=1,nk |
| 278 | DO j=1,nj |
| 279 | DO i=1,ni |
| 280 | f(i,j,k) = ... |
| 281 | ENDDO |
| 282 | ENDDO |
| 283 | ENDDO |
| 284 | |
| 285 | }}} |
| 286 | This ensures that one accesses continginuos memory blocks during the loop, which makes it faster. I saw this in an optimization course back in 2004, as well, but it seems to not always be done in ORCHIDEE. Have compilers just gotten better? Some people have also suggested a guideline for the loops (i.e., loop over points first, then PFT, then nparts, etc.), since this also does not seem consistent. |
| 287 | |
| 288 | Additional: What is the purpose of a SAVE attribute in a modular variable declaration? Modular variables are outside of the execution context, so they should be saved by default. It seems SAVE is only applicable inside a function or a subroutine. |