1 | subroutine read_dust_scenario(ngrid,nlayer,zday,pplev,tauref) |
---|
2 | |
---|
3 | ! Reading of the dust scenario file |
---|
4 | |
---|
5 | use netcdf |
---|
6 | implicit none |
---|
7 | |
---|
8 | #include "dimensions.h" |
---|
9 | #include "dimphys.h" |
---|
10 | #include "comgeomfi.h" |
---|
11 | #include "datafile.h" |
---|
12 | #include "callkeys.h" |
---|
13 | |
---|
14 | integer, intent(in) :: ngrid,nlayer |
---|
15 | real, intent(in) :: zday ! date in martian days |
---|
16 | real, dimension(ngrid,nlayer+1), intent(in) :: pplev |
---|
17 | real, dimension(ngrid), intent(out) :: tauref |
---|
18 | |
---|
19 | ! Local variables |
---|
20 | |
---|
21 | real :: realday |
---|
22 | integer nid,nvarid,ierr |
---|
23 | integer ltloop,lsloop,iloop,jloop,varloop,ig |
---|
24 | real, dimension(2) :: taubuf |
---|
25 | real tau1(4),tau |
---|
26 | real alt(4) |
---|
27 | integer latp(4),lonp(4) |
---|
28 | integer yinf,ysup,xinf,xsup,tinf,tsup |
---|
29 | real latinf,latsup,loninf,lonsup |
---|
30 | real latintmp,lonintmp,latdeg,londeg |
---|
31 | real colat,dlat,dlon,colattmp |
---|
32 | logical, save :: firstcall=.true. |
---|
33 | logical :: timeflag |
---|
34 | real,save :: radeg,pi |
---|
35 | integer :: timedim,londim,latdim |
---|
36 | real, dimension(:), allocatable, save :: lat,lon,time |
---|
37 | real, dimension(:,:,:), allocatable, save :: tautes |
---|
38 | integer, save :: timelen,lonlen,latlen |
---|
39 | character(len=33),save :: filename |
---|
40 | |
---|
41 | realday=mod(zday,669.) |
---|
42 | |
---|
43 | if (firstcall) then |
---|
44 | firstcall=.false. |
---|
45 | |
---|
46 | pi=acos(-1.) |
---|
47 | radeg=180/pi |
---|
48 | |
---|
49 | ! assimilated dust file: (NB: iaervar is a common in "callkeys.h") |
---|
50 | ! iaervar=4 means read dust_tes.nc file |
---|
51 | ! iaervar=6 means read dust_cold.nc file |
---|
52 | ! iaervar=7 means read dust_warm.nc file |
---|
53 | ! iaervar=24 means read dust_MY24.nc file |
---|
54 | ! iaervar=25 means read dust_MY25.nc file |
---|
55 | ! iaervar=26 means read dust_MY26.nc file, etc. |
---|
56 | if (iaervar.eq.4) then |
---|
57 | ! NB: 4: old TES assimilated MY24 dust scenarios (at 700Pa ref pressure!) |
---|
58 | filename="dust_tes.nc" |
---|
59 | else if (iaervar.eq.6) then |
---|
60 | filename="dust_cold.nc" |
---|
61 | else if (iaervar.eq.7) then |
---|
62 | filename="dust_warm.nc" |
---|
63 | else if (iaervar.eq.24) then |
---|
64 | filename="dust_MY24.nc" |
---|
65 | else if (iaervar.eq.25) then |
---|
66 | filename="dust_MY25.nc" |
---|
67 | else if (iaervar.eq.26) then |
---|
68 | filename="dust_MY26.nc" |
---|
69 | else if (iaervar.eq.27) then |
---|
70 | filename="dust_MY27.nc" |
---|
71 | else if (iaervar.eq.28) then |
---|
72 | filename="dust_MY28.nc" |
---|
73 | else if (iaervar.eq.29) then |
---|
74 | filename="dust_MY29.nc" |
---|
75 | else if (iaervar.eq.30) then |
---|
76 | filename="dust_MY30.nc" |
---|
77 | ! 124,125,126: old TES assimilated dust scenarios (at 700Pa ref pressure!) |
---|
78 | else if (iaervar.eq.124) then |
---|
79 | filename="dust_tes_MY24.nc" |
---|
80 | else if (iaervar.eq.125) then |
---|
81 | filename="dust_tes_MY25.nc" |
---|
82 | else if (iaervar.eq.126) then |
---|
83 | filename="dust_tes_MY26.nc" |
---|
84 | endif |
---|
85 | |
---|
86 | ! Note: datafile() is defined in "datafile.h" |
---|
87 | !ierr=NF_OPEN(trim(datafile)//"/"//trim(filename),NF_NOWRITE,nid) |
---|
88 | ierr=nf90_open(trim(datafile)//"/"//trim(filename),NF90_NOWRITE,nid) |
---|
89 | IF (ierr.NE.nf90_noerr) THEN |
---|
90 | write(*,*)'Problem opening ',trim(filename),' (in phymars/read_dust_scenario.F90)' |
---|
91 | write(*,*)'It should be in :',trim(datafile),'/' |
---|
92 | write(*,*)'1) You can change this directory address in callfis.def with' |
---|
93 | write(*,*)' datadir=/path/to/datafiles' |
---|
94 | write(*,*)'2) If necessary, dust*.nc (and other datafiles)' |
---|
95 | write(*,*)' can be obtained online on:' |
---|
96 | write(*,*)' http://www.lmd.jussieu.fr/~forget/datagcm/datafile' |
---|
97 | CALL ABORT |
---|
98 | ENDIF |
---|
99 | |
---|
100 | ierr=nf90_inq_dimid(nid,"Time",timedim) |
---|
101 | if (ierr.ne.nf90_noerr) then |
---|
102 | ! 'Time' dimension not found, look for 'time' |
---|
103 | ierr=nf90_inq_dimid(nid,"time",timedim) |
---|
104 | if (ierr.ne.nf90_noerr) then |
---|
105 | write(*,*)"Error: read_dust_scenario <time> not found" |
---|
106 | endif |
---|
107 | endif |
---|
108 | ierr=nf90_inquire_dimension(nid,timedim,len=timelen) |
---|
109 | ierr=nf90_inq_dimid(nid,"latitude",latdim) |
---|
110 | ierr=nf90_inquire_dimension(nid,latdim,len=latlen) |
---|
111 | ierr=nf90_inq_dimid(nid,"longitude",londim) |
---|
112 | ierr=nf90_inquire_dimension(nid,londim,len=lonlen) |
---|
113 | |
---|
114 | |
---|
115 | allocate(tautes(lonlen,latlen,timelen)) |
---|
116 | allocate(lat(latlen), lon(lonlen), time(timelen)) |
---|
117 | |
---|
118 | ierr=nf90_inq_varid(nid,"dustop",nvarid) |
---|
119 | ierr=nf90_get_var(nid,nvarid,tautes) |
---|
120 | IF (ierr .NE. nf90_noerr) THEN |
---|
121 | PRINT*, "Error: read_dust_scenario <dustop> not found" |
---|
122 | write(*,*)trim(nf90_strerror(ierr)) |
---|
123 | stop |
---|
124 | ENDIF |
---|
125 | |
---|
126 | ierr=nf90_inq_varid(nid,"Time",nvarid) |
---|
127 | ierr=nf90_get_var(nid,nvarid,time) |
---|
128 | IF (ierr .NE. nf90_noerr) THEN |
---|
129 | PRINT*, "Error: read_dust_scenario <Time> not found" |
---|
130 | write(*,*)trim(nf90_strerror(ierr)) |
---|
131 | stop |
---|
132 | ENDIF |
---|
133 | |
---|
134 | ierr=nf90_inq_varid(nid,"latitude",nvarid) |
---|
135 | ierr=nf90_get_var(nid,nvarid,lat) |
---|
136 | IF (ierr .NE. nf90_noerr) THEN |
---|
137 | PRINT*, "Error: read_dust_scenario <latitude> not found" |
---|
138 | write(*,*)trim(nf90_strerror(ierr)) |
---|
139 | stop |
---|
140 | ENDIF |
---|
141 | |
---|
142 | ierr=nf90_inq_varid(nid,"longitude",nvarid) |
---|
143 | ierr=nf90_get_var(nid,nvarid,lon) |
---|
144 | IF (ierr .NE. nf90_noerr) THEN |
---|
145 | PRINT*, "Error: read_dust_scenario <longitude> not found" |
---|
146 | write(*,*)trim(nf90_strerror(ierr)) |
---|
147 | stop |
---|
148 | ENDIF |
---|
149 | |
---|
150 | ierr=nf90_close(nid) |
---|
151 | |
---|
152 | endif ! of if (firstcall) |
---|
153 | |
---|
154 | do ig=1,ngrid |
---|
155 | |
---|
156 | ! Find the four nearest points, arranged as follows: |
---|
157 | ! 1 2 |
---|
158 | ! 3 4 |
---|
159 | |
---|
160 | latdeg=lati(ig)*radeg ! latitude, in degrees |
---|
161 | londeg=long(ig)*radeg ! longitude, in degrees east |
---|
162 | colat=90-latdeg ! colatitude, in degrees |
---|
163 | |
---|
164 | ! Ehouarn: rounding effects and/or specific compiler issues |
---|
165 | ! sometime cause londeg to be sligthly below -180 ... |
---|
166 | if (londeg.lt.-180) then |
---|
167 | ! check if it is by a large amount |
---|
168 | if ((londeg+180).lt.-1.e-3) then |
---|
169 | write(*,*) 'reattesassim: error!!' |
---|
170 | write(*,*) ' ig=',ig,' londeg=',londeg |
---|
171 | stop |
---|
172 | else |
---|
173 | londeg=-180 |
---|
174 | endif |
---|
175 | endif |
---|
176 | |
---|
177 | ! Find encompassing latitudes |
---|
178 | if (colat<(90-lat(1))) then ! between north pole and lat(1) |
---|
179 | ysup=1 |
---|
180 | yinf=1 |
---|
181 | else if (colat>=90-(lat(latlen))) then ! between south pole and lat(laten) |
---|
182 | ysup=latlen |
---|
183 | yinf=latlen |
---|
184 | else ! general case |
---|
185 | do iloop=2,latlen |
---|
186 | if(colat<(90-lat(iloop))) then |
---|
187 | ysup=iloop-1 |
---|
188 | yinf=iloop |
---|
189 | exit |
---|
190 | endif |
---|
191 | enddo |
---|
192 | endif |
---|
193 | |
---|
194 | latinf=lat(yinf) |
---|
195 | latsup=lat(ysup) |
---|
196 | |
---|
197 | |
---|
198 | ! Find encompassing longitudes |
---|
199 | ! Note: in input file, lon(1)=-180. |
---|
200 | if (londeg>lon(lonlen)) then |
---|
201 | xsup=1 |
---|
202 | xinf=lonlen |
---|
203 | loninf=lon(xsup) |
---|
204 | lonsup=180.0 ! since lon(1)=-180.0 |
---|
205 | else |
---|
206 | do iloop=2,lonlen |
---|
207 | if(londeg<lon(iloop)) then |
---|
208 | xsup=iloop |
---|
209 | xinf=iloop-1 |
---|
210 | exit |
---|
211 | endif |
---|
212 | enddo |
---|
213 | loninf=lon(xinf) |
---|
214 | lonsup=lon(xsup) |
---|
215 | endif |
---|
216 | |
---|
217 | if ((xsup.gt.lonlen).OR.(yinf.gt.latlen).OR.(xinf.lt.1)& |
---|
218 | .OR.(ysup.lt.1)) then |
---|
219 | write (*,*) "read_dust_scenario: SYSTEM ERROR on x or y in ts_gcm" |
---|
220 | write (*,*) "xinf: ",xinf |
---|
221 | write (*,*) "xsup: ",xsup |
---|
222 | write (*,*) "yinf: ",yinf |
---|
223 | write (*,*) "ysup: ",ysup |
---|
224 | stop |
---|
225 | endif |
---|
226 | |
---|
227 | ! loninf=lon(xinf) |
---|
228 | ! lonsup=lon(xsup) |
---|
229 | ! latinf=lat(yinf) |
---|
230 | ! latsup=lat(ysup) |
---|
231 | |
---|
232 | ! The four neighbouring points are arranged as follows: |
---|
233 | ! 1 2 |
---|
234 | ! 3 4 |
---|
235 | |
---|
236 | latp(1)=ysup |
---|
237 | latp(2)=ysup |
---|
238 | latp(3)=yinf |
---|
239 | latp(4)=yinf |
---|
240 | |
---|
241 | lonp(1)=xinf |
---|
242 | lonp(2)=xsup |
---|
243 | lonp(3)=xinf |
---|
244 | lonp(4)=xsup |
---|
245 | |
---|
246 | ! Linear interpolation on time, for all four neighbouring points |
---|
247 | |
---|
248 | if ((realday<time(1)).or.(realday>time(timelen))) then |
---|
249 | tinf=timelen |
---|
250 | tsup=1 |
---|
251 | timeflag=.true. |
---|
252 | else |
---|
253 | timeflag=.false. |
---|
254 | do iloop=2,timelen |
---|
255 | if (realday<time(iloop)) then |
---|
256 | tinf=iloop-1 |
---|
257 | tsup=iloop |
---|
258 | exit |
---|
259 | endif |
---|
260 | enddo |
---|
261 | endif |
---|
262 | |
---|
263 | ! Bilinear interpolation on the four nearest points |
---|
264 | |
---|
265 | if ((colat<(90-lat(1))).OR.(colat>(90-lat(latlen))).OR.(latsup==latinf)) then |
---|
266 | dlat=0 |
---|
267 | else |
---|
268 | dlat=((90-latinf)-colat)/((90-latinf)-(90-latsup)) |
---|
269 | endif |
---|
270 | |
---|
271 | if (lonsup==loninf) then |
---|
272 | dlon=0 |
---|
273 | else |
---|
274 | dlon=(londeg-loninf)/(lonsup-loninf) |
---|
275 | endif |
---|
276 | |
---|
277 | do iloop=1,4 |
---|
278 | taubuf(1)=tautes(lonp(iloop),latp(iloop),tinf) |
---|
279 | taubuf(2)=tautes(lonp(iloop),latp(iloop),tsup) |
---|
280 | if (timeflag) then |
---|
281 | if (realday>time(timelen)) then |
---|
282 | tau1(iloop)=taubuf(1)+(taubuf(2)-taubuf(1))*(realday-time(tinf))/(time(tsup)+(669-time(tinf))) |
---|
283 | else |
---|
284 | tau1(iloop)=taubuf(1)+(taubuf(2)-taubuf(1))*realday/(time(tsup)+(669-time(tinf))) |
---|
285 | endif |
---|
286 | else |
---|
287 | tau1(iloop)=taubuf(1)+(taubuf(2)-taubuf(1))*(realday-time(tinf))/(time(tsup)-time(tinf)) |
---|
288 | endif |
---|
289 | if (tau1(iloop)<0) then |
---|
290 | write (*,*) "read_dust_scenario: SYSTEM ERROR on tau" |
---|
291 | write (*,*) "utime ",realday |
---|
292 | write (*,*) "time(tinf) ",time(tinf) |
---|
293 | write (*,*) "time(tsup) ",time(tsup) |
---|
294 | write (*,*) "tau1 ",taubuf(1) |
---|
295 | write (*,*) "tau2 ",taubuf(2) |
---|
296 | write (*,*) "tau ",tau1(iloop) |
---|
297 | stop |
---|
298 | endif |
---|
299 | enddo |
---|
300 | |
---|
301 | if ((dlat>1).OR.(dlon>1) .OR. (dlat<0) .OR. (dlon<0)) then |
---|
302 | write (*,*) "read_dust_scenario: SYSTEM ERROR on dlat or dlon in ts_gcm" |
---|
303 | write (*,*) "dlat: ",dlat |
---|
304 | write (*,*) "lat: ",latdeg |
---|
305 | write (*,*) "dlon: ",dlon |
---|
306 | write (*,*) "lon: ",londeg |
---|
307 | stop |
---|
308 | endif |
---|
309 | |
---|
310 | tau= dlat*(dlon*(tau1(2)+tau1(3)-tau1(1)-tau1(4))+tau1(1)-tau1(3)) +dlon*(tau1(4)-tau1(3))+tau1(3) |
---|
311 | |
---|
312 | tauref(ig)=tau |
---|
313 | ! |
---|
314 | enddo ! of ig=1,ngrid |
---|
315 | |
---|
316 | if (filename(1:8)=="dust_tes") then |
---|
317 | ! when using old TES files, correction for: |
---|
318 | ! - the reference pressure was 700Pa (unlike 610Pa now) |
---|
319 | ! - the 1.3 conversion factor from IR absorbtion opacity to |
---|
320 | ! IR extinction opacity |
---|
321 | tauref(:)=tauref(:)*1.3*(610./700.) |
---|
322 | endif |
---|
323 | |
---|
324 | if (swrtype.eq.1) then ! Fouquart (NB: swrtype is set in callkeys.h) |
---|
325 | ! when using old radiative transfer (like in MCD 4.x) |
---|
326 | ! needed to decrease opacity (*0.825) to compensate overestimation of |
---|
327 | ! heating rates |
---|
328 | tauref(:)=tauref(:)*0.825/1.3 |
---|
329 | endif |
---|
330 | |
---|
331 | end |
---|