1+ #:include "common.fypp"
2+ #:set INT_INDEX_TYPES_ALT_NAME = list(zip(["int_index", "int_index_low"], ["integer(int_index)", "integer(int_index_low)"], ["default", "low"]))
3+
14module test_sorting
25
36 use, intrinsic :: iso_fortran_env, only: compiler_version, error_unit
@@ -54,14 +57,17 @@ module test_sorting
5457 type(string_type) :: string_dummy(0:string_size-1)
5558 type(bitset_large) :: bitsetl_dummy(0:bitset_size-1)
5659 type(bitset_64) :: bitset64_dummy(0:bitset_size-1)
57- integer (int_index) :: index (0 :max (test_size, char_size, string_size)- 1 )
60+ integer(int_index) :: index_default(0:max(test_size, char_size, string_size)-1)
61+ integer(int_index_low) :: index_low(0:max(test_size, char_size, string_size)-1)
5862 integer(int32) :: work(0:test_size/2-1)
5963 character(len=4) :: char_work(0:char_size/2-1)
6064 type(string_type) :: string_work(0:string_size/2-1)
6165 type(bitset_large) :: bitsetl_work(0:bitset_size/2-1)
6266 type(bitset_64) :: bitset64_work(0:bitset_size/2-1)
63- integer (int_index) :: iwork (0 :max (test_size, char_size, &
67+ integer(int_index) :: iwork_default (0:max(test_size, char_size, &
6468 string_size)/2-1)
69+ integer(int_index_low) :: iwork_low(0:max(test_size, char_size, &
70+ string_size)/2-1)
6571 integer :: count, i, index1, index2, j, k, l, temp
6672 real(sp) :: arand, brand
6773 character(*), parameter :: filename = 'test_sorting.txt'
@@ -82,7 +88,6 @@ subroutine collect_sorting(testsuite)
8288 type(unittest_type), allocatable, intent(out) :: testsuite(:)
8389
8490 testsuite = [ &
85- new_unittest(' int_ord_sorts' , test_int_ord_sorts), &
8691 new_unittest('char_ord_sorts', test_char_ord_sorts), &
8792 new_unittest('string_ord_sorts', test_string_ord_sorts), &
8893 new_unittest('bitset_large_ord_sorts', test_bitsetl_ord_sorts), &
@@ -94,11 +99,14 @@ subroutine collect_sorting(testsuite)
9499 new_unittest('string_sorts', test_string_sorts), &
95100 new_unittest('bitset_large_sorts', test_bitsetl_sorts), &
96101 new_unittest('bitset_64_sorts', test_bitset64_sorts), &
97- new_unittest(' int_sort_indexes' , test_int_sort_indexes), &
98- new_unittest(' char_sort_indexes' , test_char_sort_indexes), &
99- new_unittest(' string_sort_indexes' , test_string_sort_indexes), &
100- new_unittest(' bitset_large_sort_indexes' , test_bitsetl_sort_indexes), &
101- new_unittest(' bitset_64_sort_indexes' , test_bitset64_sort_indexes) &
102+ #:for ki, ti, namei in INT_INDEX_TYPES_ALT_NAME
103+ new_unittest('int_sort_indexes_${namei}$', test_int_sort_indexes_${namei}$), &
104+ new_unittest('char_sort_indexes_${namei}$', test_char_sort_indexes_${namei}$), &
105+ new_unittest('string_sort_indexes_${namei}$', test_string_sort_indexes_${namei}$), &
106+ new_unittest('bitset_large_sort_indexes_${namei}$', test_bitsetl_sort_indexes_${namei}$), &
107+ new_unittest('bitset_64_sort_indexes_${namei}$', test_bitset64_sort_indexes_${namei}$), &
108+ #:endfor
109+ new_unittest('int_ord_sorts', test_int_ord_sorts) &
102110 ]
103111
104112 end subroutine collect_sorting
@@ -1207,47 +1215,48 @@ subroutine test_bitset64_sort( a, a_name, ltest )
12071215 end if
12081216 end subroutine test_bitset64_sort
12091217
1210- subroutine test_int_sort_indexes (error )
1218+ #:for ki, ti, namei in INT_INDEX_TYPES_ALT_NAME
1219+ subroutine test_int_sort_indexes_${namei}$(error)
12111220 !> Error handling
12121221 type(error_type), allocatable, intent(out) :: error
12131222 integer(int64) :: i
12141223 integer(int32), allocatable :: d1(:)
1215- integer (int64) , allocatable :: index (:)
1224+ ${ti}$ , allocatable :: index(:)
12161225 logical :: ltest
12171226
1218- call test_int_sort_index ( blocks, " Blocks" , ltest )
1227+ call test_int_sort_index_${namei}$ ( blocks, "Blocks", ltest )
12191228 call check(error, ltest)
12201229 if (allocated(error)) return
12211230
1222- call test_int_sort_index ( decrease, " Decreasing" , ltest )
1231+ call test_int_sort_index_${namei}$ ( decrease, "Decreasing", ltest )
12231232 call check(error, ltest)
12241233 if (allocated(error)) return
12251234
1226- call test_int_sort_index ( identical, " Identical" , ltest )
1235+ call test_int_sort_index_${namei}$ ( identical, "Identical", ltest )
12271236 call check(error, ltest)
12281237 if (allocated(error)) return
12291238
1230- call test_int_sort_index ( increase, " Increasing" , ltest )
1239+ call test_int_sort_index_${namei}$ ( increase, "Increasing", ltest )
12311240 call check(error, ltest)
12321241 if (allocated(error)) return
12331242
1234- call test_int_sort_index ( rand1, " Random dense" , ltest )
1243+ call test_int_sort_index_${namei}$ ( rand1, "Random dense", ltest )
12351244 call check(error, ltest)
12361245 if (allocated(error)) return
12371246
1238- call test_int_sort_index ( rand2, " Random order" , ltest )
1247+ call test_int_sort_index_${namei}$ ( rand2, "Random order", ltest )
12391248 call check(error, ltest)
12401249 if (allocated(error)) return
12411250
1242- call test_int_sort_index ( rand0, " Random sparse" , ltest )
1251+ call test_int_sort_index_${namei}$ ( rand0, "Random sparse", ltest )
12431252 call check(error, ltest)
12441253 if (allocated(error)) return
12451254
1246- call test_int_sort_index ( rand3, " Random 3" , ltest )
1255+ call test_int_sort_index_${namei}$ ( rand3, "Random 3", ltest )
12471256 call check(error, ltest)
12481257 if (allocated(error)) return
12491258
1250- call test_int_sort_index ( rand10, " Random 10" , ltest )
1259+ call test_int_sort_index_${namei}$ ( rand10, "Random 10", ltest )
12511260 call check(error, ltest)
12521261 if (allocated(error)) return
12531262
@@ -1257,9 +1266,9 @@ subroutine test_int_sort_indexes(error)
12571266 call verify_sort( d1, ltest, i )
12581267 call check(error, ltest)
12591268
1260- end subroutine test_int_sort_indexes
1269+ end subroutine test_int_sort_indexes_${namei}$
12611270
1262- subroutine test_int_sort_index ( a , a_name , ltest )
1271+ subroutine test_int_sort_index_${namei}$ ( a, a_name, ltest )
12631272 integer(int32), intent(inout) :: a(:)
12641273 character(*), intent(in) :: a_name
12651274 logical, intent(out) :: ltest
@@ -1275,57 +1284,57 @@ subroutine test_int_sort_index( a, a_name, ltest )
12751284 do i = 1, repeat
12761285 dummy = a
12771286 call system_clock( t0, rate )
1278- call sort_index( dummy, index , work, iwork )
1287+ call sort_index( dummy, index_${namei}$ , work, iwork_${namei}$ )
12791288 call system_clock( t1, rate )
12801289 tdiff = tdiff + t1 - t0
12811290 end do
12821291 tdiff = tdiff/repeat
12831292
1284- dummy = a(index (0 :size (a)- 1 ))
1293+ dummy = a(index_${namei}$ (0:size(a)-1))
12851294 call verify_sort( dummy, valid, i )
12861295 ltest = (ltest .and. valid)
12871296 if ( .not. valid ) then
12881297 write( *, * ) "SORT_INDEX did not sort " // a_name // "."
12891298 write(*,*) 'i = ', i
1290- write (* ,' (a18, 2i7)' ) ' a(index (i-1:i)) = ' , a(index (i-1 :i))
1299+ write(*,'(a18, 2i7)') 'a(index_${namei}$ (i-1:i)) = ', a(index_${namei}$ (i-1:i))
12911300 end if
12921301 write( lun, '("| Integer |", 1x, i7, 2x, "|", 1x, a15, " |", ' // &
12931302 'a12, " |", F10.6, " |" )' ) &
12941303 test_size, a_name, "Sort_Index", tdiff/rate
12951304
12961305 dummy = a
1297- call sort_index( dummy, index , work, iwork , reverse= .true. )
1298- dummy = a(index (size (a)- 1 ))
1306+ call sort_index( dummy, index_${namei}$ , work, iwork_${namei}$ , reverse=.true. )
1307+ dummy = a(index_${namei}$ (size(a)-1))
12991308 call verify_reverse_sort( dummy, valid, i )
13001309 ltest = (ltest .and. valid)
13011310 if ( .not. valid ) then
13021311 write( *, * ) "SORT_INDEX did not reverse sort " // &
13031312 a_name // "."
13041313 write(*,*) 'i = ', i
1305- write (* ,' (a18, 2i7)' ) ' a(index (i-1:i)) = ' , a(index (i-1 :i))
1314+ write(*,'(a18, 2i7)') 'a(index_${namei}$ (i-1:i)) = ', a(index_${namei}$ (i-1:i))
13061315 end if
13071316
1308- end subroutine test_int_sort_index
1317+ end subroutine test_int_sort_index_${namei}$
13091318
1310- subroutine test_char_sort_indexes (error )
1319+ subroutine test_char_sort_indexes_${namei}$ (error)
13111320 !> Error handling
13121321 type(error_type), allocatable, intent(out) :: error
13131322 logical :: ltest
13141323
1315- call test_char_sort_index ( char_decrease, " Char. Decrease" , ltest )
1324+ call test_char_sort_index_${namei}$ ( char_decrease, "Char. Decrease", ltest )
13161325 call check(error, ltest)
13171326 if (allocated(error)) return
13181327
1319- call test_char_sort_index ( char_increase, " Char. Increase" , ltest )
1328+ call test_char_sort_index_${namei}$ ( char_increase, "Char. Increase", ltest )
13201329 call check(error, ltest)
13211330 if (allocated(error)) return
13221331
1323- call test_char_sort_index ( char_rand, " Char. Random" , ltest )
1332+ call test_char_sort_index_${namei}$ ( char_rand, "Char. Random", ltest )
13241333 call check(error, ltest)
13251334
1326- end subroutine test_char_sort_indexes
1335+ end subroutine test_char_sort_indexes_${namei}$
13271336
1328- subroutine test_char_sort_index ( a , a_name , ltest )
1337+ subroutine test_char_sort_index_${namei}$ ( a, a_name, ltest )
13291338 character(len=4), intent(in) :: a(0:)
13301339 character(*), intent(in) :: a_name
13311340 logical, intent(out) :: ltest
@@ -1342,7 +1351,7 @@ subroutine test_char_sort_index( a, a_name, ltest )
13421351 char_dummy = a
13431352 call system_clock( t0, rate )
13441353
1345- call sort_index( char_dummy, index , char_work, iwork )
1354+ call sort_index( char_dummy, index_${namei}$ , char_work, iwork_${namei}$ )
13461355
13471356 call system_clock( t1, rate )
13481357
@@ -1362,27 +1371,27 @@ subroutine test_char_sort_index( a, a_name, ltest )
13621371 'a12, " |", F10.6, " |" )' ) &
13631372 char_size, a_name, "Sort_Index", tdiff/rate
13641373
1365- end subroutine test_char_sort_index
1374+ end subroutine test_char_sort_index_${namei}$
13661375
1367- subroutine test_string_sort_indexes (error )
1376+ subroutine test_string_sort_indexes_${namei}$ (error)
13681377 !> Error handling
13691378 type(error_type), allocatable, intent(out) :: error
13701379 logical :: ltest
13711380
1372- call test_string_sort_index ( string_decrease, " String Decrease" , ltest )
1381+ call test_string_sort_index_${namei}$ ( string_decrease, "String Decrease", ltest )
13731382 call check(error, ltest)
13741383 if (allocated(error)) return
13751384
1376- call test_string_sort_index ( string_increase, " String Increase" , ltest )
1385+ call test_string_sort_index_${namei}$ ( string_increase, "String Increase", ltest )
13771386 call check(error, ltest)
13781387 if (allocated(error)) return
13791388
1380- call test_string_sort_index ( string_rand, " String Random" , ltest )
1389+ call test_string_sort_index_${namei}$ ( string_rand, "String Random", ltest )
13811390 call check(error, ltest)
13821391
1383- end subroutine test_string_sort_indexes
1392+ end subroutine test_string_sort_indexes_${namei}$
13841393
1385- subroutine test_string_sort_index ( a , a_name , ltest )
1394+ subroutine test_string_sort_index_${namei}$ ( a, a_name, ltest )
13861395 type(string_type), intent(in) :: a(0:)
13871396 character(*), intent(in) :: a_name
13881397 logical, intent(out) :: ltest
@@ -1398,7 +1407,7 @@ subroutine test_string_sort_index( a, a_name, ltest )
13981407 do i = 1, repeat
13991408 string_dummy = a
14001409 call system_clock( t0, rate )
1401- call sort_index( string_dummy, index , string_work, iwork )
1410+ call sort_index( string_dummy, index_${namei}$ , string_work, iwork_${namei}$ )
14021411 call system_clock( t1, rate )
14031412 tdiff = tdiff + t1 - t0
14041413 end do
@@ -1416,27 +1425,27 @@ subroutine test_string_sort_index( a, a_name, ltest )
14161425 'a12, " |", F10.6, " |" )' ) &
14171426 string_size, a_name, "Sort_Index", tdiff/rate
14181427
1419- end subroutine test_string_sort_index
1428+ end subroutine test_string_sort_index_${namei}$
14201429
1421- subroutine test_bitsetl_sort_indexes (error )
1430+ subroutine test_bitsetl_sort_indexes_${namei}$ (error)
14221431 !> Error handling
14231432 type(error_type), allocatable, intent(out) :: error
14241433 logical :: ltest
14251434
1426- call test_bitsetl_sort_index ( bitsetl_decrease, " Bitset Decrease" , ltest )
1435+ call test_bitsetl_sort_index_${namei}$ ( bitsetl_decrease, "Bitset Decrease", ltest )
14271436 call check(error, ltest)
14281437 if (allocated(error)) return
14291438
1430- call test_bitsetl_sort_index ( bitsetl_increase, " Bitset Increase" , ltest )
1439+ call test_bitsetl_sort_index_${namei}$ ( bitsetl_increase, "Bitset Increase", ltest )
14311440 call check(error, ltest)
14321441 if (allocated(error)) return
14331442
1434- call test_bitsetl_sort_index ( bitsetl_rand, " Bitset Random" , ltest )
1443+ call test_bitsetl_sort_index_${namei}$ ( bitsetl_rand, "Bitset Random", ltest )
14351444 call check(error, ltest)
14361445
1437- end subroutine test_bitsetl_sort_indexes
1446+ end subroutine test_bitsetl_sort_indexes_${namei}$
14381447
1439- subroutine test_bitsetl_sort_index ( a , a_name , ltest )
1448+ subroutine test_bitsetl_sort_index_${namei}$ ( a, a_name, ltest )
14401449 type(bitset_large), intent(in) :: a(0:)
14411450 character(*), intent(in) :: a_name
14421451 logical, intent(out) :: ltest
@@ -1453,7 +1462,7 @@ subroutine test_bitsetl_sort_index( a, a_name, ltest )
14531462 do i = 1, repeat
14541463 bitsetl_dummy = a
14551464 call system_clock( t0, rate )
1456- call sort_index( bitsetl_dummy, index , bitsetl_work, iwork )
1465+ call sort_index( bitsetl_dummy, index_${namei}$ , bitsetl_work, iwork_${namei}$ )
14571466 call system_clock( t1, rate )
14581467 tdiff = tdiff + t1 - t0
14591468 end do
@@ -1473,27 +1482,27 @@ subroutine test_bitsetl_sort_index( a, a_name, ltest )
14731482 'a12, " |", F10.6, " |" )' ) &
14741483 bitset_size, a_name, "Sort_Index", tdiff/rate
14751484
1476- end subroutine test_bitsetl_sort_index
1485+ end subroutine test_bitsetl_sort_index_${namei}$
14771486
1478- subroutine test_bitset64_sort_indexes (error )
1487+ subroutine test_bitset64_sort_indexes_${namei}$ (error)
14791488 !> Error handling
14801489 type(error_type), allocatable, intent(out) :: error
14811490 logical :: ltest
14821491
1483- call test_bitset64_sort_index ( bitset64_decrease, " Bitset Decrease" , ltest )
1492+ call test_bitset64_sort_index_${namei}$ ( bitset64_decrease, "Bitset Decrease", ltest )
14841493 call check(error, ltest)
14851494 if (allocated(error)) return
14861495
1487- call test_bitset64_sort_index ( bitset64_increase, " Bitset Increase" , ltest )
1496+ call test_bitset64_sort_index_${namei}$ ( bitset64_increase, "Bitset Increase", ltest )
14881497 call check(error, ltest)
14891498 if (allocated(error)) return
14901499
1491- call test_bitset64_sort_index ( bitset64_rand, " Bitset Random" , ltest )
1500+ call test_bitset64_sort_index_${namei}$ ( bitset64_rand, "Bitset Random", ltest )
14921501 call check(error, ltest)
14931502
1494- end subroutine test_bitset64_sort_indexes
1503+ end subroutine test_bitset64_sort_indexes_${namei}$
14951504
1496- subroutine test_bitset64_sort_index ( a , a_name , ltest )
1505+ subroutine test_bitset64_sort_index_${namei}$ ( a, a_name, ltest )
14971506 type(bitset_64), intent(in) :: a(0:)
14981507 character(*), intent(in) :: a_name
14991508 logical, intent(out) :: ltest
@@ -1510,7 +1519,7 @@ subroutine test_bitset64_sort_index( a, a_name, ltest )
15101519 do i = 1, repeat
15111520 bitset64_dummy = a
15121521 call system_clock( t0, rate )
1513- call sort_index( bitset64_dummy, index , bitset64_work, iwork )
1522+ call sort_index( bitset64_dummy, index_${namei}$ , bitset64_work, iwork_${namei}$ )
15141523 call system_clock( t1, rate )
15151524 tdiff = tdiff + t1 - t0
15161525 end do
@@ -1530,7 +1539,8 @@ subroutine test_bitset64_sort_index( a, a_name, ltest )
15301539 'a12, " |", F10.6, " |" )' ) &
15311540 bitset_size, a_name, "Sort_Index", tdiff/rate
15321541
1533- end subroutine test_bitset64_sort_index
1542+ end subroutine test_bitset64_sort_index_${namei}$
1543+ #:endfor
15341544
15351545 subroutine verify_sort( a, valid, i )
15361546 integer(int32), intent(in) :: a(0:)
0 commit comments