- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am looking for a style guide.
I recall Tom Lahey's suggestions...
I use upper case for IF, ENDIF, DO, SUBROUTINE, TRANSPOSE, etc. for all the Fortran intrinsics. And therefore lower case or mixed case for my Functions, Subroutines, and Variables. e.g.
REAL(KIND=8) :: MyTime
CHARACTER(LEN=24) ::Acsii_Time
And for arguments spaces after the commas. e.g.:
CALL my sub(a, b, c, d)
But interested in whether there are any standards at all?
And if so where those might be posted??
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The thing about style guides is that there are so many of them. Many organizations adopt particular style guides, but there isn't one style that is right and everything else is wrong. For example, do you indent the END DO the same as the DO, or the same as the body of the DO? I like the latter, but many people prefer the former. Case is definitely a personal preference - a lot depends on what you got used to initially. I think the best thing is to develop a style and stick to it. My only requirement is that the code be readable and not confusing (so use meaningful variable names and try to avoid reusing names of intrinsic functions, though sometimes this can be tough.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As Steve notes, many people, books and organizations have different preferences and conventions. My personal favorite is to follow Clerman and Spector and Rouson et al. style advice. I also firmly believe that ‘=‘ should ALWAYS be surrounded by at least one space on each side if it shows up in the context of variable assignment, or a DO or FORALL spec. Addition and subtraction and all binary operators (user defined or intrinsic) using the .___. notation (.and. .or. etc.) should always be surrounded by one or more blanks as well, except possibly in index specifications. I also try to align common attributes in variable declarations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran coders can really benefit from significantly better tools for code refactoring that include "style enforcers" i.e., once the tool has been "taught" the style one wants, the code file (.f90 etc.) can be "refactored" to that style with the click of a button or a keyboard short-cut key. As I mentioned on the Windows form, the Fortran plug-in for Code::Blocks created by Darius Markauskas and offered at http://darmar.vgtu.lt/ is starting to provide some features I like. I don't work enough on Linux to pursue this in detail, but I've seen people customize/extend Eclipse IDE and Emacs to do some of these things.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By default Emacs can be very easily configured to indent block constructs and capitalize or upper-case Fortran keywords. Once these settings are set simply doing M-x indent-program or M-q should reformat the code. I have yet to see something that enforces conventions like those advocated in Clerman and Spector, e.g., compile time constants (parameters) are upper-case, procedures are CamelCase. Type names have _t appended, module names _m appended etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use nedit and it highlights and bolds the intrinsics.
The idea of shortcuts for typing seem like a foreign concept to me. I have seen all sorts of movies with hackes pounding away on the keyboard in a race against the machines with the screen dumping like a "Matrix" movie scene, but as I am usually looking at my right hand in the right hand rule gang sign and contemplating cross products and curls I cannot relate to being key-poking limited as I am usually beard stroking and visualizing the math for a long while before the fingers need to actually poke at the keys.
Code:Bloxs seems to not recognise ifort and I had icc errors, so I put a forum post on there.
So I guess I'll just stick to "==" instead of ".eq." and using my spaces before and after "=", and capping the SUBROUTINE, etc.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page