- Timestamp:
- Sep 25, 2024, 12:03:08 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
LMDZ6/branches/Amaury_dev/libf/dyn3d_common/iso_verif_dyn.f90
r5224 r5229 1 function iso_verif_noNaN_nostop(x, err_msg) 2 IMPLICIT NONE 3 ! si x est NaN, on affiche message 4 ! d'erreur et return 1 si erreur 1 LOGICAL FUNCTION iso_verif_noNaN_nostop(x, err_msg) RESULT(lerr) 2 IMPLICIT NONE 3 ! If "x" is NaN, print an error message . 4 REAL, INTENT(IN) :: x 5 CHARACTER(LEN=*), INTENT(IN) :: err_msg 6 REAL, PARAMETER :: borne = 1e19 7 lerr = x > -borne .AND. x < borne 8 IF(.NOT.lerr) RETURN 9 WRITE(*,*) 'erreur detectee par iso_verif_nonNaN:' 10 WRITE(*,*) err_msg 11 WRITE(*,*) 'x=',x 12 END FUNCTION iso_verif_noNaN_nostop 5 13 6 ! input: 7 REAL :: x 8 CHARACTER(LEN = *) :: err_msg ! message d''erreur à afficher 9 10 ! output 11 REAL :: borne 12 parameter (borne = 1e19) 13 INTEGER :: iso_verif_noNaN_nostop 14 15 IF ((x>-borne).AND.(x<borne)) THEN 16 iso_verif_noNAN_nostop = 0 17 else 18 WRITE(*, *) 'erreur detectee par iso_verif_nonNaN:' 19 WRITE(*, *) err_msg 20 WRITE(*, *) 'x=', x 21 iso_verif_noNaN_nostop = 1 22 endif 23 24 RETURN 25 END FUNCTION iso_verif_nonan_nostop 26 27 function iso_verif_egalite_nostop & 28 (a, b, err_msg) 29 IMPLICIT NONE 30 ! compare a et b. Si pas egal, on affiche message 31 ! d'erreur et stoppe 32 ! pour egalite, on verifie erreur absolue et arreur relative 33 34 ! input: 35 REAL :: a, b 36 CHARACTER(LEN = *) :: err_msg ! message d''erreur à afficher 37 38 ! locals 39 REAL :: errmax ! erreur maximale en absolu. 40 REAL :: errmaxrel ! erreur maximale en relatif autorisée 41 parameter (errmax = 1e-8) 42 parameter (errmaxrel = 1e-3) 43 44 ! output 45 INTEGER :: iso_verif_egalite_nostop 46 47 iso_verif_egalite_nostop = 0 48 49 IF (abs(a - b)>errmax) THEN 50 IF (abs((a - b) / max(max(abs(b), abs(a)), 1e-18)) & 51 >errmaxrel) THEN 52 WRITE(*, *) 'erreur detectee par iso_verif_egalite:' 53 WRITE(*, *) err_msg 54 WRITE(*, *) 'a=', a 55 WRITE(*, *) 'b=', b 56 iso_verif_egalite_nostop = 1 57 endif 58 endif 59 60 RETURN 14 LOGICAL FUNCTION iso_verif_egalite_nostop(a, b, err_msg) RESULT(lerr) 15 IMPLICIT NONE 16 ! Compare "a" and "b". If a/=b, print an error message. 17 ! Both absolute and relative errors are checked for equality. 18 REAL, INTENT(IN) :: a, b 19 CHARACTER(LEN=*), INTENT(IN) :: err_msg 20 REAL, PARAMETER :: errmax = 1e-8, & ! max absolute error 21 errmaxrel = 1e-3 ! max relative error 22 lerr = ABS(a-b) > errmax 23 IF(.NOT.lerr) RETURN 24 lerr = ABS( (a-b) / MAX(MAX(ABS(b), ABS(a)),1e-18) ) > errmaxrel 25 IF(.NOT.lerr) RETURN 26 WRITE(*,*) 'erreur detectee par iso_verif_egalite:' 27 WRITE(*,*) err_msg 28 WRITE(*,*) 'a=',a 29 WRITE(*,*) 'b=',b 61 30 END FUNCTION iso_verif_egalite_nostop 62 31 63 32 64 function iso_verif_aberrant_nostop & 65 (x, iso, q, err_msg) 66 USE lmdz_infotrac, ONLY: isoName, getKey 33 LOGICAL FUNCTION iso_verif_aberrant_nostop(x, iso, q, err_msg) RESULT(lerr) 67 34 USE ioipsl, ONLY: getin 35 USE iso_params_mod, ONLY: tnat_HDO 68 36 69 37 IMPLICIT NONE 70 38 71 ! input: 72 REAL :: x, q 73 INTEGER :: iso ! 2=HDO, 1=O18 74 CHARACTER(LEN = *) :: err_msg ! message d''erreur à afficher 39 REAL, INTENT(IN) :: x, q 40 INTEGER, INTENT(IN) :: iso ! 2=HDO, 1=O18 41 CHARACTER(LEN = *), INTENT(IN) :: err_msg 75 42 76 ! locals 77 REAL :: qmin, deltaD 78 REAL :: deltaDmax, deltaDmin, tnat 79 parameter (qmin = 1e-11) 80 parameter (deltaDmax = 200.0, deltaDmin = -999.9) 81 LOGICAL, SAVE :: ltnat1 82 LOGICAL, SAVE :: lFirst = .TRUE. 83 84 ! output 85 INTEGER :: iso_verif_aberrant_nostop 86 87 IF(lFirst) THEN 88 ltnat1 = .TRUE.; CALL getin('tnateq1', ltnat1) 89 lFirst = .FALSE. 90 END IF 91 iso_verif_aberrant_nostop = 0 92 93 ! verifier que HDO est raisonable 94 IF (q>qmin) THEN 95 IF(ltnat1) THEN 96 tnat = 1.0 97 ELSE IF(getKey('tnat', tnat, isoName(iso))) THEN 98 err_msg = 'Missing isotopic parameter "tnat"' 99 iso_verif_aberrant_nostop = 1 100 RETURN 101 END IF 102 deltaD = (x / q / tnat - 1) * 1000 103 IF ((deltaD>deltaDmax).OR.(deltaD<deltaDmin)) THEN 104 WRITE(*, *) 'erreur detectee par iso_verif_aberrant:' 105 WRITE(*, *) err_msg 106 WRITE(*, *) 'q=', q 107 WRITE(*, *) 'deltaD=', deltaD 108 WRITE(*, *) 'iso=', iso 109 iso_verif_aberrant_nostop = 1 110 endif !if ((deltaD.gt.deltaDmax).OR.(deltaD.lt.deltaDmin)) THEN 111 endif !if (q(i,k,iq).gt.qmin) THEN 112 RETURN 43 REAL, PARAMETER :: qmin = 1e-11, & 44 deltaDmax = 200.0, & 45 deltaDmin =-999.9 46 LOGICAL :: ltnat1 47 LOGICAL, SAVE :: lFirst=.TRUE. 48 REAL, SAVE :: tnat 49 REAL :: deltaD 50 IF(lFirst) THEN 51 ltnat1 = .TRUE.; CALL getin('tnateq1', ltnat1) 52 tnat = tnat_HDO; IF(ltnat1) tnat = 1.0 53 lFirst = .FALSE. 54 END IF 55 lerr = q > qmin 56 IF(.NOT.lerr) RETURN 57 deltaD = (x / q /tnat - 1.) * 1000. 58 lerr = deltaD > deltaDmax .OR. deltaD < deltaDmin 59 IF(.NOT.lerr) RETURN 60 WRITE(*,*) 'erreur detectee par iso_verif_aberrant:' 61 WRITE(*,*) err_msg 62 WRITE(*,*) 'q=',q 63 WRITE(*,*) 'deltaD=',deltaD 64 WRITE(*,*) 'iso=',iso 113 65 END FUNCTION iso_verif_aberrant_nostop 114
Note: See TracChangeset
for help on using the changeset viewer.