Skip to content

Commit c7572a3

Browse files
committed
Replace problematic where with do loop and double if block
1 parent 9d70a71 commit c7572a3

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

pdf_utilities.F90

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -816,33 +816,37 @@ subroutine calc_comp_corrs_binormal( xpyp, xm, ym, mu_x_1, mu_x_2, & ! In
816816
real ( kind = core_rknd ), dimension(gr%nz), intent(out) :: &
817817
corr_x_y_1, & ! Correlation of x and y (1st PDF component) [-]
818818
corr_x_y_2 ! Correlation of x and y (2nd PDF component) [-]
819+
820+
integer :: i
819821

822+
do i=1, gr%nz
820823

821-
where ( sigma_x_1_sqd * sigma_y_1_sqd > zero &
822-
.or. sigma_x_2_sqd * sigma_y_2_sqd > zero )
824+
if ( sigma_x_1_sqd(i) * sigma_y_1_sqd(i) > zero &
825+
.or. sigma_x_2_sqd(i) * sigma_y_2_sqd(i) > zero ) then
823826

824-
! Calculate corr_x_y_1 (which also equals corr_x_y_2).
825-
corr_x_y_1 &
826-
= ( xpyp &
827-
- mixt_frac * ( mu_x_1 - xm ) * ( mu_y_1 - ym ) &
828-
- ( one - mixt_frac ) * ( mu_x_2 - xm ) * ( mu_y_2 - ym ) ) &
829-
/ ( mixt_frac * sqrt( sigma_x_1_sqd * sigma_y_1_sqd ) &
830-
+ ( one - mixt_frac ) * sqrt( sigma_x_2_sqd * sigma_y_2_sqd ) )
827+
! Calculate corr_x_y_1 (which also equals corr_x_y_2).
828+
corr_x_y_1(i) &
829+
= ( xpyp(i) &
830+
- mixt_frac(i) * ( mu_x_1(i) - xm(i) ) * ( mu_y_1(i) - ym(i) ) &
831+
- ( one - mixt_frac(i) ) * ( mu_x_2(i) - xm(i) ) * ( mu_y_2(i) - ym(i) ) ) &
832+
/ ( mixt_frac(i) * sqrt( sigma_x_1_sqd(i) * sigma_y_1_sqd(i) ) &
833+
+ ( one - mixt_frac(i) ) * sqrt( sigma_x_2_sqd(i) * sigma_y_2_sqd(i) ) )
831834

832-
! The correlation must fall within the bounds of
833-
! -1 <= corr_x_y_1 (= corr_x_y_2) <= 1.
834-
where ( corr_x_y_1 > one )
835-
corr_x_y_1 = one
836-
elsewhere ( corr_x_y_1 < -one )
837-
corr_x_y_1 = -one
838-
endwhere
835+
! The correlation must fall within the bounds of
836+
! -1 <= corr_x_y_1 (= corr_x_y_2) <= 1.
837+
if ( corr_x_y_1(i) > one ) then
838+
corr_x_y_1(i) = one
839+
elseif ( corr_x_y_1(i) < -one ) then
840+
corr_x_y_1(i) = -one
841+
endif
839842

840-
elsewhere ! sigma_x_1^2 * sigma_y_1^2 = 0 and sigma_x_2^2 * sigma_y_2^2 = 0.
843+
else ! sigma_x_1^2 * sigma_y_1^2 = 0 and sigma_x_2^2 * sigma_y_2^2 = 0.
841844

842-
! The correlation is undefined (output as 0).
843-
corr_x_y_1 = zero
845+
! The correlation is undefined (output as 0).
846+
corr_x_y_1(i) = zero
847+
end if
844848

845-
endwhere
849+
end do
846850

847851
! Set corr_x_y_2 equal to corr_x_y_1.
848852
corr_x_y_2 = corr_x_y_1

0 commit comments

Comments
 (0)