- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
This concerns the auto indenting possible in Visual Studio via the Ctrl-K-D command. Current we have the indenting option set to the 'smart' in 'Tools | Options | Text Editor | Fortran | Tabs'.
There are two scenarios where the formatting is wrong:
1. Line continuations in an if condition. e.g.:
if (test == .true. .and. & test2 == .true) ! Ctrl-K-D places the below inline with the if, no indent. test = .false; ! Would prefer to be indented as below instead test = .false; endif
2. Another issue is when we use the ';' to have an if statement on the one line (because we can!). Using Ctrl-K-D incorrectly indents the subsequent code.
if (test == .true.) then; test = .false.; else; test2 = .false.; endif ! Next line is indented when it should not be
Has anyone encountered this issue and found a solution?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I cannot help you with the VS editor question, but I notice some problems with the code that you showed. Please read #7 of Dr. Fortran's post, https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/275071#comment-1548435, in which he discusses why the == operator should not be used with logical expressions (use .EQV. instead). Instead of "if(test == .true.)", you could probably use the correct and shorter "if(test)".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess, the first program should read: (added program statement and declarations, so it can be compiled)
program p
logical test, test2
if (test .eqv. .true. .and. &
test2 .eqv. .true.) then
test = .false.
endif
if (test .eqv. .true.) then; test = .false.; else; test2 = .false.; endif
continue
end
Indeed, as mecej4 noted, use .eqv. in stead of == and use if(test) then ...
findent (https://sourceforge.net/projects/findent/) indents the program as follows:
program p
logical test, test2
if (test .eqv. .true. .and. &
test2 .eqv. .true.) then
test = .false.;
endif
if (test .eqv. .true.) then; test = .false.; else; test2 = .false.; endif
continue
end
which is more or less what you want.

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