Changeset 8
- Timestamp:
- Jan 29, 2022, 7:28:33 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
strings_mod.F90
r7 r8 5 5 PRIVATE 6 6 PUBLIC :: maxlen, init_printout, msg, fmsg, get_in, lunout, prt_level 7 PUBLIC :: strLower, strHead, strStack, str Reduce, strClean, strFind, strIdx, find8 PUBLIC :: strUpper, strTail, strStackm, str Reducef, strParse, strCount, strReplace, cat7 PUBLIC :: strLower, strHead, strStack, strCount, strReduce, strClean, strIdx 8 PUBLIC :: strUpper, strTail, strStackm, strParse, strReplace, strFind, find, cat 9 9 PUBLIC :: dispTable, dispOutliers, dispNameList 10 10 PUBLIC :: is_numeric, bool2str, int2str, real2str, dble2str … … 347 347 INTEGER, OPTIONAL, INTENT(OUT) :: nb 348 348 CHARACTER(LEN=maxlen), ALLOCATABLE :: s1(:) 349 INTEGER :: n 350 s1 = strReducef(str, n); CALL MOVE_ALLOC(FROM=s1, TO=str) 351 IF(PRESENT(nb)) nb = n 349 INTEGER :: k, n, n1 350 IF(PRESENT(nb)) nb = 0 351 CALL MOVE_ALLOC(FROM=str, TO=s1); CALL strClean(s1) 352 n1 = SIZE(s1, DIM=1) !--- Total nb. of elements in "s1" 353 n = COUNT( [( ALL(s1(1:k-1)/=s1(k)), k=1, n1 )] ) !--- Nb of unique elements in "s1" 354 ALLOCATE(str(n)) 355 IF(n==0) RETURN 356 str(1) = s1(1) 357 n=1; DO k=1,n1; IF(ANY(s1(1:k-1)==s1(k))) CYCLE; n=n+1; str(n)=s1(k); END DO 358 IF(PRESENT(nb)) nb=n 352 359 END SUBROUTINE strReduce_1 353 360 !============================================================================================================================== … … 370 377 END IF 371 378 END SUBROUTINE strReduce_2 372 !==============================================================================================================================373 FUNCTION strReducef(str_in, nb) RESULT(str_ou)374 CHARACTER(LEN=*), INTENT(IN) :: str_in(:)375 INTEGER, OPTIONAL, INTENT(OUT) :: nb376 CHARACTER(LEN=LEN(str_in)), ALLOCATABLE :: str_ou(:)377 CHARACTER(LEN=LEN(str_in)), ALLOCATABLE :: s1(:)378 INTEGER :: k, n, n1379 IF(PRESENT(nb)) nb = 0380 s1 = str_in; CALL strClean(s1)381 n1 = SIZE(s1, DIM=1) !--- Total nb of elements in "s1"382 n = COUNT( [( ALL(s1(1:k-1)/=s1(k)), k=1, n1 )] ) !--- Nb of unique elements in "s1"383 ALLOCATE(str_ou(n)); IF(n==0) RETURN; str_ou(1) = s1(1)384 n=1; DO k=2,n1; IF(ANY(s1(1:k-1)==s1(k))) CYCLE; n=n+1; str_ou(n)=s1(k); END DO385 IF(PRESENT(nb)) nb = n386 END FUNCTION strReducef387 379 !============================================================================================================================== 388 380 … … 1417 1409 1418 1410 END MODULE strings_mod 1419
Note: See TracChangeset
for help on using the changeset viewer.