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

Generate minimally-spaced character, integer, real sequences or sequences at fixed intervals of size step from start to stop.
More...

Detailed Description

Generate minimally-spaced character, integer, real sequences or sequences at fixed intervals of size step from start to stop.

Parameters
[in]start: The input scalar of the same type and kind as the output range, representing the start point of the output range.
If start is of type character, then it must be of length type parameter 1.
[in]stop: The input scalar of the same type and kind as the output range representing the end point of the output range.
If stop is of type character, then it must be of length type parameter 1.
[in]step: The non-zero input scalar representing the size of the interval between adjacent values in the output range.
  1. If range is of type character, then step must have the default integer kind IK.
  2. If range is of type integer, or real then step must have the same type and kind parameter as range.
(optional, default = dynamically set to the smallest possible spacing between any two values between start and stop.
This means step = sign(1, stop - start) for output range of type character or integer and a variable step set by the intrinsic nearest(range(i), stop - start) for the element i of range.)
Returns
range : The output allocatable of
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of length type parameter 1,
  2. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64),
  3. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the minimally or evenly -spaced sequence within the interval starting with start and stop.
Note that the specified value of stop may not necessarily be the ending value in the sequence.
  1. If range is of type character, then range has the shape (1 : 1 + (ichar(stop) - ichar(start)) / step).
  2. If range is of type integer, then range has the shape (1 : 1 + (stop - start) / step).
  3. If range is of type real and step is missing, then range is an allocatable of shape (:) whose size is determined at runtime based on the real number representation model of the computer.
  4. If range is of type real, then range has the shape (1 : 1 + (stop - start) / step).


Possible calling interfaces

! real range.
range = getRange(start, stop) ! allocatable (unknown size)
range(1 : 1 + (stop - start) / step) = getRange(start, stop, step)
! integer range.
range(1 : 1 + stop - start) = getRange(start, stop)
range(1 : 1 + (stop - start) / step) = getRange(start, stop, step)
! character range.
range(1 : 1 + ichar(stop) - ichar(start)) = getRange(start, stop)
range(1 : 1 + (ichar(stop) - ichar(start)) / step) = getRange(start, stop, step)
Generate minimally-spaced character, integer, real sequences or sequences at fixed intervals of size ...
This module contains procedures and generic interfaces for generating ranges of discrete character,...
Warning
The condition step /= 0 must hold for the corresponding input arguments.
The condition len(stop) == 1 must hold for the corresponding input character arguments.
The condition len(start) == 1 must hold for the corresponding input character arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Beware that the output real sequences with default minimum spacings with arbitrary start and stop can readily overflow the computer memory.
This is because the number of representable real values between any two given start and stop is generally extremely large.
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.
See also
getRange
setRange
getLinSpace
setLinSpace
getLogSpace
setLogSpace


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_io, only: display_type
5 use pm_kind, only: IKL, IKS, IKD, IKH
6 use pm_arrayRange, only: getRange
7
8 implicit none
9
10 type(display_type) :: disp
11 disp = display_type(file = "main.out.F90")
12
13 call disp%skip
14 call disp%show("!%%%%%%%%%%")
15 call disp%show("!real range")
16 call disp%show("!%%%%%%%%%%")
17 call disp%skip
18
19 block
20 real, allocatable :: range(:) ! all non-default kinds are also supported.
21
22 call disp%skip
23 call disp%show("range = getRange(0., 10 * nearest(0., 1.))")
24 range = getRange(0., 10 * nearest(0., 1.))
25 call disp%show("range")
26 call disp%show( range , deliml = """" )
27 call disp%skip
28
29 call disp%skip
30 call disp%show("range = getRange(1., 1. + 10 * epsilon(1.))")
31 range = getRange(1., 1. + 10 * epsilon(1.))
32 call disp%show("range")
33 call disp%show( range , deliml = """" )
34 call disp%skip
35
36 call disp%skip
37 call disp%show("range = getRange(1., 1. - 10 * epsilon(1.))")
38 range = getRange(1., 1. - 10 * epsilon(1.))
39 call disp%show("range")
40 call disp%show( range , deliml = """" )
41 call disp%skip
42
43 call disp%skip
44 call disp%show("range = getRange(0., 9., 2.)")
45 range = getRange(0., 9., 2.)
46 call disp%show("range")
47 call disp%show( range , deliml = """" )
48 call disp%skip
49
50 call disp%skip
51 call disp%show("range = getRange(9., 0., -2.)")
52 range = getRange(9., 0., -2.)
53 call disp%show("range")
54 call disp%show( range , deliml = """" )
55 call disp%skip
56
57 end block
58
59 call disp%skip
60 call disp%show("!%%%%%%%%%%%%%%%")
61 call disp%show("!character range")
62 call disp%show("!%%%%%%%%%%%%%%%")
63 call disp%skip
64
65 block
66 character(:), allocatable :: range ! all non-default kinds are also supported.
67
68 call disp%skip
69 call disp%show("range = getRange('A', 'Z')")
70 range = getRange('A', 'Z')
71 call disp%show("range")
72 call disp%show( range , deliml = """" )
73 call disp%skip
74
75 call disp%skip
76 call disp%show("range = getRange('A', 'Z', 2)")
77 range = getRange('A', 'Z', 2)
78 call disp%show("range")
79 call disp%show( range , deliml = """" )
80 call disp%skip
81
82 call disp%skip
83 call disp%show("range = getRange('A', 'Z', 3)")
84 range = getRange('A', 'Z', 3)
85 call disp%show("range")
86 call disp%show( range , deliml = """" )
87 call disp%skip
88
89 call disp%skip
90 call disp%show("range = getRange('A', 'z', 3)")
91 range = getRange('A', 'z', 3)
92 call disp%show("range")
93 call disp%show( range , deliml = """" )
94 call disp%skip
95
96 call disp%skip
97 call disp%show("range = getRange('Z', 'A', -2)")
98 range = getRange('Z', 'A', -2)
99 call disp%show("range")
100 call disp%show( range , deliml = """" )
101 call disp%skip
102 end block
103
104 call disp%skip
105 call disp%show("!%%%%%%%%%%%%%")
106 call disp%show("!8-bit integer")
107 call disp%show("!%%%%%%%%%%%%%")
108 call disp%skip
109
110 call disp%skip
111 call disp%show("getRange(0_IKL, 10_IKL)")
112 call disp%show( getRange(0_IKL, 10_IKL) )
113 call disp%skip
114 call disp%show("getRange(0_IKL, 10_IKL, 2_IKL)")
115 call disp%show( getRange(0_IKL, 10_IKL, 2_IKL) )
116 call disp%skip
117 call disp%show("getRange(0_IKL, 10_IKL, 3_IKL)")
118 call disp%show( getRange(0_IKL, 10_IKL, 3_IKL) )
119 call disp%skip
120
121 ! Generate sequence in reverse.
122
123 call disp%skip
124 call disp%show("getRange(10_IKL, 0_IKL, -2_IKL)")
125 call disp%show( getRange(10_IKL, 0_IKL, -2_IKL) )
126 call disp%skip
127 call disp%show("getRange(10_IKL, 0_IKL, -3_IKL)")
128 call disp%show( getRange(10_IKL, 0_IKL, -3_IKL) )
129 call disp%skip
130
131 call disp%skip
132 call disp%show("!%%%%%%%%%%%%%%")
133 call disp%show("!16-bit integer")
134 call disp%show("!%%%%%%%%%%%%%%")
135 call disp%skip
136
137 call disp%skip
138 call disp%show("getRange(0_IKS, 10_IKS)")
139 call disp%show( getRange(0_IKS, 10_IKS) )
140 call disp%skip
141 call disp%show("getRange(0_IKS, 10_IKS, 2_IKS)")
142 call disp%show( getRange(0_IKS, 10_IKS, 2_IKS) )
143 call disp%skip
144 call disp%show("getRange(0_IKS, 10_IKS, 3_IKS)")
145 call disp%show( getRange(0_IKS, 10_IKS, 3_IKS) )
146 call disp%skip
147
148 ! Generate sequence in reverse.
149
150 call disp%skip
151 call disp%show("getRange(10_IKS, 0_IKS, -2_IKS)")
152 call disp%show( getRange(10_IKS, 0_IKS, -2_IKS) )
153 call disp%skip
154 call disp%show("getRange(10_IKS, 0_IKS, -3_IKS)")
155 call disp%show( getRange(10_IKS, 0_IKS, -3_IKS) )
156 call disp%skip
157
158 call disp%skip
159 call disp%show("!%%%%%%%%%%%%%%")
160 call disp%show("!32-bit integer")
161 call disp%show("!%%%%%%%%%%%%%%")
162 call disp%skip
163
164 call disp%skip
165 call disp%show("getRange(0_IKD, 10_IKD)")
166 call disp%show( getRange(0_IKD, 10_IKD) )
167 call disp%skip
168 call disp%show("getRange(0_IKD, 10_IKD, 2_IKD)")
169 call disp%show( getRange(0_IKD, 10_IKD, 2_IKD) )
170 call disp%skip
171 call disp%show("getRange(0_IKD, 10_IKD, 3_IKD)")
172 call disp%show( getRange(0_IKD, 10_IKD, 3_IKD) )
173 call disp%skip
174
175 ! Generate sequence in reverse.
176
177 call disp%skip
178 call disp%show("getRange(10_IKD, 0_IKD, -2_IKD)")
179 call disp%show( getRange(10_IKD, 0_IKD, -2_IKD) )
180 call disp%skip
181 call disp%show("getRange(10_IKD, 0_IKD, -3_IKD)")
182 call disp%show( getRange(10_IKD, 0_IKD, -3_IKD) )
183 call disp%skip
184
185 call disp%skip
186 call disp%show("!%%%%%%%%%%%%%%")
187 call disp%show("!64-bit integer")
188 call disp%show("!%%%%%%%%%%%%%%")
189 call disp%skip
190
191 call disp%skip
192 call disp%show("getRange(0_IKH, 10_IKH)")
193 call disp%show( getRange(0_IKH, 10_IKH) )
194 call disp%skip
195 call disp%show("getRange(0_IKH, 10_IKH, 2_IKH)")
196 call disp%show( getRange(0_IKH, 10_IKH, 2_IKH) )
197 call disp%skip
198 call disp%show("getRange(0_IKH, 10_IKH, 3_IKH)")
199 call disp%show( getRange(0_IKH, 10_IKH, 3_IKH) )
200 call disp%skip
201
202 ! Generate sequence in reverse.
203
204 call disp%skip
205 call disp%show("getRange(10_IKH, 0_IKH, -2_IKH)")
206 call disp%show( getRange(10_IKH, 0_IKH, -2_IKH) )
207 call disp%skip
208 call disp%show("getRange(10_IKH, 0_IKH, -3_IKH)")
209 call disp%show( getRange(10_IKH, 0_IKH, -3_IKH) )
210 call disp%skip
211
212end 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 LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
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 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 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!real range
4!%%%%%%%%%%
5
6
7range = getRange(0., 10 * nearest(0., 1.))
8range
9"+0.00000000", "+0.140129846E-44", "+0.280259693E-44", "+0.420389539E-44", "+0.560519386E-44", "+0.700649232E-44", "+0.840779079E-44", "+0.980908925E-44", "+0.112103877E-43", "+0.126116862E-43", "+0.140129846E-43"
10
11
12range = getRange(1., 1. + 10 * epsilon(1.))
13range
14"+1.00000000", "+1.00000012", "+1.00000024", "+1.00000036", "+1.00000048", "+1.00000060", "+1.00000072", "+1.00000083", "+1.00000095", "+1.00000107", "+1.00000119"
15
16
17range = getRange(1., 1. - 10 * epsilon(1.))
18range
19"+1.00000000", "+0.999999940", "+0.999999881", "+0.999999821", "+0.999999762", "+0.999999702", "+0.999999642", "+0.999999583", "+0.999999523", "+0.999999464", "+0.999999404", "+0.999999344", "+0.999999285", "+0.999999225", "+0.999999166", "+0.999999106", "+0.999999046", "+0.999998987", "+0.999998927", "+0.999998868", "+0.999998808"
20
21
22range = getRange(0., 9., 2.)
23range
24"+0.00000000", "+2.00000000", "+4.00000000", "+6.00000000", "+8.00000000"
25
26
27range = getRange(9., 0., -2.)
28range
29"+9.00000000", "+7.00000000", "+5.00000000", "+3.00000000", "+1.00000000"
30
31
32!%%%%%%%%%%%%%%%
33!character range
34!%%%%%%%%%%%%%%%
35
36
37range = getRange('A', 'Z')
38range
39"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
40
41
42range = getRange('A', 'Z', 2)
43range
44"ACEGIKMOQSUWY"
45
46
47range = getRange('A', 'Z', 3)
48range
49"ADGJMPSVY"
50
51
52range = getRange('A', 'z', 3)
53range
54"ADGJMPSVY\_behknqtwz"
55
56
57range = getRange('Z', 'A', -2)
58range
59"ZXVTRPNLJHFDB"
60
61
62!%%%%%%%%%%%%%
63!8-bit integer
64!%%%%%%%%%%%%%
65
66
67getRange(0_IKL, 10_IKL)
68+0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10
69
70getRange(0_IKL, 10_IKL, 2_IKL)
71+0, +2, +4, +6, +8, +10
72
73getRange(0_IKL, 10_IKL, 3_IKL)
74+0, +3, +6, +9
75
76
77getRange(10_IKL, 0_IKL, -2_IKL)
78+10, +8, +6, +4, +2, +0
79
80getRange(10_IKL, 0_IKL, -3_IKL)
81+10, +7, +4, +1
82
83
84!%%%%%%%%%%%%%%
85!16-bit integer
86!%%%%%%%%%%%%%%
87
88
89getRange(0_IKS, 10_IKS)
90+0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10
91
92getRange(0_IKS, 10_IKS, 2_IKS)
93+0, +2, +4, +6, +8, +10
94
95getRange(0_IKS, 10_IKS, 3_IKS)
96+0, +3, +6, +9
97
98
99getRange(10_IKS, 0_IKS, -2_IKS)
100+10, +8, +6, +4, +2, +0
101
102getRange(10_IKS, 0_IKS, -3_IKS)
103+10, +7, +4, +1
104
105
106!%%%%%%%%%%%%%%
107!32-bit integer
108!%%%%%%%%%%%%%%
109
110
111getRange(0_IKD, 10_IKD)
112+0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10
113
114getRange(0_IKD, 10_IKD, 2_IKD)
115+0, +2, +4, +6, +8, +10
116
117getRange(0_IKD, 10_IKD, 3_IKD)
118+0, +3, +6, +9
119
120
121getRange(10_IKD, 0_IKD, -2_IKD)
122+10, +8, +6, +4, +2, +0
123
124getRange(10_IKD, 0_IKD, -3_IKD)
125+10, +7, +4, +1
126
127
128!%%%%%%%%%%%%%%
129!64-bit integer
130!%%%%%%%%%%%%%%
131
132
133getRange(0_IKH, 10_IKH)
134+0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10
135
136getRange(0_IKH, 10_IKH, 2_IKH)
137+0, +2, +4, +6, +8, +10
138
139getRange(0_IKH, 10_IKH, 3_IKH)
140+0, +3, +6, +9
141
142
143getRange(10_IKH, 0_IKH, -2_IKH)
144+10, +8, +6, +4, +2, +0
145
146getRange(10_IKH, 0_IKH, -3_IKH)
147+10, +7, +4, +1
148
149
Test:
test_pm_arrayRange


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:
Fatemeh Bagheri, Tuesday 08:49 PM, August 10, 2021, Dallas, TX

Definition at line 135 of file pm_arrayRange.F90.


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