54 procedure flip_1D_dp, flip_2D_dp, flip_3D_dp, flip_4D_dp, flip_1D_i4, flip_2D_i4, flip_3D_i4, flip_4D_i4
59 procedure unpack_chunkwise_i1, unpack_chunkwise_dp
87 MODULE PROCEDURE arange_i4, arange_i8, arange_dp, arange_sp
108 MODULE PROCEDURE cumsum_i4, cumsum_i8, cumsum_dp, cumsum_sp, cumsum_dpc, cumsum_spc
132 MODULE PROCEDURE imaxloc_i4, imaxloc_i8, imaxloc_sp, imaxloc_dp
156 MODULE PROCEDURE iminloc_i4, iminloc_i8, iminloc_sp, iminloc_dp
179 MODULE PROCEDURE linspace_i4, linspace_i8, linspace_dp, linspace_sp
226 MODULE PROCEDURE is_close_sp, is_close_dp
262 MODULE PROCEDURE equal_sp, equal_dp
268 MODULE PROCEDURE notequal_sp, notequal_dp
274 MODULE PROCEDURE greaterequal_sp, greaterequal_dp
280 MODULE PROCEDURE lesserequal_sp, lesserequal_dp
285 MODULE PROCEDURE equal_sp, equal_dp
290 MODULE PROCEDURE notequal_sp, notequal_dp
295 MODULE PROCEDURE greaterequal_sp, greaterequal_dp
300 MODULE PROCEDURE lesserequal_sp, lesserequal_dp
404 MODULE PROCEDURE locate_0d_dp, locate_0d_sp, locate_1d_dp, locate_1d_sp
449 swap_xy_dp, swap_xy_sp, swap_xy_i4, &
450 swap_vec_dp, swap_vec_sp, swap_vec_i4
502 logical pure function relational_operator_dp(a, b) result(boolean)
504 real(dp),
intent(in) :: a, b
510 logical pure function relational_operator_sp(a, b) result(boolean)
512 real(sp),
intent(in) :: a, b
526 function arange_i4(lower, upper)
530 integer(i4),
intent(in) :: lower
531 integer(i4),
intent(in),
optional :: upper
532 integer(i4),
dimension(:),
allocatable :: arange_i4
534 integer(i4) :: istart, istop
537 if (
present(upper))
then
545 allocate(arange_i4(istop-istart+1_i4))
547 forall(i=istart:istop) arange_i4(i-istart+1) = i
549 end function arange_i4
551 function arange_i8(lower, upper)
555 integer(i8),
intent(in) :: lower
556 integer(i8),
intent(in),
optional :: upper
557 integer(i8),
dimension(:),
allocatable :: arange_i8
559 integer(i8) :: istart, istop
562 if (
present(upper))
then
570 allocate(arange_i8(istop-istart+1_i8))
572 forall(i=istart:istop) arange_i8(i-istart+1) = i
574 end function arange_i8
576 function arange_dp(lower, upper)
580 real(dp),
intent(in) :: lower
581 real(dp),
intent(in),
optional :: upper
582 real(dp),
dimension(:),
allocatable :: arange_dp
584 integer(i8) :: istart, istop
587 if (
present(upper))
then
588 istart = int(lower,i8)
589 istop = int(upper,i8)
592 istop = int(lower,i8)
595 allocate(arange_dp(istop-istart+1_i8))
597 forall(i=istart:istop) arange_dp(i-istart+1) = real(i,dp)
599 end function arange_dp
601 function arange_sp(lower, upper)
605 real(sp),
intent(in) :: lower
606 real(sp),
intent(in),
optional :: upper
607 real(sp),
dimension(:),
allocatable :: arange_sp
609 integer(i8) :: istart, istop
612 if (
present(upper))
then
613 istart = int(lower,i8)
614 istop = int(upper,i8)
617 istop = int(lower,i8)
620 allocate(arange_sp(istop-istart+1_i8))
622 forall(i=istart:istop) arange_sp(i-istart+1) = real(i,sp)
624 end function arange_sp
628 function cumsum_i4(arr)
632 integer(i4),
dimension(:),
intent(in) :: arr
633 integer(i4),
dimension(size(arr,1)) :: cumsum_i4
637 cumsum_i4(1) = arr(1)
639 cumsum_i4(i) = cumsum_i4(i-1) + arr(i)
642 end function cumsum_i4
644 function cumsum_i8(arr)
648 integer(i8),
dimension(:),
intent(in) :: arr
649 integer(i8),
dimension(size(arr,1)) :: cumsum_i8
653 cumsum_i8(1) = arr(1)
655 cumsum_i8(i) = cumsum_i8(i-1) + arr(i)
658 end function cumsum_i8
660 function cumsum_dp(arr)
664 real(dp),
dimension(:),
intent(in) :: arr
665 real(dp),
dimension(size(arr,1)) :: cumsum_dp
669 cumsum_dp(1) = arr(1)
671 cumsum_dp(i) = cumsum_dp(i-1) + arr(i)
674 end function cumsum_dp
676 function cumsum_dpc(arr)
680 complex(dpc),
dimension(:),
intent(in) :: arr
681 complex(dpc),
dimension(size(arr,1)) :: cumsum_dpc
685 cumsum_dpc(1) = arr(1)
687 cumsum_dpc(i) = cumsum_dpc(i-1) + arr(i)
690 end function cumsum_dpc
692 function cumsum_sp(arr)
696 real(sp),
dimension(:),
intent(in) :: arr
697 real(sp),
dimension(size(arr,1)) :: cumsum_sp
701 cumsum_sp(1) = arr(1)
703 cumsum_sp(i) = cumsum_sp(i-1) + arr(i)
706 end function cumsum_sp
708 function cumsum_spc(arr)
712 complex(spc),
dimension(:),
intent(in) :: arr
713 complex(spc),
dimension(size(arr,1)) :: cumsum_spc
717 cumsum_spc(1) = arr(1)
719 cumsum_spc(i) = cumsum_spc(i-1) + arr(i)
722 end function cumsum_spc
726 function imaxloc_i4(arr, mask)
730 integer(i4),
dimension(:),
intent(in) :: arr
731 logical,
dimension(:),
intent(in),
optional :: mask
732 integer(i4) :: imaxloc_i4
734 integer(i4),
dimension(1) :: imax
736 if (
present(mask))
then
737 imax = maxloc(arr, 1, mask)
739 imax = maxloc(arr, 1)
743 end function imaxloc_i4
745 function imaxloc_i8(arr, mask)
749 integer(i8),
dimension(:),
intent(in) :: arr
750 logical,
dimension(:),
intent(in),
optional :: mask
751 integer(i4) :: imaxloc_i8
753 integer(i4),
dimension(1) :: imax
755 if (
present(mask))
then
756 imax = maxloc(arr, 1, mask)
758 imax = maxloc(arr, 1)
762 end function imaxloc_i8
764 function imaxloc_dp(arr, mask)
768 real(dp),
dimension(:),
intent(in) :: arr
769 logical,
dimension(:),
intent(in),
optional :: mask
770 integer(i4) :: imaxloc_dp
772 integer(i4),
dimension(1) :: imax
774 if (
present(mask))
then
775 imax = maxloc(arr, 1, mask)
777 imax = maxloc(arr, 1)
781 end function imaxloc_dp
783 function imaxloc_sp(arr, mask)
787 real(sp),
dimension(:),
intent(in) :: arr
788 logical,
dimension(:),
intent(in),
optional :: mask
789 integer(i4) :: imaxloc_sp
791 integer(i4),
dimension(1) :: imax
793 if (
present(mask))
then
794 imax = maxloc(arr, 1, mask)
796 imax = maxloc(arr, 1)
800 end function imaxloc_sp
804 function iminloc_i4(arr, mask)
808 integer(i4),
dimension(:),
intent(in) :: arr
809 logical,
dimension(:),
intent(in),
optional :: mask
810 integer(i4) :: iminloc_i4
812 integer(i4),
dimension(1) :: imin
814 if (
present(mask))
then
815 imin = minloc(arr, 1, mask)
817 imin = minloc(arr, 1)
821 end function iminloc_i4
823 function iminloc_i8(arr, mask)
827 integer(i8),
dimension(:),
intent(in) :: arr
828 logical,
dimension(:),
intent(in),
optional :: mask
829 integer(i4) :: iminloc_i8
831 integer(i4),
dimension(1) :: imin
833 if (
present(mask))
then
834 imin = minloc(arr, 1, mask)
836 imin = minloc(arr, 1)
840 end function iminloc_i8
842 function iminloc_dp(arr, mask)
846 real(dp),
dimension(:),
intent(in) :: arr
847 logical,
dimension(:),
intent(in),
optional :: mask
848 integer(i4) :: iminloc_dp
850 integer(i4),
dimension(1) :: imin
852 if (
present(mask))
then
853 imin = minloc(arr, 1, mask)
855 imin = minloc(arr, 1)
859 end function iminloc_dp
861 function iminloc_sp(arr, mask)
865 real(sp),
dimension(:),
intent(in) :: arr
866 logical,
dimension(:),
intent(in),
optional :: mask
867 integer(i4) :: iminloc_sp
869 integer(i4),
dimension(1) :: imin
871 if (
present(mask))
then
872 imin = minloc(arr, 1, mask)
874 imin = minloc(arr, 1)
878 end function iminloc_sp
882 function linspace_i4(lower, upper, nstep)
886 integer(i4),
intent(in) :: lower
887 integer(i4),
intent(in) :: upper
888 integer(i4),
intent(in) :: nstep
889 integer(i4),
dimension(nstep) :: linspace_i4
891 linspace_i4 = lower + nint(
arange(0.0_dp,real(nstep-1_i4,dp))/real(nstep-1_i4,dp) * real(upper-lower,dp), i4)
893 end function linspace_i4
895 function linspace_i8(lower, upper, nstep)
899 integer(i8),
intent(in) :: lower
900 integer(i8),
intent(in) :: upper
901 integer(i4),
intent(in) :: nstep
902 integer(i8),
dimension(nstep) :: linspace_i8
904 linspace_i8 = lower + nint(
arange(0.0_dp,real(nstep-1_i4,dp))/real(nstep-1_i4,dp) * real(upper-lower,dp), i8)
906 end function linspace_i8
908 function linspace_dp(lower, upper, nstep)
912 real(dp),
intent(in) :: lower
913 real(dp),
intent(in) :: upper
914 integer(i4),
intent(in) :: nstep
915 real(dp),
dimension(nstep) :: linspace_dp
917 linspace_dp = lower +
arange(0.0_dp,real(nstep-1_i4,dp))/real(nstep-1_i4,dp) * (upper-lower)
919 end function linspace_dp
921 function linspace_sp(lower, upper, nstep)
925 real(sp),
intent(in) :: lower
926 real(sp),
intent(in) :: upper
927 integer(i4),
intent(in) :: nstep
928 real(sp),
dimension(nstep) :: linspace_sp
930 linspace_sp = lower +
arange(0.0_sp,real(nstep-1_i4,sp))/real(nstep-1_i4,sp) * (upper-lower)
932 end function linspace_sp
936 logical elemental pure function is_close_dp(a, b, rtol, atol, equal_nan) result(boolean)
938 real(dp),
intent(in) :: a
939 real(dp),
intent(in) :: b
940 real(dp),
intent(in),
optional :: rtol, atol
941 logical,
intent(in),
optional :: equal_nan
949 if (
present(rtol)) rt = rtol
950 if (
present(atol)) at = atol
951 if (
present(equal_nan)) n = equal_nan
953 if ((rt < 0._dp).or.(at < 0._dp)) error stop
960 boolean = abs(a - b) <= max(rt * max(abs(a),abs(b)), at)
962 end function is_close_dp
966 logical elemental pure function is_close_sp(a, b, rtol, atol, equal_nan) result(boolean)
968 real(sp),
intent(in) :: a
969 real(sp),
intent(in) :: b
970 real(sp),
intent(in),
optional :: rtol, atol
971 logical,
intent(in),
optional :: equal_nan
979 if (
present(rtol)) rt = rtol
980 if (
present(atol)) at = atol
981 if (
present(equal_nan)) n = equal_nan
983 if ((rt < 0._sp).or.(at < 0._sp)) error stop
990 boolean = abs(a - b) <= max(rt * max(abs(a),abs(b)), at)
992 end function is_close_sp
996 logical elemental pure function equal_dp(a, b) result(boolean)
998 real(dp),
intent(in) :: a
999 real(dp),
intent(in) :: b
1003 boolean = .not. ((epsilon(1.0_dp) * abs(b) - abs(a - b)) < 0.0_dp)
1005 end function equal_dp
1008 logical elemental pure function equal_sp(a, b) result(boolean)
1010 real(sp),
intent(in) :: a
1011 real(sp),
intent(in) :: b
1015 boolean = .not. ((epsilon(1.0_sp) * abs(b) - abs(a - b)) < 0.0_sp)
1017 end function equal_sp
1021 logical elemental pure function greaterequal_dp(a, b) result(boolean)
1023 real(dp),
intent(in) :: a
1024 real(dp),
intent(in) :: b
1026 boolean = equal_dp(a, b).or.(a > b)
1028 end function greaterequal_dp
1031 logical elemental pure function greaterequal_sp(a, b) result(boolean)
1033 real(sp),
intent(in) :: a
1034 real(sp),
intent(in) :: b
1036 boolean = equal_sp(a, b).or.(a > b)
1038 end function greaterequal_sp
1042 logical elemental pure function lesserequal_dp(a, b) result(boolean)
1044 real(dp),
intent(in) :: a
1045 real(dp),
intent(in) :: b
1047 boolean = equal_dp(a, b).or.(a < b)
1049 end function lesserequal_dp
1052 logical elemental pure function lesserequal_sp(a, b) result(boolean)
1054 real(sp),
intent(in) :: a
1055 real(sp),
intent(in) :: b
1057 boolean = equal_sp(a, b).or.(a < b)
1059 end function lesserequal_sp
1063 logical elemental pure function notequal_dp(a, b) result(boolean)
1065 real(dp),
intent(in) :: a
1066 real(dp),
intent(in) :: b
1068 boolean = .not.equal_dp(a, b)
1070 end function notequal_dp
1073 logical elemental pure function notequal_sp(a, b) result(boolean)
1075 real(sp),
intent(in) :: a
1076 real(sp),
intent(in) :: b
1078 boolean = .not.equal_sp(a, b)
1080 end function notequal_sp
1087 use,
intrinsic :: ieee_arithmetic, only : ieee_is_finite
1091 REAL(dp),
INTENT(IN) :: a
1100 use,
intrinsic :: ieee_arithmetic, only : ieee_is_finite
1104 REAL(sp),
INTENT(IN) :: a
1114 use,
intrinsic :: ieee_arithmetic, only : isnan => ieee_is_nan
1118 REAL(dp),
INTENT(IN) :: a
1127 use,
intrinsic :: ieee_arithmetic, only : isnan => ieee_is_nan
1131 REAL(sp),
INTENT(IN) :: a
1141 use,
intrinsic :: ieee_arithmetic, only : ieee_is_normal
1145 REAL(dp),
INTENT(IN) :: a
1154 use,
intrinsic :: ieee_arithmetic, only : ieee_is_normal
1158 REAL(sp),
INTENT(IN) :: a
1171 FUNCTION locate_0d_dp(x, y)
1173 REAL(dp),
DIMENSION(:),
INTENT(IN) :: x
1174 REAL(dp),
INTENT(IN) :: y
1175 INTEGER(i4) :: locate_0d_dp
1177 INTEGER(i4),
dimension(1) :: c
1179 c = minloc(abs(x - y))
1180 if (
le(x(c(1)), y))
then
1183 locate_0d_dp = c(1) - 1
1186 END FUNCTION locate_0d_dp
1188 FUNCTION locate_0d_sp(x, y)
1190 REAL(sp),
DIMENSION(:),
INTENT(IN) :: x
1191 REAL(sp),
INTENT(IN) :: y
1192 INTEGER(i4) :: locate_0d_sp
1194 INTEGER(i4),
dimension(1) :: c
1196 c = minloc(abs(x - y))
1197 if (
le(x(c(1)), y))
then
1200 locate_0d_sp = c(1) - 1
1203 END FUNCTION locate_0d_sp
1205 FUNCTION locate_1d_dp(x, y)
1207 REAL(dp),
DIMENSION(:),
INTENT(IN) :: x
1208 REAL(dp),
DIMENSION(:),
INTENT(IN) :: y
1209 INTEGER(i4),
DIMENSION(:),
allocatable :: locate_1d_dp
1211 INTEGER(i4) :: ny, i
1212 INTEGER(i4),
dimension(1) :: c
1216 if (.not.
allocated(locate_1d_dp))
allocate(locate_1d_dp(ny))
1219 c = minloc(abs(x - y(i)))
1220 if (
le(x(c(1)), y(i)))
then
1221 locate_1d_dp(i) = c(1)
1223 locate_1d_dp(i) = c(1) - 1
1227 END FUNCTION locate_1d_dp
1229 FUNCTION locate_1d_sp(x, y)
1231 REAL(sp),
DIMENSION(:),
INTENT(IN) :: x
1232 REAL(sp),
DIMENSION(:),
INTENT(IN) :: y
1233 INTEGER(i4),
DIMENSION(:),
allocatable :: locate_1d_sp
1235 INTEGER(i4) :: ny, i
1236 INTEGER(i4),
dimension(1) :: c
1240 if (.not.
allocated(locate_1d_sp))
allocate(locate_1d_sp(ny))
1243 c = minloc(abs(x - y(i)))
1244 if (
le(x(c(1)), y(i)))
then
1245 locate_1d_sp(i) = c(1)
1247 locate_1d_sp(i) = c(1) - 1
1251 END FUNCTION locate_1d_sp
1255 elemental pure subroutine swap_xy_dp(x, y)
1257 real(dp),
intent(inout) :: x
1258 real(dp),
intent(inout) :: y
1266 end subroutine swap_xy_dp
1268 elemental pure subroutine swap_xy_sp(x, y)
1270 real(sp),
intent(inout) :: x
1271 real(sp),
intent(inout) :: y
1279 end subroutine swap_xy_sp
1281 elemental pure subroutine swap_xy_i4(x, y)
1283 integer(i4),
intent(inout) :: x
1284 integer(i4),
intent(inout) :: y
1292 end subroutine swap_xy_i4
1295 subroutine swap_vec_dp(x, i1, i2)
1297 real(dp),
dimension(:),
intent(inout) :: x
1298 integer(i4),
intent(in) :: i1
1299 integer(i4),
intent(in) :: i2
1307 end subroutine swap_vec_dp
1309 subroutine swap_vec_sp(x, i1, i2)
1311 real(sp),
dimension(:),
intent(inout) :: x
1312 integer(i4),
intent(in) :: i1
1313 integer(i4),
intent(in) :: i2
1321 end subroutine swap_vec_sp
1323 subroutine swap_vec_i4(x, i1, i2)
1325 integer(i4),
dimension(:),
intent(inout) :: x
1326 integer(i4),
intent(in) :: i1
1327 integer(i4),
intent(in) :: i2
1335 end subroutine swap_vec_i4
1341 use,
intrinsic :: ieee_arithmetic, only : ieee_value, &
1342 ieee_signaling_nan, &
1344 ieee_negative_inf, &
1345 ieee_positive_inf, &
1346 ieee_negative_denormal, &
1347 ieee_positive_denormal, &
1348 ieee_negative_normal, &
1349 ieee_positive_normal, &
1350 ieee_negative_zero, &
1355 real(dp),
intent(in) :: x
1356 character(len = *),
intent(in) :: ieee
1370 character(len = 21) :: ieee_up
1372 ieee_up = toupper(ieee)
1373 select case(trim(ieee_up))
1374 case(
'IEEE_SIGNALING_NAN')
1376 case(
'IEEE_QUIET_NAN')
1378 case(
'IEEE_NEGATIVE_INF')
1380 case(
'IEEE_POSITIVE_INF')
1382 case(
'IEEE_NEGATIVE_DENORMAL')
1384 case(
'IEEE_POSITIVE_DENORMAL')
1386 case(
'IEEE_NEGATIVE_NORMAL')
1388 case(
'IEEE_POSITIVE_NORMAL')
1390 case(
'IEEE_NEGATIVE_ZERO')
1392 case(
'IEEE_POSITIVE_ZERO')
1402 use,
intrinsic :: ieee_arithmetic, only : ieee_value, &
1403 ieee_signaling_nan, &
1405 ieee_negative_inf, &
1406 ieee_positive_inf, &
1407 ieee_negative_denormal, &
1408 ieee_positive_denormal, &
1409 ieee_negative_normal, &
1410 ieee_positive_normal, &
1411 ieee_negative_zero, &
1416 real(sp),
intent(in) :: x
1417 character(len = *),
intent(in) :: ieee
1431 character(len = 21) :: ieee_up
1433 ieee_up = toupper(ieee)
1434 select case(trim(ieee_up))
1435 case(
'IEEE_SIGNALING_NAN')
1437 case(
'IEEE_QUIET_NAN')
1439 case(
'IEEE_NEGATIVE_INF')
1441 case(
'IEEE_POSITIVE_INF')
1443 case(
'IEEE_NEGATIVE_DENORMAL')
1445 case(
'IEEE_POSITIVE_DENORMAL')
1447 case(
'IEEE_NEGATIVE_NORMAL')
1449 case(
'IEEE_POSITIVE_NORMAL')
1451 case(
'IEEE_NEGATIVE_ZERO')
1453 case(
'IEEE_POSITIVE_ZERO')
1461 subroutine flip_1d_dp(data, iDim)
1464 real(dp),
dimension(:),
allocatable,
intent(inout) :: data
1465 integer(i4),
intent(in) :: idim
1467 real(dp),
dimension(:),
allocatable :: temp_data
1468 integer(i4) :: idim1
1470 if (idim > 1_i4)
then
1474 allocate(temp_data(
size(
data, 1)))
1476 do idim1 = 1,
size(
data, 1)
1477 temp_data(
size(
data, 1) - idim1 + 1) =
data(idim1)
1479 call move_alloc(temp_data, data)
1480 end subroutine flip_1d_dp
1482 subroutine flip_2d_dp(data, iDim)
1486 real(dp),
dimension(:, :),
allocatable,
intent(inout) :: data
1487 integer(i4),
intent(in) :: idim
1489 real(dp),
dimension(:, :),
allocatable :: temp_data
1490 integer(i4) :: idim2, idim1
1492 if (idim > 2_i4)
then
1497 allocate(temp_data(
size(
data, 1),
size(
data, 2)))
1499 if (idim == 1_i4)
then
1500 do idim2 = 1,
size(
data, 2)
1501 do idim1 = 1,
size(
data, 1)
1502 temp_data(
size(
data, 1) - idim1 + 1, idim2) =
data(idim1, idim2)
1505 else if (idim == 2_i4)
then
1506 do idim2 = 1,
size(
data, 2)
1507 temp_data(:,
size(
data, 2) - idim2 + 1) =
data(:, idim2)
1510 call move_alloc(temp_data, data)
1511 end subroutine flip_2d_dp
1513 subroutine flip_3d_dp(data, iDim)
1516 real(dp),
dimension(:, :, :),
allocatable,
intent(inout) :: data
1517 integer(i4),
intent(in) :: idim
1519 real(dp),
dimension(:, :, :),
allocatable :: temp_data
1520 integer(i4) :: idim3, idim2, idim1
1522 if (idim > 3_i4)
then
1527 allocate(temp_data(
size(
data, 1),
size(
data, 2),
size(
data, 3)))
1529 if (idim == 1_i4)
then
1530 do idim3 = 1,
size(
data, 3)
1531 do idim2 = 1,
size(
data, 2)
1532 do idim1 = 1,
size(
data, 1)
1533 temp_data(
size(
data, 1) - idim1 + 1, idim2, idim3) =
data(idim1, idim2, idim3)
1537 else if (idim == 2_i4)
then
1538 do idim3 = 1,
size(
data, 3)
1539 do idim2 = 1,
size(
data, 2)
1540 temp_data(:,
size(
data, 2) - idim2 + 1, idim3) =
data(:, idim2, idim3)
1543 else if (idim == 3_i4)
then
1544 do idim3 = 1,
size(
data, 3)
1545 temp_data(:, :,
size(
data, 3) - idim3 + 1) =
data(:, :, idim3)
1548 call move_alloc(temp_data, data)
1549 end subroutine flip_3d_dp
1551 subroutine flip_4d_dp(data, iDim)
1554 real(dp),
dimension(:, :, :, :),
allocatable,
intent(inout) :: data
1555 integer(i4),
intent(in) :: idim
1557 real(dp),
dimension(:, :, :, :),
allocatable :: temp_data
1558 integer(i4) :: idim4, idim3, idim2, idim1
1560 if (idim > 4_i4)
then
1565 allocate(temp_data(
size(
data, 1),
size(
data, 2),
size(
data, 3),
size(
data, 4)))
1567 if (idim == 1_i4)
then
1568 do idim4 = 1,
size(
data, 4)
1569 do idim3 = 1,
size(
data, 3)
1570 do idim2 = 1,
size(
data, 2)
1571 do idim1 = 1,
size(
data, 1)
1572 temp_data(
size(
data, 1) - idim1 + 1, idim2, idim3, idim4) =
data(idim1, idim2, idim3, idim4)
1577 else if (idim == 2_i4)
then
1578 do idim4 = 1,
size(
data, 4)
1579 do idim3 = 1,
size(
data, 3)
1580 do idim2 = 1,
size(
data, 2)
1581 temp_data(:,
size(
data, 2) - idim2 + 1, idim3, idim4) =
data(:, idim2, idim3, idim4)
1585 else if (idim == 3_i4)
then
1586 do idim4 = 1,
size(
data, 4)
1587 do idim3 = 1,
size(
data, 3)
1588 temp_data(:, :,
size(
data, 3) - idim3 + 1, idim4) =
data(:, :, idim3, idim4)
1591 else if (idim == 4_i4)
then
1592 do idim4 = 1,
size(
data, 4)
1593 temp_data(:, :, :,
size(
data, 4) - idim4 + 1) =
data(:, :, :, idim4)
1596 call move_alloc(temp_data, data)
1597 end subroutine flip_4d_dp
1599 subroutine flip_1d_i4(data, iDim)
1602 integer(i4),
dimension(:),
allocatable,
intent(inout) :: data
1603 integer(i4),
intent(in) :: idim
1605 integer(i4),
dimension(:),
allocatable :: temp_data
1606 integer(i4) :: idim1
1608 if (idim > 1_i4)
then
1612 allocate(temp_data(
size(
data, 1)))
1614 do idim1 = 1,
size(
data, 1)
1615 temp_data(
size(
data, 1) - idim1 + 1) =
data(idim1)
1617 call move_alloc(temp_data, data)
1618 end subroutine flip_1d_i4
1620 subroutine flip_2d_i4(data, iDim)
1624 integer(i4),
dimension(:, :),
allocatable,
intent(inout) :: data
1625 integer(i4),
intent(in) :: idim
1627 integer(i4),
dimension(:, :),
allocatable :: temp_data
1628 integer(i4) :: idim2, idim1
1630 if (idim > 2_i4)
then
1635 allocate(temp_data(
size(
data, 1),
size(
data, 2)))
1637 if (idim == 1_i4)
then
1638 do idim2 = 1,
size(
data, 2)
1639 do idim1 = 1,
size(
data, 1)
1640 temp_data(
size(
data, 1) - idim1 + 1, idim2) =
data(idim1, idim2)
1643 else if (idim == 2_i4)
then
1644 do idim2 = 1,
size(
data, 2)
1645 temp_data(:,
size(
data, 2) - idim2 + 1) =
data(:, idim2)
1648 call move_alloc(temp_data, data)
1649 end subroutine flip_2d_i4
1651 subroutine flip_3d_i4(data, iDim)
1654 integer(i4),
dimension(:, :, :),
allocatable,
intent(inout) :: data
1655 integer(i4),
intent(in) :: idim
1657 integer(i4),
dimension(:, :, :),
allocatable :: temp_data
1658 integer(i4) :: idim3, idim2, idim1
1660 if (idim > 3_i4)
then
1665 allocate(temp_data(
size(
data, 1),
size(
data, 2),
size(
data, 3)))
1667 if (idim == 1_i4)
then
1668 do idim3 = 1,
size(
data, 3)
1669 do idim2 = 1,
size(
data, 2)
1670 do idim1 = 1,
size(
data, 1)
1671 temp_data(
size(
data, 1) - idim1 + 1, idim2, idim3) =
data(idim1, idim2, idim3)
1675 else if (idim == 2_i4)
then
1676 do idim3 = 1,
size(
data, 3)
1677 do idim2 = 1,
size(
data, 2)
1678 temp_data(:,
size(
data, 2) - idim2 + 1, idim3) =
data(:, idim2, idim3)
1681 else if (idim == 3_i4)
then
1682 do idim3 = 1,
size(
data, 3)
1683 temp_data(:, :,
size(
data, 3) - idim3 + 1) =
data(:, :, idim3)
1686 call move_alloc(temp_data, data)
1687 end subroutine flip_3d_i4
1689 subroutine flip_4d_i4(data, iDim)
1692 integer(i4),
dimension(:, :, :, :),
allocatable,
intent(inout) :: data
1693 integer(i4),
intent(in) :: idim
1695 integer(i4),
dimension(:, :, :, :),
allocatable :: temp_data
1696 integer(i4) :: idim4, idim3, idim2, idim1
1698 if (idim > 4_i4)
then
1703 allocate(temp_data(
size(
data, 1),
size(
data, 2),
size(
data, 3),
size(
data, 4)))
1705 if (idim == 1_i4)
then
1706 do idim4 = 1,
size(
data, 4)
1707 do idim3 = 1,
size(
data, 3)
1708 do idim2 = 1,
size(
data, 2)
1709 do idim1 = 1,
size(
data, 1)
1710 temp_data(
size(
data, 1) - idim1 + 1, idim2, idim3, idim4) =
data(idim1, idim2, idim3, idim4)
1715 else if (idim == 2_i4)
then
1716 do idim4 = 1,
size(
data, 4)
1717 do idim3 = 1,
size(
data, 3)
1718 do idim2 = 1,
size(
data, 2)
1719 temp_data(:,
size(
data, 2) - idim2 + 1, idim3, idim4) =
data(:, idim2, idim3, idim4)
1723 else if (idim == 3_i4)
then
1724 do idim4 = 1,
size(
data, 4)
1725 do idim3 = 1,
size(
data, 3)
1726 temp_data(:, :,
size(
data, 3) - idim3 + 1, idim4) =
data(:, :, idim3, idim4)
1729 else if (idim == 4_i4)
then
1730 do idim4 = 1,
size(
data, 4)
1731 temp_data(:, :, :,
size(
data, 4) - idim4 + 1) =
data(:, :, :, idim4)
1734 call move_alloc(temp_data, data)
1735 end subroutine flip_4d_i4
1737 function unpack_chunkwise_dp(vector, mask, field, chunksizeArg)
result(unpacked)
1745 real(dp),
dimension(:),
intent(in) :: vector
1746 logical,
dimension(:),
intent(in) :: mask
1747 real(dp),
intent(in) :: field
1748 real(dp),
dimension(size(mask, kind=i8)) :: unpacked
1749 integer(i8),
intent(in),
optional :: chunksizearg
1751 integer(i8) :: i, chunksize, indexmin, indexmax, currentcounts, counts
1753 if (
present(chunksizearg))
then
1754 chunksize = chunksizearg
1756 chunksize = int(huge(0_i4), i8)
1760 indexmax = i * chunksize
1761 currentcounts = 1_i8
1762 do while (indexmax <
size(mask, kind=i8))
1764 indexmin = (i-1) * chunksize + 1_i8
1765 indexmax = minval([i * chunksize,
size(mask, kind=i8)])
1767 counts = count(mask(indexmin: indexmax), kind=i8)
1769 if (counts == (indexmax - indexmin + 1_i8))
then
1770 unpacked(indexmin: indexmax) = vector(currentcounts: currentcounts + counts - 1_i8)
1771 else if (counts == 0_i8)
then
1772 unpacked(indexmin: indexmax) = field
1774 unpacked(indexmin: indexmax) = unpack(vector(currentcounts: currentcounts + counts - 1_i8), &
1775 mask(indexmin: indexmax), &
1779 currentcounts = currentcounts + counts
1783 end function unpack_chunkwise_dp
1785 function unpack_chunkwise_i1(vector, mask, field, chunksizeArg)
result(unpacked)
1791 integer(i1),
dimension(:),
intent(in) :: vector
1792 logical,
dimension(:),
intent(in) :: mask
1793 integer(i1),
intent(in) :: field
1794 integer(i1),
dimension(size(mask, kind=i8)) :: unpacked
1795 integer(i8),
intent(in),
optional :: chunksizearg
1797 integer(i8) :: i, chunksize, indexmin, indexmax, currentcounts, counts
1799 if (
present(chunksizearg))
then
1800 chunksize = chunksizearg
1802 chunksize = int(huge(0_i4), i8)
1806 indexmax = i * chunksize
1807 currentcounts = 1_i8
1808 do while (indexmax <
size(mask, kind=i8))
1810 indexmin = (i-1) * chunksize + 1_i8
1811 indexmax = minval([i * chunksize,
size(mask, kind=i8)])
1813 counts = count(mask(indexmin: indexmax), kind=i8)
1815 unpacked(indexmin: indexmax) = unpack(vector(currentcounts: currentcounts + counts - 1_i8), &
1816 mask(indexmin: indexmax), &
1819 currentcounts = currentcounts + counts
1823 end function unpack_chunkwise_i1
Numbers within a given range.
Comparison of real values.
Comparison of real values.
flip an array at a certain dimension
Comparison of real values: a >= b.
Comparison of real values: a >= b.
First location in array of element with the maximum value.
First location in array of element with the minimum value.
Comparison of real values.
.true. if nor IEEE Inf nor IEEE NaN.
Comparison of real values: a <= b.
Comparison of real values: a <= b.
Evenly spaced numbers in interval.
Find closest values in a monotonic series, returns the indexes.
Comparison of real values for inequality.
Comparison of real values for inequality.
abstract interface for a relational operator on double precision arguments
abstract interface for a relational operator on single precision arguments
Swap to values or two elements in array.
chunk version of the unpack operation
Define number representations.
integer, parameter sp
Single Precision Real Kind.
integer, parameter i4
4 Byte Integer Kind
integer, parameter i8
8 Byte Integer Kind
integer, parameter i1
1 Byte Integer Kind
integer, parameter dpc
Double Precision Complex Kind.
integer, parameter dp
Double Precision Real Kind.
integer, parameter spc
Single Precision Complex Kind.
Write out concatenated strings.
subroutine, public message(t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15, t16, uni, advance, show, reset_format)
Write out an error message to stdout.
character(len(whitespaces)) function, public compress(whitespaces, n)
Remove white spaces.
character(len=len_trim(lower)) function, public toupper(lower)
Convert to upper case.
General utilities for the CHS library.
elemental pure logical function is_nan_sp(a)
elemental pure logical function is_normal_dp(a)
elemental pure logical function is_normal_sp(a)
real(sp) function special_value_sp(x, ieee)
real(dp) function special_value_dp(x, ieee)
elemental pure logical function is_nan_dp(a)
elemental pure logical function is_finite_dp(a)
elemental pure logical function is_finite_sp(a)