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

Generate and return an output array whose elements are the reversed-order elements of the input array, such that
  array = array(lenArray:1:-1),
  where lenArray = len(array) if array is a scalar character, or lenArray = size(array) is an array of rank 1. More...

Detailed Description

Generate and return an output array whose elements are the reversed-order elements of the input array, such that
  array = array(lenArray:1:-1),
  where lenArray = len(array) if array is a scalar character, or lenArray = size(array) is an array of rank 1.

Parameters
[in]array: The input contiguous array of shape (:) of either
  • type css_pdt or,
  • type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU), or
  • type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64), or
  • type logical of kind any supported by the processor (e.g., LK), 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,
  • a scalar character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary length type parameter,
whose elements will be reversed in order.
Returns
ArrayReversed : The output contiguous array of the same type, kind, shape, and size as the input array that will contain the reversed array.


Possible calling interfaces

ArrayReversed = getReversed(array)
Generate and return an output array whose elements are the reversed-order elements of the input array...
This module contains procedures and generic interfaces for reversing the order of elements in arrays ...
Warning
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
The primary purpose of the procedures under this generic interface is to provide an efficient generic method of reversing an array.
This generic interface is particularly useful in case of scalar character input arguments.
With further compiler and language template enhancements in the future, the need for the procedures under this generic interface might be resolved in the future.
See pm_arrayReverse for the relevant benchmarks.
See also
setReversed
setShuffled
getRemapped
setRemapped


Example usage

1program example
2
3 use pm_kind, only: LK
4 use pm_kind, only: SK ! All kinds are supported.
5 use pm_kind, only: IK ! All kinds are supported.
6 use pm_kind, only: CK ! All kinds are supported.
7 use pm_kind, only: RK ! All kinds are supported.
8 use pm_io, only: display_type
10
11 implicit none
12
13 character(:, SK), allocatable :: string1_SK , string2_SK
14 character(9, SK), allocatable :: Array1_SK(:) , Array2_SK(:) ! Can be any processor-supported kind.
15 integer(IK) , allocatable :: Array1_IK(:) , Array2_IK(:) ! Can be any processor-supported kind.
16 complex(CK) , allocatable :: Array1_CK(:) , Array2_CK(:) ! Can be any processor-supported kind.
17 real(RK) , allocatable :: Array1_RK(:) , Array2_RK(:) ! Can be any processor-supported kind.
18 logical(LK) , allocatable :: Array1_LK(:) , Array2_LK(:)
19
20 type(display_type) :: disp
21
22 disp = display_type(file = "main.out.F90")
23
24 call disp%skip()
25 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
26 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%show("! Reverse an array via a function call.")
28 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
29 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
30 call disp%skip()
31
32 string1_SK = "ABCDEF"
33 Array1_SK = ["AA", "BB", "CC", "DD", "EE", "FF"]
34 Array1_IK = [1_IK, 2_IK, 3_IK, 4_IK, 5_IK, 6_IK]
35 Array1_RK = [1._RK, 2._RK, 3._RK, 4._RK, 5._RK, 6._RK]
36 Array1_CK = [(1._CK, -1._CK), (2._CK, -2._CK), (3._CK, -3._CK), (4._CK, -4._CK), (5._CK, -5._CK), (6._CK, -6._CK)]
37 Array1_LK = [.false._LK, .true._LK, .false._LK, .true._LK, .false._LK, .true._LK]
38
39 string2_SK = string1_SK
40 Array2_SK = Array1_SK
41 Array2_IK = Array1_IK
42 Array2_RK = Array1_RK
43 Array2_CK = Array1_CK
44 Array2_LK = Array1_LK
45
46 call disp%skip()
47 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%")
48 call disp%show("! Reverse character scalar.")
49 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%")
50 call disp%skip()
51
52 call disp%show("string2_SK")
53 call disp%show( string2_SK, deliml = SK_"""" )
54 call disp%show("getReversed(string2_SK)")
55 call disp%show( getReversed(string2_SK) )
56
57 call disp%skip()
58 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
59 call disp%show("! Reverse character array.")
60 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
61 call disp%skip()
62
63 call disp%show("Array2_SK")
64 call disp%show( Array2_SK, deliml = SK_"""" )
65 call disp%show("getReversed(Array2_SK)")
66 Array2_SK = getReversed(Array2_SK) ! bypass gfortran 10.3 bug.
67 call disp%show( Array2_SK, deliml = SK_"""" )
68
69 call disp%skip()
70 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%")
71 call disp%show("! Reverse logical array.")
72 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%")
73 call disp%skip()
74
75 call disp%show("Array2_LK")
76 call disp%show( Array2_LK )
77 call disp%show("getReversed(Array2_LK)")
78 call disp%show( getReversed(Array2_LK) )
79
80 call disp%skip()
81 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%")
82 call disp%show("! Reverse integer array.")
83 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%")
84 call disp%skip()
85
86 call disp%show("Array2_IK")
87 call disp%show( Array2_IK )
88 call disp%show("getReversed(Array2_IK)")
89 call disp%show( getReversed(Array2_IK) )
90
91 call disp%skip()
92 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%")
93 call disp%show("! Reverse complex array.")
94 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%")
95 call disp%skip()
96
97 call disp%show("Array2_CK")
98 call disp%show( Array2_CK )
99 call disp%show("getReversed(Array2_CK)")
100 call disp%show( getReversed(Array2_CK) )
101
102 call disp%skip()
103 call disp%show("!%%%%%%%%%%%%%%%%%%%%")
104 call disp%show("! Reverse real array.")
105 call disp%show("!%%%%%%%%%%%%%%%%%%%%")
106 call disp%skip()
107
108 call disp%show("Array2_RK")
109 call disp%show( Array2_RK )
110 call disp%show("getReversed(Array2_RK)")
111 call disp%show( getReversed(Array2_RK) )
112
113end program example
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
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 LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter CK
The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
Definition: pm_kind.F90:542
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 SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

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!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4! Reverse an array via a function call.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9!%%%%%%%%%%%%%%%%%%%%%%%%%%
10! Reverse character scalar.
11!%%%%%%%%%%%%%%%%%%%%%%%%%%
12
13string2_SK
14"ABCDEF"
15getReversed(string2_SK)
16FEDCBA
17
18!%%%%%%%%%%%%%%%%%%%%%%%%%
19! Reverse character array.
20!%%%%%%%%%%%%%%%%%%%%%%%%%
21
22Array2_SK
23"AA ", "BB ", "CC ", "DD ", "EE ", "FF "
24getReversed(Array2_SK)
25"FF ", "EE ", "DD ", "CC ", "BB ", "AA "
26
27!%%%%%%%%%%%%%%%%%%%%%%%
28! Reverse logical array.
29!%%%%%%%%%%%%%%%%%%%%%%%
30
31Array2_LK
32F, T, F, T, F, T
33getReversed(Array2_LK)
34T, F, T, F, T, F
35
36!%%%%%%%%%%%%%%%%%%%%%%%
37! Reverse integer array.
38!%%%%%%%%%%%%%%%%%%%%%%%
39
40Array2_IK
41+1, +2, +3, +4, +5, +6
42getReversed(Array2_IK)
43+6, +5, +4, +3, +2, +1
44
45!%%%%%%%%%%%%%%%%%%%%%%%
46! Reverse complex array.
47!%%%%%%%%%%%%%%%%%%%%%%%
48
49Array2_CK
50(+1.0000000000000000, -1.0000000000000000), (+2.0000000000000000, -2.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+4.0000000000000000, -4.0000000000000000), (+5.0000000000000000, -5.0000000000000000), (+6.0000000000000000, -6.0000000000000000)
51getReversed(Array2_CK)
52(+6.0000000000000000, -6.0000000000000000), (+5.0000000000000000, -5.0000000000000000), (+4.0000000000000000, -4.0000000000000000), (+3.0000000000000000, -3.0000000000000000), (+2.0000000000000000, -2.0000000000000000), (+1.0000000000000000, -1.0000000000000000)
53
54!%%%%%%%%%%%%%%%%%%%%
55! Reverse real array.
56!%%%%%%%%%%%%%%%%%%%%
57
58Array2_RK
59+1.0000000000000000, +2.0000000000000000, +3.0000000000000000, +4.0000000000000000, +5.0000000000000000, +6.0000000000000000
60getReversed(Array2_RK)
61+6.0000000000000000, +5.0000000000000000, +4.0000000000000000, +3.0000000000000000, +2.0000000000000000, +1.0000000000000000
62
Test:
test_pm_arrayReverse
Todo:
Low Priority: This generic interface can be extended to 2D input objects.


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, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin

Definition at line 116 of file pm_arrayReverse.F90.


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