-
Notifications
You must be signed in to change notification settings - Fork 6
/
mo_functional.f90
4635 lines (4119 loc) · 160 KB
/
mo_functional.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!> \file mo_functional.f90
!> \brief functional-fortran - Functional programming for modern Fortran
!> \url https://github.com/wavebitscientific/functional-fortran
!> \details While not designed as a purely functional programming language,
!> modern Fortran goes a long way by letting the programmer use pure functions
!> to encourage good functional discipline, express code in mathematical form,
!> and minimize bug-prone mutable state. This library provides a set of commonly
!> used tools in functional programming, with the purpose to help Fortran programmers
!> be less imperative and more functional.
!> \authors Milan Curcic <mcurcic@wavebitscientific.com>, Mai 2016
!> \date 2016-2017
!> \copyright Copyright (c) 2016-2017, Wavebit Scientific LLC
!> All rights reserved.
!>
!> Licensed under the BSD-3 clause license.
! Modified Matthias Cuntz, Dec 2017 - downloaded version 0.3.0 - adapt to JAMS
! - make functionals and interfaces one module
module mo_functional
use mo_kind, only: i1, i2, i4, i8, r4=>sp, r8=>dp
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
use mo_kind, only: r16=>dp
#else
use mo_kind, only: r16=>qp
#endif
implicit none
private
public :: arange, complement, empty, filter, foldl, foldr, foldt, head, init, &
insert, intersection, iterfold, last, limit, map, reverse, set, sort, &
split, subscript, tail, unfold, union
public :: operator(.complement.)
public :: operator(.head.)
public :: operator(.init.)
public :: operator(.intersection.)
public :: operator(.last.)
public :: operator(.reverse.)
public :: operator(.set.)
public :: operator(.sort.)
public :: operator(.tail.)
public :: operator(.union.)
public :: f_i1, f_i2, f_i4, f_i8
public :: f_r4, f_r8, f_r16
public :: f_c4, f_c8, f_c16
public :: f_array_i1, f_array_i2, f_array_i4, f_array_i8
public :: f_array_r4, f_array_r8, f_array_r16
public :: f_array_c4, f_array_c8, f_array_c16
public :: f2_i1, f2_i2, f2_i4, f2_i8
public :: f2_r4, f2_r8, f2_r16
public :: f2_c4, f2_c8, f2_c16
public :: f_i1_logical, f_i2_logical, f_i4_logical, f_i8_logical
public :: f_r4_logical, f_r8_logical, f_r16_logical
public :: f_c4_logical, f_c8_logical, f_c16_logical
interface ! procedure interfaces
pure integer(kind=i1) function f_i1(x)
!! f :: i1 -> i1
import :: i1
integer(kind=i1), intent(in) :: x
end function f_i1
!
pure integer(kind=i2) function f_i2(x)
!! f :: i2 -> i2
import :: i2
integer(kind=i2), intent(in) :: x
end function f_i2
!
pure integer(kind=i4) function f_i4(x)
!! f :: i4 -> i4
import :: i4
integer(kind=i4), intent(in) :: x
end function f_i4
!
pure integer(kind=i8) function f_i8(x)
!! f :: i8 -> i8
import :: i8
integer(kind=i8), intent(in) :: x
end function f_i8
!
pure real(kind=r4) function f_r4(x)
!! f :: r4 -> r4
import :: r4
real(kind=r4), intent(in) :: x
end function f_r4
!
pure real(kind=r8) function f_r8(x)
!! f :: r8 -> r8
import :: r8
real(kind=r8), intent(in) :: x
end function f_r8
!
pure real(kind=r16) function f_r16(x)
!! f :: r16 -> r16
import :: r16
real(kind=r16), intent(in) :: x
end function f_r16
!
pure complex(kind=r4) function f_c4(x)
!! f :: c4 -> c4
import :: r4
complex(kind=r4), intent(in) :: x
end function f_c4
!
pure complex(kind=r8) function f_c8(x)
!! f :: c8 -> c8
import :: r8
complex(kind=r8), intent(in) :: x
end function f_c8
!
pure complex(kind=r16) function f_c16(x)
!! f :: c16 -> c16
import :: r16
complex(kind=r16), intent(in) :: x
end function f_c16
!
pure function f_array_i1(x) result(f)
!! f :: [i1] -> [i1]
import :: i1
integer(kind=i1), dimension(:), intent(in) :: x
integer(kind=i1), dimension(:), allocatable :: f
end function f_array_i1
!
pure function f_array_i2(x) result(f)
!! f :: [i2] -> [i2]
import :: i2
integer(kind=i2), dimension(:), intent(in) :: x
integer(kind=i2), dimension(:), allocatable :: f
end function f_array_i2
!
pure function f_array_i4(x) result(f)
!! f :: [i4] -> [i4]
import :: i4
integer(kind=i4), dimension(:), intent(in) :: x
integer(kind=i4), dimension(:), allocatable :: f
end function f_array_i4
!
pure function f_array_i8(x) result(f)
!! f :: [i8] -> [i8]
import :: i8
integer(kind=i8), dimension(:), intent(in) :: x
integer(kind=i8), dimension(:), allocatable :: f
end function f_array_i8
!
pure function f_array_r4(x) result(f)
!! f :: [r4] -> [r4]
import :: r4
real(kind=r4), dimension(:), intent(in) :: x
real(kind=r4), dimension(:), allocatable :: f
end function f_array_r4
!
pure function f_array_r8(x) result(f)
!! f :: [r8] -> [r8]
import :: r8
real(kind=r8), dimension(:), intent(in) :: x
real(kind=r8), dimension(:), allocatable :: f
end function f_array_r8
!
pure function f_array_r16(x) result(f)
!! f :: [r16] -> [r16]
import :: r16
real(kind=r16), dimension(:), intent(in) :: x
real(kind=r16), dimension(:), allocatable :: f
end function f_array_r16
!
pure function f_array_c4(x) result(f)
!! f :: [c4] -> [c4]
import :: r4
complex(kind=r4), dimension(:), intent(in) :: x
complex(kind=r4), dimension(:), allocatable :: f
end function f_array_c4
!
pure function f_array_c8(x) result(f)
!! f :: [c8] -> [c8]
import :: r8
complex(kind=r8), dimension(:), intent(in) :: x
complex(kind=r8), dimension(:), allocatable :: f
end function f_array_c8
!
pure function f_array_c16(x) result(f)
!! f :: [c16] -> [c16]
import :: r16
complex(kind=r16), dimension(:), intent(in) :: x
complex(kind=r16), dimension(:), allocatable :: f
end function f_array_c16
!
pure integer(kind=i1) function f2_i1(x,y)
!! f :: i1 i1 -> i1
import :: i1
integer(kind=i1), intent(in) :: x, y
end function f2_i1
!
pure integer(kind=i2) function f2_i2(x,y)
!! f :: i2 i2 -> i2
import :: i2
integer(kind=i2), intent(in) :: x, y
end function f2_i2
!
pure integer(kind=i4) function f2_i4(x,y)
!! f :: i4 i4 -> i4
import :: i4
integer(kind=i4), intent(in) :: x, y
end function f2_i4
!
pure integer(kind=i8) function f2_i8(x,y)
!! f :: i8 i8 -> i8
import :: i8
integer(kind=i8), intent(in) :: x, y
end function f2_i8
!
pure real(kind=r4) function f2_r4(x,y)
!! f :: r4 r4 -> r4
import :: r4
real(kind=r4), intent(in) :: x, y
end function f2_r4
!
pure real(kind=r8) function f2_r8(x,y)
!! f :: r8 r8 -> r8
import :: r8
real(kind=r8), intent(in) :: x, y
end function f2_r8
!
pure real(kind=r16) function f2_r16(x,y)
!! f :: r16 r16 -> r16
import :: r16
real(kind=r16), intent(in) :: x, y
end function f2_r16
!
pure complex(kind=r4) function f2_c4(x,y)
!! f :: c4 c4 -> c4
import :: r4
complex(kind=r4), intent(in) :: x, y
end function f2_c4
!
pure complex(kind=r8) function f2_c8(x,y)
!! f :: c8 c8 -> c8
import :: r8
complex(kind=r8), intent(in) :: x, y
end function f2_c8
!
pure complex(kind=r16) function f2_c16(x,y)
!! f :: c16 c16 -> c16
import :: r16
complex(kind=r16), intent(in) :: x, y
end function f2_c16
!
pure logical function f_i1_logical(x)
!! f :: i1 -> logical
import :: i1
integer(kind=i1), intent(in) :: x
end function f_i1_logical
!
pure logical function f_i2_logical(x)
!! f :: i2 -> logical
import :: i2
integer(kind=i2), intent(in) :: x
end function f_i2_logical
!
pure logical function f_i4_logical(x)
!! f :: i4 -> logical
import :: i4
integer(kind=i4), intent(in) :: x
end function f_i4_logical
!
pure logical function f_i8_logical(x)
!! f :: i8 -> logical
import :: i8
integer(kind=i8), intent(in) :: x
end function f_i8_logical
!
pure logical function f_r4_logical(x)
!! f :: r4 -> logical
import :: r4
real(kind=r4), intent(in) :: x
end function f_r4_logical
!
pure logical function f_r8_logical(x)
!! f :: r8 -> logical
import :: r8
real(kind=r8), intent(in) :: x
end function f_r8_logical
!
pure logical function f_r16_logical(x)
!! f :: r16 -> logical
import :: r16
real(kind=r16), intent(in) :: x
end function f_r16_logical
!
pure logical function f_c4_logical(x)
!! f :: c4 -> logical
import :: r4
complex(kind=r4), intent(in) :: x
end function f_c4_logical
!
pure logical function f_c8_logical(x)
!! f :: c8 -> logical
import :: r8
complex(kind=r8), intent(in) :: x
end function f_c8_logical
!
pure logical function f_c16_logical(x)
!! f :: c16 -> logical
import :: r16
complex(kind=r16), intent(in) :: x
end function f_c16_logical
end interface
interface arange
module procedure arange_i1, arange_i2, arange_i4, arange_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
arange_r4, arange_r8, &
#else
arange_r4, arange_r8, arange_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
arange_c4, arange_c8
#else
arange_c4, arange_c8, arange_c16
#endif
end interface arange
interface complement
module procedure complement_i1, complement_i2, complement_i4, complement_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
complement_r4, complement_r8, &
#else
complement_r4, complement_r8, complement_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
complement_c4, complement_c8
#else
complement_c4, complement_c8, complement_c16
#endif
end interface complement
interface operator(.complement.)
module procedure complement_i1, complement_i2, complement_i4, complement_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
complement_r4, complement_r8, &
#else
complement_r4, complement_r8, complement_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
complement_c4, complement_c8
#else
complement_c4, complement_c8, complement_c16
#endif
end interface operator(.complement.)
interface empty
module procedure empty_i1, empty_i2, empty_i4, empty_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
empty_r4, empty_r8, &
#else
empty_r4, empty_r8, empty_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
empty_c4, empty_c8
#else
empty_c4, empty_c8, empty_c16
#endif
end interface empty
interface filter
module procedure filter_i1, filter_i2, filter_i4, filter_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
filter_r4, filter_r8, &
#else
filter_r4, filter_r8, filter_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
filter_c4, filter_c8
#else
filter_c4, filter_c8, filter_c16
#endif
end interface filter
interface foldl
module procedure foldl_i1, foldl_i2, foldl_i4, foldl_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
foldl_r4, foldl_r8, &
#else
foldl_r4, foldl_r8, foldl_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
foldl_c4, foldl_c8
#else
foldl_c4, foldl_c8, foldl_c16
#endif
end interface foldl
interface foldr
module procedure foldr_i1, foldr_i2, foldr_i4, foldr_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
foldr_r4, foldr_r8, &
#else
foldr_r4, foldr_r8, foldr_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
foldr_c4, foldr_c8
#else
foldr_c4, foldr_c8, foldr_c16
#endif
end interface foldr
interface foldt
module procedure foldt_i1, foldt_i2, foldt_i4, foldt_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
foldt_r4, foldt_r8, &
#else
foldt_r4, foldt_r8, foldt_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
foldt_c4, foldt_c8
#else
foldt_c4, foldt_c8, foldt_c16
#endif
end interface foldt
interface head
module procedure head_i1, head_i2, head_i4, head_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
head_r4, head_r8, &
#else
head_r4, head_r8, head_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
head_c4, head_c8
#else
head_c4, head_c8, head_c16
#endif
end interface head
interface operator(.head.)
module procedure head_i1, head_i2, head_i4, head_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
head_r4, head_r8, &
#else
head_r4, head_r8, head_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
head_c4, head_c8
#else
head_c4, head_c8, head_c16
#endif
end interface operator(.head.)
interface init
module procedure init_i1, init_i2, init_i4, init_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
init_r4, init_r8, &
#else
init_r4, init_r8, init_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
init_c4, init_c8
#else
init_c4, init_c8, init_c16
#endif
end interface init
interface operator(.init.)
module procedure init_i1, init_i2, init_i4, init_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
init_r4, init_r8, &
#else
init_r4, init_r8, init_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
init_c4, init_c8
#else
init_c4, init_c8, init_c16
#endif
end interface operator(.init.)
interface insert
module procedure insert_i1, insert_i2, insert_i4, insert_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
insert_r4, insert_r8, &
#else
insert_r4, insert_r8, insert_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
insert_c4, insert_c8
#else
insert_c4, insert_c8, insert_c16
#endif
end interface insert
interface intersection
module procedure intersection_i1, intersection_i2, intersection_i4, intersection_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
intersection_r4, intersection_r8, &
#else
intersection_r4, intersection_r8, intersection_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
intersection_c4, intersection_c8
#else
intersection_c4, intersection_c8, intersection_c16
#endif
end interface intersection
interface operator(.intersection.)
module procedure intersection_i1, intersection_i2, intersection_i4, intersection_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
intersection_r4, intersection_r8, &
#else
intersection_r4, intersection_r8, intersection_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
intersection_c4, intersection_c8
#else
intersection_c4, intersection_c8, intersection_c16
#endif
end interface operator(.intersection.)
interface iterfold
module procedure iterfold_i1, iterfold_i2, iterfold_i4, iterfold_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
iterfold_r4, iterfold_r8, &
#else
iterfold_r4, iterfold_r8, iterfold_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
iterfold_c4, iterfold_c8
#else
iterfold_c4, iterfold_c8, iterfold_c16
#endif
end interface iterfold
interface last
module procedure last_i1, last_i2, last_i4, last_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
last_r4, last_r8, &
#else
last_r4, last_r8, last_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
last_c4, last_c8
#else
last_c4, last_c8, last_c16
#endif
end interface last
interface operator(.last.)
module procedure last_i1, last_i2, last_i4, last_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
last_r4, last_r8, &
#else
last_r4, last_r8, last_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
last_c4, last_c8
#else
last_c4, last_c8, last_c16
#endif
end interface operator(.last.)
interface limit
module procedure limit_i1, limit_i2, limit_i4, limit_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
limit_r4, limit_r8, &
#else
limit_r4, limit_r8, limit_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
limit_c4, limit_c8
#else
limit_c4, limit_c8, limit_c16
#endif
end interface limit
interface map
module procedure map_i1, map_i2, map_i4, map_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
map_r4, map_r8, &
#else
map_r4, map_r8, map_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
map_c4, map_c8
#else
map_c4, map_c8, map_c16
#endif
end interface map
interface reverse
module procedure reverse_i1, reverse_i2, reverse_i4, reverse_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
reverse_r4, reverse_r8, &
#else
reverse_r4, reverse_r8, reverse_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
reverse_c4, reverse_c8
#else
reverse_c4, reverse_c8, reverse_c16
#endif
end interface reverse
interface operator(.reverse.)
module procedure reverse_i1, reverse_i2, reverse_i4, reverse_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
reverse_r4, reverse_r8, &
#else
reverse_r4, reverse_r8, reverse_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
reverse_c4, reverse_c8
#else
reverse_c4, reverse_c8, reverse_c16
#endif
end interface operator(.reverse.)
interface set
module procedure set_i1, set_i2, set_i4, set_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
set_r4, set_r8, &
#else
set_r4, set_r8, set_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
set_c4, set_c8
#else
set_c4, set_c8, set_c16
#endif
end interface set
interface operator(.set.)
module procedure set_i1, set_i2, set_i4, set_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
set_r4, set_r8, &
#else
set_r4, set_r8, set_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
set_c4, set_c8
#else
set_c4, set_c8, set_c16
#endif
end interface operator(.set.)
interface sort
module procedure sort_i1, sort_i2, sort_i4, sort_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
sort_r4, sort_r8, &
#else
sort_r4, sort_r8, sort_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
sort_c4, sort_c8
#else
sort_c4, sort_c8, sort_c16
#endif
end interface sort
interface operator(.sort.)
module procedure sort_i1, sort_i2, sort_i4, sort_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
sort_r4, sort_r8, &
#else
sort_r4, sort_r8, sort_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
sort_c4, sort_c8
#else
sort_c4, sort_c8, sort_c16
#endif
end interface operator(.sort.)
interface split
module procedure split_i1, split_i2, split_i4, split_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
split_r4, split_r8, &
#else
split_r4, split_r8, split_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
split_c4, split_c8
#else
split_c4, split_c8, split_c16
#endif
end interface split
interface subscript
module procedure subscript_i1, subscript_i2, subscript_i4, subscript_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
subscript_r4, subscript_r8, &
#else
subscript_r4, subscript_r8, subscript_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
subscript_c4, subscript_c8
#else
subscript_c4, subscript_c8, subscript_c16
#endif
end interface subscript
interface tail
module procedure tail_i1, tail_i2, tail_i4, tail_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
tail_r4, tail_r8, &
#else
tail_r4, tail_r8, tail_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
tail_c4, tail_c8
#else
tail_c4, tail_c8, tail_c16
#endif
end interface tail
interface operator(.tail.)
module procedure tail_i1, tail_i2, tail_i4, tail_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
tail_r4, tail_r8, &
#else
tail_r4, tail_r8, tail_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
tail_c4, tail_c8
#else
tail_c4, tail_c8, tail_c16
#endif
end interface operator(.tail.)
interface unfold
module procedure unfold_i1, unfold_i2, unfold_i4, unfold_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
unfold_r4, unfold_r8, &
#else
unfold_r4, unfold_r8, unfold_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
unfold_c4, unfold_c8
#else
unfold_c4, unfold_c8, unfold_c16
#endif
end interface unfold
interface union
module procedure union_i1, union_i2, union_i4, union_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
union_r4, union_r8, &
#else
union_r4, union_r8, union_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
union_c4, union_c8
#else
union_c4, union_c8, union_c16
#endif
end interface union
interface operator(.union.)
module procedure union_i1, union_i2, union_i4, union_i8, &
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
union_r4, union_r8, &
#else
union_r4, union_r8, union_r16, &
#endif
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
union_c4, union_c8
#else
union_c4, union_c8, union_c16
#endif
end interface operator(.union.)
interface operator(<)
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
module procedure lt_c4, lt_c8
#else
module procedure lt_c4, lt_c8, lt_c16
#endif
end interface operator(<)
interface operator(>=)
#if defined (__pgiFortran__) || defined (__NAGf90Fortran__) || defined (__NAG__)
module procedure ge_c4, ge_c8
#else
module procedure ge_c4, ge_c8, ge_c16
#endif
end interface operator(>=)
contains
pure elemental logical function ge_c4(lhs, rhs) result(res)
!! Private `>=` implementation for 4-byte complex numbers.
complex(kind=r4), intent(in) :: lhs, rhs
res = abs(lhs) >= abs(rhs)
end function ge_c4
pure elemental logical function ge_c8(lhs,rhs) result(res)
!! Private `>=` implementation for 8-byte complex numbers.
complex(kind=r8), intent(in) :: lhs, rhs
res = abs(lhs) >= abs(rhs)
end function ge_c8
pure elemental logical function ge_c16(lhs,rhs) result(res)
!! Private `>=` implementation for 16-byte complex numbers.
complex(kind=r16), intent(in) :: lhs, rhs
res = abs(lhs) >= abs(rhs)
end function ge_c16
pure elemental logical function lt_c4(lhs,rhs) result(res)
!! Private `<` implementation for 4-byte complex numbers.
complex(kind=r4), intent(in) :: lhs, rhs
res = abs(lhs) < abs(rhs)
end function lt_c4
pure elemental logical function lt_c8(lhs,rhs) result(res)
!! Private `<` implementation for 8-byte complex numbers.
complex(kind=r8), intent(in) :: lhs, rhs
res = abs(lhs) < abs(rhs)
end function lt_c8
pure elemental logical function lt_c16(lhs,rhs) result(res)
!! Private `<` implementation for 16-byte complex numbers.
complex(kind=r16), intent(in) :: lhs, rhs
res = abs(lhs) < abs(rhs)
end function lt_c16
pure function arange_i1(start,end,increment) result(arange)
!! Returns an array of integers given `start`, `end`, and `increment` values.
!! Increment defaults to 1 if not provided.
!! This specific procedure is for 1-byte integers.
!! Oveloaded by generic procedure `arange`.
integer(kind=i1), intent(in) :: start !! Start value of the array
integer(kind=i1), intent(in) :: end !! End value of the array
integer(kind=i1), intent(in), optional :: increment !! Array increment
integer(kind=i1), dimension(:), allocatable :: arange
integer(kind=i1) :: incr
integer(kind=i1) :: i
integer(kind=i1) :: length
if(present(increment))then
incr = increment
else
incr = 1
endif
length = (end-start)/incr+1
allocate(arange(length))
#ifdef __pgiFortran__
do i=1, length
#else
do concurrent(i=1:length)
#endif
arange(i) = start+(i-1)*incr
enddo
end function arange_i1
pure function arange_i2(start,end,increment) result(arange)
!! Returns an array of integers given `start`, `end`, and `increment` values.
!! Increment defaults to 1 if not provided.
!! This specific procedure is for 2-byte integers.
!! Oveloaded by generic procedure `arange`.
integer(kind=i2), intent(in) :: start !! Start value of the array
integer(kind=i2), intent(in) :: end !! End value of the array
integer(kind=i2), intent(in), optional :: increment !! Array increment
integer(kind=i2), dimension(:), allocatable :: arange
integer(kind=i2) :: incr
integer(kind=i2) :: i
integer(kind=i2) :: length
if(present(increment))then
incr = increment
else
incr = 1
endif
length = (end-start)/incr+1
allocate(arange(length))
#ifdef __pgiFortran__
do i=1, length
#else
do concurrent(i=1:length)
#endif
arange(i) = start+(i-1)*incr
enddo
end function arange_i2
pure function arange_i4(start,end,increment) result(arange)
!! Returns an array of integers given `start`, `end`, and `increment` values.
!! Increment defaults to 1 if not provided.
!! This specific procedure is for 4-byte integers.
!! Oveloaded by generic procedure `arange`.
integer(kind=i4), intent(in) :: start !! Start value of the array
integer(kind=i4), intent(in) :: end !! End value of the array
integer(kind=i4), intent(in), optional :: increment !! Array increment
integer(kind=i4), dimension(:), allocatable :: arange
integer(kind=i4) :: incr
integer(kind=i4) :: i
integer(kind=i4) :: length
if(present(increment))then
incr = increment
else
incr = 1
endif
length = (end-start)/incr+1
allocate(arange(length))
#ifdef __pgiFortran__
do i=1, length
#else
do concurrent(i=1:length)
#endif
arange(i) = start+(i-1)*incr
enddo
end function arange_i4
pure function arange_i8(start,end,increment) result(arange)
!! Returns an array of integers given `start`, `end`, and `increment` values.
!! Increment defaults to 1 if not provided.
!! This specific procedure is for 8-byte integers.
!! Oveloaded by generic procedure `arange`.
integer(kind=i8), intent(in) :: start !! Start value of the array
integer(kind=i8), intent(in) :: end !! End value of the array
integer(kind=i8), intent(in), optional :: increment !! Array increment
integer(kind=i8), dimension(:), allocatable :: arange
integer(kind=i8) :: incr
integer(kind=i8) :: i
integer(kind=i8) :: length
if(present(increment))then
incr = increment
else
incr = 1
endif
length = (end-start)/incr+1
allocate(arange(length))
#ifdef __pgiFortran__
do i=1, length
#else
do concurrent(i=1:length)
#endif
arange(i) = start+(i-1)*incr
enddo
end function arange_i8
pure function arange_r4(start,end,increment) result(arange)
!! Returns an array of reals given `start`, `end`, and `increment` values.
!! Increment defaults to 1 if not provided.
!! This specific procedure is for 4-byte reals.
!! Oveloaded by generic procedure `arange`.
real(kind=r4), intent(in) :: start !! Start value of the array
real(kind=r4), intent(in) :: end !! End value of the array
real(kind=r4), intent(in), optional :: increment !! Array increment
real(kind=r4), dimension(:), allocatable :: arange
real(kind=r4) :: incr
integer(kind=i4) :: i
integer(kind=i4) :: length
if(present(increment))then
incr = increment
else
incr = 1
endif
length = (end-start+0.5*incr)/incr+1
allocate(arange(length))
#ifdef __pgiFortran__
do i=1, length
#else
do concurrent(i=1:length)
#endif
arange(i) = start+(i-1)*incr
enddo
end function arange_r4
pure function arange_r8(start,end,increment) result(arange)
!! Returns an array of reals given `start`, `end`, and `increment` values.
!! Increment defaults to 1 if not provided.
!! This specific procedure is for 8-byte reals.
!! Oveloaded by generic procedure `arange`.
real(kind=r8), intent(in) :: start !! Start value of the array
real(kind=r8), intent(in) :: end !! End value of the array
real(kind=r8), intent(in), optional :: increment !! Array increment
real(kind=r8), dimension(:), allocatable :: arange
real(kind=r8) :: incr
integer(kind=i4) :: i
integer(kind=i4) :: length
if(present(increment))then
incr = increment
else
incr = 1
endif
length = (end-start+0.5*incr)/incr+1
allocate(arange(length))
#ifdef __pgiFortran__
do i=1, length