source: LMDZ5/trunk/libf/phylmd/StratAer/interp_sulf_input.F90 @ 2695

Last change on this file since 2695 was 2695, checked in by oboucher, 8 years ago

Removing useless global variables
Interpolation only done once a month
Changing test orders in implicit coagulation routine as some compilers didn't like it

File size: 9.8 KB
Line 
1SUBROUTINE interp_sulf_input(debutphy,pdtphys,paprs,tr_seri)
2
3  USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, &
4                      nf95_inq_varid, nf95_inquire_dimension, nf95_open
5  USE netcdf, ONLY: nf90_get_var, nf90_noerr, nf90_nowrite
6
7  USE mod_grid_phy_lmdz
8  USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
9  USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
10  USE phys_local_var_mod, ONLY : OCS_backgr_tend, SO2_backgr_tend
11  USE phys_local_var_mod, ONLY : OCS_lifetime, SO2_lifetime
12  USE mod_phys_lmdz_para
13  USE dimphy
14  USE phys_cal_mod
15  USE infotrac
16  USE aerophys
17  USE YOMCST
18
19  IMPLICIT NONE
20
21  include "dimensions.h"
22
23! Variable input
24  REAL paprs(klon,klev+1)
25  REAL tr_seri(klon,klev,nbtr)
26  REAL, INTENT(IN)    :: pdtphys    ! Pas d'integration pour la physique (seconde)
27  LOGICAL, INTENT(IN) :: debutphy   ! le flag de l'initialisation de la physique
28
29! Variables locales
30  INTEGER n_lat   ! number of latitudes in the input data
31  INTEGER n_lon   ! number of longitudes in the input data
32  INTEGER, SAVE :: n_lev   ! number of levels in the input data
33  INTEGER n_mth   ! number of months in the input data
34  REAL OCS_tmp, SO2_tmp
35  INTEGER, SAVE :: mth_pre
36
37! Champs reconstitues
38  REAL paprs_glo(klon_glo,klev+1)
39
40  REAL, POINTER:: latitude(:)
41! (of input data sorted in strictly ascending order)
42
43  REAL, POINTER:: longitude(:)
44! (of input data sorted in strictly ascending order)
45
46  REAL, POINTER:: time(:)
47! (of input data sorted in strictly ascending order)
48
49  REAL, POINTER:: lev(:)
50! levels of input data
51
52  REAL, ALLOCATABLE :: OCS_clim_in(:, :, :, :)
53  REAL, ALLOCATABLE :: SO2_clim_in(:, :, :, :)
54  REAL, ALLOCATABLE :: OCS_clim_mth(:, :, :)
55  REAL, ALLOCATABLE :: SO2_clim_mth(:, :, :)
56  REAL, ALLOCATABLE :: OCS_clim_tmp(:, :)
57  REAL, ALLOCATABLE :: SO2_clim_tmp(:, :)
58  REAL OCS_clim_glo(klon_glo,klev)
59  REAL SO2_clim_glo(klon_glo,klev)
60  REAL, ALLOCATABLE :: OCS_lifetime_in(:, :, :, :)
61  REAL, ALLOCATABLE :: SO2_lifetime_in(:, :, :, :)
62  REAL, ALLOCATABLE :: OCS_lifetime_mth(:, :, :)
63  REAL, ALLOCATABLE :: SO2_lifetime_mth(:, :, :)
64  REAL, ALLOCATABLE :: OCS_lifetime_tmp(:, :)
65  REAL, ALLOCATABLE :: SO2_lifetime_tmp(:, :)
66  REAL OCS_lifetime_glo(klon_glo,klev)
67  REAL SO2_lifetime_glo(klon_glo,klev)
68!
69  REAL, ALLOCATABLE, SAVE :: OCS_clim(:,:)
70  REAL, ALLOCATABLE, SAVE :: SO2_clim(:,:)
71!$OMP THREADPRIVATE(OCS_clim,SO2_clim)
72!
73  INTEGER i, k, kk, ilon, ilev, j
74  REAL p_bound
75
76! For NetCDF:
77  INTEGER ncid_in  ! IDs for input files
78  INTEGER varid, ncerr
79   
80  INTEGER, PARAMETER :: lev_input=17
81!--pressure at interfaces of input data (in Pa)
82  REAL, DIMENSION(lev_input+1), PARAMETER ::          &
83                    paprs_input=(/                    &
84  1.00000002e+05,   6.06530673e+04,   3.67879449e+04, &
85  2.23130165e+04,   1.35335286e+04,   8.20850004e+03, &
86  4.97870695e+03,   3.01973841e+03,   1.83156393e+03, &
87  1.11089968e+03,   6.73794715e+02,   4.08677153e+02, &
88  2.47875223e+02,   1.50343923e+02,   9.11881985e+01, &
89  5.53084382e+01,   3.35462635e+01,   0.0           /)
90!
91  REAL, PARAMETER :: epsilon_OCS=1.0e-20     ! minimum OCS concentration [kg/kgA] for weighting of lifetime
92  REAL, PARAMETER :: epsilon_SO2=1.0e-20     ! minimum SO2 concentration [kg/kgA] for weighting of lifetime
93  REAL, PARAMETER :: min_OCS_lifetime= 3600. !minimum OCS lifetime [sec]
94  REAL, PARAMETER :: min_SO2_lifetime=86400. !minimum SO2 lifetime [sec]
95
96 IF (.NOT.ALLOCATED(OCS_clim)) ALLOCATE(OCS_clim(klon,klev))
97 IF (.NOT.ALLOCATED(SO2_clim)) ALLOCATE(SO2_clim(klon,klev))
98
99  IF (debutphy.OR.mth_cur.NE.mth_pre) THEN
100
101!--preparation of global fields
102  CALL gather(paprs, paprs_glo)
103
104  IF (is_mpi_root.AND.is_omp_root) THEN
105
106!--reading emission files
107    CALL nf95_open("ocs_so2_annual_lmdz.nc", nf90_nowrite, ncid_in)
108
109    CALL nf95_inq_varid(ncid_in, "LEV", varid)
110    CALL nf95_gw_var(ncid_in, varid, lev)
111    n_lev = size(lev)
112
113    CALL nf95_inq_varid(ncid_in, "lat", varid)
114    CALL nf95_gw_var(ncid_in, varid, latitude)
115    n_lat = size(latitude)
116
117    CALL nf95_inq_varid(ncid_in, "lon", varid)
118    CALL nf95_gw_var(ncid_in, varid, longitude)
119    n_lon = size(longitude)
120
121    CALL nf95_inq_varid(ncid_in, "TIME", varid)
122    CALL nf95_gw_var(ncid_in, varid, time)
123    n_mth = size(time)
124
125    IF (.NOT.ALLOCATED(OCS_clim_in))     ALLOCATE(OCS_clim_in(n_lon, n_lat, n_lev, n_mth))
126    IF (.NOT.ALLOCATED(SO2_clim_in))     ALLOCATE(SO2_clim_in(n_lon, n_lat, n_lev, n_mth))
127    IF (.NOT.ALLOCATED(OCS_lifetime_in)) ALLOCATE(OCS_lifetime_in(n_lon, n_lat, n_lev, n_mth))
128    IF (.NOT.ALLOCATED(SO2_lifetime_in)) ALLOCATE(SO2_lifetime_in(n_lon, n_lat, n_lev, n_mth))
129
130    CALL nf95_inq_varid(ncid_in, "OCS", varid)
131    ncerr = nf90_get_var(ncid_in, varid, OCS_clim_in)
132    print *,'code erreur OCS=', ncerr, varid
133
134    CALL nf95_inq_varid(ncid_in, "SO2", varid)
135    ncerr = nf90_get_var(ncid_in, varid, SO2_clim_in)
136    print *,'code erreur SO2=', ncerr, varid
137
138    CALL nf95_inq_varid(ncid_in, "OCS_LIFET", varid)
139    ncerr = nf90_get_var(ncid_in, varid, OCS_lifetime_in)
140    print *,'code erreur OCS_lifetime_in=', ncerr, varid
141
142    CALL nf95_inq_varid(ncid_in, "SO2_LIFET", varid)
143    ncerr = nf90_get_var(ncid_in, varid, SO2_lifetime_in)
144    print *,'code erreur SO2_lifetime_in=', ncerr, varid
145
146    CALL nf95_close(ncid_in)
147
148    IF (.NOT.ALLOCATED(OCS_clim_mth)) ALLOCATE(OCS_clim_mth(n_lon, n_lat, n_lev))
149    IF (.NOT.ALLOCATED(SO2_clim_mth)) ALLOCATE(SO2_clim_mth(n_lon, n_lat, n_lev))
150    IF (.NOT.ALLOCATED(OCS_clim_tmp)) ALLOCATE(OCS_clim_tmp(klon_glo, n_lev))
151    IF (.NOT.ALLOCATED(SO2_clim_tmp)) ALLOCATE(SO2_clim_tmp(klon_glo, n_lev))
152    IF (.NOT.ALLOCATED(OCS_lifetime_mth)) ALLOCATE(OCS_lifetime_mth(n_lon, n_lat, n_lev))
153    IF (.NOT.ALLOCATED(SO2_lifetime_mth)) ALLOCATE(SO2_lifetime_mth(n_lon, n_lat, n_lev))
154    IF (.NOT.ALLOCATED(OCS_lifetime_tmp)) ALLOCATE(OCS_lifetime_tmp(klon_glo, n_lev))
155    IF (.NOT.ALLOCATED(SO2_lifetime_tmp)) ALLOCATE(SO2_lifetime_tmp(klon_glo, n_lev))
156
157!---select the correct month, undo multiplication with 1.e12 (precision reasons)
158!---correct latitudinal order and convert input from volume mixing ratio to mass mixing ratio
159    DO j=1,n_lat
160      SO2_clim_mth(:,j,:) = 1.e-12*SO2_clim_in(:,n_lat+1-j,:,mth_cur)*mSO2mol/mAIRmol
161      OCS_clim_mth(:,j,:) = 1.e-12*OCS_clim_in(:,n_lat+1-j,:,mth_cur)*mOCSmol/mAIRmol
162      SO2_lifetime_mth(:,j,:) = SO2_lifetime_in(:,n_lat+1-j,:,mth_cur)
163      OCS_lifetime_mth(:,j,:) = OCS_lifetime_in(:,n_lat+1-j,:,mth_cur)
164    ENDDO
165
166!---reduce to a klon_glo grid but keep the levels
167    CALL grid2dTo1d_glo(OCS_clim_mth,OCS_clim_tmp)
168    CALL grid2dTo1d_glo(SO2_clim_mth,SO2_clim_tmp)
169    CALL grid2dTo1d_glo(OCS_lifetime_mth,OCS_lifetime_tmp)
170    CALL grid2dTo1d_glo(SO2_lifetime_mth,SO2_lifetime_tmp)
171
172!--set lifetime to very high value in uninsolated areas
173    DO i=1, klon_glo
174      DO kk=1, n_lev
175        IF (OCS_lifetime_tmp(i,kk)==0.0) THEN
176          OCS_lifetime_tmp(i,kk)=1.0e12
177        ENDIF
178        IF (SO2_lifetime_tmp(i,kk)==0.0) THEN
179          SO2_lifetime_tmp(i,kk)=1.0e12
180        ENDIF
181      ENDDO
182    ENDDO
183
184  !---regrid weighted lifetime and climatologies
185  DO i=1, klon
186    DO k=1, klev
187     OCS_lifetime_glo(i,k)=0.0
188     SO2_lifetime_glo(i,k)=0.0
189     OCS_clim_glo(i,k)=0.0
190     SO2_clim_glo(i,k)=0.0
191     DO kk=1, n_lev
192      OCS_lifetime_glo(i,k)=OCS_lifetime_glo(i,k)+ &
193           MAX(0.0,MIN(paprs_glo(i,k),paprs_input(kk))-MAX(paprs_glo(i,k+1),paprs_input(kk+1))) &
194           *OCS_lifetime_tmp(i,kk)/(paprs_glo(i,k)-paprs_glo(i,k+1))
195      SO2_lifetime_glo(i,k)=SO2_lifetime_glo(i,k)+ &
196           MAX(0.0,MIN(paprs_glo(i,k),paprs_input(kk))-MAX(paprs_glo(i,k+1),paprs_input(kk+1))) &
197           *SO2_lifetime_tmp(i,kk)/(paprs_glo(i,k)-paprs_glo(i,k+1))
198      OCS_clim_glo(i,k)=OCS_clim_glo(i,k)+ &
199           MAX(0.0,MIN(paprs_glo(i,k),paprs_input(kk))-MAX(paprs_glo(i,k+1),paprs_input(kk+1))) &
200           *OCS_clim_tmp(i,kk)/(paprs_glo(i,k)-paprs_glo(i,k+1))
201      SO2_clim_glo(i,k)=SO2_clim_glo(i,k)+ &
202           MAX(0.0,MIN(paprs_glo(i,k),paprs_input(kk))-MAX(paprs_glo(i,k+1),paprs_input(kk+1))) &
203           *SO2_clim_tmp(i,kk)/(paprs_glo(i,k)-paprs_glo(i,k+1))
204      ENDDO
205    ENDDO
206  ENDDO
207
208  ENDIF ! is_mpi_root
209
210!--keep memory of previous month
211  mth_pre=mth_cur
212
213!--scatter global fields around
214  CALL scatter(OCS_clim_glo, OCS_clim)
215  CALL scatter(SO2_clim_glo, SO2_clim)
216  CALL scatter(OCS_lifetime_glo, OCS_lifetime)
217  CALL scatter(SO2_lifetime_glo, SO2_lifetime)
218
219  IF (is_mpi_root.AND.is_omp_root) THEN
220!
221    DEALLOCATE(OCS_clim_in,SO2_clim_in)
222    DEALLOCATE(OCS_clim_mth,SO2_clim_mth)
223    DEALLOCATE(OCS_clim_tmp,SO2_clim_tmp)
224    DEALLOCATE(OCS_lifetime_in,SO2_lifetime_in)
225    DEALLOCATE(OCS_lifetime_mth,SO2_lifetime_mth)
226    DEALLOCATE(OCS_lifetime_tmp,SO2_lifetime_tmp)
227!
228  ENDIF !--is_mpi_root and is_omp_root
229
230  ENDIF ! debutphy.OR.new month
231
232!--set to background value everywhere in the very beginning, later only in the troposphere
233!--a little dangerous as the MAXVAL is not computed on the global field
234  IF (debutphy.AND.MAXVAL(tr_seri).LT.1.e-30) THEN
235    p_bound=0.0
236  ELSE
237    p_bound=50000.
238  ENDIF
239
240!--regridding tracer concentration on the vertical
241  DO i=1, klon
242    DO k=1, klev
243      !
244      OCS_tmp=tr_seri(i,k,id_OCS_strat)
245      SO2_tmp=tr_seri(i,k,id_SO2_strat)
246      !--OCS and SO2 prescribed below p_bound
247      IF (paprs(i,k).GT.p_bound) THEN
248        tr_seri(i,k,id_OCS_strat)=OCS_clim(i,k)
249        tr_seri(i,k,id_SO2_strat)=SO2_clim(i,k)
250      ENDIF
251      OCS_backgr_tend(i,k)=tr_seri(i,k,id_OCS_strat)-OCS_tmp
252      SO2_backgr_tend(i,k)=tr_seri(i,k,id_SO2_strat)-SO2_tmp
253    ENDDO
254  ENDDO
255
256  !convert SO2_backgr_tend from kg(SO2)/kgA to kg(S)/m2/layer/s for saving as diagnostic
257  DO ilon=1, klon
258    DO ilev=1, klev
259      SO2_backgr_tend(ilon,ilev)=SO2_backgr_tend(ilon,ilev)*mSatom/mSO2mol*(paprs(ilon,ilev)-paprs(ilon,ilev+1))/RG/pdtphys
260      OCS_backgr_tend(ilon,ilev)=OCS_backgr_tend(ilon,ilev)*mSatom/mOCSmol*(paprs(ilon,ilev)-paprs(ilon,ilev+1))/RG/pdtphys
261    ENDDO
262  ENDDO
263 
264  RETURN
265
266END SUBROUTINE interp_sulf_input
Note: See TracBrowser for help on using the repository browser.