source: LMDZ5/branches/testing/libf/phylmd/rrtm/readaerosolstrato2_rrtm.F90 @ 5431

Last change on this file since 5431 was 2787, checked in by Laurent Fairhead, 8 years ago

Merged trunk changes r2727:2785 into testing branch

File size: 13.8 KB
RevLine 
[2536]1!
2! $Id: readaerosolstrato2_rrtm.F90 2526 2016-05-26 22:13:40Z oboucher $
3!
[2720]4SUBROUTINE readaerosolstrato2_rrtm(debut)
[2536]5
[2720]6    USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, &
[2536]7                        nf95_inq_varid, nf95_open
[2720]8    USE netcdf, ONLY: nf90_get_var, nf90_noerr, nf90_nowrite
[2536]9
10    USE phys_cal_mod, ONLY : mth_cur
11    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo
12    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
13    USE mod_phys_lmdz_omp_data, ONLY :  is_omp_root
14    USE mod_phys_lmdz_para
15    USE phys_state_var_mod
16    USE phys_local_var_mod
17    USE aero_mod
18    USE dimphy
[2720]19    USE YOERAD, ONLY : NLW
20    USE YOMCST
[2536]21
[2720]22    IMPLICIT NONE
[2536]23
[2539]24    INCLUDE "clesphys.h"
[2536]25
26    CHARACTER (len = 80) :: abort_message
27    CHARACTER (LEN=20) :: modname = 'readaerosolstrato2'
28
29! Variable input
[2720]30    LOGICAL, INTENT(IN) ::  debut
[2536]31
32! Variables locales
[2720]33    INTEGER n_lat   ! number of latitudes in the input data
34    INTEGER n_lon   ! number of longitudes
35    INTEGER n_lev   ! number of levels in the input data
36    INTEGER n_month ! number of months in the input data
37    INTEGER n_wav   ! number of wavelengths in the input data
38    REAL, POINTER:: latitude(:)
39    REAL, POINTER:: time(:)
40    REAL, POINTER:: lev(:)
41    REAL, POINTER:: wav(:)
42    INTEGER i,k,wave,band
[2787]43    INTEGER, SAVE :: mth_pre=1
44!$OMP THREADPRIVATE(mth_pre)
[2536]45
[2720]46    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: tau_aer_strat
47    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: piz_aer_strat
48    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cg_aer_strat
49    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: taulw_aer_strat
[2536]50!$OMP THREADPRIVATE(tau_aer_strat,piz_aer_strat,cg_aer_strat,taulw_aer_strat)
51
52! Champs reconstitues
[2720]53    REAL, ALLOCATABLE:: tauaerstrat(:, :, :, :)
54    REAL, ALLOCATABLE:: pizaerstrat(:, :, :, :)
55    REAL, ALLOCATABLE:: cgaerstrat(:, :, :, :)
56    REAL, ALLOCATABLE:: taulwaerstrat(:, :, :, :)
[2536]57
[2720]58    REAL, ALLOCATABLE:: tauaerstrat_mois(:, :, :, :)
59    REAL, ALLOCATABLE:: pizaerstrat_mois(:, :, :, :)
60    REAL, ALLOCATABLE:: cgaerstrat_mois(:, :, :, :)
61    REAL, ALLOCATABLE:: taulwaerstrat_mois(:, :, :, :)
[2536]62
[2720]63    REAL, ALLOCATABLE:: tauaerstrat_mois_glo(:, :, :)
64    REAL, ALLOCATABLE:: pizaerstrat_mois_glo(:, :, :)
65    REAL, ALLOCATABLE:: cgaerstrat_mois_glo(:, :, :)
66    REAL, ALLOCATABLE:: taulwaerstrat_mois_glo(:, :, :)
[2536]67
68! For NetCDF:
[2720]69    INTEGER ncid_in  ! IDs for input files
70    INTEGER varid, ncerr
[2536]71
72!--------------------------------------------------------
73
[2539]74    IF (.not.ALLOCATED(tau_aer_strat)) ALLOCATE(tau_aer_strat(klon,klev,NSW))
75    IF (.not.ALLOCATED(piz_aer_strat)) ALLOCATE(piz_aer_strat(klon,klev,NSW))
76    IF (.not.ALLOCATED(cg_aer_strat))  ALLOCATE(cg_aer_strat(klon,klev,NSW))
[2536]77
[2539]78    IF (.not.ALLOCATED(taulw_aer_strat)) ALLOCATE(taulw_aer_strat(klon,klev,NLW))
[2536]79
80!--we only read monthly strat aerosol data
81    IF (debut.OR.mth_cur.NE.mth_pre) THEN
82
83!--only root reads the data
[2729]84      IF (is_mpi_root.AND.is_omp_root) THEN
[2536]85
86!--check mth_cur
[2729]87        IF (mth_cur.LT.1.OR.mth_cur.GT.12) THEN
88          print *,'probleme avec le mois dans readaerosolstrat =', mth_cur
89        ENDIF
[2536]90
91!--initialize n_lon as input data is 2D (lat-alt) only
[2729]92        n_lon = nbp_lon
[2536]93
94!--Starts with SW optical properties
95
[2729]96        CALL nf95_open("tauswstrat.2D.nc", nf90_nowrite, ncid_in)
[2536]97
[2729]98        CALL nf95_inq_varid(ncid_in, "LEV", varid)
99        CALL nf95_gw_var(ncid_in, varid, lev)
100        n_lev = size(lev)
101        IF (n_lev.NE.klev) THEN
102           abort_message='Le nombre de niveaux n est pas egal a klev'
103           CALL abort_physic(modname,abort_message,1)
104        ENDIF
[2536]105
[2729]106        CALL nf95_inq_varid(ncid_in, "LAT", varid)
107        CALL nf95_gw_var(ncid_in, varid, latitude)
108        n_lat = size(latitude)
109        IF (n_lat.NE.nbp_lat) THEN
110           print *, 'latitude=', n_lat, nbp_lat
111           abort_message='Le nombre de lat n est pas egal a nbp_lat'
112           CALL abort_physic(modname,abort_message,1)
113        ENDIF
[2536]114
[2729]115        CALL nf95_inq_varid(ncid_in, "TIME", varid)
116        CALL nf95_gw_var(ncid_in, varid, time)
117        n_month = size(time)
118        IF (n_month.NE.12) THEN
119           abort_message='Le nombre de month n est pas egal a 12'
120           CALL abort_physic(modname,abort_message,1)
121        ENDIF
[2536]122
[2729]123        CALL nf95_inq_varid(ncid_in, "WAV", varid)
124        CALL nf95_gw_var(ncid_in, varid, wav)
125        n_wav = size(wav)
126        print *, 'WAV aerosol strato=', n_wav, wav
127        IF (n_wav.NE.NSW) THEN
128           abort_message='Le nombre de wav n est pas egal a NSW'
129           CALL abort_physic(modname,abort_message,1)
130        ENDIF
[2536]131
[2729]132        ALLOCATE(tauaerstrat(n_lat, n_lev, n_wav, n_month))
133        ALLOCATE(pizaerstrat(n_lat, n_lev, n_wav, n_month))
134        ALLOCATE(cgaerstrat(n_lat, n_lev, n_wav, n_month))
[2536]135
[2729]136        ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
137        ALLOCATE(pizaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
138        ALLOCATE(cgaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
[2536]139
[2729]140        ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev, n_wav))
141        ALLOCATE(pizaerstrat_mois_glo(klon_glo, n_lev, n_wav))
142        ALLOCATE(cgaerstrat_mois_glo(klon_glo, n_lev, n_wav))
[2536]143
144!--reading stratospheric aerosol tau per layer
[2729]145        CALL nf95_inq_varid(ncid_in, "TAU_SUN", varid)
146        ncerr = nf90_get_var(ncid_in, varid, tauaerstrat)
147        print *,'code erreur readaerosolstrato=', ncerr, varid
[2536]148
149!--reading stratospheric aerosol omega per layer
[2729]150        CALL nf95_inq_varid(ncid_in, "OME_SUN", varid)
151        ncerr = nf90_get_var(ncid_in, varid, pizaerstrat)
152        print *,'code erreur readaerosolstrato=', ncerr, varid
[2536]153
154!--reading stratospheric aerosol g per layer
[2729]155        CALL nf95_inq_varid(ncid_in, "GGG_SUN", varid)
156        ncerr = nf90_get_var(ncid_in, varid, cgaerstrat)
157        print *,'code erreur readaerosolstrato sw=', ncerr, varid
[2536]158
[2729]159        CALL nf95_close(ncid_in)
[2536]160
161!--select the correct month
162!--and copy into 1st longitude
[2729]163        tauaerstrat_mois(1,:,:,:) = tauaerstrat(:,:,:,mth_cur)
164        pizaerstrat_mois(1,:,:,:) = pizaerstrat(:,:,:,mth_cur)
165        cgaerstrat_mois(1,:,:,:)  = cgaerstrat(:,:,:,mth_cur)
[2536]166
167!--copy longitudes
[2729]168        DO i=2, n_lon
169         tauaerstrat_mois(i,:,:,:) = tauaerstrat_mois(1,:,:,:)
170         pizaerstrat_mois(i,:,:,:) = pizaerstrat_mois(1,:,:,:)
171         cgaerstrat_mois(i,:,:,:)  = cgaerstrat_mois(1,:,:,:)
172        ENDDO
[2536]173
174!---reduce to a klon_glo grid
[2729]175        DO band=1, NSW
176          CALL grid2dTo1d_glo(tauaerstrat_mois(:,:,:,band),tauaerstrat_mois_glo(:,:,band))
177          CALL grid2dTo1d_glo(pizaerstrat_mois(:,:,:,band),pizaerstrat_mois_glo(:,:,band))
178          CALL grid2dTo1d_glo(cgaerstrat_mois(:,:,:,band),cgaerstrat_mois_glo(:,:,band))
179        ENDDO
[2536]180
181!--Now LW optical properties
182!
[2729]183        CALL nf95_open("taulwstrat.2D.nc", nf90_nowrite, ncid_in)
[2536]184
[2729]185        CALL nf95_inq_varid(ncid_in, "LEV", varid)
186        CALL nf95_gw_var(ncid_in, varid, lev)
187        n_lev = size(lev)
188        IF (n_lev.NE.klev) THEN
189           abort_message='Le nombre de niveaux n est pas egal a klev'
190           CALL abort_physic(modname,abort_message,1)
191        ENDIF
[2536]192
[2729]193        CALL nf95_inq_varid(ncid_in, "LAT", varid)
194        CALL nf95_gw_var(ncid_in, varid, latitude)
195        n_lat = size(latitude)
196        IF (n_lat.NE.nbp_lat) THEN
197           abort_message='Le nombre de lat n est pas egal a nbp_lat'
198           CALL abort_physic(modname,abort_message,1)
199        ENDIF
[2536]200
[2729]201        CALL nf95_inq_varid(ncid_in, "TIME", varid)
202        CALL nf95_gw_var(ncid_in, varid, time)
203        n_month = size(time)
204        IF (n_month.NE.12) THEN
205           abort_message='Le nombre de month n est pas egal a 12'
206           CALL abort_physic(modname,abort_message,1)
207        ENDIF
[2536]208
[2729]209        CALL nf95_inq_varid(ncid_in, "WAV", varid)
210        CALL nf95_gw_var(ncid_in, varid, wav)
211        n_wav = size(wav)
212        print *, 'WAV aerosol strato=', n_wav, wav
213        IF (n_wav.NE.NLW) THEN
214           abort_message='Le nombre de wav n est pas egal a NLW'
215           CALL abort_physic(modname,abort_message,1)
216        ENDIF
[2536]217
[2729]218        ALLOCATE(taulwaerstrat(n_lat, n_lev, n_wav, n_month))
219        ALLOCATE(taulwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
220        ALLOCATE(taulwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
[2536]221
222!--reading stratospheric aerosol lw tau per layer
[2729]223        CALL nf95_inq_varid(ncid_in, "TAU_EAR", varid)
224        ncerr = nf90_get_var(ncid_in, varid, taulwaerstrat)
225        print *,'code erreur readaerosolstrato lw=', ncerr, varid
[2536]226
[2729]227        CALL nf95_close(ncid_in)
[2536]228
229!--select the correct month
230!--and copy into 1st longitude
[2729]231        taulwaerstrat_mois(1,:,:,:) = taulwaerstrat(:,:,:,mth_cur)
[2536]232!--copy longitudes
[2729]233        DO i=2, n_lon
234          taulwaerstrat_mois(i,:,:,:) = taulwaerstrat_mois(1,:,:,:)
235        ENDDO
[2536]236
237!---reduce to a klon_glo grid
[2729]238        DO band=1, NLW
239          CALL grid2dTo1d_glo(taulwaerstrat_mois(:,:,:,band),taulwaerstrat_mois_glo(:,:,band))
240        ENDDO
[2536]241
[2729]242      ELSE !--proc other than mpi_root and omp_root
243           !--dummy allocation needed for debug mode
[2536]244
[2729]245        ALLOCATE(tauaerstrat_mois_glo(1,1,1))
246        ALLOCATE(pizaerstrat_mois_glo(1,1,1))
247        ALLOCATE(cgaerstrat_mois_glo(1,1,1))
248        ALLOCATE(taulwaerstrat_mois_glo(1,1,1))
249
250      ENDIF !--is_mpi_root and is_omp_root
251
[2536]252!$OMP BARRIER
253
254!--keep memory of previous month
[2729]255      mth_pre=mth_cur
[2536]256
257!--scatter on all proc
[2729]258      CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
259      CALL scatter(pizaerstrat_mois_glo,piz_aer_strat)
260      CALL scatter(cgaerstrat_mois_glo,cg_aer_strat)
261      CALL scatter(taulwaerstrat_mois_glo,taulw_aer_strat)
[2536]262
[2729]263      IF (is_mpi_root.AND.is_omp_root) THEN
[2536]264!
[2729]265        DEALLOCATE(tauaerstrat, pizaerstrat, cgaerstrat)
266        DEALLOCATE(tauaerstrat_mois, pizaerstrat_mois, cgaerstrat_mois)
267        DEALLOCATE(taulwaerstrat,taulwaerstrat_mois)
[2536]268!
[2729]269      ENDIF !--is_mpi_root and is_omp_root
[2536]270
[2729]271      DEALLOCATE(tauaerstrat_mois_glo,pizaerstrat_mois_glo,cgaerstrat_mois_glo)
272      DEALLOCATE(taulwaerstrat_mois_glo)
273
[2536]274!$OMP BARRIER
275
276    ENDIF !--debut ou nouveau mois
277
278!--total vertical aod at the 5 SW wavelengths
279!--for now use band 3 AOD into all 5 wavelengths
[2594]280!--it is only a reasonable approximation for 550 nm (wave=2)
[2536]281    band=3
282    DO i=1, klon
283    DO k=1, klev
284      IF (stratomask(i,k).GT.0.999999) THEN
[2594]285        DO wave=1, nwave_sw
286          tausum_aero(i,wave,id_STRAT_phy)=tausum_aero(i,wave,id_STRAT_phy)+tau_aer_strat(i,k,band)
[2536]287        ENDDO
288      ENDIF
289    ENDDO
290    ENDDO
291
292!--weighted average for cg, piz and tau, adding strat aerosols on top of tropospheric ones
[2539]293    DO band=1, NSW
[2729]294      WHERE (stratomask.GT.0.999999)
[2539]295!--anthropogenic aerosols bands 1 to NSW
[2729]296        cg_aero_sw_rrtm(:,:,2,band)  = ( cg_aero_sw_rrtm(:,:,2,band)*piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) + &
297                                         cg_aer_strat(:,:,band)*piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /              &
298                                    MAX( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
299                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band), 1.e-15 )
300        piz_aero_sw_rrtm(:,:,2,band) = ( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
301                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /                                     &
302                                    MAX( tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band), 1.e-15 )
303        tau_aero_sw_rrtm(:,:,2,band)  = tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band)
[2539]304!--natural aerosols bands 1 to NSW
[2729]305        cg_aero_sw_rrtm(:,:,1,band)  = ( cg_aero_sw_rrtm(:,:,1,band)*piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) + &
306                                         cg_aer_strat(:,:,band)*piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /              &
307                                    MAX( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                             &
308                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band), 1.e-15 )
309        piz_aero_sw_rrtm(:,:,1,band) = ( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                             &
310                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /                                     &
311                                    MAX( tau_aero_sw_rrtm(:,:,1,band) + tau_aer_strat(:,:,band), 1.e-15 )
312        tau_aero_sw_rrtm(:,:,1,band)  = tau_aero_sw_rrtm(:,:,1,band) + tau_aer_strat(:,:,band)
[2536]313!--no stratospheric aerosol in index 1 for these tests
[2729]314!        cg_aero_sw_rrtm(:,:,1,band)  =  cg_aero_sw_rrtm(:,:,1,band)
315!        piz_aero_sw_rrtm(:,:,1,band)  = piz_aero_sw_rrtm(:,:,1,band)
316!        tau_aero_sw_rrtm(:,:,1,band)  = tau_aero_sw_rrtm(:,:,1,band)
[2536]317    ENDWHERE
318    ENDDO
319
[2594]320!--total vertical aod at 10 um
321!--this is approximated from band 7 of RRTM
322    band=7
323    DO i=1, klon
324    DO k=1, klev
325      IF (stratomask(i,k).GT.0.999999) THEN
326        DO wave=1, nwave_lw
327          tausum_aero(i,nwave_sw+wave,id_STRAT_phy)=tausum_aero(i,nwave_sw+wave,id_STRAT_phy)+taulw_aer_strat(i,k,band)
328        ENDDO
329      ENDIF
330    ENDDO
331    ENDDO
332
[2539]333    DO band=1, NLW
[2729]334      WHERE (stratomask.GT.0.999999)
335        tau_aero_lw_rrtm(:,:,2,band)  = tau_aero_lw_rrtm(:,:,2,band) + taulw_aer_strat(:,:,band)
336        tau_aero_lw_rrtm(:,:,1,band)  = tau_aero_lw_rrtm(:,:,1,band) + taulw_aer_strat(:,:,band)
[2536]337!--no stratospheric aerosols in index 1 for these tests
338!    tau_aero_lw_rrtm(:,:,1,band)  = tau_aero_lw_rrtm(:,:,1,band)
[2729]339      ENDWHERE
[2536]340    ENDDO
341
342!--default SSA value if there is no aerosol
343!--to avoid 0 values that seems to cause some problem to RRTM
344    WHERE (tau_aero_sw_rrtm.LT.1.e-14)
345      piz_aero_sw_rrtm = 1.0
346    ENDWHERE
347
348!--in principle this should not be necessary
349!--as these variables have min values already but just in case
350!--put 1e-15 min value to both SW and LW AOD
351    tau_aero_sw_rrtm = MAX(tau_aero_sw_rrtm,1.e-15)
352    tau_aero_lw_rrtm = MAX(tau_aero_lw_rrtm,1.e-15)
353
[2720]354END SUBROUTINE readaerosolstrato2_rrtm
Note: See TracBrowser for help on using the repository browser.