source: LMDZ6/trunk/libf/phylmd/StratAer/interp_sulf_input.f90 @ 5310

Last change on this file since 5310 was 5271, checked in by abarral, 2 weeks ago

Move dimensions.h into a module
Nb: doesn't compile yet

  • Property svn:keywords set to Id
File size: 13.3 KB
Line 
1!
2! $Id: interp_sulf_input.f90 5271 2024-10-24 14:25:39Z abarral $
3!
4SUBROUTINE interp_sulf_input(debutphy,pdtphys,paprs,tr_seri)
5
6  USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, &
7                      nf95_inq_varid, nf95_inquire_dimension, nf95_open
8  USE netcdf, ONLY: nf90_get_var, nf90_noerr, nf90_nowrite
9
10  USE mod_grid_phy_lmdz
11  USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
12  USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
13  USE phys_local_var_mod, ONLY : budg_3D_backgr_ocs, budg_3D_backgr_so2
14  USE phys_local_var_mod, ONLY : OCS_lifetime, SO2_lifetime, H2SO4_lifetime, O3_clim
15  USE mod_phys_lmdz_para
16  USE dimphy
17  USE phys_cal_mod
18  USE infotrac_phy
19  USE aerophys
20  USE yomcst_mod_h
21  USE strataer_local_var_mod, ONLY : flag_newclim_file,flag_verbose_strataer
22
23  USE dimensions_mod, ONLY: iim, jjm, llm, ndm
24IMPLICIT NONE
25
26
27
28! Variable input
29  REAL paprs(klon,klev+1)
30  REAL tr_seri(klon,klev,nbtr)
31  REAL, INTENT(IN)    :: pdtphys    ! Pas d'integration pour la physique (seconde)
32  LOGICAL, INTENT(IN) :: debutphy   ! le flag de l'initialisation de la physique
33
34! Variables locales
35  INTEGER n_lat   ! number of latitudes in the input data
36  INTEGER n_lon   ! number of longitudes in the input data
37  INTEGER, SAVE :: n_lev   ! number of levels in the input data
38!$OMP THREADPRIVATE(n_lev)
39  INTEGER n_mth   ! number of months in the input data
40  INTEGER, SAVE :: mth_pre
41!$OMP THREADPRIVATE(mth_pre)
42
43! Champs reconstitues
44  REAL paprs_glo(klon_glo,klev+1)
45
46  REAL, ALLOCATABLE :: latitude(:)
47! (of input data sorted in strictly ascending order)
48
49  REAL, ALLOCATABLE :: longitude(:)
50! (of input data sorted in strictly ascending order)
51
52  REAL, ALLOCATABLE :: time(:)
53! (of input data sorted in strictly ascending order)
54
55  REAL, ALLOCATABLE :: lev(:)
56! levels of input data
57
58  REAL, ALLOCATABLE :: OCS_clim_in(:, :, :, :)
59  REAL, ALLOCATABLE :: SO2_clim_in(:, :, :, :)
60  REAL, ALLOCATABLE :: OCS_clim_mth(:, :, :)
61  REAL, ALLOCATABLE :: SO2_clim_mth(:, :, :)
62  REAL, ALLOCATABLE :: OCS_clim_tmp(:, :)
63  REAL, ALLOCATABLE :: SO2_clim_tmp(:, :)
64  REAL OCS_clim_glo(klon_glo,klev)
65  REAL SO2_clim_glo(klon_glo,klev)
66 
67  REAL, ALLOCATABLE :: O3_clim_in(:, :, :, :)
68  REAL, ALLOCATABLE :: O3_clim_mth(:, :, :)
69  REAL, ALLOCATABLE :: O3_clim_tmp(:, :)
70  REAL O3_clim_glo(klon_glo,klev)
71 
72  ! fixed climatos
73  REAL, ALLOCATABLE :: OCS_lifetime_in(:, :, :, :)
74  REAL, ALLOCATABLE :: SO2_lifetime_in(:, :, :, :)
75  REAL, ALLOCATABLE :: OCS_lifetime_mth(:, :, :)
76  REAL, ALLOCATABLE :: SO2_lifetime_mth(:, :, :)
77  REAL, ALLOCATABLE :: OCS_lifetime_tmp(:, :)
78  REAL, ALLOCATABLE :: SO2_lifetime_tmp(:, :)
79  REAL OCS_lifetime_glo(klon_glo,klev)
80  REAL SO2_lifetime_glo(klon_glo,klev)
81 
82  REAL, ALLOCATABLE :: H2SO4_lifetime_in(:, :, :, :)
83  REAL, ALLOCATABLE :: H2SO4_lifetime_mth(:, :, :)
84  REAL, ALLOCATABLE :: H2SO4_lifetime_tmp(:, :)
85
86  REAL H2SO4_lifetime_glo(klon_glo,klev)
87!
88  REAL, ALLOCATABLE, SAVE :: OCS_clim(:,:)
89  REAL, ALLOCATABLE, SAVE :: SO2_clim(:,:)
90!$OMP THREADPRIVATE(OCS_clim,SO2_clim)
91!
92  INTEGER i, k, kk, j
93  REAL p_bound
94
95! For NetCDF:
96  INTEGER             :: ncid_in  ! IDs for input files
97  INTEGER             :: varid, ncerr
98  CHARACTER (LEN=3)   :: nc_lat, nc_lon
99  CHARACTER (LEN=256) :: nc_fname
100   
101  INTEGER, PARAMETER :: lev_input=17
102!--pressure at interfaces of input data (in Pa)
103  REAL, DIMENSION(lev_input+1), PARAMETER ::          &
104                    paprs_input=(/                    &
105  1.00000002e+05,   6.06530673e+04,   3.67879449e+04, &
106  2.23130165e+04,   1.35335286e+04,   8.20850004e+03, &
107  4.97870695e+03,   3.01973841e+03,   1.83156393e+03, &
108  1.11089968e+03,   6.73794715e+02,   4.08677153e+02, &
109  2.47875223e+02,   1.50343923e+02,   9.11881985e+01, &
110  5.53084382e+01,   3.35462635e+01,   0.0           /)
111!
112 IF (.NOT.ALLOCATED(OCS_clim)) ALLOCATE(OCS_clim(klon,klev))
113 IF (.NOT.ALLOCATED(SO2_clim)) ALLOCATE(SO2_clim(klon,klev))
114
115  IF (debutphy.OR.mth_cur.NE.mth_pre) THEN
116
117!--preparation of global fields
118  CALL gather(paprs, paprs_glo)
119
120  IF (is_mpi_root.AND.is_omp_root) THEN
121
122    !--init ncdf variables
123    IF(flag_newclim_file) THEN
124      nc_fname = "ocs_so2_h2so4_annual_lmdz.nc"
125      nc_lat   = "LAT"
126      nc_lon   = "LON"
127    ELSE
128      ! old file for retro compatibility
129      nc_fname = "ocs_so2_annual_lmdz.nc"
130      nc_lat   = "lat"
131      nc_lon   = "lon"
132    ENDIF
133
134    !--reading emission files
135    CALL nf95_open(nc_fname, nf90_nowrite, ncid_in)
136    IF(flag_verbose_strataer) print *, "Open file ", nc_fname
137   
138    CALL nf95_inq_varid(ncid_in, "LEV", varid)
139    CALL nf95_gw_var(ncid_in, varid, lev)
140    n_lev = size(lev)
141   
142    CALL nf95_inq_varid(ncid_in, nc_lat, varid)
143    CALL nf95_gw_var(ncid_in, varid, latitude)
144    n_lat = size(latitude)
145   
146    CALL nf95_inq_varid(ncid_in, nc_lon, varid)
147    CALL nf95_gw_var(ncid_in, varid, longitude)
148    n_lon = size(longitude)
149   
150    CALL nf95_inq_varid(ncid_in, "TIME", varid)
151    CALL nf95_gw_var(ncid_in, varid, time)
152    n_mth = size(time)
153   
154    IF (.NOT.ALLOCATED(OCS_clim_in))     ALLOCATE(OCS_clim_in(n_lon, n_lat, n_lev, n_mth))
155    IF (.NOT.ALLOCATED(SO2_clim_in))     ALLOCATE(SO2_clim_in(n_lon, n_lat, n_lev, n_mth))
156    IF (.NOT.ALLOCATED(O3_clim_in))      ALLOCATE(O3_clim_in(n_lon, n_lat, n_lev, n_mth))
157   
158    IF (.NOT.ALLOCATED(OCS_lifetime_in)) ALLOCATE(OCS_lifetime_in(n_lon, n_lat, n_lev, n_mth))
159    IF (.NOT.ALLOCATED(SO2_lifetime_in)) ALLOCATE(SO2_lifetime_in(n_lon, n_lat, n_lev, n_mth))
160    IF (.NOT.ALLOCATED(H2SO4_lifetime_in)) ALLOCATE(H2SO4_lifetime_in(n_lon, n_lat, n_lev, n_mth))
161   
162    CALL nf95_inq_varid(ncid_in, "OCS", varid)
163    ncerr = nf90_get_var(ncid_in, varid, OCS_clim_in)
164    IF(flag_verbose_strataer) print *,'code erreur OCS=', ncerr, varid
165
166    CALL nf95_inq_varid(ncid_in, "SO2", varid)
167    ncerr = nf90_get_var(ncid_in, varid, SO2_clim_in)
168    IF(flag_verbose_strataer) print *,'code erreur SO2=', ncerr, varid
169
170    CALL nf95_inq_varid(ncid_in, "OCS_LIFET", varid)
171    ncerr = nf90_get_var(ncid_in, varid, OCS_lifetime_in)
172    IF(flag_verbose_strataer) print *,'code erreur OCS_lifetime_in=', ncerr, varid
173
174    CALL nf95_inq_varid(ncid_in, "SO2_LIFET", varid)
175    ncerr = nf90_get_var(ncid_in, varid, SO2_lifetime_in)
176    IF(flag_verbose_strataer) print *,'code erreur SO2_lifetime_in=', ncerr, varid
177   
178    IF(flag_newclim_file) THEN
179       CALL nf95_inq_varid(ncid_in, "O3", varid)
180       ncerr = nf90_get_var(ncid_in, varid, O3_clim_in)
181       IF(flag_verbose_strataer) print *,'code erreur O3=', ncerr, varid
182       
183       CALL nf95_inq_varid(ncid_in, "H2SO4_LIFET", varid)
184       ncerr = nf90_get_var(ncid_in, varid, H2SO4_lifetime_in)
185       IF(flag_verbose_strataer) print *,'code erreur H2SO4_lifetime_in=', ncerr, varid
186    ENDIF
187   
188    CALL nf95_close(ncid_in)
189
190    IF (.NOT.ALLOCATED(OCS_clim_mth)) ALLOCATE(OCS_clim_mth(n_lon, n_lat, n_lev))
191    IF (.NOT.ALLOCATED(SO2_clim_mth)) ALLOCATE(SO2_clim_mth(n_lon, n_lat, n_lev))
192    IF (.NOT.ALLOCATED(OCS_clim_tmp)) ALLOCATE(OCS_clim_tmp(klon_glo, n_lev))
193    IF (.NOT.ALLOCATED(SO2_clim_tmp)) ALLOCATE(SO2_clim_tmp(klon_glo, n_lev))
194    IF (.NOT.ALLOCATED(O3_clim_mth))  ALLOCATE(O3_clim_mth(n_lon, n_lat, n_lev))
195    IF (.NOT.ALLOCATED(O3_clim_tmp))  ALLOCATE(O3_clim_tmp(klon_glo, n_lev))
196   
197    IF (.NOT.ALLOCATED(OCS_lifetime_mth)) ALLOCATE(OCS_lifetime_mth(n_lon, n_lat, n_lev))
198    IF (.NOT.ALLOCATED(SO2_lifetime_mth)) ALLOCATE(SO2_lifetime_mth(n_lon, n_lat, n_lev))
199    IF (.NOT.ALLOCATED(OCS_lifetime_tmp)) ALLOCATE(OCS_lifetime_tmp(klon_glo, n_lev))
200    IF (.NOT.ALLOCATED(SO2_lifetime_tmp)) ALLOCATE(SO2_lifetime_tmp(klon_glo, n_lev))
201    IF (.NOT.ALLOCATED(H2SO4_lifetime_mth)) ALLOCATE(H2SO4_lifetime_mth(n_lon, n_lat, n_lev))
202    IF (.NOT.ALLOCATED(H2SO4_lifetime_tmp)) ALLOCATE(H2SO4_lifetime_tmp(klon_glo, n_lev))
203   
204!---select the correct month, undo multiplication with 1.e12 (precision reasons)
205!---correct latitudinal order and convert input from volume mixing ratio to mass mixing ratio
206    DO j=1,n_lat
207      SO2_clim_mth(:,j,:) = 1.e-12*SO2_clim_in(:,n_lat+1-j,:,mth_cur)*mSO2mol/mAIRmol
208      OCS_clim_mth(:,j,:) = 1.e-12*OCS_clim_in(:,n_lat+1-j,:,mth_cur)*mOCSmol/mAIRmol
209      SO2_lifetime_mth(:,j,:) = SO2_lifetime_in(:,n_lat+1-j,:,mth_cur)
210      OCS_lifetime_mth(:,j,:) = OCS_lifetime_in(:,n_lat+1-j,:,mth_cur)
211     
212      ! O3 from 2d model is not tracer, in VMR
213      IF(flag_newclim_file) THEN
214         H2SO4_lifetime_mth(:,j,:) = H2SO4_lifetime_in(:,n_lat+1-j,:,mth_cur)
215         ! new input files
216         O3_clim_mth(:,j,:) = 1.e-6*O3_clim_in(:,n_lat+1-j,:,mth_cur)
217      ELSE
218         H2SO4_lifetime_mth(:,j,:) = 1.e-6
219         O3_clim_mth(:,j,:) = 1.e-6
220      ENDIF
221    ENDDO
222
223!---reduce to a klon_glo grid but keep the levels
224    CALL grid2dTo1d_glo(OCS_clim_mth,OCS_clim_tmp)
225    CALL grid2dTo1d_glo(SO2_clim_mth,SO2_clim_tmp)
226    CALL grid2dTo1d_glo(O3_clim_mth,O3_clim_tmp)
227   
228    CALL grid2dTo1d_glo(OCS_lifetime_mth,OCS_lifetime_tmp)
229    CALL grid2dTo1d_glo(SO2_lifetime_mth,SO2_lifetime_tmp)
230    CALL grid2dTo1d_glo(H2SO4_lifetime_mth,H2SO4_lifetime_tmp)
231
232!--set lifetime to very high value in uninsolated areas
233    DO i=1, klon_glo
234      DO kk=1, n_lev
235!--added tests on VMR of species for realism
236        IF (OCS_clim_tmp(i,kk).LT.1.e-20) THEN
237          OCS_clim_tmp(i,kk)=1.0e-20
238        ENDIF
239        IF (SO2_clim_tmp(i,kk).LT.1.e-20) THEN
240          SO2_clim_tmp(i,kk)=1.0e-20
241        ENDIF
242        !       50 ppbv min for O3
243        IF (O3_clim_tmp(i,kk).LT.50.0e-9) THEN
244           O3_clim_tmp(i,kk)=50.0e-9
245        ENDIF
246       
247        IF (OCS_lifetime_tmp(i,kk)==0.0) THEN
248          OCS_lifetime_tmp(i,kk)=1.0e12
249        ENDIF
250        IF (SO2_lifetime_tmp(i,kk)==0.0) THEN
251          SO2_lifetime_tmp(i,kk)=1.0e12
252        ENDIF
253       IF (H2SO4_lifetime_tmp(i,kk)==0.0) THEN
254          H2SO4_lifetime_tmp(i,kk)=1.0e12
255       ENDIF
256      ENDDO
257    ENDDO
258
259  !---regrid weighted lifetime and climatologies
260  DO i=1, klon_glo
261    DO k=1, klev
262     OCS_lifetime_glo(i,k)=0.0
263     SO2_lifetime_glo(i,k)=0.0
264     O3_clim_glo(i,k)=0.0
265     
266     OCS_clim_glo(i,k)=0.0
267     SO2_clim_glo(i,k)=0.0
268     H2SO4_lifetime_glo(i,k)=0.0
269     
270     DO kk=1, n_lev
271      OCS_lifetime_glo(i,k)=OCS_lifetime_glo(i,k)+ &
272           MAX(0.0,MIN(paprs_glo(i,k),paprs_input(kk))-MAX(paprs_glo(i,k+1),paprs_input(kk+1))) &
273           *OCS_lifetime_tmp(i,kk)/(paprs_glo(i,k)-paprs_glo(i,k+1))
274      SO2_lifetime_glo(i,k)=SO2_lifetime_glo(i,k)+ &
275           MAX(0.0,MIN(paprs_glo(i,k),paprs_input(kk))-MAX(paprs_glo(i,k+1),paprs_input(kk+1))) &
276           *SO2_lifetime_tmp(i,kk)/(paprs_glo(i,k)-paprs_glo(i,k+1))
277      IF(flag_newclim_file) THEN
278         H2SO4_lifetime_glo(i,k)=H2SO4_lifetime_glo(i,k)+ &
279              MAX(0.0,MIN(paprs_glo(i,k),paprs_input(kk)) &
280              -MAX(paprs_glo(i,k+1),paprs_input(kk+1))) &
281              *H2SO4_lifetime_tmp(i,kk)/(paprs_glo(i,k)-paprs_glo(i,k+1))
282      ENDIF
283     
284      OCS_clim_glo(i,k)=OCS_clim_glo(i,k)+ &
285           MAX(0.0,MIN(paprs_glo(i,k),paprs_input(kk))-MAX(paprs_glo(i,k+1),paprs_input(kk+1))) &
286           *OCS_clim_tmp(i,kk)/(paprs_glo(i,k)-paprs_glo(i,k+1))
287      SO2_clim_glo(i,k)=SO2_clim_glo(i,k)+ &
288           MAX(0.0,MIN(paprs_glo(i,k),paprs_input(kk))-MAX(paprs_glo(i,k+1),paprs_input(kk+1))) &
289           *SO2_clim_tmp(i,kk)/(paprs_glo(i,k)-paprs_glo(i,k+1))
290      IF(flag_newclim_file) THEN
291         O3_clim_glo(i,k)=O3_clim_glo(i,k)+ &
292              MAX(0.0,MIN(paprs_glo(i,k),paprs_input(kk)) &
293              -MAX(paprs_glo(i,k+1),paprs_input(kk+1))) &
294              *O3_clim_tmp(i,kk)/(paprs_glo(i,k)-paprs_glo(i,k+1))
295      ENDIF
296      ENDDO
297    ENDDO
298  ENDDO
299
300  ENDIF !--is_mpi_root and is_omp_root
301
302!--keep memory of previous month
303  mth_pre=mth_cur
304
305!--scatter global fields around
306  CALL scatter(OCS_clim_glo, OCS_clim)
307  CALL scatter(SO2_clim_glo, SO2_clim)
308  CALL scatter(O3_clim_glo, O3_clim)
309  CALL scatter(OCS_lifetime_glo, OCS_lifetime)
310  CALL scatter(SO2_lifetime_glo, SO2_lifetime)
311  CALL scatter(H2SO4_lifetime_glo, H2SO4_lifetime)
312 
313  IF (is_mpi_root.AND.is_omp_root) THEN
314!
315    DEALLOCATE(OCS_clim_in,SO2_clim_in,O3_clim_in)
316    DEALLOCATE(OCS_clim_mth,SO2_clim_mth,O3_clim_mth)
317    DEALLOCATE(OCS_clim_tmp,SO2_clim_tmp,O3_clim_tmp)
318    DEALLOCATE(OCS_lifetime_in, SO2_lifetime_in, H2SO4_lifetime_in)
319    DEALLOCATE(OCS_lifetime_mth, SO2_lifetime_mth, H2SO4_lifetime_mth)
320    DEALLOCATE(OCS_lifetime_tmp, SO2_lifetime_tmp, H2SO4_lifetime_tmp)
321!
322  ENDIF !--is_mpi_root and is_omp_root
323
324  ENDIF ! debutphy.OR.new month
325
326!--set to background value everywhere in the very beginning, later only in the troposphere
327!--a little dangerous as the MAXVAL is not computed on the global field
328  IF (debutphy.AND.MAXVAL(tr_seri).LT.1.e-30) THEN
329    p_bound=0.0
330  ELSE
331    p_bound=50000.
332  ENDIF
333
334!--regridding tracer concentration on the vertical
335  DO i=1, klon
336    DO k=1, klev
337      !
338      !--OCS and SO2 prescribed back to their clim values below p_bound
339      IF (paprs(i,k).GT.p_bound) THEN
340        budg_3D_backgr_ocs(i,k)=OCS_clim(i,k)-tr_seri(i,k,id_OCS_strat)
341        budg_3D_backgr_so2(i,k)=SO2_clim(i,k)-tr_seri(i,k,id_SO2_strat)
342        tr_seri(i,k,id_OCS_strat)=OCS_clim(i,k)
343        tr_seri(i,k,id_SO2_strat)=SO2_clim(i,k)
344      ENDIF
345    ENDDO
346  ENDDO
347
348  !convert SO2_backgr_tend from kg(SO2)/kgA to kg(S)/m2/layer/s for saving as diagnostic
349  DO i=1, klon
350    DO k=1, klev
351      budg_3D_backgr_ocs(i,k)=budg_3D_backgr_ocs(i,k)*mSatom/mOCSmol*(paprs(i,k)-paprs(i,k+1))/RG/pdtphys
352      budg_3D_backgr_so2(i,k)=budg_3D_backgr_so2(i,k)*mSatom/mSO2mol*(paprs(i,k)-paprs(i,k+1))/RG/pdtphys
353    ENDDO
354  ENDDO
355 
356  RETURN
357
358END SUBROUTINE interp_sulf_input
Note: See TracBrowser for help on using the repository browser.