[42] | 1 | subroutine meso_readtesassim(ngrid,nlayer,zday,pplev,tauref,day_translate) |
---|
| 2 | |
---|
| 3 | ! Reading of the dust assimilation file |
---|
| 4 | |
---|
| 5 | implicit none |
---|
| 6 | |
---|
| 7 | include "dimensions.h" |
---|
| 8 | include "dimphys.h" |
---|
| 9 | include "comgeomfi.h" |
---|
| 10 | include "netcdf.inc" |
---|
| 11 | include "datafile.h" |
---|
| 12 | |
---|
| 13 | integer, intent(in) :: ngrid,nlayer |
---|
| 14 | real, intent(in) :: zday ! date in martian days |
---|
| 15 | real, dimension(ngrid,nlayer+1), intent(in) :: pplev |
---|
| 16 | real, dimension(ngrid), intent(out) :: tauref |
---|
| 17 | |
---|
| 18 | ! Local variables |
---|
| 19 | |
---|
| 20 | real :: realday |
---|
| 21 | integer nid,nvarid,ierr |
---|
| 22 | integer ltloop,lsloop,iloop,jloop,varloop,ig |
---|
| 23 | real, dimension(2) :: taubuf |
---|
| 24 | real tau1(4),tau |
---|
| 25 | real alt(4) |
---|
| 26 | integer latp(4),lonp(4) |
---|
| 27 | integer yinf,ysup,xinf,xsup,tinf,tsup |
---|
| 28 | real latinf,latsup,loninf,lonsup |
---|
| 29 | real latintmp,lonintmp,latdeg,londeg |
---|
| 30 | real colat,dlat,dlon,colattmp |
---|
| 31 | logical, save :: firstcall=.true. |
---|
| 32 | logical :: timeflag |
---|
| 33 | real radeg,pi |
---|
| 34 | integer :: timedim,londim,latdim |
---|
| 35 | real, dimension(:), allocatable, save :: lat,lon,time |
---|
| 36 | real, dimension(:,:,:), allocatable, save :: tautes |
---|
| 37 | integer, save :: timelen,lonlen,latlen |
---|
| 38 | INTEGER, external:: lnblnk |
---|
| 39 | |
---|
| 40 | !!WRF added |
---|
| 41 | INTEGER :: day_translate |
---|
| 42 | |
---|
| 43 | pi=acos(-1.) |
---|
| 44 | radeg=180/pi |
---|
| 45 | realday=mod(zday,669.) |
---|
| 46 | |
---|
| 47 | if (firstcall) then |
---|
| 48 | firstcall=.false. |
---|
| 49 | |
---|
| 50 | !! Note: datafile() is defined in "datafile.h" |
---|
| 51 | !print *,datafile(1:lnblnk(datafile)) |
---|
| 52 | !ierr=NF_OPEN (datafile(1:lnblnk(datafile))//"/input_totoptdep.nc",NF_NOWRITE,nid) |
---|
| 53 | |
---|
| 54 | !!------------------------------------- |
---|
| 55 | !! iaervar is used here to communicate the day starting the diagfi |
---|
| 56 | !! -- in addition, inpu_totoptdep.nc must be prepared |
---|
| 57 | day_translate=day_translate-1000 |
---|
| 58 | ierr=NF_OPEN ("./input_totoptdep.nc",NF_NOWRITE,nid) |
---|
| 59 | !!------------------------------------- |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | IF (ierr.NE.NF_NOERR) THEN |
---|
| 63 | !write(*,*)'Problem opening dust.nc (in phymars/readtesassim.F90)' |
---|
| 64 | !write(*,*)'It should be in :',datafile(1:lnblnk(datafile)),'/' |
---|
| 65 | !write(*,*)'1) You can change this directory address in ' |
---|
| 66 | !write(*,*)' file phymars/datafile.h' |
---|
| 67 | !write(*,*)'2) If necessary, dust.nc (and other datafiles)' |
---|
| 68 | !write(*,*)' can be obtained online on:' |
---|
| 69 | !write(*,*)' http://www.lmd.jussieu.fr/~forget/datagcm/datafile' |
---|
| 70 | write(*,*)'Problem opening input_totoptdep.nc ...' |
---|
| 71 | CALL ABORT |
---|
| 72 | ENDIF |
---|
| 73 | |
---|
| 74 | ierr=NF_INQ_DIMID(nid,"time",timedim) |
---|
| 75 | ierr=NF_INQ_DIMLEN(nid,timedim,timelen) |
---|
| 76 | ierr=NF_INQ_DIMID(nid,"lat",latdim) |
---|
| 77 | ierr=NF_INQ_DIMLEN(nid,latdim,latlen) |
---|
| 78 | ierr=NF_INQ_DIMID(nid,"lon",londim) |
---|
| 79 | ierr=NF_INQ_DIMLEN(nid,londim,lonlen) |
---|
| 80 | |
---|
| 81 | allocate(tautes(lonlen,latlen,timelen)) |
---|
| 82 | allocate(lat(latlen), lon(lonlen), time(timelen)) |
---|
| 83 | |
---|
| 84 | ierr = NF_INQ_VARID (nid, "totoptdep",nvarid) |
---|
| 85 | #ifdef NC_DOUBLE |
---|
| 86 | ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tautes) |
---|
| 87 | #else |
---|
| 88 | ierr = NF_GET_VAR_REAL(nid, nvarid, tautes) |
---|
| 89 | #endif |
---|
| 90 | IF (ierr .NE. NF_NOERR) THEN |
---|
| 91 | PRINT*, "Error: Readtesassim <totoptdep> not found" |
---|
| 92 | stop |
---|
| 93 | ENDIF |
---|
| 94 | |
---|
| 95 | !!****WRF |
---|
| 96 | !! diagfi files feature the dust opacity divided by 700 Pa |
---|
| 97 | tautes=tautes*700. |
---|
| 98 | !!****WRF |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | ierr = NF_INQ_VARID (nid, "time",nvarid) |
---|
| 102 | #ifdef NC_DOUBLE |
---|
| 103 | ierr = NF_GET_VAR_DOUBLE(nid, nvarid, time) |
---|
| 104 | #else |
---|
| 105 | ierr = NF_GET_VAR_REAL(nid, nvarid, time) |
---|
| 106 | #endif |
---|
| 107 | IF (ierr .NE. NF_NOERR) THEN |
---|
| 108 | PRINT*, "Error: Readtesassim <Time> not found" |
---|
| 109 | stop |
---|
| 110 | ENDIF |
---|
| 111 | |
---|
| 112 | !!****WRF |
---|
| 113 | PRINT *, "**** read assimilation dust" |
---|
| 114 | PRINT *, "prescribed starting day ...", day_translate |
---|
| 115 | time=time+day_translate |
---|
| 116 | !!****WRF |
---|
| 117 | |
---|
| 118 | ierr = NF_INQ_VARID (nid, "lat",nvarid) |
---|
| 119 | #ifdef NC_DOUBLE |
---|
| 120 | ierr = NF_GET_VAR_DOUBLE(nid, nvarid, lat) |
---|
| 121 | #else |
---|
| 122 | ierr = NF_GET_VAR_REAL(nid, nvarid, lat) |
---|
| 123 | #endif |
---|
| 124 | IF (ierr .NE. NF_NOERR) THEN |
---|
| 125 | PRINT*, "Error: Readtesassim <latitude> not found" |
---|
| 126 | stop |
---|
| 127 | ENDIF |
---|
| 128 | |
---|
| 129 | ierr = NF_INQ_VARID (nid, "lon",nvarid) |
---|
| 130 | #ifdef NC_DOUBLE |
---|
| 131 | ierr = NF_GET_VAR_DOUBLE(nid, nvarid, lon) |
---|
| 132 | #else |
---|
| 133 | ierr = NF_GET_VAR_REAL(nid, nvarid, lon) |
---|
| 134 | #endif |
---|
| 135 | IF (ierr .NE. NF_NOERR) THEN |
---|
| 136 | PRINT*, "Error: Readtesassim <longitude> not found" |
---|
| 137 | stop |
---|
| 138 | ENDIF |
---|
| 139 | |
---|
| 140 | endif ! of if (firstcall) |
---|
| 141 | |
---|
| 142 | do ig=1,ngrid |
---|
| 143 | |
---|
| 144 | ! Find the four nearest points, arranged as follows: |
---|
| 145 | ! 1 2 |
---|
| 146 | ! 3 4 |
---|
| 147 | |
---|
| 148 | latdeg=lati(ig)*radeg ! latitude, in degrees |
---|
| 149 | londeg=long(ig)*radeg ! longitude, in degrees east |
---|
| 150 | colat=90-latdeg ! colatitude, in degrees |
---|
| 151 | |
---|
| 152 | ! Find encompassing latitudes |
---|
| 153 | if (colat<(90-lat(1))) then ! between north pole and lat(1) |
---|
| 154 | ysup=1 |
---|
| 155 | yinf=1 |
---|
| 156 | else if (colat>=90-(lat(latlen))) then ! between south pole and lat(laten) |
---|
| 157 | ysup=latlen |
---|
| 158 | yinf=latlen |
---|
| 159 | else ! general case |
---|
| 160 | do iloop=2,latlen |
---|
| 161 | if(colat<(90-lat(iloop))) then |
---|
| 162 | ysup=iloop-1 |
---|
| 163 | yinf=iloop |
---|
| 164 | exit |
---|
| 165 | endif |
---|
| 166 | enddo |
---|
| 167 | endif |
---|
| 168 | |
---|
| 169 | latinf=lat(yinf) |
---|
| 170 | latsup=lat(ysup) |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | ! Find encompassing longitudes |
---|
| 174 | ! Note: in input file, lon(1)=-180. |
---|
| 175 | if (londeg>lon(lonlen)) then |
---|
| 176 | xsup=1 |
---|
| 177 | xinf=lonlen |
---|
| 178 | loninf=lon(xsup) |
---|
| 179 | lonsup=180.0 ! since lon(1)=-180.0 |
---|
| 180 | else |
---|
| 181 | do iloop=2,lonlen |
---|
| 182 | if(londeg<lon(iloop)) then |
---|
| 183 | xsup=iloop |
---|
| 184 | xinf=iloop-1 |
---|
| 185 | exit |
---|
| 186 | endif |
---|
| 187 | enddo |
---|
| 188 | loninf=lon(xinf) |
---|
| 189 | lonsup=lon(xsup) |
---|
| 190 | endif |
---|
| 191 | |
---|
| 192 | if ((xsup.gt.lonlen).OR.(yinf.gt.latlen).OR.(xinf.lt.1)& |
---|
| 193 | .OR.(ysup.lt.1)) then |
---|
| 194 | write (*,*) "Readtesassim: SYSTEM ERROR on x or y in ts_gcm" |
---|
| 195 | write (*,*) "xinf: ",xinf |
---|
| 196 | write (*,*) "xsup: ",xsup |
---|
| 197 | write (*,*) "yinf: ",yinf |
---|
| 198 | write (*,*) "ysup: ",ysup |
---|
| 199 | stop |
---|
| 200 | endif |
---|
| 201 | |
---|
| 202 | ! loninf=lon(xinf) |
---|
| 203 | ! lonsup=lon(xsup) |
---|
| 204 | ! latinf=lat(yinf) |
---|
| 205 | ! latsup=lat(ysup) |
---|
| 206 | |
---|
| 207 | ! The four neighbouring points are arranged as follows: |
---|
| 208 | ! 1 2 |
---|
| 209 | ! 3 4 |
---|
| 210 | |
---|
| 211 | latp(1)=ysup |
---|
| 212 | latp(2)=ysup |
---|
| 213 | latp(3)=yinf |
---|
| 214 | latp(4)=yinf |
---|
| 215 | |
---|
| 216 | lonp(1)=xinf |
---|
| 217 | lonp(2)=xsup |
---|
| 218 | lonp(3)=xinf |
---|
| 219 | lonp(4)=xsup |
---|
| 220 | |
---|
| 221 | ! Linear interpolation on time, for all four neighbouring points |
---|
| 222 | |
---|
| 223 | if ((realday<time(1)).or.(realday>time(timelen))) then |
---|
| 224 | tinf=timelen |
---|
| 225 | tsup=1 |
---|
| 226 | timeflag=.true. |
---|
| 227 | else |
---|
| 228 | do iloop=2,timelen |
---|
| 229 | if (realday<time(iloop)) then |
---|
| 230 | tinf=iloop-1 |
---|
| 231 | tsup=iloop |
---|
| 232 | exit |
---|
| 233 | endif |
---|
| 234 | enddo |
---|
| 235 | endif |
---|
| 236 | |
---|
| 237 | ! Bilinear interpolation on the four nearest points |
---|
| 238 | |
---|
| 239 | if ((colat<(90-lat(1))).OR.(colat>(90-lat(latlen))).OR.(latsup==latinf)) then |
---|
| 240 | dlat=0 |
---|
| 241 | else |
---|
| 242 | dlat=((90-latinf)-colat)/((90-latinf)-(90-latsup)) |
---|
| 243 | endif |
---|
| 244 | |
---|
| 245 | if (lonsup==loninf) then |
---|
| 246 | dlon=0 |
---|
| 247 | else |
---|
| 248 | dlon=(londeg-loninf)/(lonsup-loninf) |
---|
| 249 | endif |
---|
| 250 | |
---|
| 251 | do iloop=1,4 |
---|
| 252 | taubuf(1)=tautes(lonp(iloop),latp(iloop),tinf) |
---|
| 253 | taubuf(2)=tautes(lonp(iloop),latp(iloop),tsup) |
---|
| 254 | if (timeflag) then |
---|
| 255 | if (realday>time(timelen)) then |
---|
| 256 | tau1(iloop)=taubuf(1)+(taubuf(2)-taubuf(1))*(realday-time(tinf))/(time(tsup)+(669-time(tinf))) |
---|
| 257 | else |
---|
| 258 | tau1(iloop)=taubuf(1)+(taubuf(2)-taubuf(1))*realday/(time(tsup)+(669-time(tinf))) |
---|
| 259 | endif |
---|
| 260 | else |
---|
| 261 | tau1(iloop)=taubuf(1)+(taubuf(2)-taubuf(1))*(realday-time(tinf))/(time(tsup)-time(tinf)) |
---|
| 262 | endif |
---|
| 263 | if (tau1(iloop)<0) then |
---|
| 264 | write (*,*) "Readtesassim: SYSTEM ERROR on tau" |
---|
| 265 | write (*,*) "utime ",realday |
---|
| 266 | write (*,*) "time(tinf) ",time(tinf) |
---|
| 267 | write (*,*) "time(tsup) ",time(tsup) |
---|
| 268 | write (*,*) "tau1 ",taubuf(1) |
---|
| 269 | write (*,*) "tau2 ",taubuf(2) |
---|
| 270 | write (*,*) "tau ",tau1(iloop) |
---|
| 271 | stop |
---|
| 272 | endif |
---|
| 273 | enddo |
---|
| 274 | timeflag=.false. |
---|
| 275 | |
---|
| 276 | if ((dlat>1).OR.(dlon>1) .OR. (dlat<0) .OR. (dlon<0)) then |
---|
| 277 | write (*,*) "Readtesassim: SYSTEM ERROR on dlat or dlon in ts_gcm" |
---|
| 278 | write (*,*) "dlat: ",dlat |
---|
| 279 | write (*,*) "lat: ",latdeg |
---|
| 280 | write (*,*) "dlon: ",dlon |
---|
| 281 | write (*,*) "lon: ",londeg |
---|
| 282 | stop |
---|
| 283 | endif |
---|
| 284 | |
---|
| 285 | tau= dlat*(dlon*(tau1(2)+tau1(3)-tau1(1)-tau1(4))+tau1(1)-tau1(3)) +dlon*(tau1(4)-tau1(3))+tau1(3) |
---|
| 286 | |
---|
| 287 | !! tauref(ig)=tau*700/pplev(ig,1)*0.8 |
---|
| 288 | tauref(ig)=tau*0.825 |
---|
| 289 | |
---|
| 290 | !------------- |
---|
| 291 | ! from Oxford |
---|
| 292 | !------------- |
---|
| 293 | ! + tuning ... TES is little bit too hot compared to radio-occultations |
---|
| 294 | ! 0.825 is the MY24 value |
---|
| 295 | !tauref(ig)=tau*700.*0.825 |
---|
| 296 | !tauref(ig)=tau*700. |
---|
| 297 | !tauref(ig)=tau*700.*1.2 |
---|
| 298 | !tauref(ig)=tau*700.*0.6 |
---|
| 299 | !------------------------------------------------- |
---|
| 300 | ! NB: multiply by 700. is now done elsewhere |
---|
| 301 | !------------------------------------------------- |
---|
| 302 | |
---|
| 303 | |
---|
| 304 | enddo |
---|
| 305 | |
---|
| 306 | end |
---|