fortran-lang / fprettify

auto-formatter for modern fortran source code
https://pypi.python.org/pypi/fprettify
Other
376 stars 78 forks source link

nested loops #26

Closed Beliavsky closed 6 years ago

Beliavsky commented 6 years ago

Fprettify changes the code

program main
integer :: i,j
do i=1,2
do j=1,3
print*,i,j,i*j
end do
end do
end program main

to

program main
   integer :: i, j
   do i = 1, 2
   do j = 1, 3
      print *, i, j, i*j
   end do
   end do
end program main

I would like each loop to be indented, not just the inner-most loop.

pseewald commented 6 years ago

This is a feature since some people prefer to not indent deeply nested loops. So if a nested loop is not indented, fprettify does not impose indentation on the inner loop. However if you change your code to:

program main
integer :: i,j
do i=1,2
 do j=1,3
print*,i,j,i*j
end do
end do
end program main

fprettify will assume that you want to indent the nested loop and therefore change the code to

program main
   integer :: i, j
   do i = 1, 2
      do j = 1, 3
         print *, i, j, i*j
      end do
   end do
end program main
Beliavsky commented 6 years ago

It would be nice if fprettify had an option to transform the original un-indented code to the last code you displayed, with each loop indented.

pseewald commented 6 years ago

to strictly indent nested loops, you can now invoke fprettify as:

fprettify.py --strict-indent