Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
AFiD/factorize.F90
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (31 sloc)
1.31 KB
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
! --------------------------------------------------------------- | |
! This routine factorizes the grid resolution in the horizontal | |
! directions to make sure that efficient FFT's are used. The input | |
! is (In2) is "ny or ny" and the output (Out2) is the largest factor | |
! A loop in the main routine checks whether the largest factor is | |
! smaller than 7. If not the simulation is aborted. | |
! --------------------------------------------------------------- | |
subroutine Factorize(In2,Out2) | |
implicit none | |
integer,intent(in) :: In2 ! Horizontal grid resolution | |
integer,intent(out) :: Out2 ! Largest factor | |
integer :: Input,Divisor | |
Input=In2 | |
! Remove all factors of 2 | |
do | |
if (mod(Input,2) /= 0 .or. Input == 1) exit | |
Input = Input / 2 ! remove this factor | |
enddo | |
! consider odd factors | |
Divisor = 3 | |
do ! try 3, 5, 7, etc | |
if (Divisor > Input) exit ! if a factor is too large, exit and done | |
do ! try this factor repeatedly | |
if (mod(Input,Divisor) /= 0 .or. Input == 1) exit | |
Input = Input / Divisor ! remove this factor | |
enddo | |
Divisor = Divisor + 2 ! Next odd number | |
enddo | |
Out2=Divisor ! Largest factor. Should be small for effcient FFT | |
return | |
end |