Skip to content
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

Consistency Check for Indexed Outputs (e.g., Shell_Slices, Meridional_Slices) #574

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions src/IO/Spherical_IO.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1692,29 +1692,45 @@ SUBROUTINE nrm_to_index(nrm_coords, coord_arr, indices, rev_inds)

END SUBROUTINE nrm_to_index

Subroutine Parse_Inds(indices_inout, indcount)
Subroutine Parse_Inds(indices_inout, indmax, indcount)
IMPLICIT NONE
INTEGER, INTENT(InOut) :: indices_inout(:)
INTEGER, INTENT(InOut), Optional :: indcount
INTEGER, INTENT(In) :: indmax
tukss marked this conversation as resolved.
Show resolved Hide resolved
INTEGER, ALLOCATABLE :: indices_out(:)
INTEGER :: i, j,ind,ni, jmin, jmax
!Converts index lists of the form [1,-4] to [1,2,3,4]
!Converts index lists of the form [1,-4] to [1,2,3,4].
!Also ensures that only values within the grid bounds are retained.
i = 1
ind = 1
ni = size(indices_inout)
ALLOCATE(indices_out(1:ni))
indices_out(:) = -1
DO WHILE( (indices_inout(i) .gt. -1) .and. (i .le. ni))
indices_out(ind) = indices_inout(i)
ind = ind+1


Do While (i .lt. ni)
j = indices_inout(i)
if ((j .ge. 1) .and. (j .le. indmax)) Then
indices_out(ind) = j
ind = ind+1
Endif

IF ( indices_inout(i+1) .lt. -1) THEN
! User has specified a sub-range in this coordinate
jmax = -indices_inout(i+1)
jmin = indices_inout(i)+1
Do j = jmin,jmax
indices_out(ind) = j
ind = ind+1
ENDDO

! Only expand the subrange if the values of jmin and jmax
! are consistent and if they fall within the grid bounds.
If ((jmin .ge. 1) .and. (jmax .ge. jmin)) Then
Do j = jmin,jmax
If (j .le. indmax) Then
indices_out(ind) = j
ind = ind+1
Endif
ENDDO
Endif

i = i + 1 ! We increment an extra time here to skip the next negative number
ENDIF
i = i + 1
Expand All @@ -1726,7 +1742,7 @@ End Subroutine Parse_Inds

SUBROUTINE PROCESS_COORDINATES()
IMPLICIT NONE
INTEGER :: i
INTEGER :: i,lmax,ngrid
Real*8, Allocatable :: tmp_theta(:), tmp_phi(:)
ALLOCATE(tmp_theta(1:ntheta), tmp_phi(1:nphi))

Expand Down Expand Up @@ -1756,7 +1772,9 @@ SUBROUTINE PROCESS_COORDINATES()
DeALLOCATE(tmp_theta,tmp_phi)

! Parse the SPH_MODE_ELL list:
Call Parse_inds(sph_mode_ell, SPH_MODE_Nell)
lmax = maxval(pfi%inds_3s)
ngrid = lmax+1
Call Parse_inds(sph_mode_ell,ngrid, SPH_MODE_Nell)
If (SPH_Mode_nell .gt. 0) Then
Do i =1, sph_mode_nell
sph_mode_nmode = sph_mode_nmode+(sph_mode_ell(i)+1)
Expand All @@ -1771,6 +1789,7 @@ SUBROUTINE Interpret_Indices(indices_nrm, coord_grid, indices, revg)
REAL*8, INTENT(InOut) :: coord_grid(:), indices_nrm(:)
LOGICAL, INTENT(In), Optional :: revg
LOGICAL :: reverse_grid
Integer :: ngrid
IF (present(revg)) THEN
IF (revg) reverse_grid = .true.
ELSE
Expand All @@ -1786,7 +1805,16 @@ SUBROUTINE Interpret_Indices(indices_nrm, coord_grid, indices, revg)

! Next, interpret any range shorthand used.
! e.g., convert [1,-4,8] to [1,2,3,4,8]
Call Parse_Inds(indices)
ngrid = size(coord_grid)
Call Parse_Inds(indices,ngrid)


! Remove any indices whose values are outside of the grid bounds.

!Call Enforce_Bounds(indices,ngrid)
tukss marked this conversation as resolved.
Show resolved Hide resolved
END SUBROUTINE Interpret_Indices




tukss marked this conversation as resolved.
Show resolved Hide resolved
End Module Spherical_IO