source: LMDZ6/branches/LMDZ-COSP/libf/phylmd/cospv2/lmdz/lmdz_cospv2_interface.F90 @ 5917

Last change on this file since 5917 was 5917, checked in by idelkadi, 4 hours ago

Nouveau répertoire cospv2 avec la même structure offline

  • Property svn:executable set to *
File size: 27.6 KB
Line 
1!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2! Nouveau code d'interface entre LMDZ et COSPv2 (version 2)
3! Dans cette nouvelle version de COSP, le code a ete restructure pour optimiser les calculs
4! des differents simulateurs et pour proposer de nouvelles fonctionnalites (par exemple,
5! intervenir sur les profils sous-maille, ou subcolumns, donnes en entre a COSP afin que
6! leur definition soit coherente avec les parametrisations du modele hote).
7! Cette version de COSP propose aussi de nombreux nouveaux diagnostics, notamment pour
8! le simulateur lidar (diagnostics CALIPSO-OPAQ, lidar sol 532nm et lidar ATLID 355nm).
9! la meme organisation offline de Cosp est conservee avec les memes repertoires et sous
10! repertoires pour faciliter les mises a jours dans LMDZ et pouvoir tourner aussi Cosp
11! offline ...
12! Interface ecrite par A.Idelkadi (11/2025)
13!
14!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16subroutine lmdz_cospv2_interface(itap, dtime,  &
17                         Nptslmdz, Nlevlmdz, lon, lat, presnivs,     &
18                         overlaplmdz, sunlit, ref_liq, ref_ice, fracTerLic,       &
19                         u_wind, v_wind, phis, phi, ph, p, skt, t, sh, rh,        &
20                         tca, cca, mr_lsliq, mr_lsice, fl_lsrainI, fl_lssnowI,    &
21                         fl_ccrainI, fl_ccsnowI, mr_ozone, dtau_s, dem_s)
22
23!!! Modules specifiques a l'interface LMDZ-COSP
24  use mod_phys_lmdz_para
25  use mod_grid_phy_lmdz
26  use ioipsl
27  use iophy
28  use lmdz_xios, ONLY : using_xios
29  use wxios_mod, ONLY : missing_val
30  use lmdz_cosp_output_mod
31  use lmdz_cosp_output_write_mod
32  use lmdz_cosp_read_outputkeys
33  use lmdz_cosp_subsample_and_optics_mod, only : subsample_and_optics
34  use lmdz_cosp_construct_destroy_mod
35  use clesphys_mod_h
36
37!!! Modules faisant partie du code source de COSPv2
38  use cosp_kinds,          only: wp                         
39  USE MOD_COSP_CONFIG,     ONLY: R_UNDEF,PARASOL_NREFL,LIDAR_NCAT,LIDAR_NTYPE,SR_BINS,    &
40                                 N_HYDRO,RTTOV_MAX_CHANNELS,numMISRHgtBins,               &
41                                 cloudsat_DBZE_BINS,LIDAR_NTEMP,calipso_histBsct,         &
42                                 CFODD_NDBZE,      CFODD_NICOD,                           &
43                                 CFODD_BNDRE,      CFODD_NCLASS,                          &
44                                 CFODD_DBZE_MIN,   CFODD_DBZE_MAX,                        &
45                                 CFODD_ICOD_MIN,   CFODD_ICOD_MAX,                        &
46                                 CFODD_DBZE_WIDTH, CFODD_ICOD_WIDTH,                      &
47                                 WR_NREGIME,                                              &
48                                 numMODISTauBins,numMODISPresBins,                        &
49                                 numMODISReffIceBins,numMODISReffLiqBins,                 &
50                                 numISCCPTauBins,numISCCPPresBins,numMISRTauBins,         &
51                                 ntau,modis_histTau,tau_binBounds,                        &
52                                 modis_histTauEdges,tau_binEdges,                         &
53                                 modis_histTauCenters,tau_binCenters,ntauV1p4,            &
54                                 tau_binBoundsV1p4,tau_binEdgesV1p4, tau_binCentersV1p4,  &
55                                 grLidar532_histBsct,atlid_histBsct,                      &
56                                 !vgrid_zu,vgrid_zl,    &
57                                 !Nlvgrid_local  => Nlvgrid,                               &
58                                 !vgrid_z,                                                 &
59                                 cloudsat_preclvl, niv_sorties, vgrid_z_in
60  use cosp_phys_constants, only: amw,amd,amO3,amCO2,amCH4,amN2O,amCO
61  !use mod_cosp_io,         only: nc_read_input_file,write_cosp2_output
62  USE mod_quickbeam_optics,only: size_distribution,hydro_class_init,quickbeam_optics,     &
63                                 quickbeam_optics_init,gases
64  use quickbeam,           only: radar_cfg
65  use mod_cosp,            only: cosp_init,cosp_optical_inputs,cosp_column_inputs,        &
66                                 cosp_outputs,cosp_cleanUp,cosp_simulator
67  USE mod_rng,             ONLY: rng_state, init_rng
68  USE mod_scops,           ONLY: scops
69  USE mod_prec_scops,      ONLY: prec_scops
70  USE MOD_COSP_UTILS,      ONLY: cosp_precip_mxratio
71  use cosp_optics,         ONLY: cosp_simulator_optics,lidar_optics,modis_optics,         &
72                                 modis_optics_partition
73  use mod_cosp_stats,      ONLY: COSP_CHANGE_VERTICAL_GRID
74 
75  implicit none
76
77!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
78!! Declarations variables
79
80  ! Input/Output driver file control
81  character(len=64),PARAMETER   :: cosp_input_nl  = 'cospv2_input_nl.txt'
82  character(len=64),PARAMETER   :: cosp_output_nl = 'cospv2_output_nl.txt'
83
84  ! Input variables from LMDZ
85  integer                    :: Nptslmdz, Nlevlmdz   ! Nb de points issus de physiq.F
86  integer                    :: Nlon,Nlat,geomode
87  integer                    :: overlaplmdz   ! overlap type: 1=max,
88  real, dimension(Nlevlmdz)  :: presnivs
89  real, dimension(Nptslmdz)  :: &
90       lon,       & ! Longitude (deg)
91       lat,       & ! Latitude (deg)
92       skt,       & ! Skin temperature (K)
93       surfelev,  & ! Surface Elevation (m)
94       land,      & ! Land/sea mask (0/1)
95       u_wind,    & ! U-component of wind (m/s)
96       v_wind,    & ! V-component of wind (m/s)
97       sunlit,    & ! Sunlit flag
98       phis,      &  ! Geop au sol
99       fracTerLic
100  real, dimension(Nptslmdz,Nlevlmdz) :: &
101       phi,       & ! geop
102       p,         & ! Model pressure levels (pa)
103       ph,        & ! Moddel pressure @ half levels (pa)
104       zlev,      & ! Model level height (m)
105       zlev_half, & ! Model level height @ half-levels (m)
106       T,         & ! Temperature (K)
107       sh,         & ! Specific humidity (kg/kg)
108       rh,        & ! Relative humidity (1)
109       tca,       & ! Total cloud fraction (1)
110       cca,       & ! Convective cloud fraction (1)
111       mr_lsliq,  & ! Mass mixing ratio for stratiform cloud liquid (kg/kg)
112       mr_lsice,  & ! Mass mixing ratio for stratiform cloud ice (kg/kg)
113       mr_ccliq,  & ! Mass mixing ratio for convective cloud liquid (kg/kg)
114       mr_ccice,  & ! Mass mixing ratio for convective cloud ice (kg/kg)
115       mr_ozone,  & ! Mass mixing ratio for ozone (kg/kg)
116       fl_lsrain, & ! Precipitation flux (rain) for stratiform cloud (kg/m^2/s)
117       fl_lssnow, & ! Precipitation flux (snow) for stratiform cloud (kg/m^2/s)
118       fl_lsgrpl, & ! Precipitation flux (groupel) for stratiform cloud (kg/m^2/s)
119       fl_ccrain, & ! Precipitation flux (rain) for convective cloud (kg/m^2/s)
120       fl_ccsnow, & ! Precipitation flux (snow) for convective cloud (kg/m^2/s)
121       dtau_s,    & ! 0.67micron optical depth (stratiform cloud) (1)
122       dtau_c,    & ! 0.67micron optical depth (convective cloud) (1)
123       dem_s,     & ! 11micron emissivity (stratiform cloud)
124       dem_c,     &  ! 11microm emissivity (convective cloud)
125       ref_liq,   &
126       ref_ice
127  real, dimension(Nptslmdz,Nlevlmdz)         :: fl_lsrainI, fl_lssnowI, fl_ccrainI, fl_ccsnowI
128  real(wp),dimension(Nptslmdz,Nlevlmdz,N_HYDRO) :: &
129       frac_out,  & ! Subcolumn cloud cover (0/1)
130       Reff         ! Subcolumn effective radius
131
132  type(cosp_config), save       :: cfg                  ! Variable qui contient les cles
133                                                        ! logiques des simulateurs et des
134                                                        ! diagnostics, definie dans:
135                                                        ! lmdz_cosp_construct_destroy_mod
136!$OMP THREADPRIVATE(cfg)                                                     
137
138  integer                       :: itap, k, ip
139  real                          :: dtime
140  real, dimension(2)            :: time_bnds
141
142  real                          :: d_dtime
143  real, dimension(2)            :: d_time_bnds                                                     
144
145  ! Input namelist fields
146  integer, save ::     Npoints, Nlevels
147!$OMP THREADPRIVATE(Npoints)
148  integer, save ::                      & !
149       Ncolumns,                  & ! Number of subcolumns
150       Npoints_it,                & ! Number of gridpoints to be processed in one
151                                    ! iteration
152       Nlvgrid,                   & ! Number of vertical levels for statistical outputs
153                                    ! (USE_VGRID=.true.)
154       surface_radar,             & ! surface=1/spaceborne=0
155       cloudsat_use_gas_abs,      & ! Include gaseous absorption (1=yes/0=no)
156       cloudsat_do_ray,           & ! Calculate output Rayleigh (1=yes/0=no)
157       lidar_ice_type,            & ! Ice particle shape in lidar calculations
158                                    ! (0=ice-spheres/1=ice-non-spherical)
159       !overlap,                   & ! Overlap type: 1=max, 2=rand, 3=max/rand
160       isccp_topheight,           & ! ISCCP cloud top height
161       isccp_topheight_direction, & ! ISCCP cloud top height direction
162       rttov_platform,            & ! RTTOV: Satellite platform
163       rttov_satellite,           & ! RTTOV: Satellite
164       rttov_instrument,          & ! RTTOV: Instrument
165       rttov_Nchannels              ! RTTOV: Number of channels to be computed
166  real(wp), save ::               & !
167       emsfc_lw,                  &
168       cloudsat_radar_freq,       & ! CloudSat radar frequency (GHz)
169       cloudsat_k2,               & ! |K|^2, -1=use frequency dependent default
170       rttov_ZenAng,              & ! RTTOV: Satellite Zenith Angle
171       co2,                       & ! CO2 mixing ratio
172       ch4,                       & ! CH4 mixing ratio
173       n2o,                       & ! n2o mixing ratio
174       co                           ! co mixing ratio
175  logical, save ::                      & !
176       use_vgrid_in,                 & ! Use fixed vertical grid for outputs?
177       csat_vgrid_in,                & ! CloudSat vertical grid?
178       use_precipitation_fluxes     ! True if precipitation fluxes are input to the
179                                    ! algorithm
180
181  integer,dimension(RTTOV_MAX_CHANNELS), save :: &
182       rttov_Channels               ! RTTOV: Channel numbers
183  real(wp),dimension(RTTOV_MAX_CHANNELS), save :: &
184       rttov_Surfem                 ! RTTOV: Surface emissivity
185  character(len=64), save :: &
186       cloudsat_micro_scheme        ! Microphysical scheme used in cloudsat radar simulator
187!$OMP THREADPRIVATE(emsfc_lw)
188
189! Declaration necessaires pour les sorties IOIPSL
190  !real          :: ecrit_day, ecrit_hf, ecrit_mth, missing_val
191  !logical       :: ok_mensuelCOSP, ok_journeCOSP, ok_hfCOSP, ok_all_xml
192  logical, save :: debut_cosp=.true.
193!$OMP THREADPRIVATE(debut_cosp)
194
195  logical, save :: first_write=.true.
196!$OMP THREADPRIVATE(first_write)
197
198  integer, save :: cosp_init_flag = 0
199!$OMP THREADPRIVATE(cosp_init_flag)
200
201! Local variables
202  logical :: &
203       Lsingle     = .true.,  & ! True if using MMF_v3_single_moment CLOUDSAT
204                                ! microphysical scheme (default)
205       Ldouble     = .false.    ! True if using MMF_v3.5_two_moment CLOUDSAT
206  type(size_distribution), save :: &
207       sd                ! Hydrometeor description
208!$OMP THREADPRIVATE(sd)
209  type(radar_cfg), save :: &
210       rcfg_cloudsat     ! Radar configuration
211!$OMP THREADPRIVATE(rcfg_cloudsat)
212  type(cosp_outputs) :: &
213       cospOUT           ! COSP simulator outputs
214  type(cosp_optical_inputs) :: &
215       cospIN            ! COSP optical (or derived?) fields needed by simulators
216  type(cosp_column_inputs) :: &
217       cospstateIN       ! COSP model fields needed by simulators
218  integer :: iChunk,nChunks,start_idx,end_idx,nPtsPerIt,ij
219  real(wp),dimension(10) :: driver_time
220  character(len=256),dimension(100) :: cosp_status
221
222  ! Indices to address arrays of LS and CONV hydrometeors
223  integer,parameter :: &
224       I_LSCLIQ = 1, & ! Large-scale (stratiform) liquid
225       I_LSCICE = 2, & ! Large-scale (stratiform) ice
226       I_LSRAIN = 3, & ! Large-scale (stratiform) rain
227       I_LSSNOW = 4, & ! Large-scale (stratiform) snow
228       I_CVCLIQ = 5, & ! Convective liquid
229       I_CVCICE = 6, & ! Convective ice
230       I_CVRAIN = 7, & ! Convective rain
231       I_CVSNOW = 8, & ! Convective snow
232       I_LSGRPL = 9    ! Large-scale (stratiform) groupel
233 
234  namelist/COSP_INPUT/overlap, isccp_topheight, isccp_topheight_direction,                &
235       npoints_it, ncolumns, use_vgrid_in, Nlvgrid, csat_vgrid_in,                              &
236       cloudsat_radar_freq, surface_radar, cloudsat_use_gas_abs,cloudsat_do_ray,          &
237       cloudsat_k2, cloudsat_micro_scheme, lidar_ice_type, use_precipitation_fluxes,      &
238       rttov_platform, rttov_satellite, rttov_Instrument, rttov_Nchannels,                &
239       rttov_Channels, rttov_Surfem, rttov_ZenAng, co2, ch4, n2o, co
240
241!!Fin declaration des variables
242!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243
244  !call cpu_time(driver_time(1))
245!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246  ! Read in namelists
247!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248  ! call get_command_argument(1, cosp_input_namelist)
249
250  IF (is_master) print*,'Entree lmdz_cosp_interface, Npoints = ',Npoints
251  if (debut_cosp) then
252     Npoints=Nptslmdz
253     Nlevels=Nlevlmdz
254     ! Surface emissivity
255     emsfc_lw = 1.
256! Lecture du namelist input
257     IF (is_master) THEN
258       OPEN(10,file=cosp_input_nl,status='old')
259       READ(10,nml=cosp_input)
260       CLOSE(10)
261     ENDIF
262
263!$OMP BARRIER
264     CALL bcast(overlap)
265     CALL bcast(isccp_topheight)
266     CALL bcast(isccp_topheight_direction)
267     CALL bcast(npoints_it)
268     CALL bcast(ncolumns)
269     CALL bcast(use_vgrid_in)
270     CALL bcast(csat_vgrid_in)
271     CALL bcast(cloudsat_radar_freq)
272     CALL bcast(surface_radar)
273     CALL bcast(cloudsat_use_gas_abs)
274     CALL bcast(cloudsat_do_ray)
275     CALL bcast(cloudsat_k2)
276     CALL bcast(lidar_ice_type)
277     CALL bcast(use_precipitation_fluxes)
278     CALL bcast(rttov_platform)
279     CALL bcast(rttov_satellite)
280     CALL bcast(rttov_Instrument)
281     CALL bcast(rttov_Nchannels)
282     CALL bcast(rttov_Channels)
283     CALL bcast(rttov_Surfem)
284     CALL bcast(rttov_ZenAng)
285     CALL bcast(co2)
286     CALL bcast(ch4)
287     CALL bcast(n2o)
288     CALL bcast(co)
289     CALL bcast(cloudsat_micro_scheme)
290     CALL bcast(Nlvgrid)
291     IF (is_master) print*,'ok read  cosp_input_nl'
292
293! Clefs Outputs initialisation
294! Ici les cles sont definies en fonction des champs pour lesquels les sorties sont activees
295! Si XIOS c'est les fichiers file*COSP.xml qui indiquent quels variables sortir et donc quels
296! simulateurs activer
297    IF (using_xios) THEN
298      IF (is_master) print*,'On initialise les cles pour activer les simulateurs et sorties'
299      call cosp_outputkeys_init(cfg)
300    ELSE
301      call read_cosp_output_nl(itap,cosp_output_nl,cfg)
302      if (cosp_init_flag .eq. 0) then
303
304        ! Initialize the distributional parameters for hydrometeors in radar simulator.
305        ! In COSPv1.4, this was declared in cosp_defs.f.
306        if (cloudsat_micro_scheme == 'MMF_v3.5_two_moment')  then
307          ldouble = .true.
308          lsingle = .false.
309        endif
310        call hydro_class_init(lsingle,ldouble,sd)
311        call quickbeam_optics_init()
312
313        IF (is_master) print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag
314    !$OMP MASTER
315        call COSP_INIT(cfg%Lisccp, cfg%Lmodis, cfg%Lmisr, cfg%Lcloudsat, cfg%Lcalipso, &
316           cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov,          &
317           cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs,         &
318           cloudsat_do_ray, isccp_topheight, isccp_topheight_direction,    &
319           surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in, niv_sorties,   &
320           Nlevels, cloudsat_micro_scheme)
321    !$OMP END MASTER
322    !$OMP BARRIER
323        cosp_init_flag = 1
324        IF (is_master) print*,' just after call COSP_INIT, cosp_init_flag =', cosp_init_flag
325      endif
326    ENDIF
327   
328    IF (is_master) print*,' Cles des differents simulateurs cosp a itap :',itap
329    IF (is_master) print*,'cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
330        cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov', &
331        cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
332        cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov
333
334  endif ! debut_cosp
335
336  !!! Ici on modifie les cles logiques pour les outputs selon les champs actives dans les .xml
337  if ((itap.ge.1).and.(first_write))then
338    IF (using_xios) call read_xiosfieldactive(cfg)
339    first_write=.false.
340    if (cosp_init_flag .eq. 0) then
341
342      ! Initialize the distributional parameters for hydrometeors in radar simulator.
343      ! In COSPv1.4, this was declared in cosp_defs.f.
344      if (cloudsat_micro_scheme == 'MMF_v3.5_two_moment')  then
345         ldouble = .true.
346         lsingle = .false.
347      endif
348      call hydro_class_init(lsingle,ldouble,sd)
349      call quickbeam_optics_init()
350
351      IF (is_master) print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag
352    !$OMP MASTER
353      call COSP_INIT(cfg%Lisccp, cfg%Lmodis, cfg%Lmisr, cfg%Lcloudsat, cfg%Lcalipso, &
354          cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov,          &
355          cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs,         &
356          cloudsat_do_ray, isccp_topheight, isccp_topheight_direction,    &
357          surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in, niv_sorties,   &
358          Nlevels, cloudsat_micro_scheme)
359    !$OMP END MASTER
360    !$OMP BARRIER
361      cosp_init_flag = 1
362      IF (is_master) print*,' just after call COSP_INIT, cosp_init_flag =', cosp_init_flag
363    endif ! cosp_init_flag
364
365    IF (is_master) print*,' Cles des differents simulateurs cosp a itap :',itap
366    IF (is_master) print*,'cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
367        cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov', &
368        cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
369        cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov
370
371  endif !(itap.gt.1).and.(first_write)
372  time_bnds(1) = dtime-dtime/2.
373  time_bnds(2) = dtime+dtime/2.
374
375  d_time_bnds=time_bnds
376  d_dtime=dtime
377
378!-------------------------   Fin initialisation de COSP   --------------------------
379
380!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381! 3) Calculs des champs d'entree COSP a partir des variables LMDZ
382!
383    ! 0) Create ptop/ztop for gbx%pf and gbx%zlev are for the the interface,
384    !    also reverse CAM height/pressure values for input into CSOP
385    !    CAM state%pint from top to surface, COSP wants surface to top.
386! 0) Altitudes du modele calculees a partir de la variable geopotentiel phi et phis
387  IF (is_master) print*,'Calculs des champs entree COSP a partir des variables LMDZ'
388   zlev = phi/9.81
389   zlev_half(:,1) = phis(:)/9.81
390   do k = 2, Nlevels
391     do ip = 1, Npoints
392        zlev_half(ip,k) = phi(ip,k)/9.81 + &
393        (phi(ip,k)-phi(ip,k-1))/9.81 * (ph(ip,k)-p(ip,k)) / (p(ip,k)-p(ip,k-1))
394     enddo
395   enddo
396! 1) Quantite de nuages (couverture?), convectif (=0) et total
397   cca = 0._wp ! convective_cloud_amount (1)
398   tca = tca   ! total_cloud_amount (1)
399! 2) Humidite relative est donnee tel quel (variable rh)
400! 3) Masque terre/mer a partir de la variable fracTerLic
401   do ip = 1, Npoints
402      if (fracTerLic(ip).ge.0.5) then
403          land(ip) = 1.
404      else
405          land(ip) = 0.
406      endif
407   enddo
408! A voir l equivalent LMDZ
409  mr_ccliq = 0.0
410  mr_ccice = 0.0
411!!!  gbx%mr_hydro(:,:,I_LSCLIQ) = mr_lsliq !mixing_ratio_large_scale_cloud_liquid (kg/kg)
412!!!  gbx%mr_hydro(:,:,I_LSCICE) = mr_lsice !mixing_ratio_large_scale_cloud_ic
413!!!  gbx%mr_hydro(:,:,I_CVCLIQ) = mr_ccliq !mixing_ratio_convective_cloud_liquid
414!!!  gbx%mr_hydro(:,:,I_CVCICE) = mr_ccice !mixing_ratio_convective_cloud_ice
415! A revoir
416  fl_lsrain = fl_lsrainI + fl_ccrainI
417  fl_lssnow = fl_lssnowI + fl_ccsnowI
418!!!  gbx%rain_ls = fl_lsrain !flux_large_scale_cloud_rain (kg m^-2 s^-1)
419!!!  gbx%snow_ls = fl_lssnow !flux_large_scale_cloud_snow
420!  A voir l equivalent LMDZ
421  fl_lsgrpl = 0.
422  fl_ccsnow = 0.
423  fl_ccrain = 0.
424!!!        gbx%grpl_ls = fl_lsgrpl  !flux_large_scale_cloud_graupel
425!!!        gbx%rain_cv = fl_ccrain  !flux_convective_cloud_rain
426!!!        gbx%snow_cv = fl_ccsnow  !flux_convective_cloud_snow
427! ISCCP simulator
428  dtau_c  = 0.
429  dem_c   = 0.
430! note: reff_cosp dimensions should be same as cosp (reff_cosp has 9 hydrometeor dimension)
431  Reff(1:Npoints,1:Nlevels,1:N_HYDRO) = 0.
432  Reff(:,:,I_LSCLIQ) = ref_liq*1e-6
433  Reff(:,:,I_LSCICE) = ref_ice*1e-6
434  Reff(:,:,I_CVCLIQ) = ref_liq*1e-6
435  Reff(:,:,I_CVCICE) = ref_ice*1e-6
436
437 if (cosp_init_flag .eq. 1) then      ! cosp_init_flag = 1
438  !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
439  !call construct_cosp_outputs(cfg,Npoints,Ncolumns,Nlevels,Nlvgrid,0,cospOUT)
440  IF (is_master) print*,'construct_cosp_outputs'
441   call construct_cosp_outputs(cfg,Npoints,Ncolumns,Nlevels,niv_sorties,rttov_Nchannels,use_vgrid_in,cospOUT)
442
443! 4b) On construit la variable cospstateIN que l'on va remplir avec les champs LMDZ
444! Les champ verticaux doivent etre donnes a l'envers, c-a-d : (Nlevels:1) = (TOA:SFC)
445!
446!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
447    IF (is_master) print*,'call construct_cospstateIN'
448    call construct_cospstateIN(Npoints,Nlevels,0,cospstateIN)
449
450    cospIN%emsfc_lw                                     = emsfc_lw
451    cospstateIN%lat                                     = lat(1:Npoints)
452    cospstateIN%lon                                     = lon(1:Npoints)
453    cospstateIN%at                                      = t(1:Npoints,Nlevels:1:-1)
454    cospstateIN%qv                                      = sh(1:Npoints,Nlevels:1:-1)
455    cospstateIN%o3                                      = mr_ozone(1:Npoints,Nlevels:1:-1)
456    cospstateIN%sunlit                                  = sunlit(1:Npoints)
457    cospstateIN%skt                                     = skt(1:Npoints)
458    cospstateIN%land                                    = land(1:Npoints)
459    cospstateIN%surfelev                                = zlev_half(1:Npoints,1)
460    cospstateIN%pfull                                   = p(1:Npoints,Nlevels:1:-1)
461    cospstateIN%phalf(1:Npoints,1)                      = 0._wp
462    cospstateIN%phalf(1:Npoints,2:Nlevels+1)            = ph(1:Npoints,Nlevels:1:-1)
463    cospstateIN%hgt_matrix                              = zlev(1:Npoints,Nlevels:1:-1)
464    !cospstateIN%hgt_matrix_half(1:Npoints,Nlevels+1)    = 0._wp
465    !cospstateIN%hgt_matrix_half(1:Npoints,1:Nlevels)    = zlev_half(1:Npoints,Nlevels:1:-1)
466    cospstateIN%hgt_matrix_half(:,1:Nlevels)            = zlev_half(:,Nlevels:1:-1) ! km
467    cospIN%rcfg_cloudsat    = rcfg_cloudsat
468!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
469!
470! 4c) On construit la variable cospIN qui contient les proprietes optiques subcolumn
471! pour COSP. Elle sera essentiellement remplie dans la subroutine subsample_and_optics
472! ou sont appeles SCOPS, PREC_SCOPS et les subroutines qui calculent les signaux
473! simules pour chaque simulateur actif.
474!
475!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476    IF (is_master) print*,'call construct_cospIN'
477    call construct_cospIN(cfg,Npoints,Ncolumns,Nlevels,cospIN)
478    cospIN%emsfc_lw  = emsfc_lw
479    if (cfg%Lcloudsat) cospIN%rcfg_cloudsat = rcfg_cloudsat
480     !call cpu_time(driver_time(4))
481
482!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483! Generate subcolumns and compute optical inputs.
484!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
485     IF (is_master) print*,'call subsample_and_optics : Npoints, Nlevels, Ncolumns = ', &
486                            Npoints, Nlevels, Ncolumns
487
488     call subsample_and_optics(cfg, Npoints, Nlevels, Ncolumns, N_HYDRO,overlap, &
489                              use_precipitation_fluxes, lidar_ice_type, sd, &
490                              tca(1:Npoints,Nlevels:1:-1), cca(1:Npoints,Nlevels:1:-1), &
491                              fl_lsrain(1:Npoints,Nlevels:1:-1), &
492                              fl_lssnow(1:Npoints,Nlevels:1:-1), &
493                              fl_lsgrpl(1:Npoints,Nlevels:1:-1), &
494                              fl_ccrain(1:Npoints,Nlevels:1:-1), &
495                              fl_ccsnow(1:Npoints,Nlevels:1:-1), &
496                              mr_lsliq(1:Npoints,Nlevels:1:-1), &
497                              mr_lsice(1:Npoints,Nlevels:1:-1), &
498                              mr_ccliq(1:Npoints,Nlevels:1:-1), &
499                              mr_ccice(1:Npoints,Nlevels:1:-1), &
500                              Reff(1:Npoints,Nlevels:1:-1,:), &
501                              dtau_c(1:Npoints,Nlevels:1:-1), &
502                              dtau_s(1:Npoints,Nlevels:1:-1), &
503                              dem_c(1:Npoints,Nlevels:1:-1), &
504                              dem_s(1:Npoints,Nlevels:1:-1), cospstateIN, cospIN)
505
506     !call cpu_time(driver_time(6))
507   
508!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
509! Call COSP
510!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
511    cosp_status = COSP_SIMULATOR(cospIN, cospstateIN, cospOUT,start_idx,end_idx,.false.)
512
513 endif ! cosp_init_flag = 1
514!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
515! Output
516!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
517!
518! 7a) Ecriture des sorties 1: on cree d'abord les fichiers NCDF pour ecrire les sorties
519! en appelant lmdz_cosp_output_open (lors du premier appel de cette interface pour les
520! 2 options d'ecriture), ou sont definis les axes et les caracteristiques
521! des fichiers de sortie avec les diagnostics.
522!
523!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
524
525  if (debut_cosp) then
526   !$OMP MASTER
527
528    IF (is_master) print *, ' Open outpts files and define axis'
529    call lmdz_cosp_output_open(Nlevlmdz, Ncolumns, presnivs, dtime,  &
530                               use_vgrid_in, niv_sorties, vgrid_z_in, zlev(1,:))
531
532    !$OMP END MASTER
533    !$OMP BARRIER
534    debut_cosp=.false.
535   endif ! debut_cosp
536
537  if (cosp_init_flag .eq. 1) then
538!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539!
540! 7b) Ecriture des sorties 2: le remplissage des fichiers de sortie se fait a chaque
541! appel de cette interface avec une difference entre les 2 options d'ecriture:
542! - AVEC xios, on commence a remplir les fichiers de sortie a partir du DEUXIEME
543! appel de cette interface (lorsque cosp_init_flag = 1).
544! - SANS xios, on commence a remplir les fichiers de sortie a partir du PREMIER
545! appel de cette interface (lorsque cosp_init_flag = 1).
546!
547!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548
549    IF (is_master) print *, 'Calling write output'
550    call lmdz_cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, &
551                                 cfg, niv_sorties, cospOUT)
552!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553! Free up memory
554!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
555    call destroy_cosp_outputs(cospOUT)
556    call destroy_cospIN(cospIN)
557    call destroy_cospstateIN(cospstateIN)
558    call cosp_cleanUp()
559!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
560 endif ! cosp_init_flag = 1
561
562end subroutine lmdz_cospv2_interface
Note: See TracBrowser for help on using the repository browser.