Changeset 2582 for trunk/LMDZ.GENERIC/libf/phystd/tpindex.F
- Timestamp:
- Nov 9, 2021, 12:56:40 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.GENERIC/libf/phystd/tpindex.F
r1616 r2582 1 module tpindex_mod 2 3 implicit none 4 5 contains 6 1 7 subroutine tpindex(pw,tw,qvar,pref,tref,wrefvar,LCOEF,MT,MP, 2 8 & NVAR,wratio) … … 34 40 ! PW - The pressure to interpolate to 35 41 ! TW - The temperature to interpolate to 36 ! Pref(NP) - The pressure grid array 37 ! Tref(NT) - The temperature grid array 42 ! Qvar - The abundance to interpolate to 43 ! Pref - The tabulated (log) pressure grid 44 ! Tref - The tabulated temperature grid 45 ! WREFVAR - The tabulated abundance grid 38 46 ! 39 47 ! Outputs 40 48 ! ------- 41 ! TI - Interpolation term (pressure)42 ! UI - Interpolation term (temperature)43 49 ! MT - Temperature index (bottom left temperature) 44 50 ! of bounding box 45 51 ! MP - Pressure index (bottom left pressure) 46 52 ! of bounding box 53 ! NVAR - index (bottom left ) 54 ! of bounding box 55 ! LCOEF(4) - Interpolation coefficients 56 ! WRATIO - weight for the interpolation of abundance 47 57 ! 48 58 ! Authors … … 52 62 !================================================================== 53 63 54 use radinc_h 64 use radinc_h, only: L_PINT, L_NTREF, L_REFVAR 55 65 56 66 implicit none 57 67 58 real*8 Tref(L_NTREF) 59 real*8 pref(L_PINT) 60 real*8 wrefvar(L_REFVAR) 68 REAL,INTENT(IN) :: Tref(L_NTREF) 69 REAL,INTENT(IN) :: pref(L_PINT) 70 REAL,INTENT(IN) :: wrefvar(L_REFVAR) 71 REAL,INTENT(IN) :: PW, TW, Qvar 61 72 62 integer MT, MP, N, M, NP, NVAR 63 real*8 PW, TW, Qvar, wratio 64 real*8 PWL, LCOEF(4), T, U 73 INTEGER,INTENT(OUT) :: MT, MP, NVAR 74 REAL,INTENT(OUT) :: LCOEF(4), wratio 75 76 INTEGER :: N 77 REAL :: PWL ! local value for log10(PW) 78 REAL :: TWL ! local value for TW 79 REAL :: T ! linear interpolation weight along log(pressure) 80 REAL :: U ! linear interpolation weight along temperature 65 81 66 C======================================================================C 67 82 ! 1. For the interpolation along temperature 68 83 ! Get the upper and lower temperature grid indicies that bound the 69 ! requested temperature. If the requested temperature is outside 70 ! the T-grid, set up to extrapolate from the appropriate end. 71 ! TW : temperature to be interpolated 72 ! TREF : grid array 73 ! MT : index of TREF for bounding new temperature 74 ! U : new index (real) for temperature interpolated 84 ! requested temperature. If the sought temperature is below 85 ! the T-grid minimum, assume that lower value. If the sought teperature 86 ! is above the T-grid maximum, extrapolate. 87 ! TW : temperature to interpolate to 88 ! TREF : reference temperature array 89 ! MT : index of TREF for (lower) bounding temperature 90 ! U : weight for interpolation in temperature 75 91 76 IF(TW.LE.TREF(1)) THEN 92 TWL = TW 93 94 IF(TWL.LT.TREF(1)) THEN 95 ! Below lowest tabulated temperature 77 96 MT = 1 78 IF (TW.LT.TREF(1)) THEN79 97 TWL=TREF(1)*1.00 98 write(*,*) 'tpindex: Caution! Temperature of upper levels lower 80 99 $ than ref temperature for k-coef: k-coeff fixed for upper levels' 81 write(*,*) " TW=",TW 82 write(*,*) " TREF(1)=",TREF(1) 83 ENDIF 84 ELSE 100 write(*,*) " TW=",TWL 101 write(*,*) " TREF(1)=",TREF(1) 102 ELSEIF(TWL.GE.TREF(L_NTREF)) THEN 103 ! Above highest tabulated temperature 104 MT = L_NTREF-1 105 ELSE 106 ! Regular case, find encompassing tabulated temperatures 85 107 do n=1,L_NTREF-1 86 if(tw.gt.Tref(n) .and. TW.LE.TREF(N+1)) then108 IF (TWL.GE.TREF(N) .and. TWL.LT.TREF(N+1)) THEN 87 109 MT = n 88 goto 10 89 end if 90 end do 91 92 MT = L_NTREF-1 110 EXIT 111 END IF 112 END DO 93 113 94 10 continue95 114 END IF 96 115 97 !TB15 : case low temp : MT=1: fixed TW right above tref(1) 98 IF (MT.eq.1) THEN 99 TW=tref(1)*1.00 100 ! write(*,*) 'tpindex: Caution! Temperature of upper levels lower 101 ! $than ref temperature for k-coef: k-coeff fixed for upper levels' 102 ! write(*,*) " TW=",TW 103 ! write(*,*) " TREF(1)=",TREF(1) 104 ENDIF 116 ! weight for the temperature interpolation 117 U = (TWL-TREF(MT))/(TREF(MT+1)-TREF(MT)) 105 118 106 U = (TW-TREF(MT))/(TREF(MT+1)-TREF(MT)) 119 ! 2. For interpolation along pressure 120 ! Get the upper and lower pressure grid indicies that bound the 121 ! requested pressure. If the sought pressure is below 122 ! the P-grid minimum, assume that lower value. If the sought pressure 123 ! is above the P-grid maximum, extrapolate. 107 124 108 ! Get the upper and lower pressure grid indicies that bound the 109 ! requested pressure. If the requested pressure is outside 110 ! the P-grid, set up to extrapolate from the appropriate end. 125 PWL = log10(PW) 111 126 112 pwl = log10(pw) 127 IF(PWL.LT.PREF(1)) THEN 128 ! Below lowest tabulated pressure 129 MP = 1 130 PWL=Pref(1)*1.00 131 write(*,*) 'tpindex: Caution! Pressure of upper levels lower 132 $than ref pressure for k-coef: k-coeff fixed for upper levels' 133 write(*,*) " PWL=",PWL 134 write(*,*) " PREF(1)=",PREF(1) 135 ELSEIF(PWL.GE.PREF(L_PINT)) THEN 136 ! Above highest tabulated pressure 137 MP = L_PINT-1 138 ELSE 139 ! Regular case, find encompassing tabulated pressures 140 do n=1,L_PINT-1 141 IF (PWL.GE.PREF(N) .and. PWL.LT.PREF(N+1)) THEN 142 MP = n 143 EXIT 144 END IF 145 END DO 146 147 END IF 113 148 114 do n=2,L_PINT-1 115 if(pwl.le.Pref(n)) then 116 MP = n-1 117 goto 20 118 end if 119 end do 120 121 MP = L_PINT-1 122 123 20 continue 124 125 !TB15 : case low pressure : n=2 : fixed pwl, right above pref(1) 126 IF (MP.eq.1) THEN 127 IF (PWL.LT.PREF(1)) THEN 128 write(*,*) 'tpindex: Caution! Pressure of upper levels lower 129 $than ref pressure for k-coef: k-coeff fixed for upper levels' 130 write(*,*) " PWL=",PWL 131 write(*,*) " PREF(1)=",PREF(1) 132 ENDIF 133 PWL=Pref(1)*1.00 134 ENDIF 135 136 ! interpolated pressure 149 ! weight for the pressure interpolation 137 150 T = (PWL-PREF(MP))/(PREF(MP+1)-PREF(MP)) 138 151 139 ! Fill in the interpolation coefficients152 ! Build the interpolation coefficients (bilinear in temperature-log(pressure)) 140 153 LCOEF(1) = (1.0-T)*(1.0-U) 141 154 LCOEF(2) = T*(1.0-U) … … 143 156 LCOEF(4) = (1.0-T)*U 144 157 158 ! 3. For interpolation along abundances 145 159 ! Get the indicies for abundance of the varying species. There are 10 sets of 146 160 ! k-coefficients with differing amounts of variable vs. constant gas. 147 161 148 IF(QVAR.le.WREFVAR(1)) then 162 IF(QVAR.LE.WREFVAR(1)) THEN 163 ! Below lowest tabulated abundance 149 164 NVAR = 1 150 165 WRATIO = 0.0D0 ! put all the weight on the first point 151 ELSEIF(QVAR.ge.WREFVAR(L_REFVAR)) then 166 ELSEIF(QVAR.GE.WREFVAR(L_REFVAR)) THEN 167 ! Above highest tabulated abundance 152 168 NVAR = L_REFVAR-1 ! TB16 in order to not oversize NVAr when doing 153 169 !NVAR+1 154 170 WRATIO = 1.00D0 ! put all the weight on the last point 155 171 ELSE 172 ! Regular case, find encompassing tabulated abundances 173 ! and compute corresponding weight 156 174 DO N=2,L_REFVAR 157 IF(QVAR.GE.WREFVAR(N-1) .and. QVAR. lt.WREFVAR(N)) then175 IF(QVAR.GE.WREFVAR(N-1) .and. QVAR.LT.WREFVAR(N)) THEN 158 176 NVAR = N-1 159 177 WRATIO = (QVAR - WREFVAR(N-1))/(WREFVAR(N) - WREFVAR(N-1)) 160 GOTO 30178 EXIT 161 179 END IF 162 180 END DO 163 181 END IF 164 182 165 30 CONTINUE166 167 return168 end183 end subroutine tpindex 184 185 end module tpindex_mod 186
Note: See TracChangeset
for help on using the changeset viewer.