ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_arrayMerge::getMerged Interface Reference

Generate an ascending-sorted merger of the two ascending-sorted input arrays. More...

Detailed Description

Generate an ascending-sorted merger of the two ascending-sorted input arrays.

Parameters
[in]sortedArray1: The input scalar of either
  • type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
or the input contiguous array of rank 1 of either
  • type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) or
  • type logical of kind any supported by the processor (e.g., LK) or
  • type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or
  • type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or
  • type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128) or
  • type css_pdt of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) or
  • type css_type of default kind SK,
whose elements are already sorted in ascending order.
When the type of the input argument is complex, the array must be sorted only based on the real component of the values.
[in]sortedArray2: The input contiguous array of the same type, kind, and rank as the input sortedArray1 whose elements are already sorted in ascending order.
When the type of the input argument is complex, the array must be sorted only based on the real component of the values.
isSorted: The external user-specified function that takes two input scalar arguments of the same type and kind as the input Array.
It returns a scalar logical of default kind LK that is .true. if the first input scalar argument is sorted with respect to the second input argument according to the user-defined condition within isSorted, otherwise, it is .false..
If array is a scalar string (i.e., an assumed-length scalar character), then both input arguments to isSorted() are scalar characters of length 1 of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU).
The following illustrates the generic interface of isSorted(),
function isSorted(lhs, rhs) result(sorted)
use pm_kind, only: LK
TYPE(KIND) , intent(in) :: lhs, rhs
logical(LK) :: sorted
end function
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
where TYPE(KIND) is the same as the type and kind of the input argument Array, which can be one of the following.
character(*, SK), intent(in) :: lhs, rhs
character(1, SK), intent(in) :: lhs, rhs
type(css_type) , intent(in) :: lhs, rhs
type(css_pdt) , intent(in) :: lhs, rhs
integer(IK) , intent(in) :: lhs, rhs
logical(LK) , intent(in) :: lhs, rhs
complex(CK) , intent(in) :: lhs, rhs
real(RK) , intent(in) :: lhs, rhs
This module contains the derived types for generating allocatable containers of scalar,...
This is the css_pdt parameterized type for generating instances of container of scalar of string obje...
This is the css_type type for generating instances of container of scalar of string objects.
where the specified kind type parameters (SK, IK, LK, CK, RK) can refer to any of the supported kinds by the processor.
This user-defined equivalence check is extremely useful where a user-defined sorting criterion other than simple ascending order is needed, for example, when the case-sensitivity of an input string or array of strings is irrelevant or when sorting of the absolute values matters excluding the signs of the numbers, or when descending order is desired.
In such cases, user can define a custom sorting condition within the user-defined external function isSorted to achieve the goal.
(optional, the default sorting condition is ascending order, that is a < b.)
Returns
mergedSortedArray : The output object of the same type, kind, and rank as the input sortedArray1 whose length is the sum of the lengths of the input sortedArray1 and sortedArray2 and whose elements are the combined elements of sortedArray1 and sortedArray2 in ascending order.


Possible calling interfaces

mergedSortedArray(1 : size(sortedArray1) + size(sortedArray2)) = getMerged(sortedArray1, sortedArray2)
mergedSortedArray(1 : size(sortedArray1) + size(sortedArray2)) = getMerged(sortedArray1, sortedArray2, isSorted)
Generate an ascending-sorted merger of the two ascending-sorted input arrays.
This module contains procedures and generic interfaces for sorting and merging two previously-sorted ...
Warning
The input arguments sortedArray1 and sortedArray2 must be sorted in ascending order when isSorted() is missing, or properly sorted when isSorted() is present.
This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
Remarks
This generic interface is a functional version of the subroutine implementation pm_arrayMerge::setMerged.
See also
pm_arrayMerge::setMerged


Example usage

1program example
2
3 use pm_kind, only: IK, RK
4 use pm_kind, only: RKS, RKD, RKH
5 use pm_kind, only: IKL, IKS, IKD, IKH
7 use pm_arrayMerge, only: getMerged
8
9 implicit none
10
11 integer(IK), parameter :: NP1 = 2_IK, NP2 = 3_IK
12
13 ! 1-dimensional array of real values.
14
15 real(RKS) :: SortedArray1_RKS(NP1), SortedArray2_RKS(NP2), MergedArray_RKS(NP1+NP2)
16 real(RKD) :: SortedArray1_RKD(NP1), SortedArray2_RKD(NP2), MergedArray_RKD(NP1+NP2)
17 real(RKH) :: SortedArray1_RKH(NP1), SortedArray2_RKH(NP2), MergedArray_RKH(NP1+NP2)
18
19 ! 1-dimensional array of integer values.
20
21 integer(IKL) :: SortedArray1_IKL(NP1), SortedArray2_IKL(NP2), MergedArray_IKL(NP1+NP2)
22 integer(IKS) :: SortedArray1_IKS(NP1), SortedArray2_IKS(NP2), MergedArray_IKS(NP1+NP2)
23 integer(IKD) :: SortedArray1_IKD(NP1), SortedArray2_IKD(NP2), MergedArray_IKD(NP1+NP2)
24 integer(IKH) :: SortedArray1_IKH(NP1), SortedArray2_IKH(NP2), MergedArray_IKH(NP1+NP2)
25
26 integer(IK) :: fileUnit, i
27
28 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 ! Define the sorted arrays.
30 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31
32 SortedArray1_RKS = getLinSpace(0._RK, 4._RK, NP1)
33 SortedArray1_RKD = getLinSpace(0._RK, 4._RK, NP1)
34 SortedArray1_RKH = getLinSpace(0._RK, 4._RK, NP1)
35
36 SortedArray2_RKS = getLinSpace(1._RK, 5._RK, NP2)
37 SortedArray2_RKD = getLinSpace(1._RK, 5._RK, NP2)
38 SortedArray2_RKH = getLinSpace(1._RK, 5._RK, NP2)
39
40 SortedArray1_IKL = int(SortedArray1_RKS, kind = IKL)
41 SortedArray1_IKS = int(SortedArray1_RKS, kind = IKS)
42 SortedArray1_IKD = int(SortedArray1_RKS, kind = IKD)
43 SortedArray1_IKH = int(SortedArray1_RKS, kind = IKH)
44
45 SortedArray2_IKL = int(SortedArray2_RKS, kind = IKL)
46 SortedArray2_IKS = int(SortedArray2_RKS, kind = IKS)
47 SortedArray2_IKD = int(SortedArray2_RKS, kind = IKD)
48 SortedArray2_IKH = int(SortedArray2_RKS, kind = IKH)
49
50 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 ! Sort-merge arrays in ascending order.
52 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
54 MergedArray_IKL = getMerged(SortedArray1_IKL, SortedArray2_IKL)
55 MergedArray_IKS = getMerged(SortedArray1_IKS, SortedArray2_IKS)
56 MergedArray_IKD = getMerged(SortedArray1_IKD, SortedArray2_IKD)
57 MergedArray_IKH = getMerged(SortedArray1_IKH, SortedArray2_IKH)
58
59 MergedArray_RKS = getMerged(SortedArray1_RKS, SortedArray2_RKS)
60 MergedArray_RKD = getMerged(SortedArray1_RKD, SortedArray2_RKD)
61 MergedArray_RKH = getMerged(SortedArray1_RKH, SortedArray2_RKH)
62
63 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 ! Write arrays to the output file.
65 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
67 open(newunit = fileUnit, file = "main.out.F90")
68
69 write(fileUnit,"(*(g0,:,', '))")
70 write(fileUnit,"(*(g0,:,', '))") " SortedArray1_IKL", SortedArray1_IKL
71 write(fileUnit,"(*(g0,:,', '))") " SortedArray2_IKL", SortedArray2_IKL
72 write(fileUnit,"(*(g0,:,', '))") " MergedArray_IKL", MergedArray_IKL
73 write(fileUnit,"(*(g0,:,', '))")
74
75 write(fileUnit,"(*(g0,:,', '))")
76 write(fileUnit,"(*(g0,:,', '))") " SortedArray1_IKS", SortedArray1_IKS
77 write(fileUnit,"(*(g0,:,', '))") " SortedArray2_IKS", SortedArray2_IKS
78 write(fileUnit,"(*(g0,:,', '))") " MergedArray_IKS", MergedArray_IKS
79 write(fileUnit,"(*(g0,:,', '))")
80
81 write(fileUnit,"(*(g0,:,', '))")
82 write(fileUnit,"(*(g0,:,', '))") " SortedArray1_IKD", SortedArray1_IKD
83 write(fileUnit,"(*(g0,:,', '))") " SortedArray2_IKD", SortedArray2_IKD
84 write(fileUnit,"(*(g0,:,', '))") " MergedArray_IKD", MergedArray_IKD
85 write(fileUnit,"(*(g0,:,', '))")
86
87 write(fileUnit,"(*(g0,:,', '))")
88 write(fileUnit,"(*(g0,:,', '))") " SortedArray1_IKH", SortedArray1_IKH
89 write(fileUnit,"(*(g0,:,', '))") " SortedArray2_IKH", SortedArray2_IKH
90 write(fileUnit,"(*(g0,:,', '))") " MergedArray_IKH", MergedArray_IKH
91 write(fileUnit,"(*(g0,:,', '))")
92
93 write(fileUnit,"(*(g0,:,', '))")
94 write(fileUnit,"(*(g0,:,', '))") " SortedArray1_RKS", SortedArray1_RKS
95 write(fileUnit,"(*(g0,:,', '))") " SortedArray2_RKS", SortedArray2_RKS
96 write(fileUnit,"(*(g0,:,', '))") " MergedArray_RKS", MergedArray_RKS
97 write(fileUnit,"(*(g0,:,', '))")
98
99 write(fileUnit,"(*(g0,:,', '))")
100 write(fileUnit,"(*(g0,:,', '))") " SortedArray1_RKD", SortedArray1_RKD
101 write(fileUnit,"(*(g0,:,', '))") " SortedArray2_RKD", SortedArray2_RKD
102 write(fileUnit,"(*(g0,:,', '))") " MergedArray_RKD", MergedArray_RKD
103 write(fileUnit,"(*(g0,:,', '))")
104
105 write(fileUnit,"(*(g0,:,', '))")
106 write(fileUnit,"(*(g0,:,', '))") "SortedArray1_RKH", SortedArray1_RKH
107 write(fileUnit,"(*(g0,:,', '))") "SortedArray2_RKH", SortedArray2_RKH
108 write(fileUnit,"(*(g0,:,', '))") " MergedArray_RKH", MergedArray_RKH
109 write(fileUnit,"(*(g0,:,', '))")
110
111 close(fileUnit)
112
113end program example
Generate count evenly spaced points over the interval [x1, x2] if x1 < x2, or [x2,...
This module contains procedures and generic interfaces for generating arrays with linear or logarithm...
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
integer, parameter IKS
The single-precision integer kind in Fortran mode. On most platforms, this is a 32-bit integer kind.
Definition: pm_kind.F90:563
integer, parameter IKL
The scalar integer constant of intrinsic default kind, representing the lowest range integer kind typ...
Definition: pm_kind.F90:749
integer, parameter IKH
The scalar integer constant of intrinsic default kind, representing the highest range integer kind ty...
Definition: pm_kind.F90:828
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
Definition: pm_kind.F90:568
integer, parameter IKD
The double precision integer kind in Fortran mode. On most platforms, this is a 64-bit integer kind.
Definition: pm_kind.F90:564
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2 SortedArray1_IKL, 0, 4
3 SortedArray2_IKL, 1, 3, 5
4 MergedArray_IKL, 0, 1, 3, 4, 5
5
6
7 SortedArray1_IKS, 0, 4
8 SortedArray2_IKS, 1, 3, 5
9 MergedArray_IKS, 0, 1, 3, 4, 5
10
11
12 SortedArray1_IKD, 0, 4
13 SortedArray2_IKD, 1, 3, 5
14 MergedArray_IKD, 0, 1, 3, 4, 5
15
16
17 SortedArray1_IKH, 0, 4
18 SortedArray2_IKH, 1, 3, 5
19 MergedArray_IKH, 0, 1, 3, 4, 5
20
21
22 SortedArray1_RKS, 0.00000000, 4.00000000
23 SortedArray2_RKS, 1.00000000, 3.00000000, 5.00000000
24 MergedArray_RKS, 0.00000000, 1.00000000, 3.00000000, 4.00000000, 5.00000000
25
26
27 SortedArray1_RKD, 0.0000000000000000, 4.0000000000000000
28 SortedArray2_RKD, 1.0000000000000000, 3.0000000000000000, 5.0000000000000000
29 MergedArray_RKD, 0.0000000000000000, 1.0000000000000000, 3.0000000000000000, 4.0000000000000000, 5.0000000000000000
30
31
32SortedArray1_RKH, 0.00000000000000000000000000000000000, 4.00000000000000000000000000000000000
33SortedArray2_RKH, 1.00000000000000000000000000000000000, 3.00000000000000000000000000000000000, 5.00000000000000000000000000000000000
34 MergedArray_RKH, 0.00000000000000000000000000000000000, 1.00000000000000000000000000000000000, 3.00000000000000000000000000000000000, 4.00000000000000000000000000000000000, 5.00000000000000000000000000000000000
35
Test:
test_pm_arrayMerge


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, April 21, 2017, 1:54 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin

Definition at line 141 of file pm_arrayMerge.F90.


The documentation for this interface was generated from the following file: