Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Visual Studio Auto Code Indentation

OMeara__Mark
Beginner
292 Views

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?

 

 

0 Kudos
2 Replies
mecej4
Black Belt
292 Views

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#comme..., 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)".

willem_v_
Beginner
292 Views

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.

 

 

Reply