source: LMDZ6/trunk/libf/phylmd/cospv2/lmdz/lmdz_cosp_interface.F90

Last change on this file was 6056, checked in by idelkadi, 12 days ago

Cospv2 implementation in LMDZ (continued, corrections)

File size: 28.5 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!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14subroutine lmdz_cosp_interface(itap, dtime, freq_cosp, ok_mensuelCOSP, ok_journeCOSP,   &
15                         ok_hfCOSP, ecrit_mth, ecrit_day, ecrit_hf, ok_all_xml,   &
16                         missing_val, Nptslmdz, Nlevlmdz, lon, lat, presnivs,     &
17                         overlaplmdz, sunlit, ref_liq, ref_ice, fracTerLic,       &
18                         u_wind, v_wind, phis, phi, ph, p, skt, t, sh, rh,        &
19                         tca, cca, mr_lsliq, mr_lsice, fl_lsrainI, fl_lssnowI,    &
20                         fl_ccrainI, fl_ccsnowI, mr_ozone, dtau_s, dem_s)
21
22!--------------  Inputs  ---------------
23! itap,                                 !Increment de la physiq
24! dtime,                                !Pas de temps physiq
25! overlaplmdz,                          !Type Overlap venant de LMDZ
26! Npoints,                              !Nb de points de la grille physiq
27! Nlevels,                              !Nb de niveaux verticaux
28! Ncolumns,                             !Number of subcolumns
29! lon,lat,                              !Longitudes et latitudes de la grille LMDZ
30! ref_liq, ref_ice,                     !Rayons effectifs des particules liq et ice (en m ?)
31! fracTerLic,                           !Fraction terre a convertir en masque
32! u_wind, v_wind,                       !Vents a 10m ???
33! phi,                                  !Geopotentiel
34! phis,                                 !Geopotentiel sol
35! ph,                                   !pression pour chaque inter-couche
36! p,                                    !Pression aux milieux des couches
37! skt, t,                               !Temp au sol et temp 3D
38! sh,                                   !Humidite specifique
39! rh,                                   !Humidite relative
40! tca,                                  !Fraction nuageuse
41! cca                                   !Fraction nuageuse convective
42! mr_lsliq,                             !Liq Cloud water content
43! mr_lsice,                             !Ice Cloud water content
44! mr_ccliq,                             !Convective Cloud Liquid water content 
45! mr_ccice,                             !Cloud ice water content
46! fl_lsrain,                            !Large scale precipitation lic
47! fl_lssnow,                            !Large scale precipitation ice
48! fl_ccrain,                            !Convective precipitation lic
49! fl_ccsnow,                            !Convective precipitation ice
50! mr_ozone,                             !Concentration ozone (Kg/Kg)
51! dem_s                                 !Cloud optical emissivity
52! dtau_s                                !Cloud optical thickness
53! emsfc_lw = 1.                         !Surface emissivity dans radlwsw.F90
54
55
56!--------------  Outputs  --------------
57! La liste complete des diagnostics de sortie (observables simulees) que l'on peut
58! avoir avec COSPv2 se trouve au debut du fichier : cosp_read_otputkeys.F90
59
60
61!!! Modules specifiques a l'interface LMDZ-COSP
62  use mod_phys_lmdz_para
63  use mod_grid_phy_lmdz
64  use ioipsl
65  use iophy
66  use lmdz_xios, ONLY : using_xios
67  use lmdz_cosp_output_mod
68  use lmdz_cosp_output_write_mod
69  use lmdz_cosp_read_outputkeys
70  use lmdz_cosp_subsample_and_optics_mod, only : subsample_and_optics
71  use lmdz_cosp_construct_destroy_mod
72
73!!! Modules faisant partie du code source de COSPv2
74  use cosp_kinds,  only: wp                         
75  !use MOD_COSP_CONFIG,       only: N_HYDRO,RTTOV_MAX_CHANNELS, &
76                                    !niv_sorties, vgrid_z_in
77
78  USE MOD_COSP_CONFIG,     ONLY: &
79                                 !R_UNDEF,PARASOL_NREFL,LIDAR_NCAT,LIDAR_NTYPE,SR_BINS,    &
80                                 N_HYDRO,RTTOV_MAX_CHANNELS,niv_sorties,vgrid_z_in
81                                 !numMISRHgtBins,                                           &
82                                 !cloudsat_DBZE_BINS,LIDAR_NTEMP,calipso_histBsct,         &
83                                 !CFODD_NDBZE,      CFODD_NICOD,                           &
84                                 !CFODD_BNDRE,      CFODD_NCLASS,                          &
85                                 !CFODD_DBZE_MIN,   CFODD_DBZE_MAX,                        &
86                                 !CFODD_ICOD_MIN,   CFODD_ICOD_MAX,                        &
87                                 !CFODD_DBZE_WIDTH, CFODD_ICOD_WIDTH,                      &
88                                 !WR_NREGIME,                                              &
89                                 !numMODISTauBins,numMODISPresBins,                        &
90                                 !numMODISReffIceBins,numMODISReffLiqBins,                 &
91                                 !numISCCPTauBins,numISCCPPresBins,numMISRTauBins,         &
92                                 !ntau,modis_histTau,tau_binBounds,                        &
93                                 !modis_histTauEdges,tau_binEdges,                         &
94                                 !modis_histTauCenters,tau_binCenters,ntauV1p4,            &
95                                 !tau_binBoundsV1p4,tau_binEdgesV1p4, tau_binCentersV1p4,  &
96                                 !grLidar532_histBsct,atlid_histBsct,                      &
97                                 !vgrid_zu,vgrid_zl,    &
98                                 !Nlvgrid_local  => Nlvgrid,                               &
99                                 !vgrid_z,
100                                 !cloudsat_preclvl,niv_sorties,vgrid_z_in
101
102  use mod_quickbeam_optics,  only: size_distribution,hydro_class_init, &
103                                   quickbeam_optics_init
104  use quickbeam,            only: radar_cfg
105  use mod_cosp,             only: cosp_init,cosp_optical_inputs, &
106                                  cosp_column_inputs,cosp_outputs, &
107                                  cosp_simulator,cosp_cleanUp
108
109!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110! Declaration des variables
111!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112  IMPLICIT NONE
113
114  ! Local variables
115  character(len=64),PARAMETER:: cosp_input_nl    = 'cospv2_input_nl.txt'
116  character(len=64),PARAMETER  :: cosp_output_nl = 'cospv2_output_nl.txt'
117
118  integer, save        :: isccp_topheight, isccp_topheight_direction, overlap
119  integer, save        :: Ncolumns        ! Number of subcolumns in SCOPS
120  integer, save        :: Npoints            ! Number of gridpoints
121!$OMP THREADPRIVATE(Npoints)
122  integer, save        :: Nlevels! Number of model vertical levels
123  integer              :: Nptslmdz, Nlevlmdz  ! Nb de points issus de physiq.F
124  integer, save        :: Npoints_it   ! Max number of gridpoints to be
125                                       ! processed in one iteration
126  type(cosp_config), save       :: cfg          ! Variable qui contient les cles
127                                                ! logiques des simulateurs et des
128                                                ! diagnostics, definie dans:
129                                                ! lmdz_cosp_construct_destroy_mod
130!$OMP THREADPRIVATE(cfg)
131
132  integer               :: t0, t1, count_rate, count_max
133  real(wp), save        :: cloudsat_radar_freq, cloudsat_k2, rttov_ZenAng, co2, &
134                           ch4, n2o, co, emsfc_lw
135!$OMP THREADPRIVATE(emsfc_lw)
136
137  integer, dimension(RTTOV_MAX_CHANNELS), save   :: rttov_Channels
138  real(wp), dimension(RTTOV_MAX_CHANNELS), save  :: rttov_Surfem
139  integer, save  :: surface_radar, use_mie_tables, &
140                    cloudsat_use_gas_abs, cloudsat_do_ray, &
141                    melt_lay
142  integer, save  :: lidar_ice_type
143  integer, save  :: rttov_platform, rttov_satellite, &
144                    rttov_Instrument, rttov_Nchannels
145  logical, save  :: use_vgrid_in, csat_vgrid_in, &
146                    use_precipitation_fluxes
147
148! Declaration necessaires pour les sorties IOIPSL
149  real          :: ecrit_day, ecrit_hf, ecrit_mth, missing_val
150  logical       :: ok_mensuelCOSP, ok_journeCOSP, ok_hfCOSP, ok_all_xml
151  logical, save :: debut_cosp=.true.
152!$OMP THREADPRIVATE(debut_cosp)
153
154  logical, save :: first_write=.true.
155!$OMP THREADPRIVATE(first_write)
156
157  integer, save :: cosp_init_flag = 0
158!$OMP THREADPRIVATE(cosp_init_flag)
159
160
161!-----------------------------  Input variables from LMDZ-GCM  -------------------------------
162  integer                                  :: overlaplmdz   ! overlap type: 1=max,
163                                                            ! 2=rand, 3=max/rand
164  real, dimension(Nptslmdz,Nlevlmdz)       :: phi, p, ph, T, sh, rh, tca, cca, mr_lsliq,   &
165                                              mr_lsice, mr_ccliq, mr_ccice, fl_lsrain,     &
166                                              fl_lssnow, fl_ccrain, fl_ccsnow, fl_lsgrpl,  &
167                                              zlev, zlev_half, mr_ozone, radliq, radice,   &
168                                              dtau_s, dem_s, dtau_c, dem_c, ref_liq, ref_ice
169  real, dimension(Nptslmdz,Nlevlmdz)       :: fl_lsrainI, fl_lssnowI, fl_ccrainI, fl_ccsnowI
170  real, dimension(Nptslmdz)                :: lon, lat, skt, fracTerLic, u_wind, v_wind, &
171                                              phis, sunlit
172  real, dimension(Nptslmdz)                :: land ! variables intermediaire pour masque TerLic
173  real, dimension(Nlevlmdz)                :: presnivs
174  integer                                  :: itap, k, ip
175  real                                     :: dtime, freq_cosp
176  real, dimension(2)                       :: time_bnds
177
178  double precision                         :: d_dtime
179  double precision, dimension(2)           :: d_time_bnds
180
181
182! ######################################################################################
183! Declarations specific to COSP2
184! ######################################################################################
185
186  ! Local variables
187  logical :: &
188       Lsingle     = .true.,  & ! True if using MMF_v3_single_moment CLOUDSAT
189                                ! microphysical scheme (default)
190       Ldouble     = .false.    ! True if using MMF_v3.5_two_moment CLOUDSAT
191                                ! microphysical scheme
192  type(size_distribution), save              :: sd            ! Hydrometeor description
193!$OMP THREADPRIVATE(sd)
194  type(radar_cfg), save                      :: rcfg_cloudsat ! Radar configuration
195!$OMP THREADPRIVATE(rcfg_cloudsat)
196  real, dimension(Nptslmdz,Nlevlmdz,N_HYDRO) :: Reff          ! Liquid and Ice particles
197                                                              ! effective radius
198  type(cosp_outputs)                         :: cospOUT       ! COSP simulator outputs
199  type(cosp_optical_inputs)                  :: cospIN        ! COSP optical (or derived?)
200                                                              ! fields needed by simulators
201  type(cosp_column_inputs)                   :: cospstateIN   ! COSP model fields needed by simulators
202  character(len=256), dimension(100)         :: cosp_status
203  character(len=64), save                    :: cloudsat_micro_scheme
204
205  ! Indices to address arrays of LS and CONV hydrometeors
206  integer,parameter :: &
207       I_LSCLIQ = 1, & ! Large-scale (stratiform) liquid
208       I_LSCICE = 2, & ! Large-scale (stratiform) ice
209       I_LSRAIN = 3, & ! Large-scale (stratiform) rain
210       I_LSSNOW = 4, & ! Large-scale (stratiform) snow
211       I_CVCLIQ = 5, & ! Convective liquid
212       I_CVCICE = 6, & ! Convective ice
213       I_CVRAIN = 7, & ! Convective rain
214       I_CVSNOW = 8, & ! Convective snow
215       I_LSGRPL = 9    ! Large-scale (stratiform) groupel
216
217! Parametres qui sont lus a partir du fichier "cosp_input_nl.txt"
218   namelist/COSP_INPUT/overlap, isccp_topheight, isccp_topheight_direction,  &
219              npoints_it, ncolumns, use_vgrid_in, csat_vgrid_in,  &
220              cloudsat_radar_freq, surface_radar, use_mie_tables,  &
221              cloudsat_use_gas_abs, cloudsat_do_ray, melt_lay, cloudsat_k2,  &
222              cloudsat_micro_scheme, lidar_ice_type, use_precipitation_fluxes,   &
223              rttov_platform, rttov_satellite, rttov_Instrument, rttov_Nchannels, &
224              rttov_Channels, rttov_Surfem, rttov_ZenAng, co2, ch4, n2o, co
225
226!------------------------   Fin declaration des variables   ------------------------
227
228
229!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230! 1) Lecture du fichier "cosp_input_nl.txt", parametres d'entree pour COSP
231!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232  IF (is_master) print*,'Entree lmdz_cosp_interface' !phys_cosp2'
233  if (debut_cosp) then
234      NPoints=Nptslmdz
235      Nlevels=Nlevlmdz
236      ! Surface emissivity
237      emsfc_lw = 1.
238 
239     ! Lecture du namelist input
240     !  CALL read_cosp_input
241     IF (is_master) THEN
242        OPEN(10,file=cosp_input_nl,status='old')
243        READ(10,nml=cosp_input)
244        CLOSE(10)
245     ENDIF
246     !$OMP BARRIER
247     CALL bcast(overlap)
248     CALL bcast(isccp_topheight)
249     CALL bcast(isccp_topheight_direction)
250     CALL bcast(npoints_it)
251     CALL bcast(ncolumns)
252     CALL bcast(use_vgrid_in)
253     CALL bcast(csat_vgrid_in)
254     CALL bcast(cloudsat_radar_freq)
255     CALL bcast(surface_radar)
256     CALL bcast(cloudsat_use_gas_abs)
257     CALL bcast(cloudsat_do_ray)
258     CALL bcast(cloudsat_k2)
259     CALL bcast(lidar_ice_type)
260     CALL bcast(use_precipitation_fluxes)
261     CALL bcast(rttov_platform)
262     CALL bcast(rttov_satellite)
263     CALL bcast(rttov_Instrument)
264     CALL bcast(rttov_Nchannels)
265     CALL bcast(rttov_Channels)
266     CALL bcast(rttov_Surfem)
267     CALL bcast(rttov_ZenAng)
268     CALL bcast(co2)
269     CALL bcast(ch4)
270     CALL bcast(n2o)
271     CALL bcast(co)
272     CALL bcast(cloudsat_micro_scheme)
273
274     if (overlaplmdz.ne.overlap) then
275         print*,'Attention overlaplmdz different de overlap lu dans namelist '
276     endif
277
278     IF (is_master) print*,'ok read  cosp_input_nl'
279     ! Clefs Outputs initialisation
280     IF (using_xios) THEN
281        call cosp_outputkeys_init(cfg)
282     ELSE
283        call read_cosp_output_nl(itap,cosp_output_nl,cfg)
284     ENDIF
285     IF (is_master) print*,' Cles des differents simulateurs cosp a itap :',itap
286     IF (is_master) print*,'cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
287                           cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov', &
288                           cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
289                           cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov
290     IF (using_xios) THEN
291        IF (is_master) print*,'On passe par using_xios'
292     ELSE
293     if (cosp_init_flag .eq. 0) then
294        ! Initialize the distributional parameters for hydrometeors in radar simulator.
295        ! In COSPv1.4, this was declared in cosp_defs.f.
296        if (cloudsat_micro_scheme == 'MMF_v3.5_two_moment')  then
297          ldouble = .true.
298          lsingle = .false.
299        endif
300        call hydro_class_init(lsingle,ldouble,sd)
301        call quickbeam_optics_init()
302       !!$OMP MASTER
303       IF (is_master) print*,'Just before call COSP_INIT, cosp_init_flag =', cosp_init_flag
304       call COSP_INIT(cfg%Lisccp, cfg%Lmodis, cfg%Lmisr, cfg%Lcloudsat, cfg%Lcalipso, &
305                      cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov,          &
306                      cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs,         &
307                      cloudsat_do_ray, isccp_topheight, isccp_topheight_direction,    &
308                      surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in,      &
309                      niv_sorties, Nlevels, cloudsat_micro_scheme)
310       !!$OMP END MASTER
311       !!$OMP BARRIER
312       cosp_init_flag = 1
313       IF (is_master) print*,' just after call COSP_INIT, cosp_init_flag =', cosp_init_flag
314     endif
315    ENDIF
316    IF (is_master) print*,'Fin lecture Namelists, debut_cosp =',debut_cosp
317  endif ! debut_cosp
318
319  !!! Ici on modifie les cles logiques pour les outputs selon les champs actives dans les .xml
320  ! Verifier si besoin de passer par itap 1
321  if ((itap.gt.1).and.(first_write)) then
322     IF (using_xios) call read_xiosfieldactive(cfg)
323     first_write=.false.
324     if (cosp_init_flag .eq. 0) then
325        ! Initialize the distributional parameters for hydrometeors in radar simulator.
326        ! In COSPv1.4, this was declared in cosp_defs.f.
327        if (cloudsat_micro_scheme == 'MMF_v3.5_two_moment')  then
328           ldouble = .true.
329           lsingle = .false.
330        endif
331        call hydro_class_init(lsingle,ldouble,sd)
332        call quickbeam_optics_init()
333        !!$OMP MASTER
334        IF (is_master) print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag
335        call COSP_INIT(cfg%Lisccp, cfg%Lmodis, cfg%Lmisr, cfg%Lcloudsat, cfg%Lcalipso, &
336                    cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov,          &
337                    cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs,         &
338                    cloudsat_do_ray, isccp_topheight, isccp_topheight_direction,    &
339                    surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in,      &
340                    niv_sorties, Nlevels, cloudsat_micro_scheme)
341        !!$OMP END MASTER
342        !!$OMP BARRIER
343        cosp_init_flag = 1
344        IF (is_master) print*,' just after call COSP_INIT, cosp_init_flag =', cosp_init_flag
345     endif ! cosp_init_flag
346     IF (is_master) print*,' Cles des differents simulateurs cosp a itap :',itap
347     IF (is_master) print*,'cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
348                         cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov', &
349                         cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, &
350                         cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov
351  endif !(itap.gt.1).and.(first_write)
352
353  time_bnds(1) = dtime-dtime/2.
354  time_bnds(2) = dtime+dtime/2.
355  d_time_bnds=time_bnds
356  d_dtime=dtime
357!-------------------------   Fin initialisation de COSP   --------------------------
358
359!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360! 3) Calculs des champs d'entree COSP a partir des variables LMDZ
361!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
362    ! 0) Create ptop/ztop for gbx%pf and gbx%zlev are for the the interface,
363    !    also reverse CAM height/pressure values for input into CSOP
364    !    CAM state%pint from top to surface, COSP wants surface to top.
365! 0) Altitudes du modele calculees a partir de la variable geopotentiel phi et phis   
366    zlev = phi/9.81
367    zlev_half(:,1) = phis(:)/9.81
368    do k = 2, Nlevels
369       do ip = 1, Npoints
370          zlev_half(ip,k) = phi(ip,k)/9.81 + &
371          (phi(ip,k)-phi(ip,k-1))/9.81 * (ph(ip,k)-p(ip,k)) / (p(ip,k)-p(ip,k-1))
372        enddo
373    enddo
374! 1) Quantite de nuages (couverture?), convectif (=0) et total
375    cca = 0._wp ! convective_cloud_amount (1)
376    tca = tca   ! total_cloud_amount (1)
377    !IF (is_master) print*,'tca = ',tca
378
379! 2) Humidite relative est donnee tel quel (variable rh)
380! 3) Masque terre/mer a partir de la variable fracTerLic
381    do ip = 1, Npoints
382       if (fracTerLic(ip).ge.0.5) then
383           land(ip) = 1.
384       else
385           land(ip) = 0.
386       endif
387    enddo
388! A voir l equivalent LMDZ
389    mr_ccliq = 0.0
390    mr_ccice = 0.0
391!!!        gbx%mr_hydro(:,:,I_LSCLIQ) = mr_lsliq !mixing_ratio_large_scale_cloud_liquid (kg/kg)
392!!!        gbx%mr_hydro(:,:,I_LSCICE) = mr_lsice !mixing_ratio_large_scale_cloud_ic
393!!!        gbx%mr_hydro(:,:,I_CVCLIQ) = mr_ccliq !mixing_ratio_convective_cloud_liquid
394!!!        gbx%mr_hydro(:,:,I_CVCICE) = mr_ccice !mixing_ratio_convective_cloud_ice
395! A revoir
396    fl_lsrain = fl_lsrainI + fl_ccrainI
397    fl_lssnow = fl_lssnowI + fl_ccsnowI
398!!!        gbx%rain_ls = fl_lsrain !flux_large_scale_cloud_rain (kg m^-2 s^-1)
399!!!        gbx%snow_ls = fl_lssnow !flux_large_scale_cloud_snow
400!  A voir l equivalent LMDZ
401     fl_lsgrpl = 0.
402     fl_ccsnow = 0.
403     fl_ccrain = 0.
404!!!        gbx%grpl_ls = fl_lsgrpl  !flux_large_scale_cloud_graupel
405!!!        gbx%rain_cv = fl_ccrain  !flux_convective_cloud_rain
406!!!        gbx%snow_cv = fl_ccsnow  !flux_convective_cloud_snow
407        ! ISCCP simulator
408     dtau_c  = 0.
409     dem_c   = 0.
410! note: reff_cosp dimensions should be same as cosp (reff_cosp has 9 hydrometeor dimension)
411     Reff(1:Npoints,1:Nlevels,1:N_HYDRO) = 0.
412     Reff(:,:,I_LSCLIQ) = ref_liq*1e-6
413     Reff(:,:,I_LSCICE) = ref_ice*1e-6
414     !IF (is_master) print*,'Reff(:,:,I_LSCLIQ) = ',Reff(:,:,I_LSCLIQ)
415     !IF (is_master) print*,'Reff(:,:,I_LSCICE) = ',Reff(:,:,I_LSCICE)
416     !Reff(:,:,I_CVCLIQ) = ref_liq*1e-6
417     !Reff(:,:,I_CVCICE) = ref_ice*1e-6
418
419
420   if (cosp_init_flag .eq. 1) then      ! cosp_init_flag = 1
421!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422! 4a) On construit la variable cospOUT qui contient tous les diagnostics de sortie.
423! Elle sera remplie lors de l'appel du simulateur COSP
424!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
425        call construct_cosp_outputs(cfg,Npoints,Ncolumns,Nlevels,niv_sorties,0,cospOUT)
426
427!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428! 4b) On construit la variable cospstateIN que l'on va remplir avec les champs LMDZ
429! Les champ verticaux doivent etre donnes a l'envers, c-a-d : (Nlevels:1) = (TOA:SFC)
430!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
431       call construct_cospstateIN(Npoints,Nlevels,0,cospstateIN)
432
433       cospstateIN%lat                                     = lat(1:Npoints)
434       cospstateIN%lon                                     = lon(1:Npoints)
435       cospstateIN%at                                      = t(1:Npoints,Nlevels:1:-1)
436       cospstateIN%qv                                      = sh(1:Npoints,Nlevels:1:-1)
437       cospstateIN%o3                                      = mr_ozone(1:Npoints,Nlevels:1:-1) 
438       cospstateIN%sunlit                                  = sunlit(1:Npoints)
439       cospstateIN%skt                                     = skt(1:Npoints)
440       cospstateIN%land                                    = land(1:Npoints)
441       cospstateIN%surfelev                                = zlev_half(1:Npoints,1)
442       cospstateIN%pfull                                   = p(1:Npoints,Nlevels:1:-1)
443       cospstateIN%phalf(1:Npoints,1)                      = 0._wp
444       cospstateIN%phalf(1:Npoints,2:Nlevels+1)            = ph(1:Npoints,Nlevels:1:-1) 
445       cospstateIN%hgt_matrix                              = zlev(1:Npoints,Nlevels:1:-1)
446       !cospstateIN%hgt_matrix_half(1:Npoints,Nlevels+1)    = 0._wp
447       cospstateIN%hgt_matrix_half(1:Npoints,1:Nlevels)    = zlev_half(1:Npoints,Nlevels:1:-1)
448       !IF (is_master) print*,'cospstateIN%hgt_matrix_half(1,1)=',cospstateIN%hgt_matrix_half(1,1)
449       !IF (is_master) print*,'cospstateIN%hgt_matrix_half(1,Nlevels)=',cospstateIN%hgt_matrix_half(1,Nlevels)
450
451
452!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
453! 4c) On construit la variable cospIN qui contient les proprietes optiques subcolumn
454! pour COSP. Elle sera essentiellement remplie dans la subroutine subsample_and_optics
455! ou sont appeles SCOPS, PREC_SCOPS et les subroutines qui calculent les signaux
456! simules pour chaque simulateur actif.
457!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
458       call construct_cospIN(cfg,Npoints,Ncolumns,Nlevels,cospIN)
459       cospIN%emsfc_lw  = emsfc_lw
460       if (cfg%Lcloudsat) cospIN%rcfg_cloudsat = rcfg_cloudsat
461
462!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
463! 5) Appel de subsample_and_optics : Les champs verticaux doivent etre donnes a
464! l'envers comme pour le remplissage de cospstateIN, c-a-d : (Nlevels:1) = (TOA:SFC)
465!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
466       call subsample_and_optics(cfg, Npoints, Nlevels, Ncolumns, N_HYDRO,overlap,      &
467                              use_precipitation_fluxes, lidar_ice_type, sd,             &
468                              tca(1:Npoints,Nlevels:1:-1), cca(1:Npoints,Nlevels:1:-1), &
469                              fl_lsrain(1:Npoints,Nlevels:1:-1),                        &
470                              fl_lssnow(1:Npoints,Nlevels:1:-1),                        &
471                              fl_lsgrpl(1:Npoints,Nlevels:1:-1),                        &
472                              fl_ccrain(1:Npoints,Nlevels:1:-1),                        &
473                              fl_ccsnow(1:Npoints,Nlevels:1:-1),                        &
474                              mr_lsliq(1:Npoints,Nlevels:1:-1),                         &
475                              mr_lsice(1:Npoints,Nlevels:1:-1),                         &
476                              mr_ccliq(1:Npoints,Nlevels:1:-1),                         &
477                              mr_ccice(1:Npoints,Nlevels:1:-1),                         &
478                              Reff(1:Npoints,Nlevels:1:-1,:),                           &
479                              dtau_c(1:Npoints,Nlevels:1:-1),                           &
480                              dtau_s(1:Npoints,Nlevels:1:-1),                           &
481                              dem_c(1:Npoints,Nlevels:1:-1),                            &
482                              dem_s(1:Npoints,Nlevels:1:-1), cospstateIN, cospIN)
483
484!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
485! 6) On appelle le simulateur COSPv2
486!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
487      IF (is_master) print*,'call simulateur'
488      cosp_status = COSP_SIMULATOR(cospIN, cospstateIN, cospOUT, 1, Npoints, debug=.false.)
489   endif ! cosp_init_flag = 1
490
491!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
492! 7a) Ecriture des sorties 1: on cree d'abord les fichiers NCDF pour ecrire les sorties
493! en appelant lmdz_cosp_output_open (lors du premier appel de cette interface pour les
494! 2 options d'ecriture), ou sont definis les axes et les caracteristiques
495! des fichiers de sortie avec les diagnostics.
496!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
497    if (debut_cosp) then
498      !$OMP MASTER
499        IF (is_master) print *, ' Open outpts files and define axis'
500        call lmdz_cosp_output_open(Nlevlmdz, Ncolumns, presnivs, dtime, freq_cosp,       &
501                                   ok_mensuelCOSP, ok_journeCOSP, ok_hfCOSP, ok_all_xml, &
502                                   ecrit_mth, ecrit_day, ecrit_hf, use_vgrid_in,         &
503                                   niv_sorties, vgrid_z_in, zlev(1,:))
504      !$OMP END MASTER
505      !$OMP BARRIER
506       debut_cosp=.false.
507    endif ! debut_cosp
508
509  if (cosp_init_flag .eq. 1) then
510!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
511! 7b) Ecriture des sorties 2: le remplissage des fichiers de sortie se fait a chaque
512! appel de cette interface avec une difference entre les 2 options d'ecriture:
513! AVEC xios, on commence a remplir les fichiers de sortie a partir du DEUXIEME
514! appel de cette interface (lorsque cosp_init_flag = 1).
515! SANS xios, on commence a remplir les fichiers de sortie a partir du PREMIER
516! appel de cette interface (lorsque cosp_init_flag = 1).
517!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
518      IF (is_master) print *, 'Calling write output'
519        call lmdz_cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, freq_COSP, &
520                                    missing_val, cfg, niv_sorties, cospOUT)
521
522!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
523! 8) On libere la memoire allouee lors de cet appel a l'interface
524!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
525    call destroy_cospIN(cospIN)
526    call destroy_cospstateIN(cospstateIN)
527    call destroy_cosp_outputs(cospOUT)
528    !call cosp_cleanUp()
529
530  endif ! cosp_init_flag = 1
531 
532end subroutine lmdz_cosp_interface
Note: See TracBrowser for help on using the repository browser.