New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change all indentation from 3 spaces to 2 using findent #80
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
# Indent continuation lines for fortran files read through stdin | ||
# usage: | ||
# cat file.f90 | indent_continuation.py | ||
# | ||
import re | ||
import sys | ||
|
||
indent_chars = [ ":", "=", "::" ] | ||
indent_regex = re.compile(r"^\ *") | ||
continuation_regex = re.compile(r'&\ *$') | ||
indent_next = False | ||
current_indent = 0 | ||
parenthesis = 0 | ||
|
||
for line in sys.stdin: | ||
if not indent_next: | ||
for char in indent_chars: | ||
if char in line: | ||
current_indent = line.find(char) + len(char) + 1 | ||
|
||
if indent_next and parenthesis == 0: | ||
line = indent_regex.sub(current_indent*" ", line) | ||
indent_next = continuation_regex.search(line) | ||
print(line, end="") | ||
|
||
parenthesis += line.count("(") - line.count(")")\ | ||
+ line.count("[") - line.count("]") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
module m_allocator | ||
use iso_fortran_env, only: stderr => error_unit | ||
|
||
use m_common, only: dp, DIR_X, DIR_Y, DIR_Z, DIR_C | ||
|
||
implicit none | ||
|
||
type :: allocator_t | ||
!! An instance of type allocator_t is responsible for the | ||
!! maintenance of a linked list of instances of equal size | ||
!! [[m_allocator(module):field_t(type)]] objects: | ||
!! | ||
!! ``` | ||
!! ---- ---- ---- ---- ---- ---- | ||
!! ...-->|id=1|data|next|-->|id=0|data|next|-->null() | ||
!! ---- ---- ---- ---- ---- ---- | ||
!! ``` | ||
!! | ||
!! the last block's `next` pointer being non associated. | ||
!! | ||
!! User code can request access to a memory block by using the | ||
!! type bound procedure | ||
!! [[m_allocator(module):get_block(function)]]. If the list is | ||
!! not empty, a pointer to the first block on the list is | ||
!! returned and the block is detached from the list. If the list | ||
!! is empty (i.e. all initially allocated blocks are currently | ||
!! referenced to) then a new block is allocated before a pointer | ||
!! to it is returned. | ||
!! | ||
!! In order to reuse memory it is important that user code | ||
!! release blocks when they are not needed anymore. This is done | ||
!! by calling the type bound procedure | ||
!! [[m_allocator(module):release_block(subroutine)]]. The | ||
!! released block is then pushed in front of the block list. | ||
module m_allocator | ||
use iso_fortran_env, only: stderr => error_unit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented on the wrong side and its actually not visible due to that. I mean the 2 spaces before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #80 (comment) |
||
|
||
use m_common, only: dp, DIR_X, DIR_Y, DIR_Z, DIR_C | ||
|
||
implicit none | ||
|
||
type :: allocator_t | ||
!! An instance of type allocator_t is responsible for the | ||
!! maintenance of a linked list of instances of equal size | ||
!! [[m_allocator(module):field_t(type)]] objects: | ||
!! | ||
!! ``` | ||
!! ---- ---- ---- ---- ---- ---- | ||
!! ...-->|id=1|data|next|-->|id=0|data|next|-->null() | ||
!! ---- ---- ---- ---- ---- ---- | ||
!! ``` | ||
!! | ||
!! the last block's `next` pointer being non associated. | ||
!! | ||
!! User code can request access to a memory block by using the | ||
!! type bound procedure | ||
!! [[m_allocator(module):get_block(function)]]. If the list is | ||
!! not empty, a pointer to the first block on the list is | ||
!! returned and the block is detached from the list. If the list | ||
!! is empty (i.e. all initially allocated blocks are currently | ||
!! referenced to) then a new block is allocated before a pointer | ||
!! to it is returned. | ||
!! | ||
!! In order to reuse memory it is important that user code | ||
!! release blocks when they are not needed anymore. This is done | ||
!! by calling the type bound procedure | ||
!! [[m_allocator(module):release_block(subroutine)]]. The | ||
!! released block is then pushed in front of the block list. | ||
|
||
integer :: ngrid, sz | ||
!> The id for the next allocated block. This counter is | ||
|
@@ -45,45 +45,45 @@ module m_allocator | |
!> the list is empty | ||
! TODO: Rename first to head | ||
class(field_t), pointer :: first => null() | ||
contains | ||
contains | ||
procedure :: get_block | ||
procedure :: release_block | ||
procedure :: create_block | ||
procedure :: get_block_ids | ||
procedure :: destroy | ||
end type allocator_t | ||
end type allocator_t | ||
|
||
interface allocator_t | ||
interface allocator_t | ||
module procedure allocator_init | ||
end interface allocator_t | ||
|
||
type :: field_t | ||
!! Memory block type holding both a data field and a pointer | ||
!! to the next block. The `field_t` type also holds a integer | ||
!! `refcount` that counts the number of references to this | ||
!! field. User code is currently responsible for incrementing | ||
!! the reference count. | ||
end interface allocator_t | ||
|
||
type :: field_t | ||
!! Memory block type holding both a data field and a pointer | ||
!! to the next block. The `field_t` type also holds a integer | ||
!! `refcount` that counts the number of references to this | ||
!! field. User code is currently responsible for incrementing | ||
!! the reference count. | ||
class(field_t), pointer :: next | ||
real(dp), pointer, private :: p_data(:) | ||
real(dp), pointer, contiguous :: data(:, :, :) | ||
integer :: dir | ||
integer :: refcount = 0 | ||
integer :: id !! An integer identifying the memory block. | ||
contains | ||
contains | ||
procedure :: set_shape | ||
end type field_t | ||
end type field_t | ||
|
||
interface field_t | ||
interface field_t | ||
module procedure field_init | ||
end interface field_t | ||
end interface field_t | ||
|
||
type :: flist_t | ||
type :: flist_t | ||
class(field_t), pointer :: ptr | ||
end type flist_t | ||
end type flist_t | ||
|
||
contains | ||
contains | ||
|
||
function field_init(ngrid, next, id) result(f) | ||
function field_init(ngrid, next, id) result(f) | ||
integer, intent(in) :: ngrid, id | ||
type(field_t), pointer, intent(in) :: next | ||
type(field_t) :: f | ||
|
@@ -92,19 +92,19 @@ function field_init(ngrid, next, id) result(f) | |
f%refcount = 0 | ||
f%next => next | ||
f%id = id | ||
end function field_init | ||
end function field_init | ||
|
||
subroutine set_shape(self, dims) | ||
subroutine set_shape(self, dims) | ||
implicit none | ||
|
||
class(field_t) :: self | ||
integer, intent(in) :: dims(3) | ||
|
||
self%data(1:dims(1), 1:dims(2), 1:dims(3)) => self%p_data | ||
|
||
end subroutine set_shape | ||
end subroutine set_shape | ||
|
||
function allocator_init(nx, ny, nz, sz) result(allocator) | ||
function allocator_init(nx, ny, nz, sz) result(allocator) | ||
integer, intent(in) :: nx, ny, nz, sz | ||
type(allocator_t) :: allocator | ||
|
||
|
@@ -123,11 +123,11 @@ function allocator_init(nx, ny, nz, sz) result(allocator) | |
allocator%ydims_padded = [sz, ny_padded, nx_padded*nz_padded/sz] | ||
allocator%zdims_padded = [sz, nz_padded, nx_padded*ny_padded/sz] | ||
allocator%cdims_padded = [nx_padded, ny_padded, nz_padded] | ||
end function allocator_init | ||
end function allocator_init | ||
|
||
function create_block(self, next) result(ptr) | ||
!! Allocate memory for a new block and return a pointer to a new | ||
!! [[m_allocator(module):field_t(type)]] object. | ||
function create_block(self, next) result(ptr) | ||
!! Allocate memory for a new block and return a pointer to a new | ||
!! [[m_allocator(module):field_t(type)]] object. | ||
class(allocator_t), intent(inout) :: self | ||
type(field_t), pointer, intent(in) :: next | ||
type(field_t), pointer :: newblock | ||
|
@@ -136,28 +136,28 @@ function create_block(self, next) result(ptr) | |
allocate (newblock) | ||
newblock = field_t(self%ngrid, next, id=self%next_id) | ||
ptr => newblock | ||
end function create_block | ||
|
||
function get_block(self, dir) result(handle) | ||
!! Return a pointer to the first available memory block, i.e. the | ||
!! current head of the block list. If the list is empty, allocate | ||
!! a new block with [[m_allocator(module):create_block(function)]] | ||
!! first. | ||
!! | ||
!! Example | ||
!! ``` | ||
!! f%data => get_block() | ||
!! ``` | ||
end function create_block | ||
|
||
function get_block(self, dir) result(handle) | ||
!! Return a pointer to the first available memory block, i.e. the | ||
!! current head of the block list. If the list is empty, allocate | ||
!! a new block with [[m_allocator(module):create_block(function)]] | ||
!! first. | ||
!! | ||
!! Example | ||
!! ``` | ||
!! f%data => get_block() | ||
!! ``` | ||
class(allocator_t), intent(inout) :: self | ||
class(field_t), pointer :: handle | ||
integer, intent(in) :: dir | ||
integer :: dims(3) | ||
! If the list is empty, allocate a new block before returning a | ||
! pointer to it. | ||
if (.not. associated(self%first)) then | ||
! Construct a field_t. This effectively allocates | ||
! storage space. | ||
self%first => self%create_block(next=self%first) | ||
! Construct a field_t. This effectively allocates | ||
! storage space. | ||
self%first => self%create_block(next=self%first) | ||
end if | ||
handle => self%first | ||
self%first => self%first%next ! 2nd block becomes head block | ||
|
@@ -168,53 +168,53 @@ function get_block(self, dir) result(handle) | |
|
||
! Set dims based on direction | ||
select case(dir) | ||
case (DIR_X) | ||
dims = self%xdims_padded | ||
case (DIR_Y) | ||
dims = self%ydims_padded | ||
case (DIR_Z) | ||
dims = self%zdims_padded | ||
case (DIR_C) | ||
dims = self%cdims_padded | ||
case default | ||
error stop 'Undefined direction, allocator cannot provide a shape.' | ||
case (DIR_X) | ||
dims = self%xdims_padded | ||
case (DIR_Y) | ||
dims = self%ydims_padded | ||
case (DIR_Z) | ||
dims = self%zdims_padded | ||
case (DIR_C) | ||
dims = self%cdims_padded | ||
case default | ||
error stop 'Undefined direction, allocator cannot provide a shape.' | ||
end select | ||
|
||
! Apply bounds remapping based on requested direction | ||
call handle%set_shape(dims) | ||
end function get_block | ||
end function get_block | ||
|
||
subroutine release_block(self, handle) | ||
!! Release memory block pointed to by HANDLE to the block list. | ||
!! It is pushed to the front of the block list, in other words it | ||
!! is made the head block. | ||
subroutine release_block(self, handle) | ||
!! Release memory block pointed to by HANDLE to the block list. | ||
!! It is pushed to the front of the block list, in other words it | ||
!! is made the head block. | ||
class(allocator_t), intent(inout) :: self | ||
class(field_t), pointer :: handle | ||
handle%next => self%first | ||
self%first => handle | ||
end subroutine release_block | ||
|
||
subroutine destroy(self) | ||
!! Go through the block list from head to tail, deallocating each | ||
!! memory block in turn. Deallocation of a | ||
!! [[m_allocator(module):field_t(type)]] object automatically | ||
!! deallocates its internal allocatable | ||
!! [[field_t(type):data(variable)]] array. | ||
end subroutine release_block | ||
|
||
subroutine destroy(self) | ||
!! Go through the block list from head to tail, deallocating each | ||
!! memory block in turn. Deallocation of a | ||
!! [[m_allocator(module):field_t(type)]] object automatically | ||
!! deallocates its internal allocatable | ||
!! [[field_t(type):data(variable)]] array. | ||
class(allocator_t), intent(inout) :: self | ||
type(field_t), pointer :: current | ||
do | ||
if (.not. associated(self%first)) exit | ||
current => self%first | ||
self%first => self%first%next | ||
deallocate (current) | ||
self%next_id = self%next_id - 1 | ||
if (.not. associated(self%first)) exit | ||
current => self%first | ||
self%first => self%first%next | ||
deallocate (current) | ||
self%next_id = self%next_id - 1 | ||
end do | ||
end subroutine destroy | ||
end subroutine destroy | ||
|
||
function get_block_ids(self) | ||
!! Utility function that returns a array made of the `id` of the | ||
!! block currently in the block list. Return the array [0] if | ||
!! block list is empty. | ||
function get_block_ids(self) | ||
!! Utility function that returns a array made of the `id` of the | ||
!! block currently in the block list. Return the array [0] if | ||
!! block list is empty. | ||
! TODO: Block indices should start at 1 or return [-1] in case of | ||
! empty block list. | ||
class(allocator_t), intent(inout) :: self | ||
|
@@ -224,17 +224,17 @@ function get_block_ids(self) | |
|
||
current => self%first | ||
if (.not. associated(current)) then | ||
get_block_ids = [0] | ||
get_block_ids = [0] | ||
else | ||
i = current%id | ||
get_block_ids = [current%id] | ||
do | ||
if (.not. associated(current%next)) exit | ||
i = current%next%id | ||
get_block_ids = [get_block_ids, current%next%id] | ||
current => current%next | ||
end do | ||
i = current%id | ||
get_block_ids = [current%id] | ||
do | ||
if (.not. associated(current%next)) exit | ||
i = current%next%id | ||
get_block_ids = [get_block_ids, current%next%id] | ||
current => current%next | ||
end do | ||
end if | ||
end function get_block_ids | ||
end function get_block_ids | ||
|
||
end module m_allocator | ||
end module m_allocator |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also interesting, even the module declaration starts with two spacing. Is there a way to disable it? seems like a waste of two spaces to me. (Because its like +2 in every single line due to this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the
-I2
parameter, this can be removed