forked from zerothi/fdict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iso_var_str.f90
3674 lines (3531 loc) · 129 KB
/
iso_var_str.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
MODULE ISO_VAR_STR
! Written by J.L.Schonfelder
! Incorporating suggestions by members of the committee ISO/IEC JTC1/SC22/WG5
! Version produced (3-Nov-1998)
! Updated to exploit facilities included in Fortran 95
!-----------------------------------------------------------------------------!
! This module defines the interface and one possible implementation for a !
! dynamic length character string facility in Fortran 95. The Fortran 95 !
! language is defined by the standard ISO/IEC 1539-1 : 1997. !
! The publicly accessible interface defined by this module is conformant !
! with the auxilliary standard, ISO/IEC 1539-2 : 1999. !
! The detailed implementation may be considered as an informal definition of !
! the required semantics, and may also be used as a guide to the production !
! of a portable implementation. !
! N.B. Although every care has been taken to produce valid Fortran code in !
! construction of this module no guarantee is given or implied that this !
! code will work correctly without error on any specific processor, nor !
! is this implementation intended to be in any way optimal either in use !
! of storage or CPU cycles. !
!-----------------------------------------------------------------------------!
PRIVATE
!-----------------------------------------------------------------------------!
! By default all entities declared or defined in this module are private to !
! the module. Only those entities declared explicitly as being public are !
! accessible to programs using the module. In particular, the procedures and !
! operators defined herein are made accessible via their generic identifiers !
! only; their specific names are private. !
!-----------------------------------------------------------------------------!
TYPE VAR_STR
PRIVATE
CHARACTER,DIMENSION(:),POINTER :: chars => NULL()
ENDTYPE VAR_STR
!-----------------------------------------------------------------------------!
! The representation chosen for this definition of the module is of a string !
! type consisting of a single component that is a pointer to a rank one array !
! of characters. !
! Note: this Module is defined only for characters of default kind. A similar !
! module could be defined for non-default characters if these are supported !
! on a processor by adding a KIND parameter to the component in the type !
! definition, and to all delarations of objects of CHARACTER type. !
!-----------------------------------------------------------------------------!
CHARACTER,PARAMETER :: blank = " "
!----- GENERIC PROCEDURE INTERFACE DEFINITIONS -------------------------------!
!----- LEN interface ---------------------------------------------------------!
INTERFACE LEN
MODULE PROCEDURE len_s ! length of string
ENDINTERFACE
!----- Conversion procedure interfaces ---------------------------------------!
INTERFACE VARSTR
MODULE PROCEDURE c_to_s ! character to string
ENDINTERFACE
INTERFACE CHAR
MODULE PROCEDURE s_to_c, & ! string to character
s_to_fix_c ! string to specified length character
ENDINTERFACE
!----- ASSIGNMENT interfaces -------------------------------------------------!
INTERFACE ASSIGNMENT(=)
MODULE PROCEDURE s_ass_s, & ! string = string
c_ass_s, & ! character = string
s_ass_c ! string = character
ENDINTERFACE
!----- Concatenation operator interfaces -------------------------------------!
INTERFACE OPERATOR(//)
MODULE PROCEDURE s_concat_s, & ! string//string
s_concat_c, & ! string//character
c_concat_s ! character//string
ENDINTERFACE
!----- Repeated Concatenation interface --------------------------------------!
INTERFACE REPEAT
MODULE PROCEDURE repeat_s
ENDINTERFACE
!------ Equality comparison operator interfaces-------------------------------!
INTERFACE OPERATOR(==)
MODULE PROCEDURE s_eq_s, & ! string==string
s_eq_c, & ! string==character
c_eq_s ! character==string
ENDINTERFACE
!----- not-equality comparison operator interfaces ---------------------------!
INTERFACE OPERATOR(/=)
MODULE PROCEDURE s_ne_s, & ! string/=string
s_ne_c, & ! string/=character
c_ne_s ! character/=string
ENDINTERFACE
!----- less-than comparison operator interfaces ------------------------------!
INTERFACE OPERATOR(<)
MODULE PROCEDURE s_lt_s, & ! string<string
s_lt_c, & ! string<character
c_lt_s ! character<string
ENDINTERFACE
!----- less-than-or-equal comparison operator interfaces ---------------------!
INTERFACE OPERATOR(<=)
MODULE PROCEDURE s_le_s, & ! string<=string
s_le_c, & ! string<=character
c_le_s ! character<=string
ENDINTERFACE
!----- greater-than-or-equal comparison operator interfaces ------------------!
INTERFACE OPERATOR(>=)
MODULE PROCEDURE s_ge_s, & ! string>=string
s_ge_c, & ! string>=character
c_ge_s ! character>=string
ENDINTERFACE
!----- greater-than comparison operator interfaces ---------------------------!
INTERFACE OPERATOR(>)
MODULE PROCEDURE s_gt_s, & ! string>string
s_gt_c, & ! string>character
c_gt_s ! character>string
ENDINTERFACE
!----- LLT procedure interfaces ----------------------------------------------!
INTERFACE LLT
MODULE PROCEDURE s_llt_s, & ! LLT(string,string)
s_llt_c, & ! LLT(string,character)
c_llt_s ! LLT(character,string)
ENDINTERFACE
!----- LLE procedure interfaces ----------------------------------------------!
INTERFACE LLE
MODULE PROCEDURE s_lle_s, & ! LLE(string,string)
s_lle_c, & ! LLE(string,character)
c_lle_s ! LLE(character,string)
ENDINTERFACE
!----- LGE procedure interfaces ----------------------------------------------!
INTERFACE LGE
MODULE PROCEDURE s_lge_s, & ! LGE(string,string)
s_lge_c, & ! LGE(string,character)
c_lge_s ! LGE(character,string)
ENDINTERFACE
!----- LGT procedure interfaces ----------------------------------------------!
INTERFACE LGT
MODULE PROCEDURE s_lgt_s, & ! LGT(string,string)
s_lgt_c, & ! LGT(string,character)
c_lgt_s ! LGT(character,string)
ENDINTERFACE
!----- Input procedure interfaces --------------------------------------------!
INTERFACE GET
MODULE PROCEDURE get_d_eor, & ! default unit, EoR termination
get_u_eor, & ! specified unit, EoR termination
get_d_tset_s, & ! default unit, string set termination
get_u_tset_s, & ! specified unit, string set termination
get_d_tset_c, & ! default unit, char set termination
get_u_tset_c ! specified unit, char set termination
ENDINTERFACE
!----- Output procedure interfaces -------------------------------------------!
INTERFACE PUT
MODULE PROCEDURE put_d_s, & ! string to default unit
put_u_s, & ! string to specified unit
put_d_c, & ! char to default unit
put_u_c ! char to specified unit
ENDINTERFACE
INTERFACE PUT_LINE
MODULE PROCEDURE putline_d_s, & ! string to default unit
putline_u_s, & ! string to specified unit
putline_d_c, & ! char to default unit
putline_u_c ! char to specified unit
ENDINTERFACE
!----- Insert procedure interfaces -------------------------------------------!
INTERFACE INSERT
MODULE PROCEDURE insert_ss, & ! string in string
insert_sc, & ! char in string
insert_cs, & ! string in char
insert_cc ! char in char
ENDINTERFACE
!----- Replace procedure interfaces ------------------------------------------!
INTERFACE REPLACE
MODULE PROCEDURE replace_ss, & ! string by string, at specified
replace_sc, & ! string by char , starting
replace_cs, & ! char by string , point
replace_cc, & ! char by char
replace_ss_sf,& ! string by string, between
replace_sc_sf,& ! string by char , specified
replace_cs_sf,& ! char by string , starting and
replace_cc_sf,& ! char by char , finishing points
replace_sss, & ! in string replace string by string
replace_ssc, & ! in string replace string by char
replace_scs, & ! in string replace char by string
replace_scc, & ! in string replace char by char
replace_css, & ! in char replace string by string
replace_csc, & ! in char replace string by char
replace_ccs, & ! in char replace char by string
replace_ccc ! in char replace char by char
ENDINTERFACE
!----- Remove procedure interface --------------------------------------------!
!INTERFACE REMOVE
! MODULE PROCEDURE remove_s, & ! characters from string, between start
! remove_c ! characters from char , and finish
!ENDINTERFACE
!----- Extract procedure interface -------------------------------------------!
INTERFACE EXTRACT
MODULE PROCEDURE extract_s, & ! from string extract string, between start
extract_c ! from char extract string, and finish
ENDINTERFACE
!----- Split procedure interface ---------------------------------------------!
INTERFACE SPLIT
MODULE PROCEDURE split_s, & ! split string at first occurance of
split_c ! character in set
ENDINTERFACE
!----- Index procedure interfaces --------------------------------------------!
INTERFACE INDEX
MODULE PROCEDURE index_ss, index_sc, index_cs
ENDINTERFACE
!----- Scan procedure interfaces ---------------------------------------------!
INTERFACE SCAN
MODULE PROCEDURE scan_ss, scan_sc, scan_cs
ENDINTERFACE
!----- Verify procedure interfaces -------------------------------------------!
INTERFACE VERIFY
MODULE PROCEDURE verify_ss, verify_sc, verify_cs
ENDINTERFACE
!----- Interfaces for remaining intrinsic function overloads -----------------!
INTERFACE LEN_TRIM
MODULE PROCEDURE len_trim_s
ENDINTERFACE
INTERFACE TRIM
MODULE PROCEDURE trim_s
ENDINTERFACE
INTERFACE IACHAR
MODULE PROCEDURE iachar_s
ENDINTERFACE
INTERFACE ICHAR
MODULE PROCEDURE ichar_s
ENDINTERFACE
INTERFACE ADJUSTL
MODULE PROCEDURE adjustl_s
ENDINTERFACE
INTERFACE ADJUSTR
MODULE PROCEDURE adjustr_s
ENDINTERFACE
!----- specification of publically accessible entities -----------------------!
PUBLIC :: VAR_STR,VARSTR,CHAR,LEN,GET,PUT,PUT_LINE,INSERT,REPLACE, &
SPLIT,REPEAT,EXTRACT,INDEX,SCAN,VERIFY,LLT,LLE,LGE,LGT, &
ASSIGNMENT(=),OPERATOR(//),OPERATOR(==),OPERATOR(/=),OPERATOR(<), &
OPERATOR(<=),OPERATOR(>=),OPERATOR(>),LEN_TRIM,TRIM,IACHAR,ICHAR, &
ADJUSTL,ADJUSTR
!PUBLIC :: REMOVE
CONTAINS
!----- LEN Procedure ---------------------------------------------------------!
ELEMENTAL FUNCTION len_s(string) ! generic LEN
type(VAR_STR),INTENT(IN) :: string
INTEGER :: len_s
! returns the length of the string argument or zero if there is no current
! string value
IF(.NOT.ASSOCIATED(string%chars))THEN
len_s = 0
ELSE
len_s = SIZE(string%chars)
ENDIF
ENDFUNCTION len_s
!----- Conversion Procedures ------------------------------------------------!
ELEMENTAL FUNCTION c_to_s(chr) ! generic VAR_STR
type(VAR_STR) :: c_to_s
CHARACTER(LEN=*),INTENT(IN) :: chr
! returns the string consisting of the characters char
INTEGER :: lc
lc=LEN(chr)
ALLOCATE(c_to_s%chars(1:lc))
DO i=1,lc
c_to_s%chars(i) = chr(i:i)
ENDDO
ENDFUNCTION c_to_s
PURE FUNCTION s_to_c(string) ! generic CHAR
type(VAR_STR),INTENT(IN) :: string
CHARACTER(LEN=SIZE(string%chars)) :: s_to_c
! returns the characters of string as an automatically sized character
INTEGER :: lc
lc=SIZE(string%chars)
DO i=1,lc
s_to_c(i:i) = string%chars(i)
ENDDO
ENDFUNCTION s_to_c
PURE FUNCTION s_to_fix_c(string,length) ! generic CHAR
type(VAR_STR),INTENT(IN) :: string
INTEGER,INTENT(IN) :: length
CHARACTER(LEN=length) :: s_to_fix_c
! returns the character of fixed length, length, containing the characters
! of string either padded with blanks or truncated on the right to fit
INTEGER :: lc
lc=MIN(SIZE(string%chars),length)
DO i=1,lc
s_to_fix_c(i:i) = string%chars(i)
ENDDO
IF(lc < length)THEN ! result longer than string padding needed
s_to_fix_c(lc+1:length) = blank
ENDIF
ENDFUNCTION s_to_fix_c
!----- ASSIGNMENT Procedures -------------------------------------------------!
ELEMENTAL SUBROUTINE s_ass_s(var,expr)
type(VAR_STR),INTENT(INOUT) :: var
type(VAR_STR),INTENT(IN) :: expr
! assign a string value to a string variable overriding default assignement
! reallocates string variable to size of string value and copies characters
IF(ASSOCIATED(var%chars,expr%chars))THEN
CONTINUE ! identity assignment do nothing
ELSEIF(ASSOCIATED(var%chars))THEN
DEALLOCATE(var%chars)
ALLOCATE(var%chars(1:SIZE(expr%chars)))
var%chars = expr%chars
ELSE
ALLOCATE(var%chars(1:SIZE(expr%chars)))
var%chars = expr%chars
ENDIF
ENDSUBROUTINE s_ass_s
ELEMENTAL SUBROUTINE c_ass_s(var,expr)
CHARACTER(LEN=*),INTENT(OUT) :: var
type(VAR_STR),INTENT(IN) :: expr
! assign a string value to a character variable
! if the string is longer than the character truncate the string on the right
! if the string is shorter the character is blank padded on the right
INTEGER :: lc,ls
lc = LEN(var); ls = MIN(LEN(expr),lc)
DO i = 1,ls
var(i:i) = expr%chars(i)
ENDDO
DO i = ls+1,lc
var(i:i) = blank
ENDDO
ENDSUBROUTINE c_ass_s
ELEMENTAL SUBROUTINE s_ass_c(var,expr)
type(VAR_STR),INTENT(OUT) :: var
CHARACTER(LEN=*),INTENT(IN) :: expr
! assign a character value to a string variable
! disassociates the string variable from its current value, allocates new
! space to hold the characters and copies them from the character value
! into this space.
INTEGER :: lc
lc = LEN(expr)
IF(ASSOCIATED(var%chars))DEALLOCATE(var%chars)
ALLOCATE(var%chars(1:lc))
DO i = 1,lc
var%chars(i) = expr(i:i)
ENDDO
ENDSUBROUTINE s_ass_c
!----- Concatenation operator procedures ------------------------------------!
ELEMENTAL FUNCTION s_concat_s(string_a,string_b) ! string//string
type(VAR_STR),INTENT(IN) :: string_a,string_b
type(VAR_STR) :: s_concat_s
INTEGER :: la,lb
la = LEN(string_a); lb = LEN(string_b)
ALLOCATE(s_concat_s%chars(1:la+lb))
s_concat_s%chars(1:la) = string_a%chars
s_concat_s%chars(1+la:la+lb) = string_b%chars
ENDFUNCTION s_concat_s
ELEMENTAL FUNCTION s_concat_c(string_a,string_b) ! string//character
type(VAR_STR),INTENT(IN) :: string_a
CHARACTER(LEN=*),INTENT(IN) :: string_b
type(VAR_STR) :: s_concat_c
INTEGER :: la,lb
la = LEN(string_a); lb = LEN(string_b)
ALLOCATE(s_concat_c%chars(1:la+lb))
s_concat_c%chars(1:la) = string_a%chars
DO i = 1,lb
s_concat_c%chars(la+i) = string_b(i:i)
ENDDO
ENDFUNCTION s_concat_c
ELEMENTAL FUNCTION c_concat_s(string_a,string_b) ! character//string
CHARACTER(LEN=*),INTENT(IN) :: string_a
type(VAR_STR),INTENT(IN) :: string_b
type(VAR_STR) :: c_concat_s
INTEGER :: la,lb
la = LEN(string_a); lb = LEN(string_b)
ALLOCATE(c_concat_s%chars(1:la+lb))
DO i = 1,la
c_concat_s%chars(i) = string_a(i:i)
ENDDO
c_concat_s%chars(1+la:la+lb) = string_b%chars
ENDFUNCTION c_concat_s
!----- Reapeated concatenation procedures -----------------------------------!
ELEMENTAL FUNCTION repeat_s(string,ncopies)
type(VAR_STR),INTENT(IN) :: string
INTEGER,INTENT(IN) :: ncopies
type(VAR_STR) :: repeat_s
! Returns a string produced by the concatenation of ncopies of the
! argument string
INTEGER :: lr,ls
IF (ncopies <= 0) THEN
ALLOCATE(repeat_s%chars(1:0)) ! return a zero length string
RETURN
ENDIF
ls = LEN(string); lr = ls*ncopies
ALLOCATE(repeat_s%chars(1:lr))
DO i = 1,ncopies
repeat_s%chars(1+(i-1)*ls:i*ls) = string%chars
ENDDO
ENDFUNCTION repeat_s
!------ Equality comparison operators ----------------------------------------!
ELEMENTAL FUNCTION s_eq_s(string_a,string_b) ! string==string
type(VAR_STR),INTENT(IN) :: string_a,string_b
LOGICAL :: s_eq_s
INTEGER :: la,lb
la = LEN(string_a); lb = LEN(string_b)
IF (la > lb) THEN
s_eq_s = ALL(string_a%chars(1:lb) == string_b%chars) .AND. &
ALL(string_a%chars(lb+1:la) == blank)
ELSEIF (la < lb) THEN
s_eq_s = ALL(string_a%chars == string_b%chars(1:la)) .AND. &
ALL(blank == string_b%chars(la+1:lb))
ELSE
s_eq_s = ALL(string_a%chars == string_b%chars)
ENDIF
ENDFUNCTION s_eq_s
ELEMENTAL FUNCTION s_eq_c(string_a,string_b) ! string==character
type(VAR_STR),INTENT(IN) :: string_a
CHARACTER(LEN=*),INTENT(IN) :: string_b
LOGICAL :: s_eq_c
INTEGER :: la,lb,ls
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a%chars(i) /= string_b(i:i) )THEN
s_eq_c = .FALSE.; RETURN
ENDIF
ENDDO
IF( la > lb .AND. ANY( string_a%chars(lb+1:la) /= blank ) )THEN
s_eq_c = .FALSE.; RETURN
ELSEIF( la < lb .AND. blank /= string_b(la+1:lb) )THEN
s_eq_c = .FALSE.; RETURN
ENDIF
s_eq_c = .TRUE.
ENDFUNCTION s_eq_c
ELEMENTAL FUNCTION c_eq_s(string_a,string_b) ! character==string
CHARACTER(LEN=*),INTENT(IN) :: string_a
type(VAR_STR),INTENT(IN) :: string_b
LOGICAL :: c_eq_s
INTEGER :: la,lb,ls
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a(i:i) /= string_b%chars(i) )THEN
c_eq_s = .FALSE.; RETURN
ENDIF
ENDDO
IF( la > lb .AND. string_a(lb+1:la) /= blank )THEN
c_eq_s = .FALSE.; RETURN
ELSEIF( la < lb .AND. ANY( blank /= string_b%chars(la+1:lb) ) )THEN
c_eq_s = .FALSE.; RETURN
ENDIF
c_eq_s = .TRUE.
ENDFUNCTION c_eq_s
!------ Non-equality operators -----------------------------------------------!
ELEMENTAL FUNCTION s_ne_s(string_a,string_b) ! string/=string
type(VAR_STR),INTENT(IN) :: string_a,string_b
LOGICAL :: s_ne_s
INTEGER :: la,lb
la = LEN(string_a); lb = LEN(string_b)
IF (la > lb) THEN
s_ne_s = ANY(string_a%chars(1:lb) /= string_b%chars) .OR. &
ANY(string_a%chars(lb+1:la) /= blank)
ELSEIF (la < lb) THEN
s_ne_s = ANY(string_a%chars /= string_b%chars(1:la)) .OR. &
ANY(blank /= string_b%chars(la+1:lb))
ELSE
s_ne_s = ANY(string_a%chars /= string_b%chars)
ENDIF
ENDFUNCTION s_ne_s
ELEMENTAL FUNCTION s_ne_c(string_a,string_b) ! string/=character
type(VAR_STR),INTENT(IN) :: string_a
CHARACTER(LEN=*),INTENT(IN) :: string_b
LOGICAL :: s_ne_c
INTEGER :: la,lb,ls
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a%chars(i) /= string_b(i:i) )THEN
s_ne_c = .TRUE.; RETURN
ENDIF
ENDDO
IF( la > lb .AND. ANY( string_a%chars(lb+1:la) /= blank ) )THEN
s_ne_c = .TRUE.; RETURN
ELSEIF( la < lb .AND. blank /= string_b(la+1:lb) )THEN
s_ne_c = .TRUE.; RETURN
ENDIF
s_ne_c = .FALSE.
ENDFUNCTION s_ne_c
ELEMENTAL FUNCTION c_ne_s(string_a,string_b) ! character/=string
CHARACTER(LEN=*),INTENT(IN) :: string_a
type(VAR_STR),INTENT(IN) :: string_b
LOGICAL :: c_ne_s
INTEGER :: la,lb,ls
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a(i:i) /= string_b%chars(i) )THEN
c_ne_s = .TRUE.; RETURN
ENDIF
ENDDO
IF( la > lb .AND. string_a(lb+1:la) /= blank )THEN
c_ne_s = .TRUE.; RETURN
ELSEIF( la < lb .AND. ANY( blank /= string_b%chars(la+1:lb) ) )THEN
c_ne_s = .TRUE.; RETURN
ENDIF
c_ne_s = .FALSE.
ENDFUNCTION c_ne_s
!------ Less-than operators --------------------------------------------------!
ELEMENTAL FUNCTION s_lt_s(string_a,string_b) ! string<string
type(VAR_STR),INTENT(IN) :: string_a,string_b
LOGICAL :: s_lt_s
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a%chars(i) < string_b%chars(i) )THEN
s_lt_s = .TRUE.; RETURN
ELSEIF( string_a%chars(i) > string_b%chars(i) )THEN
s_lt_s = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
DO i = la+1,lb
IF( blank < string_b%chars(i) )THEN
s_lt_s = .TRUE.; RETURN
ELSEIF( blank > string_b%chars(i) )THEN
s_lt_s = .FALSE.; RETURN
ENDIF
ENDDO
ELSEIF( la > lb )THEN
DO i = lb+1,la
IF( string_a%chars(i) < blank )THEN
s_lt_s = .TRUE.; RETURN
ELSEIF( string_a%chars(i) > blank )THEN
s_lt_s = .FALSE.; RETURN
ENDIF
ENDDO
ENDIF
s_lt_s = .FALSE.
ENDFUNCTION s_lt_s
ELEMENTAL FUNCTION s_lt_c(string_a,string_b) ! string<character
type(VAR_STR),INTENT(IN) :: string_a
CHARACTER(LEN=*),INTENT(IN) :: string_b
LOGICAL :: s_lt_c
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a%chars(i) < string_b(i:i) )THEN
s_lt_c = .TRUE.; RETURN
ELSEIF( string_a%chars(i) > string_b(i:i) )THEN
s_lt_c = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
IF( blank < string_b(la+1:lb) )THEN
s_lt_c = .TRUE.; RETURN
ELSEIF( blank > string_b(la+1:lb) )THEN
s_lt_c = .FALSE.; RETURN
ENDIF
ELSEIF( la > lb )THEN
DO i = lb+1,la
IF( string_a%chars(i) < blank )THEN
s_lt_c = .TRUE.; RETURN
ELSEIF( string_a%chars(i) > blank )THEN
s_lt_c = .FALSE.; RETURN
ENDIF
ENDDO
ENDIF
s_lt_c = .FALSE.
ENDFUNCTION s_lt_c
ELEMENTAL FUNCTION c_lt_s(string_a,string_b) ! character<string
CHARACTER(LEN=*),INTENT(IN) :: string_a
type(VAR_STR),INTENT(IN) :: string_b
LOGICAL :: c_lt_s
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a(i:i) < string_b%chars(i) )THEN
c_lt_s = .TRUE.; RETURN
ELSEIF( string_a(i:i) > string_b%chars(i) )THEN
c_lt_s = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
DO i = la+1,lb
IF( blank < string_b%chars(i) )THEN
c_lt_s = .TRUE.; RETURN
ELSEIF( blank > string_b%chars(i) )THEN
c_lt_s = .FALSE.; RETURN
ENDIF
ENDDO
ELSEIF( la > lb )THEN
IF( string_a(lb+1:la) < blank )THEN
c_lt_s = .TRUE.; RETURN
ELSEIF( string_a(lb+1:la) > blank )THEN
c_lt_s = .FALSE.; RETURN
ENDIF
ENDIF
c_lt_s = .FALSE.
ENDFUNCTION c_lt_s
!------ Less-than-or-equal-to operators --------------------------------------!
ELEMENTAL FUNCTION s_le_s(string_a,string_b) ! string<=string
type(VAR_STR),INTENT(IN) :: string_a,string_b
LOGICAL :: s_le_s
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a%chars(i) < string_b%chars(i) )THEN
s_le_s = .TRUE.; RETURN
ELSEIF( string_a%chars(i) > string_b%chars(i) )THEN
s_le_s = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
DO i = la+1,lb
IF( blank < string_b%chars(i) )THEN
s_le_s = .TRUE.; RETURN
ELSEIF( blank > string_b%chars(i) )THEN
s_le_s = .FALSE.; RETURN
ENDIF
ENDDO
ELSEIF( la > lb )THEN
DO i = lb+1,la
IF( string_a%chars(i) < blank )THEN
s_le_s = .TRUE.; RETURN
ELSEIF( string_a%chars(i) > blank )THEN
s_le_s = .FALSE.; RETURN
ENDIF
ENDDO
ENDIF
s_le_s = .TRUE.
ENDFUNCTION s_le_s
ELEMENTAL FUNCTION s_le_c(string_a,string_b) ! string<=character
type(VAR_STR),INTENT(IN) :: string_a
CHARACTER(LEN=*),INTENT(IN) :: string_b
LOGICAL :: s_le_c
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a%chars(i) < string_b(i:i) )THEN
s_le_c = .TRUE.; RETURN
ELSEIF( string_a%chars(i) > string_b(i:i) )THEN
s_le_c = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
IF( blank < string_b(la+1:lb) )THEN
s_le_c = .TRUE.; RETURN
ELSEIF( blank > string_b(la+1:lb) )THEN
s_le_c = .FALSE.; RETURN
ENDIF
ELSEIF( la > lb )THEN
DO i = lb+1,la
IF( string_a%chars(i) < blank )THEN
s_le_c = .TRUE.; RETURN
ELSEIF( string_a%chars(i) > blank )THEN
s_le_c = .FALSE.; RETURN
ENDIF
ENDDO
ENDIF
s_le_c = .TRUE.
ENDFUNCTION s_le_c
ELEMENTAL FUNCTION c_le_s(string_a,string_b) ! character<=string
CHARACTER(LEN=*),INTENT(IN) :: string_a
type(VAR_STR),INTENT(IN) :: string_b
LOGICAL :: c_le_s
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a(i:i) < string_b%chars(i) )THEN
c_le_s = .TRUE.; RETURN
ELSEIF( string_a(i:i) > string_b%chars(i) )THEN
c_le_s = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
DO i = la+1,lb
IF( blank < string_b%chars(i) )THEN
c_le_s = .TRUE.; RETURN
ELSEIF( blank > string_b%chars(i) )THEN
c_le_s = .FALSE.; RETURN
ENDIF
ENDDO
ELSEIF( la > lb )THEN
IF( string_a(lb+1:la) < blank )THEN
c_le_s = .TRUE.; RETURN
ELSEIF( string_a(lb+1:la) > blank )THEN
c_le_s = .FALSE.; RETURN
ENDIF
ENDIF
c_le_s = .TRUE.
ENDFUNCTION c_le_s
!------ Greater-than-or-equal-to operators -----------------------------------!
ELEMENTAL FUNCTION s_ge_s(string_a,string_b) ! string>=string
type(VAR_STR),INTENT(IN) :: string_a,string_b
LOGICAL :: s_ge_s
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a%chars(i) > string_b%chars(i) )THEN
s_ge_s = .TRUE.; RETURN
ELSEIF( string_a%chars(i) < string_b%chars(i) )THEN
s_ge_s = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
DO i = la+1,lb
IF( blank > string_b%chars(i) )THEN
s_ge_s = .TRUE.; RETURN
ELSEIF( blank < string_b%chars(i) )THEN
s_ge_s = .FALSE.; RETURN
ENDIF
ENDDO
ELSEIF( la > lb )THEN
DO i = lb+1,la
IF( string_a%chars(i) > blank )THEN
s_ge_s = .TRUE.; RETURN
ELSEIF( string_a%chars(i) < blank )THEN
s_ge_s = .FALSE.; RETURN
ENDIF
ENDDO
ENDIF
s_ge_s = .TRUE.
ENDFUNCTION s_ge_s
ELEMENTAL FUNCTION s_ge_c(string_a,string_b) ! string>=character
type(VAR_STR),INTENT(IN) :: string_a
CHARACTER(LEN=*),INTENT(IN) :: string_b
LOGICAL :: s_ge_c
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a%chars(i) > string_b(i:i) )THEN
s_ge_c = .TRUE.; RETURN
ELSEIF( string_a%chars(i) < string_b(i:i) )THEN
s_ge_c = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
IF( blank > string_b(la+1:lb) )THEN
s_ge_c = .TRUE.; RETURN
ELSEIF( blank < string_b(la+1:lb) )THEN
s_ge_c = .FALSE.; RETURN
ENDIF
ELSEIF( la > lb )THEN
DO i = lb+1,la
IF( string_a%chars(i) > blank )THEN
s_ge_c = .TRUE.; RETURN
ELSEIF( string_a%chars(i) < blank )THEN
s_ge_c = .FALSE.; RETURN
ENDIF
ENDDO
ENDIF
s_ge_c = .TRUE.
ENDFUNCTION s_ge_c
ELEMENTAL FUNCTION c_ge_s(string_a,string_b) ! character>=string
CHARACTER(LEN=*),INTENT(IN) :: string_a
type(VAR_STR),INTENT(IN) :: string_b
LOGICAL :: c_ge_s
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a(i:i) > string_b%chars(i) )THEN
c_ge_s = .TRUE.; RETURN
ELSEIF( string_a(i:i) < string_b%chars(i) )THEN
c_ge_s = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
DO i = la+1,lb
IF( blank > string_b%chars(i) )THEN
c_ge_s = .TRUE.; RETURN
ELSEIF( blank < string_b%chars(i) )THEN
c_ge_s = .FALSE.; RETURN
ENDIF
ENDDO
ELSEIF( la > lb )THEN
IF( string_a(lb+1:la) > blank )THEN
c_ge_s = .TRUE.; RETURN
ELSEIF( string_a(lb+1:la) < blank )THEN
c_ge_s = .FALSE.; RETURN
ENDIF
ENDIF
c_ge_s = .TRUE.
ENDFUNCTION c_ge_s
!------ Greater-than operators -----------------------------------------------!
ELEMENTAL FUNCTION s_gt_s(string_a,string_b) ! string>string
type(VAR_STR),INTENT(IN) :: string_a,string_b
LOGICAL :: s_gt_s
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a%chars(i) > string_b%chars(i) )THEN
s_gt_s = .TRUE.; RETURN
ELSEIF( string_a%chars(i) < string_b%chars(i) )THEN
s_gt_s = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
DO i = la+1,lb
IF( blank > string_b%chars(i) )THEN
s_gt_s = .TRUE.; RETURN
ELSEIF( blank < string_b%chars(i) )THEN
s_gt_s = .FALSE.; RETURN
ENDIF
ENDDO
ELSEIF( la > lb )THEN
DO i = lb+1,la
IF( string_a%chars(i) > blank )THEN
s_gt_s = .TRUE.; RETURN
ELSEIF( string_a%chars(i) < blank )THEN
s_gt_s = .FALSE.; RETURN
ENDIF
ENDDO
ENDIF
s_gt_s = .FALSE.
ENDFUNCTION s_gt_s
ELEMENTAL FUNCTION s_gt_c(string_a,string_b) ! string>character
type(VAR_STR),INTENT(IN) :: string_a
CHARACTER(LEN=*),INTENT(IN) :: string_b
LOGICAL :: s_gt_c
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a%chars(i) > string_b(i:i) )THEN
s_gt_c = .TRUE.; RETURN
ELSEIF( string_a%chars(i) < string_b(i:i) )THEN
s_gt_c = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
IF( blank > string_b(la+1:lb) )THEN
s_gt_c = .TRUE.; RETURN
ELSEIF( blank < string_b(la+1:lb) )THEN
s_gt_c = .FALSE.; RETURN
ENDIF
ELSEIF( la > lb )THEN
DO i = lb+1,la
IF( string_a%chars(i) > blank )THEN
s_gt_c = .TRUE.; RETURN
ELSEIF( string_a%chars(i) < blank )THEN
s_gt_c = .FALSE.; RETURN
ENDIF
ENDDO
ENDIF
s_gt_c = .FALSE.
ENDFUNCTION s_gt_c
ELEMENTAL FUNCTION c_gt_s(string_a,string_b) ! character>string
CHARACTER(LEN=*),INTENT(IN) :: string_a
type(VAR_STR),INTENT(IN) :: string_b
LOGICAL :: c_gt_s
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( string_a(i:i) > string_b%chars(i) )THEN
c_gt_s = .TRUE.; RETURN
ELSEIF( string_a(i:i) < string_b%chars(i) )THEN
c_gt_s = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
DO i = la+1,lb
IF( blank > string_b%chars(i) )THEN
c_gt_s = .TRUE.; RETURN
ELSEIF( blank < string_b%chars(i) )THEN
c_gt_s = .FALSE.; RETURN
ENDIF
ENDDO
ELSEIF( la > lb )THEN
IF( string_a(lb+1:la) > blank )THEN
c_gt_s = .TRUE.; RETURN
ELSEIF( string_a(lb+1:la) < blank )THEN
c_gt_s = .FALSE.; RETURN
ENDIF
ENDIF
c_gt_s = .FALSE.
ENDFUNCTION c_gt_s
!----- LLT procedures -------------------------------------------------------!
ELEMENTAL FUNCTION s_llt_s(string_a,string_b) ! string_a<string_b ISO-646 ordering
type(VAR_STR),INTENT(IN) :: string_a,string_b
LOGICAL :: s_llt_s
! Returns TRUE if string_a preceeds string_b in the ISO 646 collating
! sequence. Otherwise the result is FALSE. The result is FALSE if both
! string_a and string_b are zero length.
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( LLT(string_a%chars(i),string_b%chars(i)) )THEN
s_llt_s = .TRUE.; RETURN
ELSEIF( LGT(string_a%chars(i),string_b%chars(i)) )THEN
s_llt_s = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
DO i = la+1,lb
IF( LLT(blank,string_b%chars(i)) )THEN
s_llt_s = .TRUE.; RETURN
ELSEIF( LGT(blank,string_b%chars(i)) )THEN
s_llt_s = .FALSE.; RETURN
ENDIF
ENDDO
ELSEIF( la > lb )THEN
DO i = lb+1,la
IF( LLT(string_a%chars(i),blank) )THEN
s_llt_s = .TRUE.; RETURN
ELSEIF( LGT(string_a%chars(i),blank) )THEN
s_llt_s = .FALSE.; RETURN
ENDIF
ENDDO
ENDIF
s_llt_s = .FALSE.
ENDFUNCTION s_llt_s
ELEMENTAL FUNCTION s_llt_c(string_a,string_b) ! string_a<string_b ISO-646 ordering
type(VAR_STR),INTENT(IN) :: string_a
CHARACTER(LEN=*),INTENT(IN) :: string_b
LOGICAL :: s_llt_c
INTEGER :: ls,la,lb
la = LEN(string_a); lb = LEN(string_b); ls = MIN(la,lb)
DO i = 1,ls
IF( LLT(string_a%chars(i),string_b(i:i)) )THEN
s_llt_c = .TRUE.; RETURN
ELSEIF( LGT(string_a%chars(i),string_b(i:i)) )THEN
s_llt_c = .FALSE.; RETURN
ENDIF
ENDDO
IF( la < lb )THEN
IF( LLT(blank,string_b(la+1:lb)) )THEN
s_llt_c = .TRUE.; RETURN
ELSEIF( LGT(blank,string_b(la+1:lb)) )THEN
s_llt_c = .FALSE.; RETURN
ENDIF
ELSEIF( la > lb )THEN
DO i = lb+1,la
IF( LLT(string_a%chars(i),blank) )THEN
s_llt_c = .TRUE.; RETURN
ELSEIF( LGT(string_a%chars(i),blank) )THEN
s_llt_c = .FALSE.; RETURN
ENDIF
ENDDO
ENDIF
s_llt_c = .FALSE.
ENDFUNCTION s_llt_c
ELEMENTAL FUNCTION c_llt_s(string_a,string_b) ! string_a,string_b ISO-646 ordering
CHARACTER(LEN=*),INTENT(IN) :: string_a
type(VAR_STR),INTENT(IN) :: string_b
LOGICAL :: c_llt_s
INTEGER :: ls,la,lb