Changeset 4349 for LMDZ6/trunk/libf/misc
- Timestamp:
- Nov 15, 2022, 4:14:52 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
LMDZ6/trunk/libf/misc/strings_mod.F90
r4348 r4349 37 37 CONTAINS 38 38 39 !============================================================================================================================== 39 40 LOGICAL FUNCTION test(lcond, lout) RESULT(lerr) 40 41 LOGICAL, INTENT(IN) :: lcond … … 42 43 lerr = lcond; lout = lcond 43 44 END FUNCTION test 45 !============================================================================================================================== 46 44 47 45 48 !============================================================================================================================== … … 104 107 LOGICAL, OPTIONAL, INTENT(IN) :: ll 105 108 INTEGER, OPTIONAL, INTENT(IN) :: unit 109 !------------------------------------------------------------------------------------------------------------------------------ 106 110 CHARACTER(LEN=maxlen) :: subn 107 111 INTEGER :: unt … … 120 124 INTEGER, OPTIONAL, INTENT(IN) :: unit 121 125 INTEGER, OPTIONAL, INTENT(IN) :: nmax 126 !------------------------------------------------------------------------------------------------------------------------------ 122 127 CHARACTER(LEN=maxlen), ALLOCATABLE :: s(:) 123 128 CHARACTER(LEN=maxlen) :: subn … … 137 142 LOGICAL, OPTIONAL, INTENT(IN) :: ll 138 143 INTEGER, OPTIONAL, INTENT(IN) :: unit 144 !------------------------------------------------------------------------------------------------------------------------------ 139 145 CHARACTER(LEN=maxlen) :: subn 140 146 INTEGER :: unt … … 151 157 INTEGER, OPTIONAL, INTENT(IN) :: unit 152 158 INTEGER, OPTIONAL, INTENT(IN) :: nmax 159 !------------------------------------------------------------------------------------------------------------------------------ 153 160 CHARACTER(LEN=maxlen) :: subn 154 161 INTEGER :: unt, nmx … … 195 202 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep 196 203 LOGICAL, OPTIONAL, INTENT(IN) :: lFirst 204 !------------------------------------------------------------------------------------------------------------------------------ 197 205 LOGICAL :: lf 198 206 lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst … … 210 218 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep 211 219 LOGICAL, OPTIONAL, INTENT(IN) :: lFirst 220 !------------------------------------------------------------------------------------------------------------------------------ 212 221 LOGICAL :: lf 213 222 INTEGER :: k … … 229 238 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep 230 239 LOGICAL, OPTIONAL, INTENT(IN) :: lFirst 240 !------------------------------------------------------------------------------------------------------------------------------ 231 241 LOGICAL :: lf 232 242 lf = .FALSE.; IF(PRESENT(lFirst)) lf=lFirst … … 244 254 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep 245 255 LOGICAL, OPTIONAL, INTENT(IN) :: lFirst 256 !------------------------------------------------------------------------------------------------------------------------------ 246 257 LOGICAL :: lf 247 258 INTEGER :: k … … 264 275 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep 265 276 LOGICAL, OPTIONAL, INTENT(IN) :: mask(:) 277 !------------------------------------------------------------------------------------------------------------------------------ 266 278 CHARACTER(LEN=:), ALLOCATABLE :: s 267 279 INTEGER :: is, i0 … … 284 296 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sep 285 297 INTEGER, OPTIONAL, INTENT(IN) :: nmax 298 !------------------------------------------------------------------------------------------------------------------------------ 286 299 CHARACTER(LEN=maxlen), ALLOCATABLE :: t(:) 287 300 CHARACTER(LEN=maxlen) :: sp … … 338 351 CHARACTER(LEN=*), ALLOCATABLE, INTENT(INOUT) :: str(:) 339 352 INTEGER, OPTIONAL, INTENT(OUT) :: nb 353 !------------------------------------------------------------------------------------------------------------------------------ 340 354 CHARACTER(LEN=maxlen), ALLOCATABLE :: s1(:) 341 355 INTEGER :: k, n, n1 … … 354 368 CHARACTER(LEN=*), ALLOCATABLE, INTENT(INOUT) :: str1(:) 355 369 CHARACTER(LEN=*), INTENT(IN) :: str2(:) 370 !------------------------------------------------------------------------------------------------------------------------------ 356 371 CHARACTER(LEN=maxlen), ALLOCATABLE :: s1(:), s2(:) 357 372 INTEGER :: k … … 373 388 374 389 !============================================================================================================================== 375 !=== GET THE INDEX OF THE FIRST APPEARANCE IN THE STRING VECTOR "str(:)" OF THE STRING(s) "s" ================================= 390 !=== GET THE INDEX OF THE FIRST APPEARANCE IN THE STRING VECTOR "str(:)" OF THE STRING(s) "s[(:)]" ============================ 391 !=== OPTIONALY: GET THE NUMBER OF FOUND ELEMENTS "n". NB: UNFOUND => INDEX=0 ============================ 376 392 !============================================================================================================================== 377 393 INTEGER FUNCTION strIdx_1(str, s) RESULT(out) … … 385 401 INTEGER, OPTIONAL, INTENT(OUT) :: n 386 402 INTEGER, ALLOCATABLE :: out(:) 403 !------------------------------------------------------------------------------------------------------------------------------ 387 404 INTEGER :: k 388 405 out = [(strIdx_1(str(:), s(k)), k=1, SIZE(s))] … … 399 416 INTEGER, OPTIONAL, INTENT(OUT) :: n 400 417 INTEGER, ALLOCATABLE :: out(:) 418 !------------------------------------------------------------------------------------------------------------------------------ 401 419 INTEGER :: k 402 420 out = PACK( [(k, k=1, SIZE(str(:), DIM=1))], MASK = str(:) == s ) … … 408 426 INTEGER, OPTIONAL, INTENT(OUT) :: n 409 427 INTEGER, ALLOCATABLE :: out(:) 428 !------------------------------------------------------------------------------------------------------------------------------ 410 429 INTEGER :: k 411 430 out = PACK( [(k, k=1, SIZE(i(:), DIM=1))], MASK = i(:) == j ) … … 417 436 INTEGER, OPTIONAL, INTENT(OUT) :: n 418 437 INTEGER, ALLOCATABLE :: out(:) 438 !------------------------------------------------------------------------------------------------------------------------------ 419 439 INTEGER :: k 420 440 out = PACK( [(k, k=1, SIZE(l(:), DIM=1))], MASK = l(:) ) 421 441 IF(PRESENT(n)) n = SIZE(out(:), DIM=1) 422 442 END FUNCTION find_boo 423 !==============================================================================================================================424 425 426 427 !==============================================================================================================================428 !=== GET 1ST APPEARANCE INDEX OF EACH ELEMENT OF "t(:)" IN "s(:)" (UNFOUND: INDEX=0) ==========================================429 !=== OPTIONALY: GET THE NUMBER OF FOUND ELEMENTS "n" ==========================================430 443 !============================================================================================================================== 431 444 … … 455 468 !=== No delimiter found: the whole string must be a valid number 456 469 IF(idx == 0) THEN !--- No element of "del" in "rawList" 457 lerr = .NOT.is_numeric(rawList(ibeg: ))!--- String must be a number470 lerr = .NOT.is_numeric(rawList(ibeg:LEN_TRIM(rawList))) !--- String must be a number 458 471 IF(lerr) idx = LEN_TRIM(rawList); RETURN !--- Set idx so that rawList(ibeg:idx-1) = whole string 459 472 END IF … … 465 478 idx0 = idx ; idx = strIdx1(rawList, del, idx+1, idel) !--- Keep start index because idx is recycled 466 479 IF(idx == 0) THEN 467 lerr = .NOT.is_numeric(rawList(ibeg: ))!--- No other delimiter: whole string must be a valid numb480 lerr = .NOT.is_numeric(rawList(ibeg:LEN_TRIM(rawList))) !--- No other delimiter: whole string must be a valid numb 468 481 IF(lerr) idx = idx0; RETURN 469 482 END IF 470 lerr = .NOT.is_numeric(rawList(ibeg:idx-1)) !--- String before second delimiter is a valid number483 lerr = .NOT.is_numeric(rawList(ibeg:idx-1)) 471 484 472 485 CONTAINS 473 486 474 487 !------------------------------------------------------------------------------------------------------------------------------ 475 INTEGER FUNCTION strIdx1(str, del, ib, id) RESULT(i dx)488 INTEGER FUNCTION strIdx1(str, del, ib, id) RESULT(i) 476 489 !--- Get the index of the first appereance of one of the delimiters "del(:)" in "str" starting from position "ib". 477 490 !--- "id" is the index in "del(:)" of the first delimiter found. 491 IMPLICIT NONE 478 492 CHARACTER(LEN=*), INTENT(IN) :: str, del(:) 479 493 INTEGER, INTENT(IN) :: ib 480 494 INTEGER, INTENT(OUT) :: id 481 495 !------------------------------------------------------------------------------------------------------------------------------ 482 INTEGER :: i, ix 483 idx = 0; id = 0 484 DO id = 1, SIZE(del) !--- Test for delimiter "del(id)" 485 ix = INDEX(str(ib:LEN_TRIM(str)), del(id)) !--- "del(id)" appears at position "idx" in "str(ib:ns)" 486 IF(ix /= 0 .AND. (ix < idx .OR. idx == 0 )) idx = ix 487 END DO 488 IF(idx /= 0) idx = idx + ib - 1 !--- Index counted from first character of "str" 496 DO i = ib, LEN_TRIM(str); id = strIdx(del, str(i:i)); IF(id /= 0) EXIT; END DO 497 IF(i > LEN_TRIM(str)) THEN; i = 0; id = 0; END IF 489 498 END FUNCTION strIdx1 490 499 … … 501 510 INTEGER, INTENT(OUT) :: nb 502 511 LOGICAL, OPTIONAL, INTENT(IN) :: lSc 512 !------------------------------------------------------------------------------------------------------------------------------ 503 513 LOGICAL :: ll 504 514 ll = .FALSE.; IF(PRESENT(lSc)) ll = lSc … … 511 521 INTEGER, ALLOCATABLE, INTENT(OUT) :: nb(:) 512 522 LOGICAL, OPTIONAL, INTENT(IN) :: lSc 513 523 !------------------------------------------------------------------------------------------------------------------------------ 514 524 LOGICAL :: ll 515 525 INTEGER :: id 516 517 526 ll = .FALSE.; IF(PRESENT(lSc)) ll = lSc .AND. INDEX('+-', delimiter) /= 0 518 527 out = .TRUE. … … 528 537 INTEGER, INTENT(OUT) :: nb 529 538 LOGICAL, OPTIONAL, INTENT(IN) :: lSc 539 !------------------------------------------------------------------------------------------------------------------------------ 530 540 INTEGER :: ib, ie, jd, nr 531 541 LOGICAL :: ll 532 542 CHARACTER(LEN=1024) :: r 533 ! modname = 'strCount'534 543 lerr = .FALSE. 535 544 ll = .FALSE.; IF(PRESENT(lSc)) ll = lSc … … 540 549 lerr = strIdx_prv(r, delimiter, ib, ie, jd, ll) 541 550 IF(fmsg('"'//TRIM(r(ib:ie-1))//'" is not numeric', ll=lerr)) RETURN 542 IF( jd == 0) EXIT551 IF(ie == 0 .OR. jd == 0) EXIT 543 552 ib = ie + LEN(delimiter(jd)) 544 553 DO WHILE(r(ib:ib) == ' ' .AND. ib < nr); ib = ib + 1; END DO !--- Skip spaces before next chain … … 560 569 !------------------------------------------------------------------------------------------------------------------------------ 561 570 CHARACTER(LEN=1024) :: r 562 INTEGER :: nr, ik, nk, ib, ie571 INTEGER :: nr, nk 563 572 lerr = .FALSE. 564 573 r = TRIM(ADJUSTL(rawList)) 565 574 nr = LEN_TRIM(r); IF(nr == 0) THEN; keys = ['']; RETURN; END IF 566 575 CALL strParse_prv(nk) !--- COUNT THE ELEMENTS 567 ALLOCATE(keys(nk)); IF(PRESENT(vals)) ALLOCATE(vals(nk)) 568 CALL strParse_prv(nk, keys, vals) !--- PARSE THE KEYS 576 ALLOCATE(keys(nk)) 577 IF(PRESENT(vals)) THEN 578 ALLOCATE(vals(nk)); CALL strParse_prv(nk, keys, vals) !--- PARSE THE KEYS 579 ELSE 580 CALL strParse_prv(nk, keys) !--- PARSE THE KEYS 581 END IF 569 582 IF(PRESENT(n)) n = nk 570 583 571 584 CONTAINS 572 585 573 SUBROUTINE strParse_prv(nk, keys, vals) 574 !--- * Get the number of elements after parsing ("nk" only is present) 586 !------------------------------------------------------------------------------------------------------------------------------ 587 SUBROUTINE strParse_prv(nkeys, keys, vals) 588 !--- * Get the number of elements after parsing ("nkeys" only is present) 575 589 !--- * Parse the <key>=<val> pairs and store result in "keys" and "vals" (already allocated) 576 INTEGER, INTENT(OUT) :: nk 590 IMPLICIT NONE 591 INTEGER, INTENT(OUT) :: nkeys 577 592 CHARACTER(LEN=maxlen), OPTIONAL, INTENT(OUT) :: keys(:) 578 593 CHARACTER(LEN=maxlen), OPTIONAL, INTENT(OUT) :: vals(:) 579 nk = 1; ib = 1 594 !------------------------------------------------------------------------------------------------------------------------------ 595 INTEGER :: ib, ie 596 nkeys = 1; ib = 1 580 597 DO 581 598 ie = INDEX(rawList(ib:nr), delimiter)+ib-1 !--- Determine the next separator start index 582 599 IF(ie == ib-1) EXIT 583 IF(PRESENT(keys)) keys(nk ) = r(ib:ie-1)!--- Get the ikth key584 IF(PRESENT(vals)) CALL parseKeys(keys( ik), vals(ik))!--- Parse the ikth <key>=<val> pair600 IF(PRESENT(keys)) keys(nkeys) = r(ib:ie-1) !--- Get the ikth key 601 IF(PRESENT(vals)) CALL parseKeys(keys(nkeys), vals(nkeys)) !--- Parse the ikth <key>=<val> pair 585 602 ib = ie + LEN(delimiter) 586 603 DO WHILE(r(ib:ib) == ' ' .AND. ib < nr); ib = ib + 1; END DO !--- Skip spaces before next chain 587 nk = nk+1588 END DO 589 IF(PRESENT(keys)) keys(nk ) = r(ib:nr)!--- Get the last key590 IF(PRESENT(vals)) CALL parseKeys(keys( ik), vals(ik))!--- Parse the last <key>=<val> pair604 nkeys = nkeys+1 605 END DO 606 IF(PRESENT(keys)) keys(nkeys) = r(ib:nr) !--- Get the last key 607 IF(PRESENT(vals)) CALL parseKeys(keys(nkeys), vals(nkeys)) !--- Parse the last <key>=<val> pair 591 608 END SUBROUTINE strParse_prv 592 609 610 !------------------------------------------------------------------------------------------------------------------------------ 593 611 SUBROUTINE parseKeys(key, val) 594 612 CHARACTER(LEN=*), INTENT(INOUT) :: key 595 613 CHARACTER(LEN=*), INTENT(OUT) :: val 614 !------------------------------------------------------------------------------------------------------------------------------ 596 615 INTEGER :: ix 597 616 ix = INDEX(key, '='); IF(ix == 0) RETURN !--- First "=" index in "key" … … 639 658 CONTAINS 640 659 660 !------------------------------------------------------------------------------------------------------------------------------ 641 661 SUBROUTINE parseKeys(key, val) 642 662 CHARACTER(LEN=*), INTENT(INOUT) :: key 643 663 CHARACTER(LEN=*), INTENT(OUT) :: val 664 !------------------------------------------------------------------------------------------------------------------------------ 644 665 INTEGER :: ix 645 666 ix = INDEX(key, '='); IF(ix == 0) RETURN !--- First "=" index in "key" … … 659 680 CHARACTER(LEN=*), INTENT(IN) :: key, val !--- "key" will be replaced by "val" 660 681 LOGICAL, OPTIONAL, INTENT(IN) :: lsurr !--- TRUE => key must be surrounded by special characters to be substituted 661 682 !------------------------------------------------------------------------------------------------------------------------------ 662 683 CHARACTER(LEN=1024) :: s, t 663 684 INTEGER :: i0, ix, nk, ns 664 685 LOGICAL :: lsur, lb, le 665 666 686 lsur = .FALSE.; IF(PRESENT(lsurr)) lsur = lsurr 667 687 nk = LEN_TRIM(key) … … 702 722 CHARACTER(LEN=*), OPTIONAL, TARGET, INTENT(IN) :: s1, s2, s3, s4, s5, s6, s7, s8, s9 703 723 CHARACTER(LEN=maxlen), ALLOCATABLE :: out(:) 724 !------------------------------------------------------------------------------------------------------------------------------ 704 725 CHARACTER(LEN=maxlen), POINTER :: s 705 726 LOGICAL :: lv(10) … … 721 742 CHARACTER(LEN=*), OPTIONAL, TARGET, DIMENSION(:), INTENT(IN) :: s1, s2, s3, s4, s5, s6, s7, s8, s9 722 743 CHARACTER(LEN=maxlen), ALLOCATABLE :: out(:,:) 744 !------------------------------------------------------------------------------------------------------------------------------ 723 745 CHARACTER(LEN=maxlen), POINTER :: s(:) 724 746 LOGICAL :: lv(10) … … 743 765 INTEGER, OPTIONAL, TARGET, INTENT(IN) :: i1, i2, i3, i4, i5, i6, i7, i8, i9 744 766 INTEGER, ALLOCATABLE :: out(:) 767 !------------------------------------------------------------------------------------------------------------------------------ 745 768 INTEGER, POINTER :: i 746 769 LOGICAL :: lv(10) … … 762 785 INTEGER, OPTIONAL, TARGET, DIMENSION(:), INTENT(IN) :: i1, i2, i3, i4, i5, i6, i7, i8, i9 763 786 INTEGER, ALLOCATABLE :: out(:,:) 787 !------------------------------------------------------------------------------------------------------------------------------ 764 788 INTEGER, POINTER :: i(:) 765 789 LOGICAL :: lv(10) … … 784 808 REAL, OPTIONAL, TARGET, INTENT(IN) :: r1, r2, r3, r4, r5, r6, r7, r8, r9 785 809 REAL, ALLOCATABLE :: out(:) 810 !------------------------------------------------------------------------------------------------------------------------------ 786 811 REAL, POINTER :: r 787 812 LOGICAL :: lv(10) … … 803 828 REAL, OPTIONAL, TARGET, DIMENSION(:), INTENT(IN) :: r1, r2, r3, r4, r5, r6, r7, r8, r9 804 829 REAL, ALLOCATABLE :: out(:,:) 830 !------------------------------------------------------------------------------------------------------------------------------ 805 831 REAL, POINTER :: r(:) 806 832 LOGICAL :: lv(10) … … 825 851 DOUBLE PRECISION, OPTIONAL, TARGET, INTENT(IN) :: d1, d2, d3, d4, d5, d6, d7, d8, d9 826 852 DOUBLE PRECISION, ALLOCATABLE :: out(:) 853 !------------------------------------------------------------------------------------------------------------------------------ 827 854 DOUBLE PRECISION, POINTER :: d 828 855 LOGICAL :: lv(10) … … 844 871 DOUBLE PRECISION, OPTIONAL, TARGET, DIMENSION(:), INTENT(IN) :: d1, d2, d3, d4, d5, d6, d7, d8, d9 845 872 DOUBLE PRECISION, ALLOCATABLE :: out(:,:) 873 !------------------------------------------------------------------------------------------------------------------------------ 846 874 DOUBLE PRECISION, POINTER :: d(:) 847 875 LOGICAL :: lv(10) … … 883 911 INTEGER, OPTIONAL, INTENT(IN) :: unit !--- Output unit (default: screen) 884 912 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: sub !--- Subroutine name 885 913 !------------------------------------------------------------------------------------------------------------------------------ 886 914 CHARACTER(LEN=2048) :: row 887 915 CHARACTER(LEN=maxlen) :: rFm, el, subn … … 893 921 INTEGER, PARAMETER :: nm=1 !--- Space between values & columns 894 922 LOGICAL :: ls, li, lr 895 896 923 subn = ''; IF(PRESENT(sub)) subn = sub 897 924 rFm = '*'; IF(PRESENT(rFmt)) rFm = rFmt !--- Specified format for reals … … 968 995 nr = LEN_TRIM(row)-1 !--- Final separator removed 969 996 CALL msg(row(1:nr), subn, unit=unt) 970 IF(ir /= 1) CYCLE !--- Titles are underlined997 IF(ir /= 1) CYCLE !--- Titles only are underlined 971 998 row=''; DO ic=1,nHd; row=TRIM(row)//REPEAT('-',n(ic))//'+'; END DO 972 999 DO ic = ib,ncmx(it); row=TRIM(row)//REPEAT('-',n(ic))//'+'; END DO … … 989 1016 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: rFmt !--- Format for reals 990 1017 LOGICAL, OPTIONAL, INTENT(IN) :: llast !--- Last variable: no final ',' 991 1018 !------------------------------------------------------------------------------------------------------------------------------ 992 1019 CHARACTER(LEN=maxlen) :: rFm, el 993 1020 CHARACTER(LEN=maxlen), ALLOCATABLE :: d(:,:) … … 997 1024 INTEGER, ALLOCATABLE :: n(:) 998 1025 LOGICAL :: ls, li, lr, la 999 1000 ! modname = 'dispNamelist'1001 1026 rFm = '*'; IF(PRESENT(rFmt)) rFm = rFmt !--- Specified format for reals 1002 1027 ls = PRESENT(s); li = PRESENT(i); lr = PRESENT(r) … … 1070 1095 REAL, INTENT(IN) :: a(:) !--- Linearized array of values 1071 1096 INTEGER, INTENT(IN) :: n(:) !--- Profile before linearization 1072 1073 1097 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: err_msg, nam(:), subn !--- Error message, variables and calling subroutine names 1074 1098 INTEGER, OPTIONAL, INTENT(IN) :: nRowMax !--- Maximum number of lines to display (default: all) … … 1076 1100 INTEGER, OPTIONAL, INTENT(IN) :: nHead !--- Number of front columns to duplicate (default: 1) 1077 1101 INTEGER, OPTIONAL, INTENT(IN) :: unit !--- Output unit (def: lunout) 1102 !------------------------------------------------------------------------------------------------------------------------------ 1078 1103 CHARACTER(LEN=maxlen), ALLOCATABLE :: ttl(:) 1079 1104 LOGICAL, ALLOCATABLE :: m(:) … … 1153 1178 INTEGER, OPTIONAL, INTENT(IN) :: nHead !--- Number of front columns to duplicate (default: 1) 1154 1179 INTEGER, OPTIONAL, INTENT(IN) :: unit !--- Output unit (def: lunout) 1155 1180 !------------------------------------------------------------------------------------------------------------------------------ 1156 1181 CHARACTER(LEN=maxlen) :: mes, sub, fm='(f12.9)', prf 1157 1182 CHARACTER(LEN=maxlen), ALLOCATABLE :: ttl(:), vnm(:) … … 1203 1228 CHARACTER(LEN=*), INTENT(IN) :: str 1204 1229 CHARACTER(LEN=maxlen), INTENT(OUT) :: val 1205 1230 !------------------------------------------------------------------------------------------------------------------------------ 1206 1231 CHARACTER(LEN=maxlen) :: v 1207 1232 CHARACTER(LEN=1024) :: s, vv … … 1210 1235 INTEGER :: nl, nn, i, j, im, ix 1211 1236 LOGICAL :: ll 1212 ! modname = 'reduceExpr_1'1213 1237 s = str 1214 1238 … … 1257 1281 CHARACTER(LEN=maxlen), ALLOCATABLE :: ky(:) 1258 1282 CHARACTER(LEN=1), ALLOCATABLE :: op(:) 1259 1283 !------------------------------------------------------------------------------------------------------------------------------ 1260 1284 CHARACTER(LEN=1024) :: s 1261 1285 DOUBLE PRECISION :: v, vm, vp 1262 1286 INTEGER :: i, ni, io 1263 1264 1287 lerr = .FALSE. 1265 1288 IF(is_numeric(str)) THEN; val=TRIM(str); RETURN; END IF … … 1275 1298 IF(id(i) /= io) CYCLE !--- Current found operator is not op(io) 1276 1299 vm = vl(i); vp = vl(i+1) !--- Couple of values used for current operation 1277 SELECT CASE( io) !--- Perform operation on the two values1278 CASE( 1); v = vm**vp !--- ^1279 CASE( 2); v = vm/vp !--- /1280 CASE( 3); v = vm*vp !--- *1281 CASE( 4); v = vm+vp !--- +1282 CASE( 5); v = vm-vp !--- +1300 SELECT CASE(op(io)) !--- Perform operation on the two values 1301 CASE('^'); v = vm**vp 1302 CASE('/'); v = vm/vp 1303 CASE('*'); v = vm*vp 1304 CASE('+'); v = vm+vp 1305 CASE('-'); v = vm-vp 1283 1306 END SELECT 1284 1307 IF(i == ni) THEN; vl = [vl(1:ni-1), v]; ELSE; vl = [vl(1:i-1), v, vl(i+2:ni+1)]; END IF … … 1296 1319 CHARACTER(LEN=*), INTENT(IN) :: str(:) 1297 1320 CHARACTER(LEN=maxlen), ALLOCATABLE, INTENT(OUT) :: val(:) 1321 !------------------------------------------------------------------------------------------------------------------------------ 1298 1322 INTEGER :: i 1299 1323 ALLOCATE(lerr(SIZE(str)),val(SIZE(str))) … … 1360 1384 INTEGER, INTENT(IN) :: i 1361 1385 INTEGER, OPTIONAL, INTENT(IN) :: nDigits 1386 !------------------------------------------------------------------------------------------------------------------------------ 1362 1387 WRITE(out,*)i 1363 1388 out = ADJUSTL(out) … … 1369 1394 REAL, INTENT(IN) :: r 1370 1395 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: fmt 1396 !------------------------------------------------------------------------------------------------------------------------------ 1371 1397 IF( PRESENT(fmt)) WRITE(out,fmt)r 1372 1398 IF(.NOT.PRESENT(fmt)) WRITE(out, * )r … … 1377 1403 DOUBLE PRECISION, INTENT(IN) :: d 1378 1404 CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: fmt 1405 !------------------------------------------------------------------------------------------------------------------------------ 1379 1406 IF( PRESENT(fmt)) WRITE(out,fmt)d 1380 1407 IF(.NOT.PRESENT(fmt)) WRITE(out, * )d … … 1397 1424 !============================================================================================================================== 1398 1425 1426 1399 1427 !============================================================================================================================== 1400 1428 FUNCTION addQuotes_1(s) RESULT(out) … … 1407 1435 CHARACTER(LEN=*), INTENT(IN) :: s(:) 1408 1436 CHARACTER(LEN=:), ALLOCATABLE :: out(:) 1437 !------------------------------------------------------------------------------------------------------------------------------ 1409 1438 INTEGER :: k, n 1410 1439 n = MAXVAL(LEN_TRIM(s), MASK=.TRUE.) … … 1418 1447 CHARACTER(LEN=*), INTENT(IN) :: s 1419 1448 CHARACTER(LEN=1) :: b, e 1449 !------------------------------------------------------------------------------------------------------------------------------ 1420 1450 out = .TRUE.; IF(TRIM(s) == '') RETURN 1421 1451 b = s(1:1); e = s(MAX(1,LEN_TRIM(s)):MAX(1,LEN_TRIM(s))) … … 1430 1460 LOGICAL FUNCTION testFile_1(fname) RESULT(out) 1431 1461 CHARACTER(LEN=*), INTENT(IN) :: fname 1462 !------------------------------------------------------------------------------------------------------------------------------ 1432 1463 INTEGER :: ierr 1433 1464 OPEN(90, FILE=fname, FORM='formatted', STATUS='old', IOSTAT=ierr); CLOSE(99) … … 1439 1470 CHARACTER(LEN=*), INTENT(IN) :: fname(:) 1440 1471 INTEGER :: k 1472 !------------------------------------------------------------------------------------------------------------------------------ 1441 1473 out = [(testFile_1(fname(k)), k=1, SIZE(fname))] 1442 1474 END FUNCTION testFile_m … … 1454 1486 CHARACTER(LEN=*), INTENT(IN) :: message, items, reason 1455 1487 INTEGER, OPTIONAL, INTENT(IN) :: nmax 1488 !------------------------------------------------------------------------------------------------------------------------------ 1456 1489 CHARACTER(LEN=maxlen), ALLOCATABLE :: s(:) 1457 1490 INTEGER :: i, nmx … … 1476 1509 1477 1510 1478 1479 1511 END MODULE strings_mod
Note: See TracChangeset
for help on using the changeset viewer.