Changeset 5246 for LMDZ6/trunk/libf/misc
- Timestamp:
- Oct 21, 2024, 2:58:45 PM (3 months ago)
- Location:
- LMDZ6/trunk/libf/misc
- Files:
-
- 24 moved
Legend:
- Unmodified
- Added
- Removed
-
LMDZ6/trunk/libf/misc/cbrt.f90
r5245 r5246 1 2 3 1 FUNCTION cbrt(x) 2 ! ! Return the cubic root for positive or negative x 3 IMPLICIT NONE 4 4 5 REALx,cbrt5 REAL :: x,cbrt 6 6 7 7 cbrt=sign(1.,x)*(abs(x)**(1./3.)) 8 8 9 10 END 9 RETURN 10 END FUNCTION cbrt 11 11 -
LMDZ6/trunk/libf/misc/chfev.f90
r5245 r5246 1 *DECK CHFEV2 3 C***BEGIN PROLOGUE CHFEV4 C***PURPOSE Evaluate a cubic polynomial given in Hermite form at an5 Carray of points. While designed for use by PCHFE, it may6 Cbe useful directly as an evaluator for a piecewise cubic7 CHermite function in applications, such as graphing, where8 Cthe interval is known in advance.9 C***LIBRARY SLATEC (PCHIP)10 C***CATEGORY E311 C***TYPE SINGLE PRECISION (CHFEV-S, DCHFEV-D)12 C***KEYWORDS CUBIC HERMITE EVALUATION, CUBIC POLYNOMIAL EVALUATION,13 CPCHIP14 C***AUTHOR Fritsch, F. N., (LLNL)15 CLawrence Livermore National Laboratory16 CP.O. Box 808 (L-316)17 CLivermore, CA 9455018 CFTS 532-4275, (510) 422-427519 C***DESCRIPTION20 C 21 CCHFEV: Cubic Hermite Function EValuator22 C 23 CEvaluates the cubic polynomial determined by function values24 CF1,F2 and derivatives D1,D2 on interval (X1,X2) at the points25 CXE(J), J=1(1)NE.26 C 27 C----------------------------------------------------------------------28 C 29 CCalling sequence:30 C 31 CINTEGER NE, NEXT(2), IERR32 CREAL X1, X2, F1, F2, D1, D2, XE(NE), FE(NE)33 C 34 CCALL CHFEV (X1,X2, F1,F2, D1,D2, NE, XE, FE, NEXT, IERR)35 C 36 CParameters:37 C 38 CX1,X2 -- (input) endpoints of interval of definition of cubic.39 C(Error return if X1.EQ.X2 .)40 C 41 CF1,F2 -- (input) values of function at X1 and X2, respectively.42 C 43 CD1,D2 -- (input) values of derivative at X1 and X2, respectively.44 C 45 CNE -- (input) number of evaluation points. (Error return if46 CNE.LT.1 .)47 C 48 CXE -- (input) real array of points at which the function is to be49 Cevaluated. If any of the XE are outside the interval50 C[X1,X2], a warning error is returned in NEXT.51 C 52 CFE -- (output) real array of values of the cubic function defined53 Cby X1,X2, F1,F2, D1,D2 at the points XE.54 C 55 CNEXT -- (output) integer array indicating number of extrapolation56 Cpoints:57 CNEXT(1) = number of evaluation points to left of interval.58 CNEXT(2) = number of evaluation points to right of interval.59 C 60 CIERR -- (output) error flag.61 CNormal return:62 CIERR = 0 (no errors).63 C"Recoverable" errors:64 CIERR = -1 if NE.LT.1 .65 CIERR = -2 if X1.EQ.X2 .66 C(The FE-array has not been changed in either case.)67 C 68 C***REFERENCES (NONE)69 C***ROUTINES CALLED XERMSG70 C***REVISION HISTORY (YYMMDD)71 C811019 DATE WRITTEN72 C820803 Minor cosmetic changes for release 1.73 C890411 Added SAVE statements (Vers. 3.2).74 C890531 Changed all specific intrinsics to generic. (WRB)75 C890703 Corrected category record. (WRB)76 C890703 REVISION DATE from Version 3.277 C891214 Prologue converted to Version 4.0 format. (BAB)78 C900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)79 C***END PROLOGUE CHFEV80 CProgramming notes:81 C 82 CTo produce a double precision version, simply:83 Ca. Change CHFEV to DCHFEV wherever it occurs,84 Cb. Change the real declaration to double precision, and85 Cc. Change the constant ZERO to double precision.86 C 87 CDECLARE ARGUMENTS.88 C 89 INTEGERNE, NEXT(2), IERR90 REALX1, X2, F1, F2, D1, D2, XE(*), FE(*)91 C 92 CDECLARE LOCAL VARIABLES.93 C 94 INTEGERI95 REALC2, C3, DEL1, DEL2, DELTA, H, X, XMI, XMA, ZERO96 97 98 C 99 CVALIDITY-CHECK ARGUMENTS.100 C 101 C***FIRST EXECUTABLE STATEMENT CHFEV102 103 104 105 C 106 CINITIALIZE.107 C 108 109 110 111 112 113 C 114 CCOMPUTE CUBIC COEFFICIENTS (EXPANDED ABOUT X1).115 C 116 117 118 119 C(DELTA IS NO LONGER NEEDED.)120 121 122 C(H, DEL1 AND DEL2 ARE NO LONGER NEEDED.)123 C 124 CEVALUATION LOOP.125 C 126 DO 500I = 1, NE127 128 129 CCOUNT EXTRAPOLATION POINTS.130 131 132 C(NOTE REDUNDANCY--IF EITHER CONDITION IS TRUE, OTHER IS FALSE.)133 500 CONTINUE134 C 135 CNORMAL RETURN.136 C 137 138 C 139 CERROR RETURNS.140 C 141 5001 CONTINUE142 CNE.LT.1 RETURN.143 144 CALL XERMSG ('SLATEC', 'CHFEV',145 +'NUMBER OF EVALUATION POINTS LESS THAN ONE', IERR, 1)146 147 C 148 5002 CONTINUE149 CX1.EQ.X2 RETURN.150 151 CALL XERMSG ('SLATEC', 'CHFEV', 'INTERVAL ENDPOINTS EQUAL', IERR,152 +1)153 154 C------------- LAST LINE OF CHFEV FOLLOWS ------------------------------155 END 1 !DECK CHFEV 2 SUBROUTINE CHFEV (X1, X2, F1, F2, D1, D2, NE, XE, FE, NEXT, IERR) 3 !***BEGIN PROLOGUE CHFEV 4 !***PURPOSE Evaluate a cubic polynomial given in Hermite form at an 5 ! array of points. While designed for use by PCHFE, it may 6 ! be useful directly as an evaluator for a piecewise cubic 7 ! Hermite function in applications, such as graphing, where 8 ! the interval is known in advance. 9 !***LIBRARY SLATEC (PCHIP) 10 !***CATEGORY E3 11 !***TYPE SINGLE PRECISION (CHFEV-S, DCHFEV-D) 12 !***KEYWORDS CUBIC HERMITE EVALUATION, CUBIC POLYNOMIAL EVALUATION, 13 ! PCHIP 14 !***AUTHOR Fritsch, F. N., (LLNL) 15 ! Lawrence Livermore National Laboratory 16 ! P.O. Box 808 (L-316) 17 ! Livermore, CA 94550 18 ! FTS 532-4275, (510) 422-4275 19 !***DESCRIPTION 20 ! 21 ! CHFEV: Cubic Hermite Function EValuator 22 ! 23 ! Evaluates the cubic polynomial determined by function values 24 ! F1,F2 and derivatives D1,D2 on interval (X1,X2) at the points 25 ! XE(J), J=1(1)NE. 26 ! 27 ! ---------------------------------------------------------------------- 28 ! 29 ! Calling sequence: 30 ! 31 ! INTEGER NE, NEXT(2), IERR 32 ! REAL X1, X2, F1, F2, D1, D2, XE(NE), FE(NE) 33 ! 34 ! CALL CHFEV (X1,X2, F1,F2, D1,D2, NE, XE, FE, NEXT, IERR) 35 ! 36 ! Parameters: 37 ! 38 ! X1,X2 -- (input) endpoints of interval of definition of cubic. 39 ! (Error return if X1.EQ.X2 .) 40 ! 41 ! F1,F2 -- (input) values of function at X1 and X2, respectively. 42 ! 43 ! D1,D2 -- (input) values of derivative at X1 and X2, respectively. 44 ! 45 ! NE -- (input) number of evaluation points. (Error return if 46 ! NE.LT.1 .) 47 ! 48 ! XE -- (input) real array of points at which the function is to be 49 ! evaluated. If any of the XE are outside the interval 50 ! [X1,X2], a warning error is returned in NEXT. 51 ! 52 ! FE -- (output) real array of values of the cubic function defined 53 ! by X1,X2, F1,F2, D1,D2 at the points XE. 54 ! 55 ! NEXT -- (output) integer array indicating number of extrapolation 56 ! points: 57 ! NEXT(1) = number of evaluation points to left of interval. 58 ! NEXT(2) = number of evaluation points to right of interval. 59 ! 60 ! IERR -- (output) error flag. 61 ! Normal return: 62 ! IERR = 0 (no errors). 63 ! "Recoverable" errors: 64 ! IERR = -1 if NE.LT.1 . 65 ! IERR = -2 if X1.EQ.X2 . 66 ! (The FE-array has not been changed in either case.) 67 ! 68 !***REFERENCES (NONE) 69 !***ROUTINES CALLED XERMSG 70 !***REVISION HISTORY (YYMMDD) 71 ! 811019 DATE WRITTEN 72 ! 820803 Minor cosmetic changes for release 1. 73 ! 890411 Added SAVE statements (Vers. 3.2). 74 ! 890531 Changed all specific intrinsics to generic. (WRB) 75 ! 890703 Corrected category record. (WRB) 76 ! 890703 REVISION DATE from Version 3.2 77 ! 891214 Prologue converted to Version 4.0 format. (BAB) 78 ! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) 79 !***END PROLOGUE CHFEV 80 ! Programming notes: 81 ! 82 ! To produce a double precision version, simply: 83 ! a. Change CHFEV to DCHFEV wherever it occurs, 84 ! b. Change the real declaration to double precision, and 85 ! c. Change the constant ZERO to double precision. 86 ! 87 ! DECLARE ARGUMENTS. 88 ! 89 INTEGER :: NE, NEXT(2), IERR 90 REAL :: X1, X2, F1, F2, D1, D2, XE(*), FE(*) 91 ! 92 ! DECLARE LOCAL VARIABLES. 93 ! 94 INTEGER :: I 95 REAL :: C2, C3, DEL1, DEL2, DELTA, H, X, XMI, XMA, ZERO 96 SAVE ZERO 97 DATA ZERO /0./ 98 ! 99 ! VALIDITY-CHECK ARGUMENTS. 100 ! 101 !***FIRST EXECUTABLE STATEMENT CHFEV 102 IF (NE .LT. 1) GO TO 5001 103 H = X2 - X1 104 IF (H .EQ. ZERO) GO TO 5002 105 ! 106 ! INITIALIZE. 107 ! 108 IERR = 0 109 NEXT(1) = 0 110 NEXT(2) = 0 111 XMI = MIN(ZERO, H) 112 XMA = MAX(ZERO, H) 113 ! 114 ! COMPUTE CUBIC COEFFICIENTS (EXPANDED ABOUT X1). 115 ! 116 DELTA = (F2 - F1)/H 117 DEL1 = (D1 - DELTA)/H 118 DEL2 = (D2 - DELTA)/H 119 ! (DELTA IS NO LONGER NEEDED.) 120 C2 = -(DEL1+DEL1 + DEL2) 121 C3 = (DEL1 + DEL2)/H 122 ! (H, DEL1 AND DEL2 ARE NO LONGER NEEDED.) 123 ! 124 ! EVALUATION LOOP. 125 ! 126 DO I = 1, NE 127 X = XE(I) - X1 128 FE(I) = F1 + X*(D1 + X*(C2 + X*C3)) 129 ! COUNT EXTRAPOLATION POINTS. 130 IF ( X.LT.XMI ) NEXT(1) = NEXT(1) + 1 131 IF ( X.GT.XMA ) NEXT(2) = NEXT(2) + 1 132 ! (NOTE REDUNDANCY--IF EITHER CONDITION IS TRUE, OTHER IS FALSE.) 133 END DO 134 ! 135 ! NORMAL RETURN. 136 ! 137 RETURN 138 ! 139 ! ERROR RETURNS. 140 ! 141 5001 CONTINUE 142 ! NE.LT.1 RETURN. 143 IERR = -1 144 CALL XERMSG ('SLATEC', 'CHFEV', & 145 'NUMBER OF EVALUATION POINTS LESS THAN ONE', IERR, 1) 146 RETURN 147 ! 148 5002 CONTINUE 149 ! X1.EQ.X2 RETURN. 150 IERR = -2 151 CALL XERMSG ('SLATEC', 'CHFEV', 'INTERVAL ENDPOINTS EQUAL', IERR, & 152 1) 153 RETURN 154 !------------- LAST LINE OF CHFEV FOLLOWS ------------------------------ 155 END SUBROUTINE CHFEV -
LMDZ6/trunk/libf/misc/cray.F90
r5245 r5246 3 3 ! 4 4 #ifdef CRAY 5 6 END 5 SUBROUTINE riencray 6 END SUBROUTINE riencray 7 7 #else 8 9 c 10 11 c 12 integern,incx,incy,ix,iy,i13 realsx((n-1)*incx+1),sy((n-1)*incy+1)14 c 15 16 17 do 10i=1,n18 19 20 21 10 continue 22 c 23 24 end 8 subroutine scopy(n,sx,incx,sy,incy) 9 ! 10 IMPLICIT NONE 11 ! 12 integer :: n,incx,incy,ix,iy,i 13 real :: sx((n-1)*incx+1),sy((n-1)*incy+1) 14 ! 15 iy=1 16 ix=1 17 do i=1,n 18 sy(iy)=sx(ix) 19 ix=ix+incx 20 iy=iy+incy 21 end do 22 ! 23 return 24 end subroutine scopy 25 25 26 27 c 28 29 c 30 integern,incx,i,ix31 realssum,sx((n-1)*incx+1)32 c 33 34 35 do 10i=1,n36 37 38 10 continue 39 c 40 41 end 26 function ssum(n,sx,incx) 27 ! 28 IMPLICIT NONE 29 ! 30 integer :: n,incx,i,ix 31 real :: ssum,sx((n-1)*incx+1) 32 ! 33 ssum=0. 34 ix=1 35 do i=1,n 36 ssum=ssum+sx(ix) 37 ix=ix+incx 38 end do 39 ! 40 return 41 end function ssum 42 42 #endif -
LMDZ6/trunk/libf/misc/fdump.f90
r5245 r5246 1 *DECK FDUMP2 3 C***BEGIN PROLOGUE FDUMP4 C***PURPOSE Symbolic dump (should be locally written).5 C***LIBRARY SLATEC (XERROR)6 C***CATEGORY R37 C***TYPE ALL (FDUMP-A)8 C***KEYWORDS ERROR, XERMSG9 C***AUTHOR Jones, R. E., (SNLA)10 C***DESCRIPTION11 C 12 C***Note*** Machine Dependent Routine13 CFDUMP is intended to be replaced by a locally written14 Cversion which produces a symbolic dump. Failing this,15 Cit should be replaced by a version which prints the16 Csubprogram nesting list. Note that this dump must be17 Cprinted on each of up to five files, as indicated by the18 CXGETUA routine. See XSETUA and XGETUA for details.19 C 20 CWritten by Ron Jones, with SLATEC Common Math Library Subcommittee21 C 22 C***REFERENCES (NONE)23 C***ROUTINES CALLED (NONE)24 C***REVISION HISTORY (YYMMDD)25 C790801 DATE WRITTEN26 C861211 REVISION DATE from Version 3.227 C891214 Prologue converted to Version 4.0 format. (BAB)28 C***END PROLOGUE FDUMP29 C***FIRST EXECUTABLE STATEMENT FDUMP30 31 END 1 !DECK FDUMP 2 SUBROUTINE FDUMP 3 !***BEGIN PROLOGUE FDUMP 4 !***PURPOSE Symbolic dump (should be locally written). 5 !***LIBRARY SLATEC (XERROR) 6 !***CATEGORY R3 7 !***TYPE ALL (FDUMP-A) 8 !***KEYWORDS ERROR, XERMSG 9 !***AUTHOR Jones, R. E., (SNLA) 10 !***DESCRIPTION 11 ! 12 ! ***Note*** Machine Dependent Routine 13 ! FDUMP is intended to be replaced by a locally written 14 ! version which produces a symbolic dump. Failing this, 15 ! it should be replaced by a version which prints the 16 ! subprogram nesting list. Note that this dump must be 17 ! printed on each of up to five files, as indicated by the 18 ! XGETUA routine. See XSETUA and XGETUA for details. 19 ! 20 ! Written by Ron Jones, with SLATEC Common Math Library Subcommittee 21 ! 22 !***REFERENCES (NONE) 23 !***ROUTINES CALLED (NONE) 24 !***REVISION HISTORY (YYMMDD) 25 ! 790801 DATE WRITTEN 26 ! 861211 REVISION DATE from Version 3.2 27 ! 891214 Prologue converted to Version 4.0 format. (BAB) 28 !***END PROLOGUE FDUMP 29 !***FIRST EXECUTABLE STATEMENT FDUMP 30 RETURN 31 END SUBROUTINE FDUMP -
LMDZ6/trunk/libf/misc/formcoord.f90
r5245 r5246 2 2 ! $Header$ 3 3 ! 4 5 6 integern,unit,ndec7 logicalrev8 realx(n),a9 character*4text4 subroutine formcoord(unit,n,x,a,rev,text) 5 implicit none 6 integer :: n,unit,ndec 7 logical :: rev 8 real :: x(n),a 9 character(len=4) :: text 10 10 11 integeri,id,i1,i2,in12 realdx,dxmin11 integer :: i,id,i1,i2,in 12 real :: dx,dxmin 13 13 14 15 16 17 18 19 20 21 22 23 24 25 14 if(rev) then 15 id=-1 16 i1=n 17 i2=n-1 18 in=1 19 write(unit,3000) text(1:1) 20 else 21 id=1 22 i1=1 23 i2=2 24 in=n 25 endif 26 26 27 28 29 30 31 32 33 34 35 27 if (n.lt.2) then 28 ndec=1 29 write(unit,1000) text,n,x(1)*a 30 else 31 dxmin=abs(x(2)-x(1)) 32 do i=2,n-1 33 dx=abs(x(i+1)-x(i)) 34 if (dx.lt.dxmin) dxmin=dx 35 enddo 36 36 37 38 39 40 41 42 43 44 45 37 ndec=-log10(dxmin)+2 38 if(mod(n,6).eq.1) then 39 write(unit,1000) text,n,x(i1)*a 40 write(unit,2000) (x(i)*a,i=i2,in,id) 41 else 42 write(unit,1000) text,n 43 write(unit,2000) (x(i)*a,i=i1,in,id) 44 endif 45 endif 46 46 47 1000 format(a4,2x,i4,' LEVELS',43x,f12.2)48 2000 format(6f12.2)49 c1000 format(a4,2x,i4,' LEVELS',43x,f12.<ndec>)50 c2000 format(6f12.<ndec>)51 3000 format('FORMAT ',a1,'REV')52 47 1000 format(a4,2x,i4,' LEVELS',43x,f12.2) 48 2000 format(6f12.2) 49 !1000 format(a4,2x,i4,' LEVELS',43x,f12.<ndec>) 50 !2000 format(6f12.<ndec>) 51 3000 format('FORMAT ',a1,'REV') 52 return 53 53 54 end54 end subroutine formcoord -
LMDZ6/trunk/libf/misc/i1mach.f90
r5245 r5246 1 *DECK I1MACH2 3 4 C***BEGIN PROLOGUE I1MACH5 C***PURPOSE Return integer machine dependent constants.6 C***LIBRARY SLATEC7 C***CATEGORY R18 C***TYPE INTEGER (I1MACH-I)9 C***KEYWORDS MACHINE CONSTANTS10 C***AUTHOR Fox, P. A., (Bell Labs)11 CHall, A. D., (Bell Labs)12 CSchryer, N. L., (Bell Labs)13 C***DESCRIPTION14 C 15 CI1MACH can be used to obtain machine-dependent parameters for the16 Clocal machine environment. It is a function subprogram with one17 C(input) argument and can be referenced as follows:18 C 19 CK = I1MACH(I)20 C 21 Cwhere I=1,...,16. The (output) value of K above is determined by22 Cthe (input) value of I. The results for various values of I are23 Cdiscussed below.24 C 25 CI/O unit numbers:26 CI1MACH( 1) = the standard input unit.27 CI1MACH( 2) = the standard output unit.28 CI1MACH( 3) = the standard punch unit.29 CI1MACH( 4) = the standard error message unit.30 C 31 CWords:32 CI1MACH( 5) = the number of bits per integer storage unit.33 CI1MACH( 6) = the number of characters per integer storage unit.34 C 35 CIntegers:36 Cassume integers are represented in the S-digit, base-A form37 C 38 Csign ( X(S-1)*A**(S-1) + ... + X(1)*A + X(0) )39 C 40 Cwhere 0 .LE. X(I) .LT. A for I=0,...,S-1.41 CI1MACH( 7) = A, the base.42 CI1MACH( 8) = S, the number of base-A digits.43 CI1MACH( 9) = A**S - 1, the largest magnitude.44 C 45 CFloating-Point Numbers:46 CAssume floating-point numbers are represented in the T-digit,47 Cbase-B form48 Csign (B**E)*( (X(1)/B) + ... + (X(T)/B**T) )49 C 50 Cwhere 0 .LE. X(I) .LT. B for I=1,...,T,51 C0 .LT. X(1), and EMIN .LE. E .LE. EMAX.52 CI1MACH(10) = B, the base.53 C 54 CSingle-Precision:55 CI1MACH(11) = T, the number of base-B digits.56 CI1MACH(12) = EMIN, the smallest exponent E.57 CI1MACH(13) = EMAX, the largest exponent E.58 C 59 CDouble-Precision:60 CI1MACH(14) = T, the number of base-B digits.61 CI1MACH(15) = EMIN, the smallest exponent E.62 CI1MACH(16) = EMAX, the largest exponent E.63 C 64 CTo alter this function for a particular environment, the desired65 Cset of DATA statements should be activated by removing the C from66 Ccolumn 1. Also, the values of I1MACH(1) - I1MACH(4) should be67 Cchecked for consistency with the local operating system.68 C 69 C***REFERENCES P. A. Fox, A. D. Hall and N. L. Schryer, Framework for70 Ca portable library, ACM Transactions on Mathematical71 CSoftware 4, 2 (June 1978), pp. 177-188.72 C***ROUTINES CALLED (NONE)73 C***REVISION HISTORY (YYMMDD)74 C750101 DATE WRITTEN75 C891012 Added VAX G-floating constants. (WRB)76 C891012 REVISION DATE from Version 3.277 C891214 Prologue converted to Version 4.0 format. (BAB)78 C900618 Added DEC RISC constants. (WRB)79 C900723 Added IBM RS 6000 constants. (WRB)80 C901009 Correct I1MACH(7) for IBM Mainframes. Should be 2 not 16.81 C(RWC)82 C910710 Added HP 730 constants. (SMR)83 C911114 Added Convex IEEE constants. (WRB)84 C920121 Added SUN -r8 compiler option constants. (WRB)85 C920229 Added Touchstone Delta i860 constants. (WRB)86 C920501 Reformatted the REFERENCES section. (WRB)87 C920625 Added Convex -p8 and -pd8 compiler option constants.88 C(BKS, WRB)89 C930201 Added DEC Alpha and SGI constants. (RWC and WRB)90 C930618 Corrected I1MACH(5) for Convex -p8 and -pd8 compiler91 Coptions. (DWL, RWC and WRB).92 C100623 Use Fortran 95 intrinsic functions (Lionel GUEZ)93 C***END PROLOGUE I1MACH94 C 95 INTEGERIMACH(16),OUTPUT96 97 98 INTEGERI99 C***FIRST EXECUTABLE STATEMENT I1MACH100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 C 118 119 120 C 121 10 CONTINUE122 123 9000 FORMAT ('1ERROR 1 IN I1MACH - I OUT OF BOUNDS')124 C 125 CCALL FDUMP126 C 127 128 END 1 !DECK I1MACH 2 INTEGER FUNCTION I1MACH (I) 3 IMPLICIT NONE 4 !***BEGIN PROLOGUE I1MACH 5 !***PURPOSE Return integer machine dependent constants. 6 !***LIBRARY SLATEC 7 !***CATEGORY R1 8 !***TYPE INTEGER (I1MACH-I) 9 !***KEYWORDS MACHINE CONSTANTS 10 !***AUTHOR Fox, P. A., (Bell Labs) 11 ! Hall, A. D., (Bell Labs) 12 ! Schryer, N. L., (Bell Labs) 13 !***DESCRIPTION 14 ! 15 ! I1MACH can be used to obtain machine-dependent parameters for the 16 ! local machine environment. It is a function subprogram with one 17 ! (input) argument and can be referenced as follows: 18 ! 19 ! K = I1MACH(I) 20 ! 21 ! where I=1,...,16. The (output) value of K above is determined by 22 ! the (input) value of I. The results for various values of I are 23 ! discussed below. 24 ! 25 ! I/O unit numbers: 26 ! I1MACH( 1) = the standard input unit. 27 ! I1MACH( 2) = the standard output unit. 28 ! I1MACH( 3) = the standard punch unit. 29 ! I1MACH( 4) = the standard error message unit. 30 ! 31 ! Words: 32 ! I1MACH( 5) = the number of bits per integer storage unit. 33 ! I1MACH( 6) = the number of characters per integer storage unit. 34 ! 35 ! Integers: 36 ! assume integers are represented in the S-digit, base-A form 37 ! 38 ! sign ( X(S-1)*A**(S-1) + ... + X(1)*A + X(0) ) 39 ! 40 ! where 0 .LE. X(I) .LT. A for I=0,...,S-1. 41 ! I1MACH( 7) = A, the base. 42 ! I1MACH( 8) = S, the number of base-A digits. 43 ! I1MACH( 9) = A**S - 1, the largest magnitude. 44 ! 45 ! Floating-Point Numbers: 46 ! Assume floating-point numbers are represented in the T-digit, 47 ! base-B form 48 ! sign (B**E)*( (X(1)/B) + ... + (X(T)/B**T) ) 49 ! 50 ! where 0 .LE. X(I) .LT. B for I=1,...,T, 51 ! 0 .LT. X(1), and EMIN .LE. E .LE. EMAX. 52 ! I1MACH(10) = B, the base. 53 ! 54 ! Single-Precision: 55 ! I1MACH(11) = T, the number of base-B digits. 56 ! I1MACH(12) = EMIN, the smallest exponent E. 57 ! I1MACH(13) = EMAX, the largest exponent E. 58 ! 59 ! Double-Precision: 60 ! I1MACH(14) = T, the number of base-B digits. 61 ! I1MACH(15) = EMIN, the smallest exponent E. 62 ! I1MACH(16) = EMAX, the largest exponent E. 63 ! 64 ! To alter this function for a particular environment, the desired 65 ! set of DATA statements should be activated by removing the C from 66 ! column 1. Also, the values of I1MACH(1) - I1MACH(4) should be 67 ! checked for consistency with the local operating system. 68 ! 69 !***REFERENCES P. A. Fox, A. D. Hall and N. L. Schryer, Framework for 70 ! a portable library, ACM Transactions on Mathematical 71 ! Software 4, 2 (June 1978), pp. 177-188. 72 !***ROUTINES CALLED (NONE) 73 !***REVISION HISTORY (YYMMDD) 74 ! 750101 DATE WRITTEN 75 ! 891012 Added VAX G-floating constants. (WRB) 76 ! 891012 REVISION DATE from Version 3.2 77 ! 891214 Prologue converted to Version 4.0 format. (BAB) 78 ! 900618 Added DEC RISC constants. (WRB) 79 ! 900723 Added IBM RS 6000 constants. (WRB) 80 ! 901009 Correct I1MACH(7) for IBM Mainframes. Should be 2 not 16. 81 ! (RWC) 82 ! 910710 Added HP 730 constants. (SMR) 83 ! 911114 Added Convex IEEE constants. (WRB) 84 ! 920121 Added SUN -r8 compiler option constants. (WRB) 85 ! 920229 Added Touchstone Delta i860 constants. (WRB) 86 ! 920501 Reformatted the REFERENCES section. (WRB) 87 ! 920625 Added Convex -p8 and -pd8 compiler option constants. 88 ! (BKS, WRB) 89 ! 930201 Added DEC Alpha and SGI constants. (RWC and WRB) 90 ! 930618 Corrected I1MACH(5) for Convex -p8 and -pd8 compiler 91 ! options. (DWL, RWC and WRB). 92 ! 100623 Use Fortran 95 intrinsic functions (Lionel GUEZ) 93 !***END PROLOGUE I1MACH 94 ! 95 INTEGER :: IMACH(16),OUTPUT 96 SAVE IMACH 97 EQUIVALENCE (IMACH(4),OUTPUT) 98 INTEGER :: I 99 !***FIRST EXECUTABLE STATEMENT I1MACH 100 IMACH( 1) = 5 101 IMACH( 2) = 6 102 IMACH( 3) = 6 103 IMACH( 4) = 6 104 IMACH( 5) = bit_size(0) 105 IMACH( 6) = IMACH( 5) / 8 106 IMACH( 7) = radix(0) 107 IMACH( 8) = digits(0) 108 IMACH( 9) = huge(0) 109 IMACH(10) = radix(0.) 110 IMACH(11) = digits(0.) 111 IMACH(12) = minexponent(0.) 112 IMACH(13) = maxexponent(0.) 113 IMACH(14) = digits(0d0) 114 IMACH(15) = minexponent(0d0) 115 IMACH(16) = maxexponent(0d0) 116 IF (I .LT. 1 .OR. I .GT. 16) GO TO 10 117 ! 118 I1MACH = IMACH(I) 119 RETURN 120 ! 121 10 CONTINUE 122 WRITE (UNIT = OUTPUT, FMT = 9000) 123 9000 FORMAT ('1ERROR 1 IN I1MACH - I OUT OF BOUNDS') 124 ! 125 ! CALL FDUMP 126 ! 127 STOP 128 END FUNCTION I1MACH -
LMDZ6/trunk/libf/misc/ismax.f90
r5245 r5246 2 2 ! $Header$ 3 3 ! 4 5 c 6 7 c 8 INTEGERn,i,incx,ismax,ix9 realsx((n-1)*incx+1),sxmax10 c 11 12 13 14 do 10i=1,n-115 16 17 18 19 20 10 continue 21 c 22 23 end 4 function ismax(n,sx,incx) 5 ! 6 IMPLICIT NONE 7 ! 8 INTEGER :: n,i,incx,ismax,ix 9 real :: sx((n-1)*incx+1),sxmax 10 ! 11 ix=1 12 ismax=1 13 sxmax=sx(1) 14 do i=1,n-1 15 ix=ix+incx 16 if(sx(ix).gt.sxmax) then 17 sxmax=sx(ix) 18 ismax=i+1 19 endif 20 end do 21 ! 22 return 23 end function ismax 24 24 -
LMDZ6/trunk/libf/misc/ismin.f90
r5245 r5246 2 2 ! $Header$ 3 3 ! 4 5 c 6 7 c 8 integern,i,incx,ismin,ix9 realsx((n-1)*incx+1),sxmin10 c 11 12 13 14 15 16 17 18 19 20 21 c 22 23 end 24 C 4 FUNCTION ismin(n,sx,incx) 5 ! 6 IMPLICIT NONE 7 ! 8 integer :: n,i,incx,ismin,ix 9 real :: sx((n-1)*incx+1),sxmin 10 ! 11 ix=1 12 ismin=1 13 sxmin=sx(1) 14 DO i=1,n-1 15 ix=ix+incx 16 if(sx(ix).lt.sxmin) then 17 sxmin=sx(ix) 18 ismin=i+1 19 endif 20 ENDDO 21 ! 22 return 23 end function ismin 24 ! -
LMDZ6/trunk/libf/misc/j4save.f90
r5245 r5246 1 *DECK J4SAVE2 3 4 C***BEGIN PROLOGUE J4SAVE5 C***SUBSIDIARY6 C***PURPOSE Save or recall global variables needed by error7 Chandling routines.8 C***LIBRARY SLATEC (XERROR)9 C***TYPE INTEGER (J4SAVE-I)10 C***KEYWORDS ERROR MESSAGES, ERROR NUMBER, RECALL, SAVE, XERROR11 C***AUTHOR Jones, R. E., (SNLA)12 C***DESCRIPTION13 C 14 CAbstract15 CJ4SAVE saves and recalls several global variables needed16 Cby the library error handling routines.17 C 18 CDescription of Parameters19 C--Input--20 CIWHICH - Index of item desired.21 C= 1 Refers to current error number.22 C= 2 Refers to current error control flag.23 C= 3 Refers to current unit number to which error24 Cmessages are to be sent. (0 means use standard.)25 C= 4 Refers to the maximum number of times any26 Cmessage is to be printed (as set by XERMAX).27 C= 5 Refers to the total number of units to which28 Ceach error message is to be written.29 C= 6 Refers to the 2nd unit for error messages30 C= 7 Refers to the 3rd unit for error messages31 C= 8 Refers to the 4th unit for error messages32 C= 9 Refers to the 5th unit for error messages33 CIVALUE - The value to be set for the IWHICH-th parameter,34 Cif ISET is .TRUE. .35 CISET - If ISET=.TRUE., the IWHICH-th parameter will BE36 Cgiven the value, IVALUE. If ISET=.FALSE., the37 CIWHICH-th parameter will be unchanged, and IVALUE38 Cis a dummy parameter.39 C--Output--40 CThe (old) value of the IWHICH-th parameter will be returned41 Cin the function value, J4SAVE.42 C 43 C***SEE ALSO XERMSG44 C***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC45 CError-handling Package, SAND82-0800, Sandia46 CLaboratories, 1982.47 C***ROUTINES CALLED (NONE)48 C***REVISION HISTORY (YYMMDD)49 C790801 DATE WRITTEN50 C891214 Prologue converted to Version 4.0 format. (BAB)51 C900205 Minor modifications to prologue. (WRB)52 C900402 Added TYPE section. (WRB)53 C910411 Added KEYWORDS section. (WRB)54 C920501 Reformatted the REFERENCES section. (WRB)55 C***END PROLOGUE J4SAVE56 LOGICALISET57 INTEGERIPARAM(9)58 59 60 61 62 INTEGERJ4SAVE,IWHICH,IVALUE63 C***FIRST EXECUTABLE STATEMENT J4SAVE64 65 66 67 END 1 !DECK J4SAVE 2 FUNCTION J4SAVE (IWHICH, IVALUE, ISET) 3 IMPLICIT NONE 4 !***BEGIN PROLOGUE J4SAVE 5 !***SUBSIDIARY 6 !***PURPOSE Save or recall global variables needed by error 7 ! handling routines. 8 !***LIBRARY SLATEC (XERROR) 9 !***TYPE INTEGER (J4SAVE-I) 10 !***KEYWORDS ERROR MESSAGES, ERROR NUMBER, RECALL, SAVE, XERROR 11 !***AUTHOR Jones, R. E., (SNLA) 12 !***DESCRIPTION 13 ! 14 ! Abstract 15 ! J4SAVE saves and recalls several global variables needed 16 ! by the library error handling routines. 17 ! 18 ! Description of Parameters 19 ! --Input-- 20 ! IWHICH - Index of item desired. 21 ! = 1 Refers to current error number. 22 ! = 2 Refers to current error control flag. 23 ! = 3 Refers to current unit number to which error 24 ! messages are to be sent. (0 means use standard.) 25 ! = 4 Refers to the maximum number of times any 26 ! message is to be printed (as set by XERMAX). 27 ! = 5 Refers to the total number of units to which 28 ! each error message is to be written. 29 ! = 6 Refers to the 2nd unit for error messages 30 ! = 7 Refers to the 3rd unit for error messages 31 ! = 8 Refers to the 4th unit for error messages 32 ! = 9 Refers to the 5th unit for error messages 33 ! IVALUE - The value to be set for the IWHICH-th parameter, 34 ! if ISET is .TRUE. . 35 ! ISET - If ISET=.TRUE., the IWHICH-th parameter will BE 36 ! given the value, IVALUE. If ISET=.FALSE., the 37 ! IWHICH-th parameter will be unchanged, and IVALUE 38 ! is a dummy parameter. 39 ! --Output-- 40 ! The (old) value of the IWHICH-th parameter will be returned 41 ! in the function value, J4SAVE. 42 ! 43 !***SEE ALSO XERMSG 44 !***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC 45 ! Error-handling Package, SAND82-0800, Sandia 46 ! Laboratories, 1982. 47 !***ROUTINES CALLED (NONE) 48 !***REVISION HISTORY (YYMMDD) 49 ! 790801 DATE WRITTEN 50 ! 891214 Prologue converted to Version 4.0 format. (BAB) 51 ! 900205 Minor modifications to prologue. (WRB) 52 ! 900402 Added TYPE section. (WRB) 53 ! 910411 Added KEYWORDS section. (WRB) 54 ! 920501 Reformatted the REFERENCES section. (WRB) 55 !***END PROLOGUE J4SAVE 56 LOGICAL :: ISET 57 INTEGER :: IPARAM(9) 58 SAVE IPARAM 59 DATA IPARAM(1),IPARAM(2),IPARAM(3),IPARAM(4)/0,2,0,10/ 60 DATA IPARAM(5)/1/ 61 DATA IPARAM(6),IPARAM(7),IPARAM(8),IPARAM(9)/0,0,0,0/ 62 INTEGER :: J4SAVE,IWHICH,IVALUE 63 !***FIRST EXECUTABLE STATEMENT J4SAVE 64 J4SAVE = IPARAM(IWHICH) 65 IF (ISET) IPARAM(IWHICH) = IVALUE 66 RETURN 67 END FUNCTION J4SAVE -
LMDZ6/trunk/libf/misc/juldate.f90
r5245 r5246 2 2 ! $Id$ 3 3 ! 4 5 cSous-routine de changement de date:6 cgregorien>>>date julienne7 cEn entree:an,mois,jour,heure,min.,sec.8 cEn sortie:tjd9 10 11 12 13 REALfrac,year,rmon,cf,a,b14 INTEGERojou15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 tjd=int(365.25*year)+int(30.6001*(rmon+1))+int(ojou) 32 ++1720994.5+b33 34 35 36 37 end 4 subroutine juldate(ian,imoi,ijou,oh,om,os,tjd,tjdsec) 5 ! Sous-routine de changement de date: 6 ! gregorien>>>date julienne 7 ! En entree:an,mois,jour,heure,min.,sec. 8 ! En sortie:tjd 9 IMPLICIT NONE 10 INTEGER,INTENT(IN) :: ian,imoi,ijou,oh,om,os 11 REAL,INTENT(OUT) :: tjd,tjdsec 12 13 REAL :: frac,year,rmon,cf,a,b 14 INTEGER :: ojou 15 16 frac=((os/60.+om)/60.+oh)/24. 17 ojou=dble(ijou)+frac 18 year=dble(ian) 19 rmon=dble(imoi) 20 if (imoi .le. 2) then 21 year=year-1. 22 rmon=rmon+12. 23 endif 24 cf=year+(rmon/100.)+(ojou/10000.) 25 if (cf .ge. 1582.1015) then 26 a=int(year/100) 27 b=2-a+int(a/4) 28 else 29 b=0 30 endif 31 tjd=int(365.25*year)+int(30.6001*(rmon+1))+int(ojou) & 32 +1720994.5+b 33 tjdsec=(ojou-int(ojou))+(tjd-int(tjd)) 34 tjd=int(tjd)+int(tjdsec) 35 tjdsec=tjdsec-int(tjdsec) 36 return 37 end subroutine juldate 38 38 39 39 -
LMDZ6/trunk/libf/misc/minmax.f90
r5245 r5246 2 2 ! $Header$ 3 3 ! 4 5 c 6 cP. Le Van4 SUBROUTINE minmax(imax, xi, zmin, zmax ) 5 ! 6 ! P. Le Van 7 7 8 INTEGERimax9 REALxi(imax)10 REALzmin,zmax11 INTEGERi8 INTEGER :: imax 9 REAL :: xi(imax) 10 REAL :: zmin,zmax 11 INTEGER :: i 12 12 13 14 13 zmin = xi(1) 14 zmax = xi(1) 15 15 16 17 18 19 16 DO i = 2, imax 17 zmin = MIN( zmin,xi(i) ) 18 zmax = MAX( zmax,xi(i) ) 19 ENDDO 20 20 21 22 END 21 RETURN 22 END SUBROUTINE minmax 23 23 -
LMDZ6/trunk/libf/misc/minmax2.f90
r5245 r5246 2 2 ! $Header$ 3 3 ! 4 SUBROUTINE minmax2(imax, jmax, lmax, xi, zmin, zmax ) 5 c 6 INTEGER lmax,jmax,imax 7 REAL xi(imax*jmax*lmax) 8 REAL zmin,zmax 9 INTEGER i 10 11 zmin = xi(1) 12 zmax = xi(1) 4 SUBROUTINE minmax2(imax, jmax, lmax, xi, zmin, zmax ) 5 ! 6 INTEGER :: lmax,jmax,imax 7 REAL :: xi(imax*jmax*lmax) 8 REAL :: zmin,zmax 9 INTEGER :: i 13 10 14 DO i = 2, imax*jmax*lmax 15 zmin = MIN( zmin,xi(i) ) 16 zmax = MAX( zmax,xi(i) ) 17 ENDDO 11 zmin = xi(1) 12 zmax = xi(1) 18 13 19 RETURN 20 END 14 DO i = 2, imax*jmax*lmax 15 zmin = MIN( zmin,xi(i) ) 16 zmax = MAX( zmax,xi(i) ) 17 ENDDO 18 19 RETURN 20 END SUBROUTINE minmax2 -
LMDZ6/trunk/libf/misc/pchdf.f90
r5245 r5246 1 *DECK PCHDF2 3 C***BEGIN PROLOGUE PCHDF4 C***SUBSIDIARY5 C***PURPOSE Computes divided differences for PCHCE and PCHSP6 C***LIBRARY SLATEC (PCHIP)7 C***TYPE SINGLE PRECISION (PCHDF-S, DPCHDF-D)8 C***AUTHOR Fritsch, F. N., (LLNL)9 C***DESCRIPTION10 C 11 CPCHDF: PCHIP Finite Difference Formula12 C 13 CUses a divided difference formulation to compute a K-point approx-14 Cimation to the derivative at X(K) based on the data in X and S.15 C 16 CCalled by PCHCE and PCHSP to compute 3- and 4-point boundary17 Cderivative approximations.18 C 19 C----------------------------------------------------------------------20 C 21 COn input:22 CK is the order of the desired derivative approximation.23 CK must be at least 3 (error return if not).24 CX contains the K values of the independent variable.25 CX need not be ordered, but the values **MUST** be26 Cdistinct. (Not checked here.)27 CS contains the associated slope values:28 CS(I) = (F(I+1)-F(I))/(X(I+1)-X(I)), I=1(1)K-1.29 C(Note that S need only be of length K-1.)30 C 31 COn return:32 CS will be destroyed.33 CIERR will be set to -1 if K.LT.2 .34 CPCHDF will be set to the desired derivative approximation if35 CIERR=0 or to zero if IERR=-1.36 C 37 C----------------------------------------------------------------------38 C 39 C***SEE ALSO PCHCE, PCHSP40 C***REFERENCES Carl de Boor, A Practical Guide to Splines, Springer-41 CVerlag, New York, 1978, pp. 10-16.42 C***ROUTINES CALLED XERMSG43 C***REVISION HISTORY (YYMMDD)44 C820503 DATE WRITTEN45 C820805 Converted to SLATEC library version.46 C870813 Minor cosmetic changes.47 C890411 Added SAVE statements (Vers. 3.2).48 C890411 REVISION DATE from Version 3.249 C891214 Prologue converted to Version 4.0 format. (BAB)50 C900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)51 C900328 Added TYPE section. (WRB)52 C910408 Updated AUTHOR and DATE WRITTEN sections in prologue. (WRB)53 C920429 Revised format and order of references. (WRB,FNF)54 C930503 Improved purpose. (FNF)55 C***END PROLOGUE PCHDF56 C 57 C**End58 C 59 CDECLARE ARGUMENTS.60 C 61 INTEGERK, IERR62 REALX(K), S(K)63 C 64 CDECLARE LOCAL VARIABLES.65 C 66 INTEGERI, J67 REALVALUE, ZERO68 69 70 C 71 CCHECK FOR LEGAL VALUE OF K.72 C 73 C***FIRST EXECUTABLE STATEMENT PCHDF74 75 C 76 CCOMPUTE COEFFICIENTS OF INTERPOLATING POLYNOMIAL.77 C 78 DO 10J = 2, K-179 DO 9I = 1, K-J80 81 9 CONTINUE82 10 CONTINUE83 C 84 CEVALUATE DERIVATIVE AT X(K).85 C 86 87 DO 20I = 2, K-188 89 20 CONTINUE90 C 91 CNORMAL RETURN.92 C 93 94 95 96 C 97 CERROR RETURN.98 C 99 5001 CONTINUE100 CK.LT.3 RETURN.101 102 103 104 105 C------------- LAST LINE OF PCHDF FOLLOWS ------------------------------106 END 1 !DECK PCHDF 2 REAL FUNCTION PCHDF (K, X, S, IERR) 3 !***BEGIN PROLOGUE PCHDF 4 !***SUBSIDIARY 5 !***PURPOSE Computes divided differences for PCHCE and PCHSP 6 !***LIBRARY SLATEC (PCHIP) 7 !***TYPE SINGLE PRECISION (PCHDF-S, DPCHDF-D) 8 !***AUTHOR Fritsch, F. N., (LLNL) 9 !***DESCRIPTION 10 ! 11 ! PCHDF: PCHIP Finite Difference Formula 12 ! 13 ! Uses a divided difference formulation to compute a K-point approx- 14 ! imation to the derivative at X(K) based on the data in X and S. 15 ! 16 ! Called by PCHCE and PCHSP to compute 3- and 4-point boundary 17 ! derivative approximations. 18 ! 19 ! ---------------------------------------------------------------------- 20 ! 21 ! On input: 22 ! K is the order of the desired derivative approximation. 23 ! K must be at least 3 (error return if not). 24 ! X contains the K values of the independent variable. 25 ! X need not be ordered, but the values **MUST** be 26 ! distinct. (Not checked here.) 27 ! S contains the associated slope values: 28 ! S(I) = (F(I+1)-F(I))/(X(I+1)-X(I)), I=1(1)K-1. 29 ! (Note that S need only be of length K-1.) 30 ! 31 ! On return: 32 ! S will be destroyed. 33 ! IERR will be set to -1 if K.LT.2 . 34 ! PCHDF will be set to the desired derivative approximation if 35 ! IERR=0 or to zero if IERR=-1. 36 ! 37 ! ---------------------------------------------------------------------- 38 ! 39 !***SEE ALSO PCHCE, PCHSP 40 !***REFERENCES Carl de Boor, A Practical Guide to Splines, Springer- 41 ! Verlag, New York, 1978, pp. 10-16. 42 !***ROUTINES CALLED XERMSG 43 !***REVISION HISTORY (YYMMDD) 44 ! 820503 DATE WRITTEN 45 ! 820805 Converted to SLATEC library version. 46 ! 870813 Minor cosmetic changes. 47 ! 890411 Added SAVE statements (Vers. 3.2). 48 ! 890411 REVISION DATE from Version 3.2 49 ! 891214 Prologue converted to Version 4.0 format. (BAB) 50 ! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) 51 ! 900328 Added TYPE section. (WRB) 52 ! 910408 Updated AUTHOR and DATE WRITTEN sections in prologue. (WRB) 53 ! 920429 Revised format and order of references. (WRB,FNF) 54 ! 930503 Improved purpose. (FNF) 55 !***END PROLOGUE PCHDF 56 ! 57 !**End 58 ! 59 ! DECLARE ARGUMENTS. 60 ! 61 INTEGER :: K, IERR 62 REAL :: X(K), S(K) 63 ! 64 ! DECLARE LOCAL VARIABLES. 65 ! 66 INTEGER :: I, J 67 REAL :: VALUE, ZERO 68 SAVE ZERO 69 DATA ZERO /0./ 70 ! 71 ! CHECK FOR LEGAL VALUE OF K. 72 ! 73 !***FIRST EXECUTABLE STATEMENT PCHDF 74 IF (K .LT. 3) GO TO 5001 75 ! 76 ! COMPUTE COEFFICIENTS OF INTERPOLATING POLYNOMIAL. 77 ! 78 DO J = 2, K-1 79 DO I = 1, K-J 80 S(I) = (S(I+1)-S(I))/(X(I+J)-X(I)) 81 END DO 82 END DO 83 ! 84 ! EVALUATE DERIVATIVE AT X(K). 85 ! 86 VALUE = S(1) 87 DO I = 2, K-1 88 VALUE = S(I) + VALUE*(X(K)-X(I)) 89 END DO 90 ! 91 ! NORMAL RETURN. 92 ! 93 IERR = 0 94 PCHDF = VALUE 95 RETURN 96 ! 97 ! ERROR RETURN. 98 ! 99 5001 CONTINUE 100 ! K.LT.3 RETURN. 101 IERR = -1 102 CALL XERMSG ('SLATEC', 'PCHDF', 'K LESS THAN THREE', IERR, 1) 103 PCHDF = ZERO 104 RETURN 105 !------------- LAST LINE OF PCHDF FOLLOWS ------------------------------ 106 END FUNCTION PCHDF -
LMDZ6/trunk/libf/misc/pchfe.f90
r5245 r5246 1 *DECK PCHFE2 3 C***BEGIN PROLOGUE PCHFE4 C***PURPOSE Evaluate a piecewise cubic Hermite function at an array of5 Cpoints. May be used by itself for Hermite interpolation,6 Cor as an evaluator for PCHIM or PCHIC.7 C***LIBRARY SLATEC (PCHIP)8 C***CATEGORY E39 C***TYPE SINGLE PRECISION (PCHFE-S, DPCHFE-D)10 C***KEYWORDS CUBIC HERMITE EVALUATION, HERMITE INTERPOLATION, PCHIP,11 CPIECEWISE CUBIC EVALUATION12 C***AUTHOR Fritsch, F. N., (LLNL)13 CLawrence Livermore National Laboratory14 CP.O. Box 808 (L-316)15 CLivermore, CA 9455016 CFTS 532-4275, (510) 422-427517 C***DESCRIPTION18 C 19 CPCHFE: Piecewise Cubic Hermite Function Evaluator20 C 21 CEvaluates the cubic Hermite function defined by N, X, F, D at22 Cthe points XE(J), J=1(1)NE.23 C 24 CTo provide compatibility with PCHIM and PCHIC, includes an25 Cincrement between successive values of the F- and D-arrays.26 C 27 C----------------------------------------------------------------------28 C 29 CCalling sequence:30 C 31 CPARAMETER (INCFD = ...)32 CINTEGER N, NE, IERR33 CREAL X(N), F(INCFD,N), D(INCFD,N), XE(NE), FE(NE)34 CLOGICAL SKIP35 C 36 CCALL PCHFE (N, X, F, D, INCFD, SKIP, NE, XE, FE, IERR)37 C 38 CParameters:39 C 40 CN -- (input) number of data points. (Error return if N.LT.2 .)41 C 42 CX -- (input) real array of independent variable values. The43 Celements of X must be strictly increasing:44 CX(I-1) .LT. X(I), I = 2(1)N.45 C(Error return if not.)46 C 47 CF -- (input) real array of function values. F(1+(I-1)*INCFD) is48 Cthe value corresponding to X(I).49 C 50 CD -- (input) real array of derivative values. D(1+(I-1)*INCFD) is51 Cthe value corresponding to X(I).52 C 53 CINCFD -- (input) increment between successive values in F and D.54 C(Error return if INCFD.LT.1 .)55 C 56 CSKIP -- (input/output) logical variable which should be set to57 C.TRUE. if the user wishes to skip checks for validity of58 Cpreceding parameters, or to .FALSE. otherwise.59 CThis will save time in case these checks have already60 Cbeen performed (say, in PCHIM or PCHIC).61 CSKIP will be set to .TRUE. on normal return.62 C 63 CNE -- (input) number of evaluation points. (Error return if64 CNE.LT.1 .)65 C 66 CXE -- (input) real array of points at which the function is to be67 Cevaluated.68 C 69 CNOTES:70 C1. The evaluation will be most efficient if the elements71 Cof XE are increasing relative to X;72 Cthat is, XE(J) .GE. X(I)73 Cimplies XE(K) .GE. X(I), all K.GE.J .74 C2. If any of the XE are outside the interval [X(1),X(N)],75 Cvalues are extrapolated from the nearest extreme cubic,76 Cand a warning error is returned.77 C 78 CFE -- (output) real array of values of the cubic Hermite function79 Cdefined by N, X, F, D at the points XE.80 C 81 CIERR -- (output) error flag.82 CNormal return:83 CIERR = 0 (no errors).84 CWarning error:85 CIERR.GT.0 means that extrapolation was performed at86 CIERR points.87 C"Recoverable" errors:88 CIERR = -1 if N.LT.2 .89 CIERR = -2 if INCFD.LT.1 .90 CIERR = -3 if the X-array is not strictly increasing.91 CIERR = -4 if NE.LT.1 .92 C(The FE-array has not been changed in any of these cases.)93 CNOTE: The above errors are checked in the order listed,94 Cand following arguments have **NOT** been validated.95 C 96 C***REFERENCES (NONE)97 C***ROUTINES CALLED CHFEV, XERMSG98 C***REVISION HISTORY (YYMMDD)99 C811020 DATE WRITTEN100 C820803 Minor cosmetic changes for release 1.101 C870707 Minor cosmetic changes to prologue.102 C890531 Changed all specific intrinsics to generic. (WRB)103 C890831 Modified array declarations. (WRB)104 C890831 REVISION DATE from Version 3.2105 C891214 Prologue converted to Version 4.0 format. (BAB)106 C900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)107 C***END PROLOGUE PCHFE108 CProgramming notes:109 C 110 C1. To produce a double precision version, simply:111 Ca. Change PCHFE to DPCHFE, and CHFEV to DCHFEV, wherever they112 Coccur,113 Cb. Change the real declaration to double precision,114 C 115 C2. Most of the coding between the call to CHFEV and the end of116 Cthe IR-loop could be eliminated if it were permissible to117 Cassume that XE is ordered relative to X.118 C 119 C3. CHFEV does not assume that X1 is less than X2. thus, it would120 Cbe possible to write a version of PCHFE that assumes a strict-121 Cly decreasing X-array by simply running the IR-loop backwards122 C(and reversing the order of appropriate tests).123 C 124 C4. The present code has a minor bug, which I have decided is not125 Cworth the effort that would be required to fix it.126 CIf XE contains points in [X(N-1),X(N)], followed by points .LT.127 CX(N-1), followed by points .GT.X(N), the extrapolation points128 Cwill be counted (at least) twice in the total returned in IERR.129 C 130 CDECLARE ARGUMENTS.131 C 132 INTEGERN, INCFD, NE, IERR133 REALX(*), F(INCFD,*), D(INCFD,*), XE(*), FE(*)134 LOGICALSKIP135 C 136 CDECLARE LOCAL VARIABLES.137 C 138 INTEGERI, IERC, IR, J, JFIRST, NEXT(2), NJ139 C 140 CVALIDITY-CHECK ARGUMENTS.141 C 142 C***FIRST EXECUTABLE STATEMENT PCHFE143 144 C 145 146 147 DO 1I = 2, N148 149 1 CONTINUE150 C 151 CFUNCTION DEFINITION IS OK, GO ON.152 C 153 5 CONTINUE154 155 156 157 C 158 CLOOP OVER INTERVALS. ( INTERVAL INDEX IS IL = IR-1 . )159 C( INTERVAL IS X(IL).LE.X.LT.X(IR) . )160 161 162 10 CONTINUE163 C 164 CSKIP OUT OF LOOP IF HAVE PROCESSED ALL EVALUATION POINTS.165 C 166 167 C 168 CLOCATE ALL POINTS IN INTERVAL.169 C 170 DO 20J = JFIRST, NE171 172 20 CONTINUE173 174 175 C 176 CHAVE LOCATED FIRST POINT BEYOND INTERVAL.177 C 178 30 179 180 C 181 40 182 183 C 184 CSKIP EVALUATION IF NO POINTS IN INTERVAL.185 C 186 187 C 188 CEVALUATE CUBIC AT XE(I), I = JFIRST (1) J-1 .189 C 190 C----------------------------------------------------------------191 CALL CHFEV (X(IR-1),X(IR), F(1,IR-1),F(1,IR), D(1,IR-1),D(1,IR),192 *NJ, XE(JFIRST), FE(JFIRST), NEXT, IERC)193 C----------------------------------------------------------------194 195 C 196 197 CIF (NEXT(2) .GT. 0) THEN198 CIN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(2) TO THE199 CRIGHT OF X(IR).200 C 201 202 CIF (IR .EQ. N) THEN203 CTHESE ARE ACTUALLY EXTRAPOLATION POINTS.204 205 206 41 207 CELSE208 CWE SHOULD NEVER HAVE GOTTEN HERE.209 210 CENDIF211 CENDIF212 42 213 C 214 215 CIF (NEXT(1) .GT. 0) THEN216 CIN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(1) TO THE217 CLEFT OF X(IR-1).218 C 219 220 CIF (IR .EQ. 2) THEN221 CTHESE ARE ACTUALLY EXTRAPOLATION POINTS.222 223 224 43 225 CELSE226 CXE IS NOT ORDERED RELATIVE TO X, SO MUST ADJUST227 CEVALUATION INTERVAL.228 C 229 CFIRST, LOCATE FIRST POINT TO LEFT OF X(IR-1).230 DO 44I = JFIRST, J-1231 232 44 CONTINUE233 CNOTE-- CANNOT DROP THROUGH HERE UNLESS THERE IS AN ERROR234 CIN CHFEV.235 236 C 237 45 238 CRESET J. (THIS WILL BE THE NEW JFIRST.)239 240 C 241 CNOW FIND OUT HOW FAR TO BACK UP IN THE X-ARRAY.242 DO 46I = 1, IR-1243 244 46 CONTINUE245 CNB-- CAN NEVER DROP THROUGH HERE, SINCE XE(J).LT.X(IR-1).246 C 247 47 248 CAT THIS POINT, EITHER XE(J) .LT. X(1)249 COR X(I-1) .LE. XE(J) .LT. X(I) .250 CRESET IR, RECOGNIZING THAT IT WILL BE INCREMENTED BEFORE251 CCYCLING.252 253 CENDIF254 CENDIF255 49 256 C 257 258 C 259 CEND OF IR-LOOP.260 C 261 50 CONTINUE262 263 264 C 265 CNORMAL RETURN.266 C 267 5000 CONTINUE268 269 C 270 CERROR RETURNS.271 C 272 5001 CONTINUE273 CN.LT.2 RETURN.274 275 CALL XERMSG ('SLATEC', 'PCHFE',276 +'NUMBER OF DATA POINTS LESS THAN TWO', IERR, 1)277 278 C 279 5002 CONTINUE280 CINCFD.LT.1 RETURN.281 282 CALL XERMSG ('SLATEC', 'PCHFE', 'INCREMENT LESS THAN ONE', IERR,283 +1)284 285 C 286 5003 CONTINUE287 CX-ARRAY NOT STRICTLY INCREASING.288 289 CALL XERMSG ('SLATEC', 'PCHFE', 'X-ARRAY NOT STRICTLY INCREASING'290 +, IERR, 1)291 292 C 293 5004 CONTINUE294 CNE.LT.1 RETURN.295 296 CALL XERMSG ('SLATEC', 'PCHFE',297 +'NUMBER OF EVALUATION POINTS LESS THAN ONE', IERR, 1)298 299 C 300 5005 CONTINUE301 CERROR RETURN FROM CHFEV.302 C*** THIS CASE SHOULD NEVER OCCUR ***303 304 CALL XERMSG ('SLATEC', 'PCHFE',305 +'ERROR RETURN FROM CHFEV -- FATAL', IERR, 2)306 307 C------------- LAST LINE OF PCHFE FOLLOWS ------------------------------308 END 1 !DECK PCHFE 2 SUBROUTINE PCHFE (N, X, F, D, INCFD, SKIP, NE, XE, FE, IERR) 3 !***BEGIN PROLOGUE PCHFE 4 !***PURPOSE Evaluate a piecewise cubic Hermite function at an array of 5 ! points. May be used by itself for Hermite interpolation, 6 ! or as an evaluator for PCHIM or PCHIC. 7 !***LIBRARY SLATEC (PCHIP) 8 !***CATEGORY E3 9 !***TYPE SINGLE PRECISION (PCHFE-S, DPCHFE-D) 10 !***KEYWORDS CUBIC HERMITE EVALUATION, HERMITE INTERPOLATION, PCHIP, 11 ! PIECEWISE CUBIC EVALUATION 12 !***AUTHOR Fritsch, F. N., (LLNL) 13 ! Lawrence Livermore National Laboratory 14 ! P.O. Box 808 (L-316) 15 ! Livermore, CA 94550 16 ! FTS 532-4275, (510) 422-4275 17 !***DESCRIPTION 18 ! 19 ! PCHFE: Piecewise Cubic Hermite Function Evaluator 20 ! 21 ! Evaluates the cubic Hermite function defined by N, X, F, D at 22 ! the points XE(J), J=1(1)NE. 23 ! 24 ! To provide compatibility with PCHIM and PCHIC, includes an 25 ! increment between successive values of the F- and D-arrays. 26 ! 27 ! ---------------------------------------------------------------------- 28 ! 29 ! Calling sequence: 30 ! 31 ! PARAMETER (INCFD = ...) 32 ! INTEGER N, NE, IERR 33 ! REAL X(N), F(INCFD,N), D(INCFD,N), XE(NE), FE(NE) 34 ! LOGICAL SKIP 35 ! 36 ! CALL PCHFE (N, X, F, D, INCFD, SKIP, NE, XE, FE, IERR) 37 ! 38 ! Parameters: 39 ! 40 ! N -- (input) number of data points. (Error return if N.LT.2 .) 41 ! 42 ! X -- (input) real array of independent variable values. The 43 ! elements of X must be strictly increasing: 44 ! X(I-1) .LT. X(I), I = 2(1)N. 45 ! (Error return if not.) 46 ! 47 ! F -- (input) real array of function values. F(1+(I-1)*INCFD) is 48 ! the value corresponding to X(I). 49 ! 50 ! D -- (input) real array of derivative values. D(1+(I-1)*INCFD) is 51 ! the value corresponding to X(I). 52 ! 53 ! INCFD -- (input) increment between successive values in F and D. 54 ! (Error return if INCFD.LT.1 .) 55 ! 56 ! SKIP -- (input/output) logical variable which should be set to 57 ! .TRUE. if the user wishes to skip checks for validity of 58 ! preceding parameters, or to .FALSE. otherwise. 59 ! This will save time in case these checks have already 60 ! been performed (say, in PCHIM or PCHIC). 61 ! SKIP will be set to .TRUE. on normal return. 62 ! 63 ! NE -- (input) number of evaluation points. (Error return if 64 ! NE.LT.1 .) 65 ! 66 ! XE -- (input) real array of points at which the function is to be 67 ! evaluated. 68 ! 69 ! NOTES: 70 ! 1. The evaluation will be most efficient if the elements 71 ! of XE are increasing relative to X; 72 ! that is, XE(J) .GE. X(I) 73 ! implies XE(K) .GE. X(I), all K.GE.J . 74 ! 2. If any of the XE are outside the interval [X(1),X(N)], 75 ! values are extrapolated from the nearest extreme cubic, 76 ! and a warning error is returned. 77 ! 78 ! FE -- (output) real array of values of the cubic Hermite function 79 ! defined by N, X, F, D at the points XE. 80 ! 81 ! IERR -- (output) error flag. 82 ! Normal return: 83 ! IERR = 0 (no errors). 84 ! Warning error: 85 ! IERR.GT.0 means that extrapolation was performed at 86 ! IERR points. 87 ! "Recoverable" errors: 88 ! IERR = -1 if N.LT.2 . 89 ! IERR = -2 if INCFD.LT.1 . 90 ! IERR = -3 if the X-array is not strictly increasing. 91 ! IERR = -4 if NE.LT.1 . 92 ! (The FE-array has not been changed in any of these cases.) 93 ! NOTE: The above errors are checked in the order listed, 94 ! and following arguments have **NOT** been validated. 95 ! 96 !***REFERENCES (NONE) 97 !***ROUTINES CALLED CHFEV, XERMSG 98 !***REVISION HISTORY (YYMMDD) 99 ! 811020 DATE WRITTEN 100 ! 820803 Minor cosmetic changes for release 1. 101 ! 870707 Minor cosmetic changes to prologue. 102 ! 890531 Changed all specific intrinsics to generic. (WRB) 103 ! 890831 Modified array declarations. (WRB) 104 ! 890831 REVISION DATE from Version 3.2 105 ! 891214 Prologue converted to Version 4.0 format. (BAB) 106 ! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) 107 !***END PROLOGUE PCHFE 108 ! Programming notes: 109 ! 110 ! 1. To produce a double precision version, simply: 111 ! a. Change PCHFE to DPCHFE, and CHFEV to DCHFEV, wherever they 112 ! occur, 113 ! b. Change the real declaration to double precision, 114 ! 115 ! 2. Most of the coding between the call to CHFEV and the end of 116 ! the IR-loop could be eliminated if it were permissible to 117 ! assume that XE is ordered relative to X. 118 ! 119 ! 3. CHFEV does not assume that X1 is less than X2. thus, it would 120 ! be possible to write a version of PCHFE that assumes a strict- 121 ! ly decreasing X-array by simply running the IR-loop backwards 122 ! (and reversing the order of appropriate tests). 123 ! 124 ! 4. The present code has a minor bug, which I have decided is not 125 ! worth the effort that would be required to fix it. 126 ! If XE contains points in [X(N-1),X(N)], followed by points .LT. 127 ! X(N-1), followed by points .GT.X(N), the extrapolation points 128 ! will be counted (at least) twice in the total returned in IERR. 129 ! 130 ! DECLARE ARGUMENTS. 131 ! 132 INTEGER :: N, INCFD, NE, IERR 133 REAL :: X(*), F(INCFD,*), D(INCFD,*), XE(*), FE(*) 134 LOGICAL :: SKIP 135 ! 136 ! DECLARE LOCAL VARIABLES. 137 ! 138 INTEGER :: I, IERC, IR, J, JFIRST, NEXT(2), NJ 139 ! 140 ! VALIDITY-CHECK ARGUMENTS. 141 ! 142 !***FIRST EXECUTABLE STATEMENT PCHFE 143 IF (SKIP) GO TO 5 144 ! 145 IF ( N.LT.2 ) GO TO 5001 146 IF ( INCFD.LT.1 ) GO TO 5002 147 DO I = 2, N 148 IF ( X(I).LE.X(I-1) ) GO TO 5003 149 END DO 150 ! 151 ! FUNCTION DEFINITION IS OK, GO ON. 152 ! 153 5 CONTINUE 154 IF ( NE.LT.1 ) GO TO 5004 155 IERR = 0 156 SKIP = .TRUE. 157 ! 158 ! LOOP OVER INTERVALS. ( INTERVAL INDEX IS IL = IR-1 . ) 159 ! ( INTERVAL IS X(IL).LE.X.LT.X(IR) . ) 160 JFIRST = 1 161 IR = 2 162 10 CONTINUE 163 ! 164 ! SKIP OUT OF LOOP IF HAVE PROCESSED ALL EVALUATION POINTS. 165 ! 166 IF (JFIRST .GT. NE) GO TO 5000 167 ! 168 ! LOCATE ALL POINTS IN INTERVAL. 169 ! 170 DO J = JFIRST, NE 171 IF (XE(J) .GE. X(IR)) GO TO 30 172 END DO 173 J = NE + 1 174 GO TO 40 175 ! 176 ! HAVE LOCATED FIRST POINT BEYOND INTERVAL. 177 ! 178 30 CONTINUE 179 IF (IR .EQ. N) J = NE + 1 180 ! 181 40 CONTINUE 182 NJ = J - JFIRST 183 ! 184 ! SKIP EVALUATION IF NO POINTS IN INTERVAL. 185 ! 186 IF (NJ .EQ. 0) GO TO 50 187 ! 188 ! EVALUATE CUBIC AT XE(I), I = JFIRST (1) J-1 . 189 ! 190 ! ---------------------------------------------------------------- 191 CALL CHFEV (X(IR-1),X(IR), F(1,IR-1),F(1,IR), D(1,IR-1),D(1,IR), & 192 NJ, XE(JFIRST), FE(JFIRST), NEXT, IERC) 193 ! ---------------------------------------------------------------- 194 IF (IERC .LT. 0) GO TO 5005 195 ! 196 IF (NEXT(2) .EQ. 0) GO TO 42 197 ! IF (NEXT(2) .GT. 0) THEN 198 ! IN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(2) TO THE 199 ! RIGHT OF X(IR). 200 ! 201 IF (IR .LT. N) GO TO 41 202 ! IF (IR .EQ. N) THEN 203 ! THESE ARE ACTUALLY EXTRAPOLATION POINTS. 204 IERR = IERR + NEXT(2) 205 GO TO 42 206 41 CONTINUE 207 ! ELSE 208 ! WE SHOULD NEVER HAVE GOTTEN HERE. 209 GO TO 5005 210 ! ENDIF 211 ! ENDIF 212 42 CONTINUE 213 ! 214 IF (NEXT(1) .EQ. 0) GO TO 49 215 ! IF (NEXT(1) .GT. 0) THEN 216 ! IN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(1) TO THE 217 ! LEFT OF X(IR-1). 218 ! 219 IF (IR .GT. 2) GO TO 43 220 ! IF (IR .EQ. 2) THEN 221 ! THESE ARE ACTUALLY EXTRAPOLATION POINTS. 222 IERR = IERR + NEXT(1) 223 GO TO 49 224 43 CONTINUE 225 ! ELSE 226 ! XE IS NOT ORDERED RELATIVE TO X, SO MUST ADJUST 227 ! EVALUATION INTERVAL. 228 ! 229 ! FIRST, LOCATE FIRST POINT TO LEFT OF X(IR-1). 230 DO I = JFIRST, J-1 231 IF (XE(I) .LT. X(IR-1)) GO TO 45 232 END DO 233 ! NOTE-- CANNOT DROP THROUGH HERE UNLESS THERE IS AN ERROR 234 ! IN CHFEV. 235 GO TO 5005 236 ! 237 45 CONTINUE 238 ! RESET J. (THIS WILL BE THE NEW JFIRST.) 239 J = I 240 ! 241 ! NOW FIND OUT HOW FAR TO BACK UP IN THE X-ARRAY. 242 DO I = 1, IR-1 243 IF (XE(J) .LT. X(I)) GO TO 47 244 END DO 245 ! NB-- CAN NEVER DROP THROUGH HERE, SINCE XE(J).LT.X(IR-1). 246 ! 247 47 CONTINUE 248 ! AT THIS POINT, EITHER XE(J) .LT. X(1) 249 ! OR X(I-1) .LE. XE(J) .LT. X(I) . 250 ! RESET IR, RECOGNIZING THAT IT WILL BE INCREMENTED BEFORE 251 ! CYCLING. 252 IR = MAX(1, I-1) 253 ! ENDIF 254 ! ENDIF 255 49 CONTINUE 256 ! 257 JFIRST = J 258 ! 259 ! END OF IR-LOOP. 260 ! 261 50 CONTINUE 262 IR = IR + 1 263 IF (IR .LE. N) GO TO 10 264 ! 265 ! NORMAL RETURN. 266 ! 267 5000 CONTINUE 268 RETURN 269 ! 270 ! ERROR RETURNS. 271 ! 272 5001 CONTINUE 273 ! N.LT.2 RETURN. 274 IERR = -1 275 CALL XERMSG ('SLATEC', 'PCHFE', & 276 'NUMBER OF DATA POINTS LESS THAN TWO', IERR, 1) 277 RETURN 278 ! 279 5002 CONTINUE 280 ! INCFD.LT.1 RETURN. 281 IERR = -2 282 CALL XERMSG ('SLATEC', 'PCHFE', 'INCREMENT LESS THAN ONE', IERR, & 283 1) 284 RETURN 285 ! 286 5003 CONTINUE 287 ! X-ARRAY NOT STRICTLY INCREASING. 288 IERR = -3 289 CALL XERMSG ('SLATEC', 'PCHFE', 'X-ARRAY NOT STRICTLY INCREASING' & 290 , IERR, 1) 291 RETURN 292 ! 293 5004 CONTINUE 294 ! NE.LT.1 RETURN. 295 IERR = -4 296 CALL XERMSG ('SLATEC', 'PCHFE', & 297 'NUMBER OF EVALUATION POINTS LESS THAN ONE', IERR, 1) 298 RETURN 299 ! 300 5005 CONTINUE 301 ! ERROR RETURN FROM CHFEV. 302 ! *** THIS CASE SHOULD NEVER OCCUR *** 303 IERR = -5 304 CALL XERMSG ('SLATEC', 'PCHFE', & 305 'ERROR RETURN FROM CHFEV -- FATAL', IERR, 2) 306 RETURN 307 !------------- LAST LINE OF PCHFE FOLLOWS ------------------------------ 308 END SUBROUTINE PCHFE -
LMDZ6/trunk/libf/misc/pchsp.f90
r5245 r5246 1 *DECK PCHSP2 3 C***BEGIN PROLOGUE PCHSP4 C***PURPOSE Set derivatives needed to determine the Hermite represen-5 Ctation of the cubic spline interpolant to given data, with6 Cspecified boundary conditions.7 C***LIBRARY SLATEC (PCHIP)8 C***CATEGORY E1A9 C***TYPE SINGLE PRECISION (PCHSP-S, DPCHSP-D)10 C***KEYWORDS CUBIC HERMITE INTERPOLATION, PCHIP,11 CPIECEWISE CUBIC INTERPOLATION, SPLINE INTERPOLATION12 C***AUTHOR Fritsch, F. N., (LLNL)13 CLawrence Livermore National Laboratory14 CP.O. Box 808 (L-316)15 CLivermore, CA 9455016 CFTS 532-4275, (510) 422-427517 C***DESCRIPTION18 C 19 CPCHSP: Piecewise Cubic Hermite Spline20 C 21 CComputes the Hermite representation of the cubic spline inter-22 Cpolant to the data given in X and F satisfying the boundary23 Cconditions specified by IC and VC.24 C 25 CTo facilitate two-dimensional applications, includes an increment26 Cbetween successive values of the F- and D-arrays.27 C 28 CThe resulting piecewise cubic Hermite function may be evaluated29 Cby PCHFE or PCHFD.30 C 31 CNOTE: This is a modified version of C. de Boor's cubic spline32 Croutine CUBSPL.33 C 34 C----------------------------------------------------------------------35 C 36 CCalling sequence:37 C 38 CPARAMETER (INCFD = ...)39 CINTEGER IC(2), N, NWK, IERR40 CREAL VC(2), X(N), F(INCFD,N), D(INCFD,N), WK(NWK)41 C 42 CCALL PCHSP (IC, VC, N, X, F, D, INCFD, WK, NWK, IERR)43 C 44 CParameters:45 C 46 CIC -- (input) integer array of length 2 specifying desired47 Cboundary conditions:48 CIC(1) = IBEG, desired condition at beginning of data.49 CIC(2) = IEND, desired condition at end of data.50 C 51 CIBEG = 0 to set D(1) so that the third derivative is con-52 Ctinuous at X(2). This is the "not a knot" condition53 Cprovided by de Boor's cubic spline routine CUBSPL.54 C< This is the default boundary condition. >55 CIBEG = 1 if first derivative at X(1) is given in VC(1).56 CIBEG = 2 if second derivative at X(1) is given in VC(1).57 CIBEG = 3 to use the 3-point difference formula for D(1).58 C(Reverts to the default b.c. if N.LT.3 .)59 CIBEG = 4 to use the 4-point difference formula for D(1).60 C(Reverts to the default b.c. if N.LT.4 .)61 CNOTES:62 C1. An error return is taken if IBEG is out of range.63 C2. For the "natural" boundary condition, use IBEG=2 and64 CVC(1)=0.65 C 66 CIEND may take on the same values as IBEG, but applied to67 Cderivative at X(N). In case IEND = 1 or 2, the value is68 Cgiven in VC(2).69 C 70 CNOTES:71 C1. An error return is taken if IEND is out of range.72 C2. For the "natural" boundary condition, use IEND=2 and73 CVC(2)=0.74 C 75 CVC -- (input) real array of length 2 specifying desired boundary76 Cvalues, as indicated above.77 CVC(1) need be set only if IC(1) = 1 or 2 .78 CVC(2) need be set only if IC(2) = 1 or 2 .79 C 80 CN -- (input) number of data points. (Error return if N.LT.2 .)81 C 82 CX -- (input) real array of independent variable values. The83 Celements of X must be strictly increasing:84 CX(I-1) .LT. X(I), I = 2(1)N.85 C(Error return if not.)86 C 87 CF -- (input) real array of dependent variable values to be inter-88 Cpolated. F(1+(I-1)*INCFD) is value corresponding to X(I).89 C 90 CD -- (output) real array of derivative values at the data points.91 CThese values will determine the cubic spline interpolant92 Cwith the requested boundary conditions.93 CThe value corresponding to X(I) is stored in94 CD(1+(I-1)*INCFD), I=1(1)N.95 CNo other entries in D are changed.96 C 97 CINCFD -- (input) increment between successive values in F and D.98 CThis argument is provided primarily for 2-D applications.99 C(Error return if INCFD.LT.1 .)100 C 101 CWK -- (scratch) real array of working storage.102 C 103 CNWK -- (input) length of work array.104 C(Error return if NWK.LT.2*N .)105 C 106 CIERR -- (output) error flag.107 CNormal return:108 CIERR = 0 (no errors).109 C"Recoverable" errors:110 CIERR = -1 if N.LT.2 .111 CIERR = -2 if INCFD.LT.1 .112 CIERR = -3 if the X-array is not strictly increasing.113 CIERR = -4 if IBEG.LT.0 or IBEG.GT.4 .114 CIERR = -5 if IEND.LT.0 of IEND.GT.4 .115 CIERR = -6 if both of the above are true.116 CIERR = -7 if NWK is too small.117 CNOTE: The above errors are checked in the order listed,118 Cand following arguments have **NOT** been validated.119 C(The D-array has not been changed in any of these cases.)120 CIERR = -8 in case of trouble solving the linear system121 Cfor the interior derivative values.122 C(The D-array may have been changed in this case.)123 C( Do **NOT** use it! )124 C 125 C***REFERENCES Carl de Boor, A Practical Guide to Splines, Springer-126 CVerlag, New York, 1978, pp. 53-59.127 C***ROUTINES CALLED PCHDF, XERMSG128 C***REVISION HISTORY (YYMMDD)129 C820503 DATE WRITTEN130 C820804 Converted to SLATEC library version.131 C870707 Minor cosmetic changes to prologue.132 C890411 Added SAVE statements (Vers. 3.2).133 C890703 Corrected category record. (WRB)134 C890831 Modified array declarations. (WRB)135 C890831 REVISION DATE from Version 3.2136 C891214 Prologue converted to Version 4.0 format. (BAB)137 C900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)138 C920429 Revised format and order of references. (WRB,FNF)139 C***END PROLOGUE PCHSP140 CProgramming notes:141 C 142 CTo produce a double precision version, simply:143 Ca. Change PCHSP to DPCHSP wherever it occurs,144 Cb. Change the real declarations to double precision, and145 Cc. Change the constants ZERO, HALF, ... to double precision.146 C 147 CDECLARE ARGUMENTS.148 C 149 INTEGERIC(2), N, INCFD, NWK, IERR150 REALVC(2), X(*), F(INCFD,*), D(INCFD,*), WK(2,*)151 C 152 CDECLARE LOCAL VARIABLES.153 C 154 INTEGERIBEG, IEND, INDEX, J, NM1155 REALG, HALF, ONE, STEMP(3), THREE, TWO, XTEMP(4), ZERO156 157 REALPCHDF158 C 159 160 C 161 CVALIDITY-CHECK ARGUMENTS.162 C 163 C***FIRST EXECUTABLE STATEMENT PCHSP164 165 166 DO 1J = 2, N167 168 1 CONTINUE169 C 170 171 172 173 174 175 176 C 177 CFUNCTION DEFINITION IS OK -- GO ON.178 C 179 180 C 181 CCOMPUTE FIRST DIFFERENCES OF X SEQUENCE AND STORE IN WK(1,.). ALSO,182 CCOMPUTE FIRST DIVIDED DIFFERENCE OF DATA AND STORE IN WK(2,.).183 DO 5J=2,N184 185 186 5 CONTINUE187 C 188 CSET TO DEFAULT BOUNDARY CONDITIONS IF N IS TOO SMALL.189 C 190 191 192 C 193 CSET UP FOR BOUNDARY CONDITIONS.194 C 195 196 197 198 CPICK UP FIRST IBEG POINTS, IN REVERSE ORDER.199 DO 10J = 1, IBEG200 201 CINDEX RUNS FROM IBEG DOWN TO 1.202 203 204 10 CONTINUE205 C--------------------------------206 207 C--------------------------------208 209 210 211 C 212 213 214 215 CPICK UP LAST IEND POINTS.216 DO 15J = 1, IEND217 218 CINDEX RUNS FROM N+1-IEND UP TO N.219 220 221 15 CONTINUE222 C--------------------------------223 224 C--------------------------------225 226 227 228 C 229 C--------------------( BEGIN CODING FROM CUBSPL )--------------------230 C 231 C**** A TRIDIAGONAL LINEAR SYSTEM FOR THE UNKNOWN SLOPES S(J) OF232 CF AT X(J), J=1,...,N, IS GENERATED AND THEN SOLVED BY GAUSS ELIM-233 CINATION, WITH S(J) ENDING UP IN D(1,J), ALL J.234 CWK(1,.) AND WK(2,.) ARE USED FOR TEMPORARY STORAGE.235 C 236 CCONSTRUCT FIRST EQUATION FROM FIRST BOUNDARY CONDITION, OF THE FORM237 CWK(2,1)*S(1) + WK(1,1)*S(2) = D(1,1)238 C 239 240 241 CNO CONDITION AT LEFT END AND N = 2.242 243 244 245 246 CNOT-A-KNOT CONDITION AT LEFT END AND N .GT. 2.247 248 249 D(1,1) =((WK(1,2) + TWO*WK(1,1))*WK(2,2)*WK(1,3)250 *+ WK(1,2)**2*WK(2,3)) / WK(1,1)251 252 253 CSLOPE PRESCRIBED AT LEFT END.254 255 256 257 CSECOND DERIVATIVE PRESCRIBED AT LEFT END.258 259 260 261 262 C 263 CIF THERE ARE INTERIOR KNOTS, GENERATE THE CORRESPONDING EQUATIONS AND264 CCARRY OUT THE FORWARD PASS OF GAUSS ELIMINATION, AFTER WHICH THE J-TH265 CEQUATION READS WK(2,J)*S(J) + WK(1,J)*S(J+1) = D(1,J).266 C 267 268 269 DO 20J=2,NM1270 271 272 D(1,J) = G*D(1,J-1)273 *+ THREE*(WK(1,J)*WK(2,J+1) + WK(1,J+1)*WK(2,J))274 275 20 CONTINUE276 277 C 278 CCONSTRUCT LAST EQUATION FROM SECOND BOUNDARY CONDITION, OF THE FORM279 C(-G*WK(2,N-1))*S(N-1) + WK(2,N)*S(N) = D(1,N)280 C 281 CIF SLOPE IS PRESCRIBED AT RIGHT END, ONE CAN GO DIRECTLY TO BACK-282 CSUBSTITUTION, SINCE ARRAYS HAPPEN TO BE SET UP JUST RIGHT FOR IT283 CAT THIS POINT.284 285 C 286 287 288 CNOT-A-KNOT AT RIGHT ENDPOINT AND AT LEFT ENDPOINT AND N = 2.289 290 291 292 CEITHER (N=3 AND NOT-A-KNOT ALSO AT LEFT) OR (N=2 AND *NOT*293 CNOT-A-KNOT AT LEFT END POINT).294 295 296 297 298 299 CNOT-A-KNOT AND N .GE. 3, AND EITHER N.GT.3 OR ALSO NOT-A-300 CKNOT AT LEFT END POINT.301 302 CDO NOT NEED TO CHECK FOLLOWING DENOMINATORS (X-DIFFERENCES).303 D(1,N) = ((WK(1,N)+TWO*G)*WK(2,N)*WK(1,N-1)304 *+ WK(1,N)**2*(F(1,N-1)-F(1,N-2))/WK(1,N-1))/G305 306 307 308 309 310 CSECOND DERIVATIVE PRESCRIBED AT RIGHT ENDPOINT.311 312 313 314 315 316 C 317 CCOMPLETE FORWARD PASS OF GAUSS ELIMINATION.318 C 319 320 321 322 C 323 CCARRY OUT BACK SUBSTITUTION324 C 325 30 CONTINUE326 DO 40J=NM1,1,-1327 328 329 40 CONTINUE330 C--------------------( END CODING FROM CUBSPL )--------------------331 C 332 CNORMAL RETURN.333 C 334 335 C 336 CERROR RETURNS.337 C 338 5001 CONTINUE339 CN.LT.2 RETURN.340 341 CALL XERMSG ('SLATEC', 'PCHSP',342 +'NUMBER OF DATA POINTS LESS THAN TWO', IERR, 1)343 344 C 345 5002 CONTINUE346 CINCFD.LT.1 RETURN.347 348 CALL XERMSG ('SLATEC', 'PCHSP', 'INCREMENT LESS THAN ONE', IERR,349 +1)350 351 C 352 5003 CONTINUE353 CX-ARRAY NOT STRICTLY INCREASING.354 355 CALL XERMSG ('SLATEC', 'PCHSP', 'X-ARRAY NOT STRICTLY INCREASING'356 +, IERR, 1)357 358 C 359 5004 CONTINUE360 CIC OUT OF RANGE RETURN.361 362 363 364 C 365 5007 CONTINUE366 CNWK TOO SMALL RETURN.367 368 369 370 C 371 5008 CONTINUE372 CSINGULAR SYSTEM.373 C*** THEORETICALLY, THIS CAN ONLY OCCUR IF SUCCESSIVE X-VALUES ***374 C*** ARE EQUAL, WHICH SHOULD ALREADY HAVE BEEN CAUGHT (IERR=-3). ***375 376 CALL XERMSG ('SLATEC', 'PCHSP', 'SINGULAR LINEAR SYSTEM', IERR,377 +1)378 379 C 380 5009 CONTINUE381 CERROR RETURN FROM PCHDF.382 C*** THIS CASE SHOULD NEVER OCCUR ***383 384 CALL XERMSG ('SLATEC', 'PCHSP', 'ERROR RETURN FROM PCHDF', IERR,385 +1)386 387 C------------- LAST LINE OF PCHSP FOLLOWS ------------------------------388 END 1 !DECK PCHSP 2 SUBROUTINE PCHSP (IC, VC, N, X, F, D, INCFD, WK, NWK, IERR) 3 !***BEGIN PROLOGUE PCHSP 4 !***PURPOSE Set derivatives needed to determine the Hermite represen- 5 ! tation of the cubic spline interpolant to given data, with 6 ! specified boundary conditions. 7 !***LIBRARY SLATEC (PCHIP) 8 !***CATEGORY E1A 9 !***TYPE SINGLE PRECISION (PCHSP-S, DPCHSP-D) 10 !***KEYWORDS CUBIC HERMITE INTERPOLATION, PCHIP, 11 ! PIECEWISE CUBIC INTERPOLATION, SPLINE INTERPOLATION 12 !***AUTHOR Fritsch, F. N., (LLNL) 13 ! Lawrence Livermore National Laboratory 14 ! P.O. Box 808 (L-316) 15 ! Livermore, CA 94550 16 ! FTS 532-4275, (510) 422-4275 17 !***DESCRIPTION 18 ! 19 ! PCHSP: Piecewise Cubic Hermite Spline 20 ! 21 ! Computes the Hermite representation of the cubic spline inter- 22 ! polant to the data given in X and F satisfying the boundary 23 ! conditions specified by IC and VC. 24 ! 25 ! To facilitate two-dimensional applications, includes an increment 26 ! between successive values of the F- and D-arrays. 27 ! 28 ! The resulting piecewise cubic Hermite function may be evaluated 29 ! by PCHFE or PCHFD. 30 ! 31 ! NOTE: This is a modified version of C. de Boor's cubic spline 32 ! routine CUBSPL. 33 ! 34 ! ---------------------------------------------------------------------- 35 ! 36 ! Calling sequence: 37 ! 38 ! PARAMETER (INCFD = ...) 39 ! INTEGER IC(2), N, NWK, IERR 40 ! REAL VC(2), X(N), F(INCFD,N), D(INCFD,N), WK(NWK) 41 ! 42 ! CALL PCHSP (IC, VC, N, X, F, D, INCFD, WK, NWK, IERR) 43 ! 44 ! Parameters: 45 ! 46 ! IC -- (input) integer array of length 2 specifying desired 47 ! boundary conditions: 48 ! IC(1) = IBEG, desired condition at beginning of data. 49 ! IC(2) = IEND, desired condition at end of data. 50 ! 51 ! IBEG = 0 to set D(1) so that the third derivative is con- 52 ! tinuous at X(2). This is the "not a knot" condition 53 ! provided by de Boor's cubic spline routine CUBSPL. 54 ! < This is the default boundary condition. > 55 ! IBEG = 1 if first derivative at X(1) is given in VC(1). 56 ! IBEG = 2 if second derivative at X(1) is given in VC(1). 57 ! IBEG = 3 to use the 3-point difference formula for D(1). 58 ! (Reverts to the default b.c. if N.LT.3 .) 59 ! IBEG = 4 to use the 4-point difference formula for D(1). 60 ! (Reverts to the default b.c. if N.LT.4 .) 61 ! NOTES: 62 ! 1. An error return is taken if IBEG is out of range. 63 ! 2. For the "natural" boundary condition, use IBEG=2 and 64 ! VC(1)=0. 65 ! 66 ! IEND may take on the same values as IBEG, but applied to 67 ! derivative at X(N). In case IEND = 1 or 2, the value is 68 ! given in VC(2). 69 ! 70 ! NOTES: 71 ! 1. An error return is taken if IEND is out of range. 72 ! 2. For the "natural" boundary condition, use IEND=2 and 73 ! VC(2)=0. 74 ! 75 ! VC -- (input) real array of length 2 specifying desired boundary 76 ! values, as indicated above. 77 ! VC(1) need be set only if IC(1) = 1 or 2 . 78 ! VC(2) need be set only if IC(2) = 1 or 2 . 79 ! 80 ! N -- (input) number of data points. (Error return if N.LT.2 .) 81 ! 82 ! X -- (input) real array of independent variable values. The 83 ! elements of X must be strictly increasing: 84 ! X(I-1) .LT. X(I), I = 2(1)N. 85 ! (Error return if not.) 86 ! 87 ! F -- (input) real array of dependent variable values to be inter- 88 ! polated. F(1+(I-1)*INCFD) is value corresponding to X(I). 89 ! 90 ! D -- (output) real array of derivative values at the data points. 91 ! These values will determine the cubic spline interpolant 92 ! with the requested boundary conditions. 93 ! The value corresponding to X(I) is stored in 94 ! D(1+(I-1)*INCFD), I=1(1)N. 95 ! No other entries in D are changed. 96 ! 97 ! INCFD -- (input) increment between successive values in F and D. 98 ! This argument is provided primarily for 2-D applications. 99 ! (Error return if INCFD.LT.1 .) 100 ! 101 ! WK -- (scratch) real array of working storage. 102 ! 103 ! NWK -- (input) length of work array. 104 ! (Error return if NWK.LT.2*N .) 105 ! 106 ! IERR -- (output) error flag. 107 ! Normal return: 108 ! IERR = 0 (no errors). 109 ! "Recoverable" errors: 110 ! IERR = -1 if N.LT.2 . 111 ! IERR = -2 if INCFD.LT.1 . 112 ! IERR = -3 if the X-array is not strictly increasing. 113 ! IERR = -4 if IBEG.LT.0 or IBEG.GT.4 . 114 ! IERR = -5 if IEND.LT.0 of IEND.GT.4 . 115 ! IERR = -6 if both of the above are true. 116 ! IERR = -7 if NWK is too small. 117 ! NOTE: The above errors are checked in the order listed, 118 ! and following arguments have **NOT** been validated. 119 ! (The D-array has not been changed in any of these cases.) 120 ! IERR = -8 in case of trouble solving the linear system 121 ! for the interior derivative values. 122 ! (The D-array may have been changed in this case.) 123 ! ( Do **NOT** use it! ) 124 ! 125 !***REFERENCES Carl de Boor, A Practical Guide to Splines, Springer- 126 ! Verlag, New York, 1978, pp. 53-59. 127 !***ROUTINES CALLED PCHDF, XERMSG 128 !***REVISION HISTORY (YYMMDD) 129 ! 820503 DATE WRITTEN 130 ! 820804 Converted to SLATEC library version. 131 ! 870707 Minor cosmetic changes to prologue. 132 ! 890411 Added SAVE statements (Vers. 3.2). 133 ! 890703 Corrected category record. (WRB) 134 ! 890831 Modified array declarations. (WRB) 135 ! 890831 REVISION DATE from Version 3.2 136 ! 891214 Prologue converted to Version 4.0 format. (BAB) 137 ! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) 138 ! 920429 Revised format and order of references. (WRB,FNF) 139 !***END PROLOGUE PCHSP 140 ! Programming notes: 141 ! 142 ! To produce a double precision version, simply: 143 ! a. Change PCHSP to DPCHSP wherever it occurs, 144 ! b. Change the real declarations to double precision, and 145 ! c. Change the constants ZERO, HALF, ... to double precision. 146 ! 147 ! DECLARE ARGUMENTS. 148 ! 149 INTEGER :: IC(2), N, INCFD, NWK, IERR 150 REAL :: VC(2), X(*), F(INCFD,*), D(INCFD,*), WK(2,*) 151 ! 152 ! DECLARE LOCAL VARIABLES. 153 ! 154 INTEGER :: IBEG, IEND, INDEX, J, NM1 155 REAL :: G, HALF, ONE, STEMP(3), THREE, TWO, XTEMP(4), ZERO 156 SAVE ZERO, HALF, ONE, TWO, THREE 157 REAL :: PCHDF 158 ! 159 DATA ZERO /0./, HALF /0.5/, ONE /1./, TWO /2./, THREE /3./ 160 ! 161 ! VALIDITY-CHECK ARGUMENTS. 162 ! 163 !***FIRST EXECUTABLE STATEMENT PCHSP 164 IF ( N.LT.2 ) GO TO 5001 165 IF ( INCFD.LT.1 ) GO TO 5002 166 DO J = 2, N 167 IF ( X(J).LE.X(J-1) ) GO TO 5003 168 END DO 169 ! 170 IBEG = IC(1) 171 IEND = IC(2) 172 IERR = 0 173 IF ( (IBEG.LT.0).OR.(IBEG.GT.4) ) IERR = IERR - 1 174 IF ( (IEND.LT.0).OR.(IEND.GT.4) ) IERR = IERR - 2 175 IF ( IERR.LT.0 ) GO TO 5004 176 ! 177 ! FUNCTION DEFINITION IS OK -- GO ON. 178 ! 179 IF ( NWK .LT. 2*N ) GO TO 5007 180 ! 181 ! COMPUTE FIRST DIFFERENCES OF X SEQUENCE AND STORE IN WK(1,.). ALSO, 182 ! COMPUTE FIRST DIVIDED DIFFERENCE OF DATA AND STORE IN WK(2,.). 183 DO J=2,N 184 WK(1,J) = X(J) - X(J-1) 185 WK(2,J) = (F(1,J) - F(1,J-1))/WK(1,J) 186 END DO 187 ! 188 ! SET TO DEFAULT BOUNDARY CONDITIONS IF N IS TOO SMALL. 189 ! 190 IF ( IBEG.GT.N ) IBEG = 0 191 IF ( IEND.GT.N ) IEND = 0 192 ! 193 ! SET UP FOR BOUNDARY CONDITIONS. 194 ! 195 IF ( (IBEG.EQ.1).OR.(IBEG.EQ.2) ) THEN 196 D(1,1) = VC(1) 197 ELSE IF (IBEG .GT. 2) THEN 198 ! PICK UP FIRST IBEG POINTS, IN REVERSE ORDER. 199 DO J = 1, IBEG 200 INDEX = IBEG-J+1 201 ! INDEX RUNS FROM IBEG DOWN TO 1. 202 XTEMP(J) = X(INDEX) 203 IF (J .LT. IBEG) STEMP(J) = WK(2,INDEX) 204 END DO 205 ! -------------------------------- 206 D(1,1) = PCHDF (IBEG, XTEMP, STEMP, IERR) 207 ! -------------------------------- 208 IF (IERR .NE. 0) GO TO 5009 209 IBEG = 1 210 ENDIF 211 ! 212 IF ( (IEND.EQ.1).OR.(IEND.EQ.2) ) THEN 213 D(1,N) = VC(2) 214 ELSE IF (IEND .GT. 2) THEN 215 ! PICK UP LAST IEND POINTS. 216 DO J = 1, IEND 217 INDEX = N-IEND+J 218 ! INDEX RUNS FROM N+1-IEND UP TO N. 219 XTEMP(J) = X(INDEX) 220 IF (J .LT. IEND) STEMP(J) = WK(2,INDEX+1) 221 END DO 222 ! -------------------------------- 223 D(1,N) = PCHDF (IEND, XTEMP, STEMP, IERR) 224 ! -------------------------------- 225 IF (IERR .NE. 0) GO TO 5009 226 IEND = 1 227 ENDIF 228 ! 229 ! --------------------( BEGIN CODING FROM CUBSPL )-------------------- 230 ! 231 ! **** A TRIDIAGONAL LINEAR SYSTEM FOR THE UNKNOWN SLOPES S(J) OF 232 ! F AT X(J), J=1,...,N, IS GENERATED AND THEN SOLVED BY GAUSS ELIM- 233 ! INATION, WITH S(J) ENDING UP IN D(1,J), ALL J. 234 ! WK(1,.) AND WK(2,.) ARE USED FOR TEMPORARY STORAGE. 235 ! 236 ! CONSTRUCT FIRST EQUATION FROM FIRST BOUNDARY CONDITION, OF THE FORM 237 ! WK(2,1)*S(1) + WK(1,1)*S(2) = D(1,1) 238 ! 239 IF (IBEG .EQ. 0) THEN 240 IF (N .EQ. 2) THEN 241 ! NO CONDITION AT LEFT END AND N = 2. 242 WK(2,1) = ONE 243 WK(1,1) = ONE 244 D(1,1) = TWO*WK(2,2) 245 ELSE 246 ! NOT-A-KNOT CONDITION AT LEFT END AND N .GT. 2. 247 WK(2,1) = WK(1,3) 248 WK(1,1) = WK(1,2) + WK(1,3) 249 D(1,1) =((WK(1,2) + TWO*WK(1,1))*WK(2,2)*WK(1,3) & 250 + WK(1,2)**2*WK(2,3)) / WK(1,1) 251 ENDIF 252 ELSE IF (IBEG .EQ. 1) THEN 253 ! SLOPE PRESCRIBED AT LEFT END. 254 WK(2,1) = ONE 255 WK(1,1) = ZERO 256 ELSE 257 ! SECOND DERIVATIVE PRESCRIBED AT LEFT END. 258 WK(2,1) = TWO 259 WK(1,1) = ONE 260 D(1,1) = THREE*WK(2,2) - HALF*WK(1,2)*D(1,1) 261 ENDIF 262 ! 263 ! IF THERE ARE INTERIOR KNOTS, GENERATE THE CORRESPONDING EQUATIONS AND 264 ! CARRY OUT THE FORWARD PASS OF GAUSS ELIMINATION, AFTER WHICH THE J-TH 265 ! EQUATION READS WK(2,J)*S(J) + WK(1,J)*S(J+1) = D(1,J). 266 ! 267 NM1 = N-1 268 IF (NM1 .GT. 1) THEN 269 DO J=2,NM1 270 IF (WK(2,J-1) .EQ. ZERO) GO TO 5008 271 G = -WK(1,J+1)/WK(2,J-1) 272 D(1,J) = G*D(1,J-1) & 273 + THREE*(WK(1,J)*WK(2,J+1) + WK(1,J+1)*WK(2,J)) 274 WK(2,J) = G*WK(1,J-1) + TWO*(WK(1,J) + WK(1,J+1)) 275 END DO 276 ENDIF 277 ! 278 ! CONSTRUCT LAST EQUATION FROM SECOND BOUNDARY CONDITION, OF THE FORM 279 ! (-G*WK(2,N-1))*S(N-1) + WK(2,N)*S(N) = D(1,N) 280 ! 281 ! IF SLOPE IS PRESCRIBED AT RIGHT END, ONE CAN GO DIRECTLY TO BACK- 282 ! SUBSTITUTION, SINCE ARRAYS HAPPEN TO BE SET UP JUST RIGHT FOR IT 283 ! AT THIS POINT. 284 IF (IEND .EQ. 1) GO TO 30 285 ! 286 IF (IEND .EQ. 0) THEN 287 IF (N.EQ.2 .AND. IBEG.EQ.0) THEN 288 ! NOT-A-KNOT AT RIGHT ENDPOINT AND AT LEFT ENDPOINT AND N = 2. 289 D(1,2) = WK(2,2) 290 GO TO 30 291 ELSE IF ((N.EQ.2) .OR. (N.EQ.3 .AND. IBEG.EQ.0)) THEN 292 ! EITHER (N=3 AND NOT-A-KNOT ALSO AT LEFT) OR (N=2 AND *NOT* 293 ! NOT-A-KNOT AT LEFT END POINT). 294 D(1,N) = TWO*WK(2,N) 295 WK(2,N) = ONE 296 IF (WK(2,N-1) .EQ. ZERO) GO TO 5008 297 G = -ONE/WK(2,N-1) 298 ELSE 299 ! NOT-A-KNOT AND N .GE. 3, AND EITHER N.GT.3 OR ALSO NOT-A- 300 ! KNOT AT LEFT END POINT. 301 G = WK(1,N-1) + WK(1,N) 302 ! DO NOT NEED TO CHECK FOLLOWING DENOMINATORS (X-DIFFERENCES). 303 D(1,N) = ((WK(1,N)+TWO*G)*WK(2,N)*WK(1,N-1) & 304 + WK(1,N)**2*(F(1,N-1)-F(1,N-2))/WK(1,N-1))/G 305 IF (WK(2,N-1) .EQ. ZERO) GO TO 5008 306 G = -G/WK(2,N-1) 307 WK(2,N) = WK(1,N-1) 308 ENDIF 309 ELSE 310 ! SECOND DERIVATIVE PRESCRIBED AT RIGHT ENDPOINT. 311 D(1,N) = THREE*WK(2,N) + HALF*WK(1,N)*D(1,N) 312 WK(2,N) = TWO 313 IF (WK(2,N-1) .EQ. ZERO) GO TO 5008 314 G = -ONE/WK(2,N-1) 315 ENDIF 316 ! 317 ! COMPLETE FORWARD PASS OF GAUSS ELIMINATION. 318 ! 319 WK(2,N) = G*WK(1,N-1) + WK(2,N) 320 IF (WK(2,N) .EQ. ZERO) GO TO 5008 321 D(1,N) = (G*D(1,N-1) + D(1,N))/WK(2,N) 322 ! 323 ! CARRY OUT BACK SUBSTITUTION 324 ! 325 30 CONTINUE 326 DO J=NM1,1,-1 327 IF (WK(2,J) .EQ. ZERO) GO TO 5008 328 D(1,J) = (D(1,J) - WK(1,J)*D(1,J+1))/WK(2,J) 329 END DO 330 ! --------------------( END CODING FROM CUBSPL )-------------------- 331 ! 332 ! NORMAL RETURN. 333 ! 334 RETURN 335 ! 336 ! ERROR RETURNS. 337 ! 338 5001 CONTINUE 339 ! N.LT.2 RETURN. 340 IERR = -1 341 CALL XERMSG ('SLATEC', 'PCHSP', & 342 'NUMBER OF DATA POINTS LESS THAN TWO', IERR, 1) 343 RETURN 344 ! 345 5002 CONTINUE 346 ! INCFD.LT.1 RETURN. 347 IERR = -2 348 CALL XERMSG ('SLATEC', 'PCHSP', 'INCREMENT LESS THAN ONE', IERR, & 349 1) 350 RETURN 351 ! 352 5003 CONTINUE 353 ! X-ARRAY NOT STRICTLY INCREASING. 354 IERR = -3 355 CALL XERMSG ('SLATEC', 'PCHSP', 'X-ARRAY NOT STRICTLY INCREASING' & 356 , IERR, 1) 357 RETURN 358 ! 359 5004 CONTINUE 360 ! IC OUT OF RANGE RETURN. 361 IERR = IERR - 3 362 CALL XERMSG ('SLATEC', 'PCHSP', 'IC OUT OF RANGE', IERR, 1) 363 RETURN 364 ! 365 5007 CONTINUE 366 ! NWK TOO SMALL RETURN. 367 IERR = -7 368 CALL XERMSG ('SLATEC', 'PCHSP', 'WORK ARRAY TOO SMALL', IERR, 1) 369 RETURN 370 ! 371 5008 CONTINUE 372 ! SINGULAR SYSTEM. 373 ! *** THEORETICALLY, THIS CAN ONLY OCCUR IF SUCCESSIVE X-VALUES *** 374 ! *** ARE EQUAL, WHICH SHOULD ALREADY HAVE BEEN CAUGHT (IERR=-3). *** 375 IERR = -8 376 CALL XERMSG ('SLATEC', 'PCHSP', 'SINGULAR LINEAR SYSTEM', IERR, & 377 1) 378 RETURN 379 ! 380 5009 CONTINUE 381 ! ERROR RETURN FROM PCHDF. 382 ! *** THIS CASE SHOULD NEVER OCCUR *** 383 IERR = -9 384 CALL XERMSG ('SLATEC', 'PCHSP', 'ERROR RETURN FROM PCHDF', IERR, & 385 1) 386 RETURN 387 !------------- LAST LINE OF PCHSP FOLLOWS ------------------------------ 388 END SUBROUTINE PCHSP -
LMDZ6/trunk/libf/misc/q_sat.f90
r5245 r5246 5 5 ! 6 6 7 8 !9 10 !======================================================================11 ! Autheur(s): Z.X. Li (LMD/CNRS)12 ! reecriture vectorisee par F. Hourdin.13 ! Objet: calculer la vapeur d'eau saturante (formule Centre Euro.)14 !======================================================================15 ! Arguments:16 ! kelvin---input-R: temperature en Kelvin17 ! millibar--input-R: pression en mb18 !19 ! q_sat----output-R: vapeur d'eau saturante en kg/kg20 !======================================================================21 !22 integernp23 REALtemp(np),pres(np),qsat(np)24 !25 REALr2es26 27 !28 REALr3les, r3ies, r3es29 30 31 !32 REALr4les, r4ies, r4es33 34 35 !36 REALrtt37 38 !39 REALretv40 7 subroutine q_sat(np,temp,pres,qsat) 8 ! 9 IMPLICIT none 10 !====================================================================== 11 ! Autheur(s): Z.X. Li (LMD/CNRS) 12 ! reecriture vectorisee par F. Hourdin. 13 ! Objet: calculer la vapeur d'eau saturante (formule Centre Euro.) 14 !====================================================================== 15 ! Arguments: 16 ! kelvin---input-R: temperature en Kelvin 17 ! millibar--input-R: pression en mb 18 ! 19 ! q_sat----output-R: vapeur d'eau saturante en kg/kg 20 !====================================================================== 21 ! 22 integer :: np 23 REAL :: temp(np),pres(np),qsat(np) 24 ! 25 REAL :: r2es 26 PARAMETER (r2es=611.14 *18.0153/28.9644) 27 ! 28 REAL :: r3les, r3ies, r3es 29 PARAMETER (R3LES=17.269) 30 PARAMETER (R3IES=21.875) 31 ! 32 REAL :: r4les, r4ies, r4es 33 PARAMETER (R4LES=35.86) 34 PARAMETER (R4IES=7.66) 35 ! 36 REAL :: rtt 37 PARAMETER (rtt=273.16) 38 ! 39 REAL :: retv 40 PARAMETER (retv=28.9644/18.0153 - 1.0) 41 41 42 realzqsat43 integerip44 !45 !------------------------------------------------------------------46 !47 !42 real :: zqsat 43 integer :: ip 44 ! 45 ! ------------------------------------------------------------------ 46 ! 47 ! 48 48 49 49 do ip=1,np 50 50 51 !write(*,*)'kelvin,millibar=',kelvin,millibar52 !write(*,*)'temp,pres=',temp(ip),pres(ip)53 !54 55 56 57 58 59 60 61 !62 63 64 65 !66 67 !write(*,*)'qsat=',qsat(ip)51 ! write(*,*)'kelvin,millibar=',kelvin,millibar 52 ! write(*,*)'temp,pres=',temp(ip),pres(ip) 53 ! 54 IF (temp(ip) .LE. rtt) THEN 55 r3es = r3ies 56 r4es = r4ies 57 ELSE 58 r3es = r3les 59 r4es = r4les 60 ENDIF 61 ! 62 zqsat=r2es/pres(ip)*EXP(r3es*(temp(ip)-rtt)/(temp(ip)-r4es)) 63 zqsat=MIN(0.5,ZQSAT) 64 zqsat=zqsat/(1.-retv *zqsat) 65 ! 66 qsat(ip)= zqsat 67 ! write(*,*)'qsat=',qsat(ip) 68 68 69 70 !71 72 END 69 enddo 70 ! 71 RETURN 72 END SUBROUTINE q_sat -
LMDZ6/trunk/libf/misc/ran1.f90
r5245 r5246 2 2 ! $Id$ 3 3 ! 4 5 6 REALRAN17 8 9 10 11 12 13 14 4 FUNCTION RAN1(IDUM) 5 IMPLICIT NONE 6 REAL :: RAN1 7 REAL,SAVE :: R(97) 8 REAL,PARAMETER :: RM1=3.8580247E-6,RM2=7.4373773E-6 9 INTEGER,SAVE :: IFF=0 10 integer,save :: ix1,ix2,ix3 11 INTEGER,PARAMETER :: M1=259200,IA1=7141,IC1=54773 12 INTEGER,PARAMETER :: M2=134456,IA2=8121,IC2=28411 13 INTEGER,PARAMETER :: M3=243000,IA3=4561,IC3=51349 14 INTEGER :: IDUM,J 15 15 16 IF (IDUM.LT.0.OR.IFF.EQ.0) THEN 17 IFF=1 18 IX1=MOD(IC1-IDUM,M1) 19 IX1=MOD(IA1*IX1+IC1,M1) 20 IX2=MOD(IX1,M2) 21 IX1=MOD(IA1*IX1+IC1,M1) 22 IX3=MOD(IX1,M3) 23 DO 11 J=1,97 24 IX1=MOD(IA1*IX1+IC1,M1) 25 IX2=MOD(IA2*IX2+IC2,M2) 26 R(J)=(REAL(IX1)+REAL(IX2)*RM2)*RM1 27 11 CONTINUE 28 IDUM=1 29 ENDIF 16 IF (IDUM.LT.0.OR.IFF.EQ.0) THEN 17 IFF=1 18 IX1=MOD(IC1-IDUM,M1) 19 IX1=MOD(IA1*IX1+IC1,M1) 20 IX2=MOD(IX1,M2) 21 IX1=MOD(IA1*IX1+IC1,M1) 22 IX3=MOD(IX1,M3) 23 DO J=1,97 30 24 IX1=MOD(IA1*IX1+IC1,M1) 31 25 IX2=MOD(IA2*IX2+IC2,M2) 32 IX3=MOD(IA3*IX3+IC3,M3)33 J=1+(97*IX3)/M334 IF(J.GT.97.OR.J.LT.1) stop 135 RAN1=R(J)36 26 R(J)=(REAL(IX1)+REAL(IX2)*RM2)*RM1 37 RETURN 38 END 27 END DO 28 IDUM=1 29 ENDIF 30 IX1=MOD(IA1*IX1+IC1,M1) 31 IX2=MOD(IA2*IX2+IC2,M2) 32 IX3=MOD(IA3*IX3+IC3,M3) 33 J=1+(97*IX3)/M3 34 IF(J.GT.97.OR.J.LT.1) stop 1 35 RAN1=R(J) 36 R(J)=(REAL(IX1)+REAL(IX2)*RM2)*RM1 37 RETURN 38 END FUNCTION RAN1 -
LMDZ6/trunk/libf/misc/sort.f90
r5245 r5246 2 2 ! $Header$ 3 3 ! 4 C 5 C 6 7 c 8 cP.Le Van9 c 10 c... cette routine met le tableau d dans l'ordre croissant ....11 cc ( pour avoir l'ordre decroissant,il suffit de remplacer l'instruc12 ction situee + bas IF(d(j).LE.p) THEN par13 cIF(d(j).GE.p) THEN14 c 4 ! 5 ! 6 SUBROUTINE sort(n,d) 7 ! 8 ! P.Le Van 9 ! 10 !... cette routine met le tableau d dans l'ordre croissant .... 11 !c ( pour avoir l'ordre decroissant,il suffit de remplacer l'instruc 12 ! tion situee + bas IF(d(j).LE.p) THEN par 13 ! IF(d(j).GE.p) THEN 14 ! 15 15 16 INTEGERn17 REALd(n) , p18 INTEGERi,j,k16 INTEGER :: n 17 REAL :: d(n) , p 18 INTEGER :: i,j,k 19 19 20 21 22 23 24 25 26 27 28 20 DO i=1,n-1 21 k=i 22 p=d(i) 23 DO j=i+1,n 24 IF(d(j).LE.p) THEN 25 k=j 26 p=d(j) 27 ENDIF 28 ENDDO 29 29 30 31 32 33 34 30 IF(k.ne.i) THEN 31 d(k)=d(i) 32 d(i)=p 33 ENDIF 34 ENDDO 35 35 36 37 END 36 RETURN 37 END SUBROUTINE sort -
LMDZ6/trunk/libf/misc/xercnt.f90
r5245 r5246 1 *DECK XERCNT2 3 4 C***BEGIN PROLOGUE XERCNT5 C***SUBSIDIARY6 C***PURPOSE Allow user control over handling of errors.7 C***LIBRARY SLATEC (XERROR)8 C***CATEGORY R3C9 C***TYPE ALL (XERCNT-A)10 C***KEYWORDS ERROR, XERROR11 C***AUTHOR Jones, R. E., (SNLA)12 C***DESCRIPTION13 C 14 CAbstract15 CAllows user control over handling of individual errors.16 CJust after each message is recorded, but before it is17 Cprocessed any further (i.e., before it is printed or18 Ca decision to abort is made), a call is made to XERCNT.19 CIf the user has provided his own version of XERCNT, he20 Ccan then override the value of KONTROL used in processing21 Cthis message by redefining its value.22 CKONTRL may be set to any value from -2 to 2.23 CThe meanings for KONTRL are the same as in XSETF, except24 Cthat the value of KONTRL changes only for this message.25 CIf KONTRL is set to a value outside the range from -2 to 2,26 Cit will be moved back into that range.27 C 28 CDescription of Parameters29 C 30 C--Input--31 CLIBRAR - the library that the routine is in.32 CSUBROU - the subroutine that XERMSG is being called from33 CMESSG - the first 20 characters of the error message.34 CNERR - same as in the call to XERMSG.35 CLEVEL - same as in the call to XERMSG.36 CKONTRL - the current value of the control flag as set37 Cby a call to XSETF.38 C 39 C--Output--40 CKONTRL - the new value of KONTRL. If KONTRL is not41 Cdefined, it will remain at its original value.42 CThis changed value of control affects only43 Cthe current occurrence of the current message.44 C 45 C***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC46 CError-handling Package, SAND82-0800, Sandia47 CLaboratories, 1982.48 C***ROUTINES CALLED (NONE)49 C***REVISION HISTORY (YYMMDD)50 C790801 DATE WRITTEN51 C861211 REVISION DATE from Version 3.252 C891214 Prologue converted to Version 4.0 format. (BAB)53 C900206 Routine changed from user-callable to subsidiary. (WRB)54 C900510 Changed calling sequence to include LIBRARY and SUBROUTINE55 Cnames, changed routine name from XERCTL to XERCNT. (RWC)56 C920501 Reformatted the REFERENCES section. (WRB)57 C***END PROLOGUE XERCNT58 CHARACTER*(*)LIBRAR, SUBROU, MESSG59 INTEGERNERR, LEVEL, KONTRL60 C***FIRST EXECUTABLE STATEMENT XERCNT61 62 END 1 !DECK XERCNT 2 SUBROUTINE XERCNT (LIBRAR, SUBROU, MESSG, NERR, LEVEL, KONTRL) 3 IMPLICIT NONE 4 !***BEGIN PROLOGUE XERCNT 5 !***SUBSIDIARY 6 !***PURPOSE Allow user control over handling of errors. 7 !***LIBRARY SLATEC (XERROR) 8 !***CATEGORY R3C 9 !***TYPE ALL (XERCNT-A) 10 !***KEYWORDS ERROR, XERROR 11 !***AUTHOR Jones, R. E., (SNLA) 12 !***DESCRIPTION 13 ! 14 ! Abstract 15 ! Allows user control over handling of individual errors. 16 ! Just after each message is recorded, but before it is 17 ! processed any further (i.e., before it is printed or 18 ! a decision to abort is made), a call is made to XERCNT. 19 ! If the user has provided his own version of XERCNT, he 20 ! can then override the value of KONTROL used in processing 21 ! this message by redefining its value. 22 ! KONTRL may be set to any value from -2 to 2. 23 ! The meanings for KONTRL are the same as in XSETF, except 24 ! that the value of KONTRL changes only for this message. 25 ! If KONTRL is set to a value outside the range from -2 to 2, 26 ! it will be moved back into that range. 27 ! 28 ! Description of Parameters 29 ! 30 ! --Input-- 31 ! LIBRAR - the library that the routine is in. 32 ! SUBROU - the subroutine that XERMSG is being called from 33 ! MESSG - the first 20 characters of the error message. 34 ! NERR - same as in the call to XERMSG. 35 ! LEVEL - same as in the call to XERMSG. 36 ! KONTRL - the current value of the control flag as set 37 ! by a call to XSETF. 38 ! 39 ! --Output-- 40 ! KONTRL - the new value of KONTRL. If KONTRL is not 41 ! defined, it will remain at its original value. 42 ! This changed value of control affects only 43 ! the current occurrence of the current message. 44 ! 45 !***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC 46 ! Error-handling Package, SAND82-0800, Sandia 47 ! Laboratories, 1982. 48 !***ROUTINES CALLED (NONE) 49 !***REVISION HISTORY (YYMMDD) 50 ! 790801 DATE WRITTEN 51 ! 861211 REVISION DATE from Version 3.2 52 ! 891214 Prologue converted to Version 4.0 format. (BAB) 53 ! 900206 Routine changed from user-callable to subsidiary. (WRB) 54 ! 900510 Changed calling sequence to include LIBRARY and SUBROUTINE 55 ! names, changed routine name from XERCTL to XERCNT. (RWC) 56 ! 920501 Reformatted the REFERENCES section. (WRB) 57 !***END PROLOGUE XERCNT 58 CHARACTER(len=*) :: LIBRAR, SUBROU, MESSG 59 INTEGER :: NERR, LEVEL, KONTRL 60 !***FIRST EXECUTABLE STATEMENT XERCNT 61 RETURN 62 END SUBROUTINE XERCNT -
LMDZ6/trunk/libf/misc/xerhlt.f90
r5245 r5246 1 *DECK XERHLT2 3 C***BEGIN PROLOGUE XERHLT4 C***SUBSIDIARY5 C***PURPOSE Abort program execution and print error message.6 C***LIBRARY SLATEC (XERROR)7 C***CATEGORY R3C8 C***TYPE ALL (XERHLT-A)9 C***KEYWORDS ABORT PROGRAM EXECUTION, ERROR, XERROR10 C***AUTHOR Jones, R. E., (SNLA)11 C***DESCRIPTION12 C 13 CAbstract14 C***Note*** machine dependent routine15 CXERHLT aborts the execution of the program.16 CThe error message causing the abort is given in the calling17 Csequence, in case one needs it for printing on a dayfile,18 Cfor example.19 C 20 CDescription of Parameters21 CMESSG is as in XERMSG.22 C 23 C***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC24 CError-handling Package, SAND82-0800, Sandia25 CLaboratories, 1982.26 C***ROUTINES CALLED (NONE)27 C***REVISION HISTORY (YYMMDD)28 C790801 DATE WRITTEN29 C861211 REVISION DATE from Version 3.230 C891214 Prologue converted to Version 4.0 format. (BAB)31 C900206 Routine changed from user-callable to subsidiary. (WRB)32 C900510 Changed calling sequence to delete length of character33 Cand changed routine name from XERABT to XERHLT. (RWC)34 C920501 Reformatted the REFERENCES section. (WRB)35 C***END PROLOGUE XERHLT36 CHARACTER*(*)MESSG37 C***FIRST EXECUTABLE STATEMENT XERHLT38 39 END 1 !DECK XERHLT 2 SUBROUTINE XERHLT (MESSG) 3 !***BEGIN PROLOGUE XERHLT 4 !***SUBSIDIARY 5 !***PURPOSE Abort program execution and print error message. 6 !***LIBRARY SLATEC (XERROR) 7 !***CATEGORY R3C 8 !***TYPE ALL (XERHLT-A) 9 !***KEYWORDS ABORT PROGRAM EXECUTION, ERROR, XERROR 10 !***AUTHOR Jones, R. E., (SNLA) 11 !***DESCRIPTION 12 ! 13 ! Abstract 14 ! ***Note*** machine dependent routine 15 ! XERHLT aborts the execution of the program. 16 ! The error message causing the abort is given in the calling 17 ! sequence, in case one needs it for printing on a dayfile, 18 ! for example. 19 ! 20 ! Description of Parameters 21 ! MESSG is as in XERMSG. 22 ! 23 !***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC 24 ! Error-handling Package, SAND82-0800, Sandia 25 ! Laboratories, 1982. 26 !***ROUTINES CALLED (NONE) 27 !***REVISION HISTORY (YYMMDD) 28 ! 790801 DATE WRITTEN 29 ! 861211 REVISION DATE from Version 3.2 30 ! 891214 Prologue converted to Version 4.0 format. (BAB) 31 ! 900206 Routine changed from user-callable to subsidiary. (WRB) 32 ! 900510 Changed calling sequence to delete length of character 33 ! and changed routine name from XERABT to XERHLT. (RWC) 34 ! 920501 Reformatted the REFERENCES section. (WRB) 35 !***END PROLOGUE XERHLT 36 CHARACTER(len=*) :: MESSG 37 !***FIRST EXECUTABLE STATEMENT XERHLT 38 STOP 39 END SUBROUTINE XERHLT -
LMDZ6/trunk/libf/misc/xermsg.f90
r5245 r5246 1 *DECK XERMSG2 3 4 C***BEGIN PROLOGUE XERMSG5 C***PURPOSE Process error messages for SLATEC and other libraries.6 C***LIBRARY SLATEC (XERROR)7 C***CATEGORY R3C8 C***TYPE ALL (XERMSG-A)9 C***KEYWORDS ERROR MESSAGE, XERROR10 C***AUTHOR Fong, Kirby, (NMFECC at LLNL)11 C***DESCRIPTION12 C 13 CXERMSG processes a diagnostic message in a manner determined by the14 Cvalue of LEVEL and the current value of the library error control15 Cflag, KONTRL. See subroutine XSETF for details.16 C 17 CLIBRAR A character constant (or character variable) with the name18 Cof the library. This will be 'SLATEC' for the SLATEC19 CCommon Math Library. The error handling package is20 Cgeneral enough to be used by many libraries21 Csimultaneously, so it is desirable for the routine that22 Cdetects and reports an error to identify the library name23 Cas well as the routine name.24 C 25 CSUBROU A character constant (or character variable) with the name26 Cof the routine that detected the error. Usually it is the27 Cname of the routine that is calling XERMSG. There are28 Csome instances where a user callable library routine calls29 Clower level subsidiary routines where the error is30 Cdetected. In such cases it may be more informative to31 Csupply the name of the routine the user called rather than32 Cthe name of the subsidiary routine that detected the33 Cerror.34 C 35 CMESSG A character constant (or character variable) with the text36 Cof the error or warning message. In the example below,37 Cthe message is a character constant that contains a38 Cgeneric message.39 C 40 CCALL XERMSG ('SLATEC', 'MMPY',41 C*'THE ORDER OF THE MATRIX EXCEEDS THE ROW DIMENSION',42 C*3, 1)43 C 44 CIt is possible (and is sometimes desirable) to generate a45 Cspecific message--e.g., one that contains actual numeric46 Cvalues. Specific numeric values can be converted into47 Ccharacter strings using formatted WRITE statements into48 Ccharacter variables. This is called standard Fortran49 Cinternal file I/O and is exemplified in the first three50 Clines of the following example. You can also catenate51 Csubstrings of characters to construct the error message.52 CHere is an example showing the use of both writing to53 Can internal file and catenating character strings.54 C 55 CCHARACTER*5 CHARN, CHARL56 CWRITE (CHARN,10) N57 CWRITE (CHARL,10) LDA58 C10 FORMAT(I5)59 CCALL XERMSG ('SLATEC', 'MMPY', 'THE ORDER'//CHARN//60 C* ' OF THE MATRIX EXCEEDS ITS ROW DIMENSION OF'//61 C* CHARL, 3, 1)62 C 63 CThere are two subtleties worth mentioning. One is that64 Cthe // for character catenation is used to construct the65 Cerror message so that no single character constant is66 Ccontinued to the next line. This avoids confusion as to67 Cwhether there are trailing blanks at the end of the line.68 CThe second is that by catenating the parts of the message69 Cas an actual argument rather than encoding the entire70 Cmessage into one large character variable, we avoid71 Chaving to know how long the message will be in order to72 Cdeclare an adequate length for that large character73 Cvariable. XERMSG calls XERPRN to print the message using74 Cmultiple lines if necessary. If the message is very long,75 CXERPRN will break it into pieces of 72 characters (as76 Crequested by XERMSG) for printing on multiple lines.77 CAlso, XERMSG asks XERPRN to prefix each line with ' * '78 Cso that the total line length could be 76 characters.79 CNote also that XERPRN scans the error message backwards80 Cto ignore trailing blanks. Another feature is that81 Cthe substring '$$' is treated as a new line sentinel82 Cby XERPRN. If you want to construct a multiline83 Cmessage without having to count out multiples of 7284 Ccharacters, just use '$$' as a separator. '$$'85 Cobviously must occur within 72 characters of the86 Cstart of each line to have its intended effect since87 CXERPRN is asked to wrap around at 72 characters in88 Caddition to looking for '$$'.89 C 90 CNERR An integer value that is chosen by the library routine's91 Cauthor. It must be in the range -99 to 999 (three92 Cprintable digits). Each distinct error should have its93 Cown error number. These error numbers should be described94 Cin the machine readable documentation for the routine.95 CThe error numbers need be unique only within each routine,96 Cso it is reasonable for each routine to start enumerating97 Cerrors from 1 and proceeding to the next integer.98 C 99 CLEVEL An integer value in the range 0 to 2 that indicates the100 Clevel (severity) of the error. Their meanings are101 C 102 C-1 A warning message. This is used if it is not clear103 Cthat there really is an error, but the user's attention104 Cmay be needed. An attempt is made to only print this105 Cmessage once.106 C 107 C0 A warning message. This is used if it is not clear108 Cthat there really is an error, but the user's attention109 Cmay be needed.110 C 111 C1 A recoverable error. This is used even if the error is112 Cso serious that the routine cannot return any useful113 Canswer. If the user has told the error package to114 Creturn after recoverable errors, then XERMSG will115 Creturn to the Library routine which can then return to116 Cthe user's routine. The user may also permit the error117 Cpackage to terminate the program upon encountering a118 Crecoverable error.119 C 120 C2 A fatal error. XERMSG will not return to its caller121 Cafter it receives a fatal error. This level should122 Chardly ever be used; it is much better to allow the123 Cuser a chance to recover. An example of one of the few124 Ccases in which it is permissible to declare a level 2125 Cerror is a reverse communication Library routine that126 Cis likely to be called repeatedly until it integrates127 Cacross some interval. If there is a serious error in128 Cthe input such that another step cannot be taken and129 Cthe Library routine is called again without the input130 Cerror having been corrected by the caller, the Library131 Croutine will probably be called forever with improper132 Cinput. In this case, it is reasonable to declare the133 Cerror to be fatal.134 C 135 CEach of the arguments to XERMSG is input; none will be modified by136 CXERMSG. A routine may make multiple calls to XERMSG with warning137 Clevel messages; however, after a call to XERMSG with a recoverable138 Cerror, the routine should return to the user. Do not try to call139 CXERMSG with a second recoverable error after the first recoverable140 Cerror because the error package saves the error number. The user141 Ccan retrieve this error number by calling another entry point in142 Cthe error handling package and then clear the error number when143 Crecovering from the error. Calling XERMSG in succession causes the144 Cold error number to be overwritten by the latest error number.145 CThis is considered harmless for error numbers associated with146 Cwarning messages but must not be done for error numbers of serious147 Cerrors. After a call to XERMSG with a recoverable error, the user148 Cmust be given a chance to call NUMXER or XERCLR to retrieve or149 Cclear the error number.150 C***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC151 CError-handling Package, SAND82-0800, Sandia152 CLaboratories, 1982.153 C***ROUTINES CALLED FDUMP, J4SAVE, XERCNT, XERHLT, XERPRN, XERSVE154 C***REVISION HISTORY (YYMMDD)155 C880101 DATE WRITTEN156 C880621 REVISED AS DIRECTED AT SLATEC CML MEETING OF FEBRUARY 1988.157 CTHERE ARE TWO BASIC CHANGES.158 C1. A NEW ROUTINE, XERPRN, IS USED INSTEAD OF XERPRT TO159 CPRINT MESSAGES. THIS ROUTINE WILL BREAK LONG MESSAGES160 CINTO PIECES FOR PRINTING ON MULTIPLE LINES. '$$' IS161 CACCEPTED AS A NEW LINE SENTINEL. A PREFIX CAN BE162 CADDED TO EACH LINE TO BE PRINTED. XERMSG USES EITHER163 C' ***' OR ' * ' AND LONG MESSAGES ARE BROKEN EVERY164 C72 CHARACTERS (AT MOST) SO THAT THE MAXIMUM LINE165 CLENGTH OUTPUT CAN NOW BE AS GREAT AS 76.166 C2. THE TEXT OF ALL MESSAGES IS NOW IN UPPER CASE SINCE THE167 CFORTRAN STANDARD DOCUMENT DOES NOT ADMIT THE EXISTENCE168 COF LOWER CASE.169 C880708 REVISED AFTER THE SLATEC CML MEETING OF JUNE 29 AND 30.170 CTHE PRINCIPAL CHANGES ARE171 C1. CLARIFY COMMENTS IN THE PROLOGUES172 C2. RENAME XRPRNT TO XERPRN173 C3. REWORK HANDLING OF '$$' IN XERPRN TO HANDLE BLANK LINES174 CSIMILAR TO THE WAY FORMAT STATEMENTS HANDLE THE /175 CCHARACTER FOR NEW RECORDS.176 C890706 REVISED WITH THE HELP OF FRED FRITSCH AND REG CLEMENS TO177 CCLEAN UP THE CODING.178 C890721 REVISED TO USE NEW FEATURE IN XERPRN TO COUNT CHARACTERS IN179 CPREFIX.180 C891013 REVISED TO CORRECT COMMENTS.181 C891214 Prologue converted to Version 4.0 format. (WRB)182 C900510 Changed test on NERR to be -9999999 < NERR < 99999999, but183 CNERR .ne. 0, and on LEVEL to be -2 < LEVEL < 3. Added184 CLEVEL=-1 logic, changed calls to XERSAV to XERSVE, and185 CXERCTL to XERCNT. (RWC)186 C920501 Reformatted the REFERENCES section. (WRB)187 C***END PROLOGUE XERMSG188 CHARACTER*(*)LIBRAR, SUBROU, MESSG189 CHARACTER*8XLIBR, XSUBR190 CHARACTER*72TEMP191 CHARACTER*20LFIRST192 INTEGERNERR, LEVEL, LKNTRL193 INTEGERJ4SAVE, MAXMES, KDUMMY, I, KOUNT, LERR, LLEVEL194 INTEGERMKNTRL, LTEMP195 C***FIRST EXECUTABLE STATEMENT XERMSG196 197 198 C 199 CLKNTRL IS A LOCAL COPY OF THE CONTROL FLAG KONTRL.200 CMAXMES IS THE MAXIMUM NUMBER OF TIMES ANY PARTICULAR MESSAGE201 CSHOULD BE PRINTED.202 C 203 CWE PRINT A FATAL ERROR MESSAGE AND TERMINATE FOR AN ERROR IN204 CCALLING XERMSG. THE ERROR NUMBER SHOULD BE POSITIVE,205 CAND THE LEVEL SHOULD BE BETWEEN 0 AND 2.206 C 207 IF (NERR.LT.-9999999 .OR. NERR.GT.99999999 .OR. NERR.EQ.0 .OR.208 *LEVEL.LT.-1 .OR. LEVEL.GT.2) THEN209 CALL XERPRN (' ***', -1, 'FATAL ERROR IN...$$ ' //210 * 'XERMSG -- INVALID ERROR NUMBER OR LEVEL$$ '//211 *'JOB ABORT DUE TO FATAL ERROR.', 72)212 213 214 215 216 C 217 CRECORD THE MESSAGE.218 C 219 220 221 C 222 CHANDLE PRINT-ONCE WARNING MESSAGES.223 C 224 225 C 226 CALLOW TEMPORARY USER OVERRIDE OF THE CONTROL FLAG.227 C 228 229 230 231 232 233 234 C 235 236 237 C 238 CSKIP PRINTING IF THE CONTROL FLAG VALUE AS RESET IN XERCNT IS239 CZERO AND THE ERROR IS NOT FATAL.240 C 241 242 243 244 245 C 246 CANNOUNCE THE NAMES OF THE LIBRARY AND SUBROUTINE BY BUILDING A247 CMESSAGE IN CHARACTER VARIABLE TEMP (NOT EXCEEDING 66 CHARACTERS)248 CAND SENDING IT OUT VIA XERPRN. PRINT ONLY IF CONTROL FLAG249 CIS NOT ZERO.250 C 251 252 253 254 255 256 257 258 259 260 261 262 263 C 264 CIF LKNTRL IS POSITIVE, PRINT AN INTRODUCTORY LINE BEFORE265 CPRINTING THE MESSAGE. THE INTRODUCTORY LINE TELLS THE CHOICE266 CFROM EACH OF THE FOLLOWING THREE OPTIONS.267 C1. LEVEL OF THE MESSAGE268 C'INFORMATIVE MESSAGE'269 C'POTENTIALLY RECOVERABLE ERROR'270 C'FATAL ERROR'271 C2. WHETHER CONTROL FLAG WILL ALLOW PROGRAM TO CONTINUE272 C'PROG CONTINUES'273 C'PROG ABORTED'274 C3. WHETHER OR NOT A TRACEBACK WAS REQUESTED. (THE TRACEBACK275 CMAY NOT BE IMPLEMENTED AT SOME SITES, SO THIS ONLY TELLS276 CWHAT WAS REQUESTED, NOT WHAT WAS DELIVERED.)277 C'TRACEBACK REQUESTED'278 C'TRACEBACK NOT REQUESTED'279 CNOTICE THAT THE LINE INCLUDING FOUR PREFIX CHARACTERS WILL NOT280 CEXCEED 74 CHARACTERS.281 CWE SKIP THE NEXT BLOCK IF THE INTRODUCTORY LINE IS NOT NEEDED.282 C 283 284 C 285 CTHE FIRST PART OF THE MESSAGE TELLS ABOUT THE LEVEL.286 C 287 288 289 290 291 292 293 294 295 296 297 C 298 CTHEN WHETHER THE PROGRAM WILL CONTINUE.299 C 300 IF ((MKNTRL.EQ.2 .AND. LEVEL.GE.1) .OR.301 *(MKNTRL.EQ.1 .AND. LEVEL.EQ.2)) THEN302 303 304 305 306 307 308 C 309 CFINALLY TELL WHETHER THERE SHOULD BE A TRACEBACK.310 C 311 312 313 314 315 316 317 318 319 320 C 321 CNOW SEND OUT THE MESSAGE.322 C 323 324 C 325 CIF LKNTRL IS POSITIVE, WRITE THE ERROR NUMBER AND REQUEST A326 CTRACEBACK.327 C 328 329 330 DO 10I=16,22331 332 10 CONTINUE333 C 334 20 335 336 337 C 338 CIF LKNTRL IS NOT ZERO, PRINT A BLANK LINE AND AN END OF MESSAGE.339 C 340 341 342 343 344 345 C 346 CIF THE ERROR IS NOT FATAL OR THE ERROR IS RECOVERABLE AND THE347 CCONTROL FLAG IS SET FOR RECOVERY, THEN RETURN.348 C 349 30 IF (LEVEL.LE.0 .OR. (LEVEL.EQ.1 .AND. MKNTRL.LE.1)) RETURN350 C 351 CTHE PROGRAM WILL BE STOPPED DUE TO AN UNRECOVERED ERROR OR A352 CFATAL ERROR. PRINT THE REASON FOR THE ABORT AND THE ERROR353 CSUMMARY IF THE CONTROL FLAG AND THE MAXIMUM ERROR COUNT PERMIT.354 C 355 356 357 CALL XERPRN358 *(' ***', -1, 'JOB ABORT DUE TO UNRECOVERED ERROR.', 72)359 360 361 362 363 364 365 366 367 368 END 1 !DECK XERMSG 2 SUBROUTINE XERMSG (LIBRAR, SUBROU, MESSG, NERR, LEVEL) 3 IMPLICIT NONE 4 !***BEGIN PROLOGUE XERMSG 5 !***PURPOSE Process error messages for SLATEC and other libraries. 6 !***LIBRARY SLATEC (XERROR) 7 !***CATEGORY R3C 8 !***TYPE ALL (XERMSG-A) 9 !***KEYWORDS ERROR MESSAGE, XERROR 10 !***AUTHOR Fong, Kirby, (NMFECC at LLNL) 11 !***DESCRIPTION 12 ! 13 ! XERMSG processes a diagnostic message in a manner determined by the 14 ! value of LEVEL and the current value of the library error control 15 ! flag, KONTRL. See subroutine XSETF for details. 16 ! 17 ! LIBRAR A character constant (or character variable) with the name 18 ! of the library. This will be 'SLATEC' for the SLATEC 19 ! Common Math Library. The error handling package is 20 ! general enough to be used by many libraries 21 ! simultaneously, so it is desirable for the routine that 22 ! detects and reports an error to identify the library name 23 ! as well as the routine name. 24 ! 25 ! SUBROU A character constant (or character variable) with the name 26 ! of the routine that detected the error. Usually it is the 27 ! name of the routine that is calling XERMSG. There are 28 ! some instances where a user callable library routine calls 29 ! lower level subsidiary routines where the error is 30 ! detected. In such cases it may be more informative to 31 ! supply the name of the routine the user called rather than 32 ! the name of the subsidiary routine that detected the 33 ! error. 34 ! 35 ! MESSG A character constant (or character variable) with the text 36 ! of the error or warning message. In the example below, 37 ! the message is a character constant that contains a 38 ! generic message. 39 ! 40 ! CALL XERMSG ('SLATEC', 'MMPY', 41 ! *'THE ORDER OF THE MATRIX EXCEEDS THE ROW DIMENSION', 42 ! *3, 1) 43 ! 44 ! It is possible (and is sometimes desirable) to generate a 45 ! specific message--e.g., one that contains actual numeric 46 ! values. Specific numeric values can be converted into 47 ! character strings using formatted WRITE statements into 48 ! character variables. This is called standard Fortran 49 ! internal file I/O and is exemplified in the first three 50 ! lines of the following example. You can also catenate 51 ! substrings of characters to construct the error message. 52 ! Here is an example showing the use of both writing to 53 ! an internal file and catenating character strings. 54 ! 55 ! CHARACTER*5 CHARN, CHARL 56 ! WRITE (CHARN,10) N 57 ! WRITE (CHARL,10) LDA 58 ! 10 FORMAT(I5) 59 ! CALL XERMSG ('SLATEC', 'MMPY', 'THE ORDER'//CHARN// 60 ! * ' OF THE MATRIX EXCEEDS ITS ROW DIMENSION OF'// 61 ! * CHARL, 3, 1) 62 ! 63 ! There are two subtleties worth mentioning. One is that 64 ! the // for character catenation is used to construct the 65 ! error message so that no single character constant is 66 ! continued to the next line. This avoids confusion as to 67 ! whether there are trailing blanks at the end of the line. 68 ! The second is that by catenating the parts of the message 69 ! as an actual argument rather than encoding the entire 70 ! message into one large character variable, we avoid 71 ! having to know how long the message will be in order to 72 ! declare an adequate length for that large character 73 ! variable. XERMSG calls XERPRN to print the message using 74 ! multiple lines if necessary. If the message is very long, 75 ! XERPRN will break it into pieces of 72 characters (as 76 ! requested by XERMSG) for printing on multiple lines. 77 ! Also, XERMSG asks XERPRN to prefix each line with ' * ' 78 ! so that the total line length could be 76 characters. 79 ! Note also that XERPRN scans the error message backwards 80 ! to ignore trailing blanks. Another feature is that 81 ! the substring '$$' is treated as a new line sentinel 82 ! by XERPRN. If you want to construct a multiline 83 ! message without having to count out multiples of 72 84 ! characters, just use '$$' as a separator. '$$' 85 ! obviously must occur within 72 characters of the 86 ! start of each line to have its intended effect since 87 ! XERPRN is asked to wrap around at 72 characters in 88 ! addition to looking for '$$'. 89 ! 90 ! NERR An integer value that is chosen by the library routine's 91 ! author. It must be in the range -99 to 999 (three 92 ! printable digits). Each distinct error should have its 93 ! own error number. These error numbers should be described 94 ! in the machine readable documentation for the routine. 95 ! The error numbers need be unique only within each routine, 96 ! so it is reasonable for each routine to start enumerating 97 ! errors from 1 and proceeding to the next integer. 98 ! 99 ! LEVEL An integer value in the range 0 to 2 that indicates the 100 ! level (severity) of the error. Their meanings are 101 ! 102 ! -1 A warning message. This is used if it is not clear 103 ! that there really is an error, but the user's attention 104 ! may be needed. An attempt is made to only print this 105 ! message once. 106 ! 107 ! 0 A warning message. This is used if it is not clear 108 ! that there really is an error, but the user's attention 109 ! may be needed. 110 ! 111 ! 1 A recoverable error. This is used even if the error is 112 ! so serious that the routine cannot return any useful 113 ! answer. If the user has told the error package to 114 ! return after recoverable errors, then XERMSG will 115 ! return to the Library routine which can then return to 116 ! the user's routine. The user may also permit the error 117 ! package to terminate the program upon encountering a 118 ! recoverable error. 119 ! 120 ! 2 A fatal error. XERMSG will not return to its caller 121 ! after it receives a fatal error. This level should 122 ! hardly ever be used; it is much better to allow the 123 ! user a chance to recover. An example of one of the few 124 ! cases in which it is permissible to declare a level 2 125 ! error is a reverse communication Library routine that 126 ! is likely to be called repeatedly until it integrates 127 ! across some interval. If there is a serious error in 128 ! the input such that another step cannot be taken and 129 ! the Library routine is called again without the input 130 ! error having been corrected by the caller, the Library 131 ! routine will probably be called forever with improper 132 ! input. In this case, it is reasonable to declare the 133 ! error to be fatal. 134 ! 135 ! Each of the arguments to XERMSG is input; none will be modified by 136 ! XERMSG. A routine may make multiple calls to XERMSG with warning 137 ! level messages; however, after a call to XERMSG with a recoverable 138 ! error, the routine should return to the user. Do not try to call 139 ! XERMSG with a second recoverable error after the first recoverable 140 ! error because the error package saves the error number. The user 141 ! can retrieve this error number by calling another entry point in 142 ! the error handling package and then clear the error number when 143 ! recovering from the error. Calling XERMSG in succession causes the 144 ! old error number to be overwritten by the latest error number. 145 ! This is considered harmless for error numbers associated with 146 ! warning messages but must not be done for error numbers of serious 147 ! errors. After a call to XERMSG with a recoverable error, the user 148 ! must be given a chance to call NUMXER or XERCLR to retrieve or 149 ! clear the error number. 150 !***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC 151 ! Error-handling Package, SAND82-0800, Sandia 152 ! Laboratories, 1982. 153 !***ROUTINES CALLED FDUMP, J4SAVE, XERCNT, XERHLT, XERPRN, XERSVE 154 !***REVISION HISTORY (YYMMDD) 155 ! 880101 DATE WRITTEN 156 ! 880621 REVISED AS DIRECTED AT SLATEC CML MEETING OF FEBRUARY 1988. 157 ! THERE ARE TWO BASIC CHANGES. 158 ! 1. A NEW ROUTINE, XERPRN, IS USED INSTEAD OF XERPRT TO 159 ! PRINT MESSAGES. THIS ROUTINE WILL BREAK LONG MESSAGES 160 ! INTO PIECES FOR PRINTING ON MULTIPLE LINES. '$$' IS 161 ! ACCEPTED AS A NEW LINE SENTINEL. A PREFIX CAN BE 162 ! ADDED TO EACH LINE TO BE PRINTED. XERMSG USES EITHER 163 ! ' ***' OR ' * ' AND LONG MESSAGES ARE BROKEN EVERY 164 ! 72 CHARACTERS (AT MOST) SO THAT THE MAXIMUM LINE 165 ! LENGTH OUTPUT CAN NOW BE AS GREAT AS 76. 166 ! 2. THE TEXT OF ALL MESSAGES IS NOW IN UPPER CASE SINCE THE 167 ! FORTRAN STANDARD DOCUMENT DOES NOT ADMIT THE EXISTENCE 168 ! OF LOWER CASE. 169 ! 880708 REVISED AFTER THE SLATEC CML MEETING OF JUNE 29 AND 30. 170 ! THE PRINCIPAL CHANGES ARE 171 ! 1. CLARIFY COMMENTS IN THE PROLOGUES 172 ! 2. RENAME XRPRNT TO XERPRN 173 ! 3. REWORK HANDLING OF '$$' IN XERPRN TO HANDLE BLANK LINES 174 ! SIMILAR TO THE WAY FORMAT STATEMENTS HANDLE THE / 175 ! CHARACTER FOR NEW RECORDS. 176 ! 890706 REVISED WITH THE HELP OF FRED FRITSCH AND REG CLEMENS TO 177 ! CLEAN UP THE CODING. 178 ! 890721 REVISED TO USE NEW FEATURE IN XERPRN TO COUNT CHARACTERS IN 179 ! PREFIX. 180 ! 891013 REVISED TO CORRECT COMMENTS. 181 ! 891214 Prologue converted to Version 4.0 format. (WRB) 182 ! 900510 Changed test on NERR to be -9999999 < NERR < 99999999, but 183 ! NERR .ne. 0, and on LEVEL to be -2 < LEVEL < 3. Added 184 ! LEVEL=-1 logic, changed calls to XERSAV to XERSVE, and 185 ! XERCTL to XERCNT. (RWC) 186 ! 920501 Reformatted the REFERENCES section. (WRB) 187 !***END PROLOGUE XERMSG 188 CHARACTER(len=*) :: LIBRAR, SUBROU, MESSG 189 CHARACTER(len=8) :: XLIBR, XSUBR 190 CHARACTER(len=72) :: TEMP 191 CHARACTER(len=20) :: LFIRST 192 INTEGER :: NERR, LEVEL, LKNTRL 193 INTEGER :: J4SAVE, MAXMES, KDUMMY, I, KOUNT, LERR, LLEVEL 194 INTEGER :: MKNTRL, LTEMP 195 !***FIRST EXECUTABLE STATEMENT XERMSG 196 LKNTRL = J4SAVE (2, 0, .FALSE.) 197 MAXMES = J4SAVE (4, 0, .FALSE.) 198 ! 199 ! LKNTRL IS A LOCAL COPY OF THE CONTROL FLAG KONTRL. 200 ! MAXMES IS THE MAXIMUM NUMBER OF TIMES ANY PARTICULAR MESSAGE 201 ! SHOULD BE PRINTED. 202 ! 203 ! WE PRINT A FATAL ERROR MESSAGE AND TERMINATE FOR AN ERROR IN 204 ! CALLING XERMSG. THE ERROR NUMBER SHOULD BE POSITIVE, 205 ! AND THE LEVEL SHOULD BE BETWEEN 0 AND 2. 206 ! 207 IF (NERR.LT.-9999999 .OR. NERR.GT.99999999 .OR. NERR.EQ.0 .OR. & 208 LEVEL.LT.-1 .OR. LEVEL.GT.2) THEN 209 CALL XERPRN (' ***', -1, 'FATAL ERROR IN...$$ ' // & 210 'XERMSG -- INVALID ERROR NUMBER OR LEVEL$$ '// & 211 'JOB ABORT DUE TO FATAL ERROR.', 72) 212 CALL XERSVE (' ', ' ', ' ', 0, 0, 0, KDUMMY) 213 CALL XERHLT (' ***XERMSG -- INVALID INPUT') 214 RETURN 215 ENDIF 216 ! 217 ! RECORD THE MESSAGE. 218 ! 219 I = J4SAVE (1, NERR, .TRUE.) 220 CALL XERSVE (LIBRAR, SUBROU, MESSG, 1, NERR, LEVEL, KOUNT) 221 ! 222 ! HANDLE PRINT-ONCE WARNING MESSAGES. 223 ! 224 IF (LEVEL.EQ.-1 .AND. KOUNT.GT.1) RETURN 225 ! 226 ! ALLOW TEMPORARY USER OVERRIDE OF THE CONTROL FLAG. 227 ! 228 XLIBR = LIBRAR 229 XSUBR = SUBROU 230 LFIRST = MESSG 231 LERR = NERR 232 LLEVEL = LEVEL 233 CALL XERCNT (XLIBR, XSUBR, LFIRST, LERR, LLEVEL, LKNTRL) 234 ! 235 LKNTRL = MAX(-2, MIN(2,LKNTRL)) 236 MKNTRL = ABS(LKNTRL) 237 ! 238 ! SKIP PRINTING IF THE CONTROL FLAG VALUE AS RESET IN XERCNT IS 239 ! ZERO AND THE ERROR IS NOT FATAL. 240 ! 241 IF (LEVEL.LT.2 .AND. LKNTRL.EQ.0) GO TO 30 242 IF (LEVEL.EQ.0 .AND. KOUNT.GT.MAXMES) GO TO 30 243 IF (LEVEL.EQ.1 .AND. KOUNT.GT.MAXMES .AND. MKNTRL.EQ.1) GO TO 30 244 IF (LEVEL.EQ.2 .AND. KOUNT.GT.MAX(1,MAXMES)) GO TO 30 245 ! 246 ! ANNOUNCE THE NAMES OF THE LIBRARY AND SUBROUTINE BY BUILDING A 247 ! MESSAGE IN CHARACTER VARIABLE TEMP (NOT EXCEEDING 66 CHARACTERS) 248 ! AND SENDING IT OUT VIA XERPRN. PRINT ONLY IF CONTROL FLAG 249 ! IS NOT ZERO. 250 ! 251 IF (LKNTRL .NE. 0) THEN 252 TEMP(1:21) = 'MESSAGE FROM ROUTINE ' 253 I = MIN(LEN(SUBROU), 16) 254 TEMP(22:21+I) = SUBROU(1:I) 255 TEMP(22+I:33+I) = ' IN LIBRARY ' 256 LTEMP = 33 + I 257 I = MIN(LEN(LIBRAR), 16) 258 TEMP(LTEMP+1:LTEMP+I) = LIBRAR (1:I) 259 TEMP(LTEMP+I+1:LTEMP+I+1) = '.' 260 LTEMP = LTEMP + I + 1 261 CALL XERPRN (' ***', -1, TEMP(1:LTEMP), 72) 262 ENDIF 263 ! 264 ! IF LKNTRL IS POSITIVE, PRINT AN INTRODUCTORY LINE BEFORE 265 ! PRINTING THE MESSAGE. THE INTRODUCTORY LINE TELLS THE CHOICE 266 ! FROM EACH OF THE FOLLOWING THREE OPTIONS. 267 ! 1. LEVEL OF THE MESSAGE 268 ! 'INFORMATIVE MESSAGE' 269 ! 'POTENTIALLY RECOVERABLE ERROR' 270 ! 'FATAL ERROR' 271 ! 2. WHETHER CONTROL FLAG WILL ALLOW PROGRAM TO CONTINUE 272 ! 'PROG CONTINUES' 273 ! 'PROG ABORTED' 274 ! 3. WHETHER OR NOT A TRACEBACK WAS REQUESTED. (THE TRACEBACK 275 ! MAY NOT BE IMPLEMENTED AT SOME SITES, SO THIS ONLY TELLS 276 ! WHAT WAS REQUESTED, NOT WHAT WAS DELIVERED.) 277 ! 'TRACEBACK REQUESTED' 278 ! 'TRACEBACK NOT REQUESTED' 279 ! NOTICE THAT THE LINE INCLUDING FOUR PREFIX CHARACTERS WILL NOT 280 ! EXCEED 74 CHARACTERS. 281 ! WE SKIP THE NEXT BLOCK IF THE INTRODUCTORY LINE IS NOT NEEDED. 282 ! 283 IF (LKNTRL .GT. 0) THEN 284 ! 285 ! THE FIRST PART OF THE MESSAGE TELLS ABOUT THE LEVEL. 286 ! 287 IF (LEVEL .LE. 0) THEN 288 TEMP(1:20) = 'INFORMATIVE MESSAGE,' 289 LTEMP = 20 290 ELSEIF (LEVEL .EQ. 1) THEN 291 TEMP(1:30) = 'POTENTIALLY RECOVERABLE ERROR,' 292 LTEMP = 30 293 ELSE 294 TEMP(1:12) = 'FATAL ERROR,' 295 LTEMP = 12 296 ENDIF 297 ! 298 ! THEN WHETHER THE PROGRAM WILL CONTINUE. 299 ! 300 IF ((MKNTRL.EQ.2 .AND. LEVEL.GE.1) .OR. & 301 (MKNTRL.EQ.1 .AND. LEVEL.EQ.2)) THEN 302 TEMP(LTEMP+1:LTEMP+14) = ' PROG ABORTED,' 303 LTEMP = LTEMP + 14 304 ELSE 305 TEMP(LTEMP+1:LTEMP+16) = ' PROG CONTINUES,' 306 LTEMP = LTEMP + 16 307 ENDIF 308 ! 309 ! FINALLY TELL WHETHER THERE SHOULD BE A TRACEBACK. 310 ! 311 IF (LKNTRL .GT. 0) THEN 312 TEMP(LTEMP+1:LTEMP+20) = ' TRACEBACK REQUESTED' 313 LTEMP = LTEMP + 20 314 ELSE 315 TEMP(LTEMP+1:LTEMP+24) = ' TRACEBACK NOT REQUESTED' 316 LTEMP = LTEMP + 24 317 ENDIF 318 CALL XERPRN (' ***', -1, TEMP(1:LTEMP), 72) 319 ENDIF 320 ! 321 ! NOW SEND OUT THE MESSAGE. 322 ! 323 CALL XERPRN (' * ', -1, MESSG, 72) 324 ! 325 ! IF LKNTRL IS POSITIVE, WRITE THE ERROR NUMBER AND REQUEST A 326 ! TRACEBACK. 327 ! 328 IF (LKNTRL .GT. 0) THEN 329 WRITE (TEMP, '(''ERROR NUMBER = '', I8)') NERR 330 DO I=16,22 331 IF (TEMP(I:I) .NE. ' ') GO TO 20 332 END DO 333 ! 334 20 CALL XERPRN (' * ', -1, TEMP(1:15) // TEMP(I:23), 72) 335 CALL FDUMP 336 ENDIF 337 ! 338 ! IF LKNTRL IS NOT ZERO, PRINT A BLANK LINE AND AN END OF MESSAGE. 339 ! 340 IF (LKNTRL .NE. 0) THEN 341 CALL XERPRN (' * ', -1, ' ', 72) 342 CALL XERPRN (' ***', -1, 'END OF MESSAGE', 72) 343 CALL XERPRN (' ', 0, ' ', 72) 344 ENDIF 345 ! 346 ! IF THE ERROR IS NOT FATAL OR THE ERROR IS RECOVERABLE AND THE 347 ! CONTROL FLAG IS SET FOR RECOVERY, THEN RETURN. 348 ! 349 30 IF (LEVEL.LE.0 .OR. (LEVEL.EQ.1 .AND. MKNTRL.LE.1)) RETURN 350 ! 351 ! THE PROGRAM WILL BE STOPPED DUE TO AN UNRECOVERED ERROR OR A 352 ! FATAL ERROR. PRINT THE REASON FOR THE ABORT AND THE ERROR 353 ! SUMMARY IF THE CONTROL FLAG AND THE MAXIMUM ERROR COUNT PERMIT. 354 ! 355 IF (LKNTRL.GT.0 .AND. KOUNT.LT.MAX(1,MAXMES)) THEN 356 IF (LEVEL .EQ. 1) THEN 357 CALL XERPRN & 358 (' ***', -1, 'JOB ABORT DUE TO UNRECOVERED ERROR.', 72) 359 ELSE 360 CALL XERPRN(' ***', -1, 'JOB ABORT DUE TO FATAL ERROR.', 72) 361 ENDIF 362 CALL XERSVE (' ', ' ', ' ', -1, 0, 0, KDUMMY) 363 CALL XERHLT (' ') 364 ELSE 365 CALL XERHLT (MESSG) 366 ENDIF 367 RETURN 368 END SUBROUTINE XERMSG -
LMDZ6/trunk/libf/misc/xerprn.f90
r5245 r5246 1 *DECK XERPRN2 3 4 C***BEGIN PROLOGUE XERPRN5 C***SUBSIDIARY6 C***PURPOSE Print error messages processed by XERMSG.7 C***LIBRARY SLATEC (XERROR)8 C***CATEGORY R3C9 C***TYPE ALL (XERPRN-A)10 C***KEYWORDS ERROR MESSAGES, PRINTING, XERROR11 C***AUTHOR Fong, Kirby, (NMFECC at LLNL)12 C***DESCRIPTION13 C 14 CThis routine sends one or more lines to each of the (up to five)15 Clogical units to which error messages are to be sent. This routine16 Cis called several times by XERMSG, sometimes with a single line to17 Cprint and sometimes with a (potentially very long) message that may18 Cwrap around into multiple lines.19 C 20 CPREFIX Input argument of type CHARACTER. This argument contains21 Ccharacters to be put at the beginning of each line before22 Cthe body of the message. No more than 16 characters of23 CPREFIX will be used.24 C 25 CNPREF Input argument of type INTEGER. This argument is the number26 Cof characters to use from PREFIX. If it is negative, the27 Cintrinsic function LEN is used to determine its length. If28 Cit is zero, PREFIX is not used. If it exceeds 16 or if29 CLEN(PREFIX) exceeds 16, only the first 16 characters will be30 Cused. If NPREF is positive and the length of PREFIX is less31 Cthan NPREF, a copy of PREFIX extended with blanks to length32 CNPREF will be used.33 C 34 CMESSG Input argument of type CHARACTER. This is the text of a35 Cmessage to be printed. If it is a long message, it will be36 Cbroken into pieces for printing on multiple lines. Each line37 Cwill start with the appropriate prefix and be followed by a38 Cpiece of the message. NWRAP is the number of characters per39 Cpiece; that is, after each NWRAP characters, we break and40 Cstart a new line. In addition the characters '$$' embedded41 Cin MESSG are a sentinel for a new line. The counting of42 Ccharacters up to NWRAP starts over for each new line. The43 Cvalue of NWRAP typically used by XERMSG is 72 since many44 Colder error messages in the SLATEC Library are laid out to45 Crely on wrap-around every 72 characters.46 C 47 CNWRAP Input argument of type INTEGER. This gives the maximum size48 Cpiece into which to break MESSG for printing on multiple49 Clines. An embedded '$$' ends a line, and the count restarts50 Cat the following character. If a line break does not occur51 Con a blank (it would split a word) that word is moved to the52 Cnext line. Values of NWRAP less than 16 will be treated as53 C16. Values of NWRAP greater than 132 will be treated as 132.54 CThe actual line length will be NPREF + NWRAP after NPREF has55 Cbeen adjusted to fall between 0 and 16 and NWRAP has been56 Cadjusted to fall between 16 and 132.57 C 58 C***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC59 CError-handling Package, SAND82-0800, Sandia60 CLaboratories, 1982.61 C***ROUTINES CALLED I1MACH, XGETUA62 C***REVISION HISTORY (YYMMDD)63 C880621 DATE WRITTEN64 C880708 REVISED AFTER THE SLATEC CML SUBCOMMITTEE MEETING OF65 CJUNE 29 AND 30 TO CHANGE THE NAME TO XERPRN AND TO REWORK66 CTHE HANDLING OF THE NEW LINE SENTINEL TO BEHAVE LIKE THE67 CSLASH CHARACTER IN FORMAT STATEMENTS.68 C890706 REVISED WITH THE HELP OF FRED FRITSCH AND REG CLEMENS TO69 CSTREAMLINE THE CODING AND FIX A BUG THAT CAUSED EXTRA BLANK70 CLINES TO BE PRINTED.71 C890721 REVISED TO ADD A NEW FEATURE. A NEGATIVE VALUE OF NPREF72 CCAUSES LEN(PREFIX) TO BE USED AS THE LENGTH.73 C891013 REVISED TO CORRECT ERROR IN CALCULATING PREFIX LENGTH.74 C891214 Prologue converted to Version 4.0 format. (WRB)75 C900510 Added code to break messages between words. (RWC)76 C920501 Reformatted the REFERENCES section. (WRB)77 C***END PROLOGUE XERPRN78 CHARACTER*(*)PREFIX, MESSG79 INTEGERNPREF, NWRAP80 CHARACTER*148CBUFF81 INTEGERIU(5), NUNIT82 CHARACTER*2NEWLIN83 84 INTEGERN, I1MACH, I, LPREF, LWRAP, LENMSG, NEXTC85 INTEGERLPIECE, IDELTA86 C***FIRST EXECUTABLE STATEMENT XERPRN87 88 C 89 CA ZERO VALUE FOR A LOGICAL UNIT NUMBER MEANS TO USE THE STANDARD90 CERROR MESSAGE UNIT INSTEAD. I1MACH(4) RETRIEVES THE STANDARD91 CERROR MESSAGE UNIT.92 C 93 94 DO 10I=1,NUNIT95 96 10 CONTINUE97 C 98 CLPREF IS THE LENGTH OF THE PREFIX. THE PREFIX IS PLACED AT THE99 CBEGINNING OF CBUFF, THE CHARACTER BUFFER, AND KEPT THERE DURING100 CTHE REST OF THIS ROUTINE.101 C 102 103 104 105 106 107 108 109 C 110 CLWRAP IS THE MAXIMUM NUMBER OF CHARACTERS WE WANT TO TAKE AT ONE111 CTIME FROM MESSG TO PRINT ON ONE LINE.112 C 113 114 C 115 CSET LENMSG TO THE LENGTH OF MESSG, IGNORE ANY TRAILING BLANKS.116 C 117 118 119 DO 20I=1,N120 121 122 20 CONTINUE123 30 CONTINUE124 C 125 CIF THE MESSAGE IS ALL BLANKS, THEN PRINT ONE BLANK LINE.126 C 127 128 129 DO 40I=1,NUNIT130 131 40 CONTINUE132 133 134 C 135 CSET NEXTC TO THE POSITION IN MESSG WHERE THE NEXT SUBSTRING136 CSTARTS. FROM THIS POSITION WE SCAN FOR THE NEW LINE SENTINEL.137 CWHEN NEXTC EXCEEDS LENMSG, THERE IS NO MORE TO PRINT.138 CWE LOOP BACK TO LABEL 50 UNTIL ALL PIECES HAVE BEEN PRINTED.139 C 140 CWE LOOK FOR THE NEXT OCCURRENCE OF THE NEW LINE SENTINEL. THE141 CINDEX INTRINSIC FUNCTION RETURNS ZERO IF THERE IS NO OCCURRENCE142 COR IF THE LENGTH OF THE FIRST ARGUMENT IS LESS THAN THE LENGTH143 COF THE SECOND ARGUMENT.144 C 145 CTHERE ARE SEVERAL CASES WHICH SHOULD BE CHECKED FOR IN THE146 CFOLLOWING ORDER. WE ARE ATTEMPTING TO SET LPIECE TO THE NUMBER147 COF CHARACTERS THAT SHOULD BE TAKEN FROM MESSG STARTING AT148 CPOSITION NEXTC.149 C 150 CLPIECE .EQ. 0 THE NEW LINE SENTINEL DOES NOT OCCUR IN THE151 CREMAINDER OF THE CHARACTER STRING. LPIECE152 CSHOULD BE SET TO LWRAP OR LENMSG+1-NEXTC,153 CWHICHEVER IS LESS.154 C 155 CLPIECE .EQ. 1 THE NEW LINE SENTINEL STARTS AT MESSG(NEXTC:156 CNEXTC). LPIECE IS EFFECTIVELY ZERO, AND WE157 CPRINT NOTHING TO AVOID PRODUCING UNNECESSARY158 CBLANK LINES. THIS TAKES CARE OF THE SITUATION159 CWHERE THE LIBRARY ROUTINE HAS A MESSAGE OF160 CEXACTLY 72 CHARACTERS FOLLOWED BY A NEW LINE161 CSENTINEL FOLLOWED BY MORE CHARACTERS. NEXTC162 CSHOULD BE INCREMENTED BY 2.163 C 164 CLPIECE .GT. LWRAP+1 REDUCE LPIECE TO LWRAP.165 C 166 CELSE THIS LAST CASE MEANS 2 .LE. LPIECE .LE. LWRAP+1167 CRESET LPIECE = LPIECE-1. NOTE THAT THIS168 CPROPERLY HANDLES THE END CASE WHERE LPIECE .EQ.169 CLWRAP+1. THAT IS, THE SENTINEL FALLS EXACTLY170 CAT THE END OF A LINE.171 C 172 173 50 LPIECE = INDEX(MESSG(NEXTC:LENMSG), NEWLIN)174 175 C 176 CTHERE WAS NO NEW LINE SENTINEL FOUND.177 C 178 179 180 181 DO 52I=LPIECE+1,2,-1182 183 184 185 186 187 52 CONTINUE188 189 54 190 191 192 C 193 CWE HAVE A NEW LINE SENTINEL AT MESSG(NEXTC:NEXTC+1).194 CDON'T PRINT A BLANK LINE.195 C 196 197 198 199 C 200 CLPIECE SHOULD BE SET DOWN TO LWRAP.201 C 202 203 204 DO 56I=LPIECE+1,2,-1205 206 207 208 209 210 56 CONTINUE211 58 212 213 214 C 215 CIF WE ARRIVE HERE, IT MEANS 2 .LE. LPIECE .LE. LWRAP+1.216 CWE SHOULD DECREMENT LPIECE BY ONE.217 C 218 219 220 221 222 C 223 CPRINT224 C 225 DO 60I=1,NUNIT226 227 60 CONTINUE228 C 229 230 231 END 1 !DECK XERPRN 2 SUBROUTINE XERPRN (PREFIX, NPREF, MESSG, NWRAP) 3 IMPLICIT NONE 4 !***BEGIN PROLOGUE XERPRN 5 !***SUBSIDIARY 6 !***PURPOSE Print error messages processed by XERMSG. 7 !***LIBRARY SLATEC (XERROR) 8 !***CATEGORY R3C 9 !***TYPE ALL (XERPRN-A) 10 !***KEYWORDS ERROR MESSAGES, PRINTING, XERROR 11 !***AUTHOR Fong, Kirby, (NMFECC at LLNL) 12 !***DESCRIPTION 13 ! 14 ! This routine sends one or more lines to each of the (up to five) 15 ! logical units to which error messages are to be sent. This routine 16 ! is called several times by XERMSG, sometimes with a single line to 17 ! print and sometimes with a (potentially very long) message that may 18 ! wrap around into multiple lines. 19 ! 20 ! PREFIX Input argument of type CHARACTER. This argument contains 21 ! characters to be put at the beginning of each line before 22 ! the body of the message. No more than 16 characters of 23 ! PREFIX will be used. 24 ! 25 ! NPREF Input argument of type INTEGER. This argument is the number 26 ! of characters to use from PREFIX. If it is negative, the 27 ! intrinsic function LEN is used to determine its length. If 28 ! it is zero, PREFIX is not used. If it exceeds 16 or if 29 ! LEN(PREFIX) exceeds 16, only the first 16 characters will be 30 ! used. If NPREF is positive and the length of PREFIX is less 31 ! than NPREF, a copy of PREFIX extended with blanks to length 32 ! NPREF will be used. 33 ! 34 ! MESSG Input argument of type CHARACTER. This is the text of a 35 ! message to be printed. If it is a long message, it will be 36 ! broken into pieces for printing on multiple lines. Each line 37 ! will start with the appropriate prefix and be followed by a 38 ! piece of the message. NWRAP is the number of characters per 39 ! piece; that is, after each NWRAP characters, we break and 40 ! start a new line. In addition the characters '$$' embedded 41 ! in MESSG are a sentinel for a new line. The counting of 42 ! characters up to NWRAP starts over for each new line. The 43 ! value of NWRAP typically used by XERMSG is 72 since many 44 ! older error messages in the SLATEC Library are laid out to 45 ! rely on wrap-around every 72 characters. 46 ! 47 ! NWRAP Input argument of type INTEGER. This gives the maximum size 48 ! piece into which to break MESSG for printing on multiple 49 ! lines. An embedded '$$' ends a line, and the count restarts 50 ! at the following character. If a line break does not occur 51 ! on a blank (it would split a word) that word is moved to the 52 ! next line. Values of NWRAP less than 16 will be treated as 53 ! 16. Values of NWRAP greater than 132 will be treated as 132. 54 ! The actual line length will be NPREF + NWRAP after NPREF has 55 ! been adjusted to fall between 0 and 16 and NWRAP has been 56 ! adjusted to fall between 16 and 132. 57 ! 58 !***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC 59 ! Error-handling Package, SAND82-0800, Sandia 60 ! Laboratories, 1982. 61 !***ROUTINES CALLED I1MACH, XGETUA 62 !***REVISION HISTORY (YYMMDD) 63 ! 880621 DATE WRITTEN 64 ! 880708 REVISED AFTER THE SLATEC CML SUBCOMMITTEE MEETING OF 65 ! JUNE 29 AND 30 TO CHANGE THE NAME TO XERPRN AND TO REWORK 66 ! THE HANDLING OF THE NEW LINE SENTINEL TO BEHAVE LIKE THE 67 ! SLASH CHARACTER IN FORMAT STATEMENTS. 68 ! 890706 REVISED WITH THE HELP OF FRED FRITSCH AND REG CLEMENS TO 69 ! STREAMLINE THE CODING AND FIX A BUG THAT CAUSED EXTRA BLANK 70 ! LINES TO BE PRINTED. 71 ! 890721 REVISED TO ADD A NEW FEATURE. A NEGATIVE VALUE OF NPREF 72 ! CAUSES LEN(PREFIX) TO BE USED AS THE LENGTH. 73 ! 891013 REVISED TO CORRECT ERROR IN CALCULATING PREFIX LENGTH. 74 ! 891214 Prologue converted to Version 4.0 format. (WRB) 75 ! 900510 Added code to break messages between words. (RWC) 76 ! 920501 Reformatted the REFERENCES section. (WRB) 77 !***END PROLOGUE XERPRN 78 CHARACTER(len=*) :: PREFIX, MESSG 79 INTEGER :: NPREF, NWRAP 80 CHARACTER(len=148) :: CBUFF 81 INTEGER :: IU(5), NUNIT 82 CHARACTER(len=2) :: NEWLIN 83 PARAMETER (NEWLIN = '$$') 84 INTEGER :: N, I1MACH, I, LPREF, LWRAP, LENMSG, NEXTC 85 INTEGER :: LPIECE, IDELTA 86 !***FIRST EXECUTABLE STATEMENT XERPRN 87 CALL XGETUA(IU,NUNIT) 88 ! 89 ! A ZERO VALUE FOR A LOGICAL UNIT NUMBER MEANS TO USE THE STANDARD 90 ! ERROR MESSAGE UNIT INSTEAD. I1MACH(4) RETRIEVES THE STANDARD 91 ! ERROR MESSAGE UNIT. 92 ! 93 N = I1MACH(4) 94 DO I=1,NUNIT 95 IF (IU(I) .EQ. 0) IU(I) = N 96 END DO 97 ! 98 ! LPREF IS THE LENGTH OF THE PREFIX. THE PREFIX IS PLACED AT THE 99 ! BEGINNING OF CBUFF, THE CHARACTER BUFFER, AND KEPT THERE DURING 100 ! THE REST OF THIS ROUTINE. 101 ! 102 IF ( NPREF .LT. 0 ) THEN 103 LPREF = LEN(PREFIX) 104 ELSE 105 LPREF = NPREF 106 ENDIF 107 LPREF = MIN(16, LPREF) 108 IF (LPREF .NE. 0) CBUFF(1:LPREF) = PREFIX 109 ! 110 ! LWRAP IS THE MAXIMUM NUMBER OF CHARACTERS WE WANT TO TAKE AT ONE 111 ! TIME FROM MESSG TO PRINT ON ONE LINE. 112 ! 113 LWRAP = MAX(16, MIN(132, NWRAP)) 114 ! 115 ! SET LENMSG TO THE LENGTH OF MESSG, IGNORE ANY TRAILING BLANKS. 116 ! 117 LENMSG = LEN(MESSG) 118 N = LENMSG 119 DO I=1,N 120 IF (MESSG(LENMSG:LENMSG) .NE. ' ') GO TO 30 121 LENMSG = LENMSG - 1 122 END DO 123 30 CONTINUE 124 ! 125 ! IF THE MESSAGE IS ALL BLANKS, THEN PRINT ONE BLANK LINE. 126 ! 127 IF (LENMSG .EQ. 0) THEN 128 CBUFF(LPREF+1:LPREF+1) = ' ' 129 DO I=1,NUNIT 130 WRITE(IU(I), '(A)') CBUFF(1:LPREF+1) 131 END DO 132 RETURN 133 ENDIF 134 ! 135 ! SET NEXTC TO THE POSITION IN MESSG WHERE THE NEXT SUBSTRING 136 ! STARTS. FROM THIS POSITION WE SCAN FOR THE NEW LINE SENTINEL. 137 ! WHEN NEXTC EXCEEDS LENMSG, THERE IS NO MORE TO PRINT. 138 ! WE LOOP BACK TO LABEL 50 UNTIL ALL PIECES HAVE BEEN PRINTED. 139 ! 140 ! WE LOOK FOR THE NEXT OCCURRENCE OF THE NEW LINE SENTINEL. THE 141 ! INDEX INTRINSIC FUNCTION RETURNS ZERO IF THERE IS NO OCCURRENCE 142 ! OR IF THE LENGTH OF THE FIRST ARGUMENT IS LESS THAN THE LENGTH 143 ! OF THE SECOND ARGUMENT. 144 ! 145 ! THERE ARE SEVERAL CASES WHICH SHOULD BE CHECKED FOR IN THE 146 ! FOLLOWING ORDER. WE ARE ATTEMPTING TO SET LPIECE TO THE NUMBER 147 ! OF CHARACTERS THAT SHOULD BE TAKEN FROM MESSG STARTING AT 148 ! POSITION NEXTC. 149 ! 150 ! LPIECE .EQ. 0 THE NEW LINE SENTINEL DOES NOT OCCUR IN THE 151 ! REMAINDER OF THE CHARACTER STRING. LPIECE 152 ! SHOULD BE SET TO LWRAP OR LENMSG+1-NEXTC, 153 ! WHICHEVER IS LESS. 154 ! 155 ! LPIECE .EQ. 1 THE NEW LINE SENTINEL STARTS AT MESSG(NEXTC: 156 ! NEXTC). LPIECE IS EFFECTIVELY ZERO, AND WE 157 ! PRINT NOTHING TO AVOID PRODUCING UNNECESSARY 158 ! BLANK LINES. THIS TAKES CARE OF THE SITUATION 159 ! WHERE THE LIBRARY ROUTINE HAS A MESSAGE OF 160 ! EXACTLY 72 CHARACTERS FOLLOWED BY A NEW LINE 161 ! SENTINEL FOLLOWED BY MORE CHARACTERS. NEXTC 162 ! SHOULD BE INCREMENTED BY 2. 163 ! 164 ! LPIECE .GT. LWRAP+1 REDUCE LPIECE TO LWRAP. 165 ! 166 ! ELSE THIS LAST CASE MEANS 2 .LE. LPIECE .LE. LWRAP+1 167 ! RESET LPIECE = LPIECE-1. NOTE THAT THIS 168 ! PROPERLY HANDLES THE END CASE WHERE LPIECE .EQ. 169 ! LWRAP+1. THAT IS, THE SENTINEL FALLS EXACTLY 170 ! AT THE END OF A LINE. 171 ! 172 NEXTC = 1 173 50 LPIECE = INDEX(MESSG(NEXTC:LENMSG), NEWLIN) 174 IF (LPIECE .EQ. 0) THEN 175 ! 176 ! THERE WAS NO NEW LINE SENTINEL FOUND. 177 ! 178 IDELTA = 0 179 LPIECE = MIN(LWRAP, LENMSG+1-NEXTC) 180 IF (LPIECE .LT. LENMSG+1-NEXTC) THEN 181 DO I=LPIECE+1,2,-1 182 IF (MESSG(NEXTC+I-1:NEXTC+I-1) .EQ. ' ') THEN 183 LPIECE = I-1 184 IDELTA = 1 185 GOTO 54 186 ENDIF 187 END DO 188 ENDIF 189 54 CBUFF(LPREF+1:LPREF+LPIECE) = MESSG(NEXTC:NEXTC+LPIECE-1) 190 NEXTC = NEXTC + LPIECE + IDELTA 191 ELSEIF (LPIECE .EQ. 1) THEN 192 ! 193 ! WE HAVE A NEW LINE SENTINEL AT MESSG(NEXTC:NEXTC+1). 194 ! DON'T PRINT A BLANK LINE. 195 ! 196 NEXTC = NEXTC + 2 197 GO TO 50 198 ELSEIF (LPIECE .GT. LWRAP+1) THEN 199 ! 200 ! LPIECE SHOULD BE SET DOWN TO LWRAP. 201 ! 202 IDELTA = 0 203 LPIECE = LWRAP 204 DO I=LPIECE+1,2,-1 205 IF (MESSG(NEXTC+I-1:NEXTC+I-1) .EQ. ' ') THEN 206 LPIECE = I-1 207 IDELTA = 1 208 GOTO 58 209 ENDIF 210 END DO 211 58 CBUFF(LPREF+1:LPREF+LPIECE) = MESSG(NEXTC:NEXTC+LPIECE-1) 212 NEXTC = NEXTC + LPIECE + IDELTA 213 ELSE 214 ! 215 ! IF WE ARRIVE HERE, IT MEANS 2 .LE. LPIECE .LE. LWRAP+1. 216 ! WE SHOULD DECREMENT LPIECE BY ONE. 217 ! 218 LPIECE = LPIECE - 1 219 CBUFF(LPREF+1:LPREF+LPIECE) = MESSG(NEXTC:NEXTC+LPIECE-1) 220 NEXTC = NEXTC + LPIECE + 2 221 ENDIF 222 ! 223 ! PRINT 224 ! 225 DO I=1,NUNIT 226 WRITE(IU(I), '(A)') CBUFF(1:LPREF+LPIECE) 227 END DO 228 ! 229 IF (NEXTC .LE. LENMSG) GO TO 50 230 RETURN 231 END SUBROUTINE XERPRN -
LMDZ6/trunk/libf/misc/xersve.f90
r5245 r5246 1 *DECK XERSVE2 SUBROUTINE XERSVE (LIBRAR, SUBROU, MESSG, KFLAG, NERR, LEVEL, 3 +ICOUNT)4 5 C***BEGIN PROLOGUE XERSVE6 C***SUBSIDIARY7 C***PURPOSE Record that an error has occurred.8 C***LIBRARY SLATEC (XERROR)9 C***CATEGORY R310 C***TYPE ALL (XERSVE-A)11 C***KEYWORDS ERROR, XERROR12 C***AUTHOR Jones, R. E., (SNLA)13 C***DESCRIPTION14 C 15 C*Usage:16 C 17 CINTEGER KFLAG, NERR, LEVEL, ICOUNT18 CCHARACTER * (len) LIBRAR, SUBROU, MESSG19 C 20 CCALL XERSVE (LIBRAR, SUBROU, MESSG, KFLAG, NERR, LEVEL, ICOUNT)21 C 22 C*Arguments:23 C 24 CLIBRAR :IN is the library that the message is from.25 CSUBROU :IN is the subroutine that the message is from.26 CMESSG :IN is the message to be saved.27 CKFLAG :IN indicates the action to be performed.28 Cwhen KFLAG > 0, the message in MESSG is saved.29 Cwhen KFLAG=0 the tables will be dumped and30 Ccleared.31 Cwhen KFLAG < 0, the tables will be dumped and32 Cnot cleared.33 CNERR :IN is the error number.34 CLEVEL :IN is the error severity.35 CICOUNT :OUT the number of times this message has been seen,36 Cor zero if the table has overflowed and does not37 Ccontain this message specifically. When KFLAG=0,38 CICOUNT will not be altered.39 C 40 C*Description:41 C 42 CRecord that this error occurred and possibly dump and clear the43 Ctables.44 C 45 C***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC46 CError-handling Package, SAND82-0800, Sandia47 CLaboratories, 1982.48 C***ROUTINES CALLED I1MACH, XGETUA49 C***REVISION HISTORY (YYMMDD)50 C800319 DATE WRITTEN51 C861211 REVISION DATE from Version 3.252 C891214 Prologue converted to Version 4.0 format. (BAB)53 C900413 Routine modified to remove reference to KFLAG. (WRB)54 C900510 Changed to add LIBRARY NAME and SUBROUTINE to calling55 Csequence, use IF-THEN-ELSE, make number of saved entries56 Ceasily changeable, changed routine name from XERSAV to57 CXERSVE. (RWC)58 C910626 Added LIBTAB and SUBTAB to SAVE statement. (BKS)59 C920501 Reformatted the REFERENCES section. (WRB)60 C***END PROLOGUE XERSVE61 62 INTEGERLUN(5)63 CHARACTER*(*)LIBRAR, SUBROU, MESSG64 CHARACTER*8LIBTAB(LENTAB), SUBTAB(LENTAB), LIB, SUB65 CHARACTER*20MESTAB(LENTAB), MES66 67 68 69 INTEGERNERR,LEVEL,KONTRL70 INTEGERNERTAB, LEVTAB, KOUNT, KOUNTX, NMSG71 INTEGERKFLAG, ICOUNT, NUNIT, KUNIT, IUNIT, I1MACH, I72 C***FIRST EXECUTABLE STATEMENT XERSVE73 C 74 75 C 76 CDump the table.77 C 78 79 C 80 CPrint to each unit.81 C 82 83 DO 20KUNIT = 1,NUNIT84 85 86 C 87 CPrint the table header.88 C 89 90 C 91 CPrint body of table.92 C 93 DO 10I = 1,NMSG94 WRITE (IUNIT,9010) LIBTAB(I), SUBTAB(I), MESTAB(I),95 *NERTAB(I),LEVTAB(I),KOUNT(I)96 10 CONTINUE97 C 98 CPrint number of other errors.99 C 100 101 102 20 CONTINUE103 C 104 CClear the error tables.105 C 106 107 108 109 110 111 C 112 CPROCESS A MESSAGE...113 CSEARCH FOR THIS MESSG, OR ELSE AN EMPTY SLOT FOR THIS MESSG,114 COR ELSE DETERMINE THAT THE ERROR TABLE IS FULL.115 C 116 117 118 119 DO 30I = 1,NMSG120 IF (LIB.EQ.LIBTAB(I) .AND. SUB.EQ.SUBTAB(I) .AND.121 * MES.EQ.MESTAB(I) .AND. NERR.EQ.NERTAB(I) .AND.122 *LEVEL.EQ.LEVTAB(I)) THEN123 124 125 126 127 30 CONTINUE128 C 129 130 C 131 CEmpty slot found for new message.132 C 133 134 135 136 137 138 139 140 141 142 C 143 CTable is full.144 C 145 146 147 148 149 150 C 151 CFormats.152 C 153 9000 FORMAT ('0 ERROR MESSAGE SUMMARY' /154 + ' LIBRARY SUBROUTINE MESSAGE START NERR',155 +' LEVEL COUNT')156 9010 FORMAT (1X,A,3X,A,3X,A,3I10)157 9020 FORMAT ('0OTHER ERRORS NOT INDIVIDUALLY TABULATED = ', I10)158 9030 FORMAT (1X)159 END 1 !DECK XERSVE 2 SUBROUTINE XERSVE (LIBRAR, SUBROU, MESSG, KFLAG, NERR, LEVEL, & 3 ICOUNT) 4 IMPLICIT NONE 5 !***BEGIN PROLOGUE XERSVE 6 !***SUBSIDIARY 7 !***PURPOSE Record that an error has occurred. 8 !***LIBRARY SLATEC (XERROR) 9 !***CATEGORY R3 10 !***TYPE ALL (XERSVE-A) 11 !***KEYWORDS ERROR, XERROR 12 !***AUTHOR Jones, R. E., (SNLA) 13 !***DESCRIPTION 14 ! 15 ! *Usage: 16 ! 17 ! INTEGER KFLAG, NERR, LEVEL, ICOUNT 18 ! CHARACTER * (len) LIBRAR, SUBROU, MESSG 19 ! 20 ! CALL XERSVE (LIBRAR, SUBROU, MESSG, KFLAG, NERR, LEVEL, ICOUNT) 21 ! 22 ! *Arguments: 23 ! 24 ! LIBRAR :IN is the library that the message is from. 25 ! SUBROU :IN is the subroutine that the message is from. 26 ! MESSG :IN is the message to be saved. 27 ! KFLAG :IN indicates the action to be performed. 28 ! when KFLAG > 0, the message in MESSG is saved. 29 ! when KFLAG=0 the tables will be dumped and 30 ! cleared. 31 ! when KFLAG < 0, the tables will be dumped and 32 ! not cleared. 33 ! NERR :IN is the error number. 34 ! LEVEL :IN is the error severity. 35 ! ICOUNT :OUT the number of times this message has been seen, 36 ! or zero if the table has overflowed and does not 37 ! contain this message specifically. When KFLAG=0, 38 ! ICOUNT will not be altered. 39 ! 40 ! *Description: 41 ! 42 ! Record that this error occurred and possibly dump and clear the 43 ! tables. 44 ! 45 !***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC 46 ! Error-handling Package, SAND82-0800, Sandia 47 ! Laboratories, 1982. 48 !***ROUTINES CALLED I1MACH, XGETUA 49 !***REVISION HISTORY (YYMMDD) 50 ! 800319 DATE WRITTEN 51 ! 861211 REVISION DATE from Version 3.2 52 ! 891214 Prologue converted to Version 4.0 format. (BAB) 53 ! 900413 Routine modified to remove reference to KFLAG. (WRB) 54 ! 900510 Changed to add LIBRARY NAME and SUBROUTINE to calling 55 ! sequence, use IF-THEN-ELSE, make number of saved entries 56 ! easily changeable, changed routine name from XERSAV to 57 ! XERSVE. (RWC) 58 ! 910626 Added LIBTAB and SUBTAB to SAVE statement. (BKS) 59 ! 920501 Reformatted the REFERENCES section. (WRB) 60 !***END PROLOGUE XERSVE 61 INTEGER,PARAMETER :: LENTAB=10 62 INTEGER :: LUN(5) 63 CHARACTER(len=*) :: LIBRAR, SUBROU, MESSG 64 CHARACTER(len=8) :: LIBTAB(LENTAB), SUBTAB(LENTAB), LIB, SUB 65 CHARACTER(len=20) :: MESTAB(LENTAB), MES 66 DIMENSION NERTAB(LENTAB), LEVTAB(LENTAB), KOUNT(LENTAB) 67 SAVE LIBTAB, SUBTAB, MESTAB, NERTAB, LEVTAB, KOUNT, KOUNTX, NMSG 68 DATA KOUNTX/0/, NMSG/0/ 69 INTEGER :: NERR,LEVEL,KONTRL 70 INTEGER :: NERTAB, LEVTAB, KOUNT, KOUNTX, NMSG 71 INTEGER :: KFLAG, ICOUNT, NUNIT, KUNIT, IUNIT, I1MACH, I 72 !***FIRST EXECUTABLE STATEMENT XERSVE 73 ! 74 IF (KFLAG.LE.0) THEN 75 ! 76 ! Dump the table. 77 ! 78 IF (NMSG.EQ.0) RETURN 79 ! 80 ! Print to each unit. 81 ! 82 CALL XGETUA (LUN, NUNIT) 83 DO KUNIT = 1,NUNIT 84 IUNIT = LUN(KUNIT) 85 IF (IUNIT.EQ.0) IUNIT = I1MACH(4) 86 ! 87 ! Print the table header. 88 ! 89 WRITE (IUNIT,9000) 90 ! 91 ! Print body of table. 92 ! 93 DO I = 1,NMSG 94 WRITE (IUNIT,9010) LIBTAB(I), SUBTAB(I), MESTAB(I), & 95 NERTAB(I),LEVTAB(I),KOUNT(I) 96 END DO 97 ! 98 ! Print number of other errors. 99 ! 100 IF (KOUNTX.NE.0) WRITE (IUNIT,9020) KOUNTX 101 WRITE (IUNIT,9030) 102 END DO 103 ! 104 ! Clear the error tables. 105 ! 106 IF (KFLAG.EQ.0) THEN 107 NMSG = 0 108 KOUNTX = 0 109 ENDIF 110 ELSE 111 ! 112 ! PROCESS A MESSAGE... 113 ! SEARCH FOR THIS MESSG, OR ELSE AN EMPTY SLOT FOR THIS MESSG, 114 ! OR ELSE DETERMINE THAT THE ERROR TABLE IS FULL. 115 ! 116 LIB = LIBRAR 117 SUB = SUBROU 118 MES = MESSG 119 DO I = 1,NMSG 120 IF (LIB.EQ.LIBTAB(I) .AND. SUB.EQ.SUBTAB(I) .AND. & 121 MES.EQ.MESTAB(I) .AND. NERR.EQ.NERTAB(I) .AND. & 122 LEVEL.EQ.LEVTAB(I)) THEN 123 KOUNT(I) = KOUNT(I) + 1 124 ICOUNT = KOUNT(I) 125 RETURN 126 ENDIF 127 END DO 128 ! 129 IF (NMSG.LT.LENTAB) THEN 130 ! 131 ! Empty slot found for new message. 132 ! 133 NMSG = NMSG + 1 134 LIBTAB(I) = LIB 135 SUBTAB(I) = SUB 136 MESTAB(I) = MES 137 NERTAB(I) = NERR 138 LEVTAB(I) = LEVEL 139 KOUNT (I) = 1 140 ICOUNT = 1 141 ELSE 142 ! 143 ! Table is full. 144 ! 145 KOUNTX = KOUNTX+1 146 ICOUNT = 0 147 ENDIF 148 ENDIF 149 RETURN 150 ! 151 ! Formats. 152 ! 153 9000 FORMAT ('0 ERROR MESSAGE SUMMARY' / & 154 ' LIBRARY SUBROUTINE MESSAGE START NERR', & 155 ' LEVEL COUNT') 156 9010 FORMAT (1X,A,3X,A,3X,A,3I10) 157 9020 FORMAT ('0OTHER ERRORS NOT INDIVIDUALLY TABULATED = ', I10) 158 9030 FORMAT (1X) 159 END SUBROUTINE XERSVE -
LMDZ6/trunk/libf/misc/xgetua.f90
r5245 r5246 1 *DECK XGETUA2 3 4 C***BEGIN PROLOGUE XGETUA5 C***PURPOSE Return unit number(s) to which error messages are being6 Csent.7 C***LIBRARY SLATEC (XERROR)8 C***CATEGORY R3C9 C***TYPE ALL (XGETUA-A)10 C***KEYWORDS ERROR, XERROR11 C***AUTHOR Jones, R. E., (SNLA)12 C***DESCRIPTION13 C 14 CAbstract15 CXGETUA may be called to determine the unit number or numbers16 Cto which error messages are being sent.17 CThese unit numbers may have been set by a call to XSETUN,18 Cor a call to XSETUA, or may be a default value.19 C 20 CDescription of Parameters21 C--Output--22 CIUNIT - an array of one to five unit numbers, depending23 Con the value of N. A value of zero refers to the24 Cdefault unit, as defined by the I1MACH machine25 Cconstant routine. Only IUNIT(1),...,IUNIT(N) are26 Cdefined by XGETUA. The values of IUNIT(N+1),...,27 CIUNIT(5) are not defined (for N .LT. 5) or altered28 Cin any way by XGETUA.29 CN - the number of units to which copies of the30 Cerror messages are being sent. N will be in the31 Crange from 1 to 5.32 C 33 C***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC34 CError-handling Package, SAND82-0800, Sandia35 CLaboratories, 1982.36 C***ROUTINES CALLED J4SAVE37 C***REVISION HISTORY (YYMMDD)38 C790801 DATE WRITTEN39 C861211 REVISION DATE from Version 3.240 C891214 Prologue converted to Version 4.0 format. (BAB)41 C920501 Reformatted the REFERENCES section. (WRB)42 C***END PROLOGUE XGETUA43 44 INTEGERIUNITA, N, J4SAVE, INDEX, I45 C***FIRST EXECUTABLE STATEMENT XGETUA46 47 DO 30I=1,N48 49 50 51 30 CONTINUE52 53 END 1 !DECK XGETUA 2 SUBROUTINE XGETUA (IUNITA, N) 3 IMPLICIT NONE 4 !***BEGIN PROLOGUE XGETUA 5 !***PURPOSE Return unit number(s) to which error messages are being 6 ! sent. 7 !***LIBRARY SLATEC (XERROR) 8 !***CATEGORY R3C 9 !***TYPE ALL (XGETUA-A) 10 !***KEYWORDS ERROR, XERROR 11 !***AUTHOR Jones, R. E., (SNLA) 12 !***DESCRIPTION 13 ! 14 ! Abstract 15 ! XGETUA may be called to determine the unit number or numbers 16 ! to which error messages are being sent. 17 ! These unit numbers may have been set by a call to XSETUN, 18 ! or a call to XSETUA, or may be a default value. 19 ! 20 ! Description of Parameters 21 ! --Output-- 22 ! IUNIT - an array of one to five unit numbers, depending 23 ! on the value of N. A value of zero refers to the 24 ! default unit, as defined by the I1MACH machine 25 ! constant routine. Only IUNIT(1),...,IUNIT(N) are 26 ! defined by XGETUA. The values of IUNIT(N+1),..., 27 ! IUNIT(5) are not defined (for N .LT. 5) or altered 28 ! in any way by XGETUA. 29 ! N - the number of units to which copies of the 30 ! error messages are being sent. N will be in the 31 ! range from 1 to 5. 32 ! 33 !***REFERENCES R. E. Jones and D. K. Kahaner, XERROR, the SLATEC 34 ! Error-handling Package, SAND82-0800, Sandia 35 ! Laboratories, 1982. 36 !***ROUTINES CALLED J4SAVE 37 !***REVISION HISTORY (YYMMDD) 38 ! 790801 DATE WRITTEN 39 ! 861211 REVISION DATE from Version 3.2 40 ! 891214 Prologue converted to Version 4.0 format. (BAB) 41 ! 920501 Reformatted the REFERENCES section. (WRB) 42 !***END PROLOGUE XGETUA 43 DIMENSION IUNITA(5) 44 INTEGER :: IUNITA, N, J4SAVE, INDEX, I 45 !***FIRST EXECUTABLE STATEMENT XGETUA 46 N = J4SAVE(5,0,.FALSE.) 47 DO I=1,N 48 INDEX = I+4 49 IF (I.EQ.1) INDEX = 3 50 IUNITA(I) = J4SAVE(INDEX,0,.FALSE.) 51 END DO 52 RETURN 53 END SUBROUTINE XGETUA
Note: See TracChangeset
for help on using the changeset viewer.