!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! Nouveau code d'interface entre LMDZ et COSPv2 (version 2) ! Dans cette nouvelle version de COSP, le code a ete restructure pour optimiser les calculs ! des differents simulateurs et pour proposer de nouvelles fonctionnalites (par exemple, ! intervenir sur les profils sous-maille, ou subcolumns, donnes en entre a COSP afin que ! leur definition soit coherente avec les parametrisations du modele hote). ! Cette version de COSP propose aussi de nombreux nouveaux diagnostics, notamment pour ! le simulateur lidar (diagnostics CALIPSO-OPAQ, lidar sol 532nm et lidar ATLID 355nm). ! la meme organisation offline de Cosp est conservee avec les memes repertoires et sous ! repertoires pour faciliter les mises a jours dans LMDZ et pouvoir tourner aussi Cosp ! offline ... ! Interface ecrite par A.Idelkadi (11/2025) ! !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% subroutine lmdz_cospv2_interface(itap, dtime, & Nptslmdz, Nlevlmdz, lon, lat, presnivs, & overlaplmdz, sunlit, ref_liq, ref_ice, fracTerLic, & u_wind, v_wind, phis, phi, ph, p, skt, t, sh, rh, & tca, cca, mr_lsliq, mr_lsice, fl_lsrainI, fl_lssnowI, & fl_ccrainI, fl_ccsnowI, mr_ozone, dtau_s, dem_s) !!! Modules specifiques a l'interface LMDZ-COSP use mod_phys_lmdz_para use mod_grid_phy_lmdz use ioipsl use iophy use lmdz_xios, ONLY : using_xios use wxios_mod, ONLY : missing_val use lmdz_cosp_output_mod use lmdz_cosp_output_write_mod use lmdz_cosp_read_outputkeys use lmdz_cosp_subsample_and_optics_mod, only : subsample_and_optics use lmdz_cosp_construct_destroy_mod use clesphys_mod_h !!! Modules faisant partie du code source de COSPv2 use cosp_kinds, only: wp USE MOD_COSP_CONFIG, ONLY: R_UNDEF,PARASOL_NREFL,LIDAR_NCAT,LIDAR_NTYPE,SR_BINS, & N_HYDRO,RTTOV_MAX_CHANNELS,numMISRHgtBins, & cloudsat_DBZE_BINS,LIDAR_NTEMP,calipso_histBsct, & CFODD_NDBZE, CFODD_NICOD, & CFODD_BNDRE, CFODD_NCLASS, & CFODD_DBZE_MIN, CFODD_DBZE_MAX, & CFODD_ICOD_MIN, CFODD_ICOD_MAX, & CFODD_DBZE_WIDTH, CFODD_ICOD_WIDTH, & WR_NREGIME, & numMODISTauBins,numMODISPresBins, & numMODISReffIceBins,numMODISReffLiqBins, & numISCCPTauBins,numISCCPPresBins,numMISRTauBins, & ntau,modis_histTau,tau_binBounds, & modis_histTauEdges,tau_binEdges, & modis_histTauCenters,tau_binCenters,ntauV1p4, & tau_binBoundsV1p4,tau_binEdgesV1p4, tau_binCentersV1p4, & grLidar532_histBsct,atlid_histBsct, & !vgrid_zu,vgrid_zl, & !Nlvgrid_local => Nlvgrid, & !vgrid_z, & cloudsat_preclvl, niv_sorties, vgrid_z_in use cosp_phys_constants, only: amw,amd,amO3,amCO2,amCH4,amN2O,amCO !use mod_cosp_io, only: nc_read_input_file,write_cosp2_output USE mod_quickbeam_optics,only: size_distribution,hydro_class_init,quickbeam_optics, & quickbeam_optics_init,gases use quickbeam, only: radar_cfg use mod_cosp, only: cosp_init,cosp_optical_inputs,cosp_column_inputs, & cosp_outputs,cosp_cleanUp,cosp_simulator USE mod_rng, ONLY: rng_state, init_rng USE mod_scops, ONLY: scops USE mod_prec_scops, ONLY: prec_scops USE MOD_COSP_UTILS, ONLY: cosp_precip_mxratio use cosp_optics, ONLY: cosp_simulator_optics,lidar_optics,modis_optics, & modis_optics_partition use mod_cosp_stats, ONLY: COSP_CHANGE_VERTICAL_GRID implicit none !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% !! Declarations variables ! Input/Output driver file control character(len=64),PARAMETER :: cosp_input_nl = 'cospv2_input_nl.txt' character(len=64),PARAMETER :: cosp_output_nl = 'cospv2_output_nl.txt' ! Input variables from LMDZ integer :: Nptslmdz, Nlevlmdz ! Nb de points issus de physiq.F integer :: Nlon,Nlat,geomode integer :: overlaplmdz ! overlap type: 1=max, real, dimension(Nlevlmdz) :: presnivs real, dimension(Nptslmdz) :: & lon, & ! Longitude (deg) lat, & ! Latitude (deg) skt, & ! Skin temperature (K) surfelev, & ! Surface Elevation (m) land, & ! Land/sea mask (0/1) u_wind, & ! U-component of wind (m/s) v_wind, & ! V-component of wind (m/s) sunlit, & ! Sunlit flag phis, & ! Geop au sol fracTerLic real, dimension(Nptslmdz,Nlevlmdz) :: & phi, & ! geop p, & ! Model pressure levels (pa) ph, & ! Moddel pressure @ half levels (pa) zlev, & ! Model level height (m) zlev_half, & ! Model level height @ half-levels (m) T, & ! Temperature (K) sh, & ! Specific humidity (kg/kg) rh, & ! Relative humidity (1) tca, & ! Total cloud fraction (1) cca, & ! Convective cloud fraction (1) mr_lsliq, & ! Mass mixing ratio for stratiform cloud liquid (kg/kg) mr_lsice, & ! Mass mixing ratio for stratiform cloud ice (kg/kg) mr_ccliq, & ! Mass mixing ratio for convective cloud liquid (kg/kg) mr_ccice, & ! Mass mixing ratio for convective cloud ice (kg/kg) mr_ozone, & ! Mass mixing ratio for ozone (kg/kg) fl_lsrain, & ! Precipitation flux (rain) for stratiform cloud (kg/m^2/s) fl_lssnow, & ! Precipitation flux (snow) for stratiform cloud (kg/m^2/s) fl_lsgrpl, & ! Precipitation flux (groupel) for stratiform cloud (kg/m^2/s) fl_ccrain, & ! Precipitation flux (rain) for convective cloud (kg/m^2/s) fl_ccsnow, & ! Precipitation flux (snow) for convective cloud (kg/m^2/s) dtau_s, & ! 0.67micron optical depth (stratiform cloud) (1) dtau_c, & ! 0.67micron optical depth (convective cloud) (1) dem_s, & ! 11micron emissivity (stratiform cloud) dem_c, & ! 11microm emissivity (convective cloud) ref_liq, & ref_ice real, dimension(Nptslmdz,Nlevlmdz) :: fl_lsrainI, fl_lssnowI, fl_ccrainI, fl_ccsnowI real(wp),dimension(Nptslmdz,Nlevlmdz,N_HYDRO) :: & frac_out, & ! Subcolumn cloud cover (0/1) Reff ! Subcolumn effective radius type(cosp_config), save :: cfg ! Variable qui contient les cles ! logiques des simulateurs et des ! diagnostics, definie dans: ! lmdz_cosp_construct_destroy_mod !$OMP THREADPRIVATE(cfg) integer :: itap, k, ip real :: dtime real, dimension(2) :: time_bnds real :: d_dtime real, dimension(2) :: d_time_bnds ! Input namelist fields integer, save :: Npoints, Nlevels !$OMP THREADPRIVATE(Npoints) integer, save :: & ! Ncolumns, & ! Number of subcolumns Npoints_it, & ! Number of gridpoints to be processed in one ! iteration Nlvgrid, & ! Number of vertical levels for statistical outputs ! (USE_VGRID=.true.) surface_radar, & ! surface=1/spaceborne=0 cloudsat_use_gas_abs, & ! Include gaseous absorption (1=yes/0=no) cloudsat_do_ray, & ! Calculate output Rayleigh (1=yes/0=no) lidar_ice_type, & ! Ice particle shape in lidar calculations ! (0=ice-spheres/1=ice-non-spherical) !overlap, & ! Overlap type: 1=max, 2=rand, 3=max/rand isccp_topheight, & ! ISCCP cloud top height isccp_topheight_direction, & ! ISCCP cloud top height direction rttov_platform, & ! RTTOV: Satellite platform rttov_satellite, & ! RTTOV: Satellite rttov_instrument, & ! RTTOV: Instrument rttov_Nchannels ! RTTOV: Number of channels to be computed real(wp), save :: & ! emsfc_lw, & cloudsat_radar_freq, & ! CloudSat radar frequency (GHz) cloudsat_k2, & ! |K|^2, -1=use frequency dependent default rttov_ZenAng, & ! RTTOV: Satellite Zenith Angle co2, & ! CO2 mixing ratio ch4, & ! CH4 mixing ratio n2o, & ! n2o mixing ratio co ! co mixing ratio logical, save :: & ! use_vgrid_in, & ! Use fixed vertical grid for outputs? csat_vgrid_in, & ! CloudSat vertical grid? use_precipitation_fluxes ! True if precipitation fluxes are input to the ! algorithm integer,dimension(RTTOV_MAX_CHANNELS), save :: & rttov_Channels ! RTTOV: Channel numbers real(wp),dimension(RTTOV_MAX_CHANNELS), save :: & rttov_Surfem ! RTTOV: Surface emissivity character(len=64), save :: & cloudsat_micro_scheme ! Microphysical scheme used in cloudsat radar simulator !$OMP THREADPRIVATE(emsfc_lw) ! Declaration necessaires pour les sorties IOIPSL !real :: ecrit_day, ecrit_hf, ecrit_mth, missing_val !logical :: ok_mensuelCOSP, ok_journeCOSP, ok_hfCOSP, ok_all_xml logical, save :: debut_cosp=.true. !$OMP THREADPRIVATE(debut_cosp) logical, save :: first_write=.true. !$OMP THREADPRIVATE(first_write) integer, save :: cosp_init_flag = 0 !$OMP THREADPRIVATE(cosp_init_flag) ! Local variables logical :: & Lsingle = .true., & ! True if using MMF_v3_single_moment CLOUDSAT ! microphysical scheme (default) Ldouble = .false. ! True if using MMF_v3.5_two_moment CLOUDSAT type(size_distribution), save :: & sd ! Hydrometeor description !$OMP THREADPRIVATE(sd) type(radar_cfg), save :: & rcfg_cloudsat ! Radar configuration !$OMP THREADPRIVATE(rcfg_cloudsat) type(cosp_outputs) :: & cospOUT ! COSP simulator outputs type(cosp_optical_inputs) :: & cospIN ! COSP optical (or derived?) fields needed by simulators type(cosp_column_inputs) :: & cospstateIN ! COSP model fields needed by simulators integer :: iChunk,nChunks,start_idx,end_idx,nPtsPerIt,ij real(wp),dimension(10) :: driver_time character(len=256),dimension(100) :: cosp_status ! Indices to address arrays of LS and CONV hydrometeors integer,parameter :: & I_LSCLIQ = 1, & ! Large-scale (stratiform) liquid I_LSCICE = 2, & ! Large-scale (stratiform) ice I_LSRAIN = 3, & ! Large-scale (stratiform) rain I_LSSNOW = 4, & ! Large-scale (stratiform) snow I_CVCLIQ = 5, & ! Convective liquid I_CVCICE = 6, & ! Convective ice I_CVRAIN = 7, & ! Convective rain I_CVSNOW = 8, & ! Convective snow I_LSGRPL = 9 ! Large-scale (stratiform) groupel namelist/COSP_INPUT/overlap, isccp_topheight, isccp_topheight_direction, & npoints_it, ncolumns, use_vgrid_in, Nlvgrid, csat_vgrid_in, & cloudsat_radar_freq, surface_radar, cloudsat_use_gas_abs,cloudsat_do_ray, & cloudsat_k2, cloudsat_micro_scheme, lidar_ice_type, use_precipitation_fluxes, & rttov_platform, rttov_satellite, rttov_Instrument, rttov_Nchannels, & rttov_Channels, rttov_Surfem, rttov_ZenAng, co2, ch4, n2o, co !!Fin declaration des variables !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% !call cpu_time(driver_time(1)) !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! Read in namelists !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! call get_command_argument(1, cosp_input_namelist) IF (is_master) print*,'Entree lmdz_cosp_interface, Npoints = ',Npoints if (debut_cosp) then Npoints=Nptslmdz Nlevels=Nlevlmdz ! Surface emissivity emsfc_lw = 1. ! Lecture du namelist input IF (is_master) THEN OPEN(10,file=cosp_input_nl,status='old') READ(10,nml=cosp_input) CLOSE(10) ENDIF !$OMP BARRIER CALL bcast(overlap) CALL bcast(isccp_topheight) CALL bcast(isccp_topheight_direction) CALL bcast(npoints_it) CALL bcast(ncolumns) CALL bcast(use_vgrid_in) CALL bcast(csat_vgrid_in) CALL bcast(cloudsat_radar_freq) CALL bcast(surface_radar) CALL bcast(cloudsat_use_gas_abs) CALL bcast(cloudsat_do_ray) CALL bcast(cloudsat_k2) CALL bcast(lidar_ice_type) CALL bcast(use_precipitation_fluxes) CALL bcast(rttov_platform) CALL bcast(rttov_satellite) CALL bcast(rttov_Instrument) CALL bcast(rttov_Nchannels) CALL bcast(rttov_Channels) CALL bcast(rttov_Surfem) CALL bcast(rttov_ZenAng) CALL bcast(co2) CALL bcast(ch4) CALL bcast(n2o) CALL bcast(co) CALL bcast(cloudsat_micro_scheme) CALL bcast(Nlvgrid) IF (is_master) print*,'ok read cosp_input_nl' ! Clefs Outputs initialisation ! Ici les cles sont definies en fonction des champs pour lesquels les sorties sont activees ! Si XIOS c'est les fichiers file*COSP.xml qui indiquent quels variables sortir et donc quels ! simulateurs activer IF (using_xios) THEN IF (is_master) print*,'On initialise les cles pour activer les simulateurs et sorties' call cosp_outputkeys_init(cfg) ELSE call read_cosp_output_nl(itap,cosp_output_nl,cfg) if (cosp_init_flag .eq. 0) then ! Initialize the distributional parameters for hydrometeors in radar simulator. ! In COSPv1.4, this was declared in cosp_defs.f. if (cloudsat_micro_scheme == 'MMF_v3.5_two_moment') then ldouble = .true. lsingle = .false. endif call hydro_class_init(lsingle,ldouble,sd) call quickbeam_optics_init() IF (is_master) print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag !$OMP MASTER call COSP_INIT(cfg%Lisccp, cfg%Lmodis, cfg%Lmisr, cfg%Lcloudsat, cfg%Lcalipso, & cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov, & cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs, & cloudsat_do_ray, isccp_topheight, isccp_topheight_direction, & surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in, niv_sorties, & Nlevels, cloudsat_micro_scheme) !$OMP END MASTER !$OMP BARRIER cosp_init_flag = 1 IF (is_master) print*,' just after call COSP_INIT, cosp_init_flag =', cosp_init_flag endif ENDIF IF (is_master) print*,' Cles des differents simulateurs cosp a itap :',itap IF (is_master) print*,'cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, & cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov', & cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, & cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov endif ! debut_cosp !!! Ici on modifie les cles logiques pour les outputs selon les champs actives dans les .xml if ((itap.ge.1).and.(first_write))then IF (using_xios) call read_xiosfieldactive(cfg) first_write=.false. if (cosp_init_flag .eq. 0) then ! Initialize the distributional parameters for hydrometeors in radar simulator. ! In COSPv1.4, this was declared in cosp_defs.f. if (cloudsat_micro_scheme == 'MMF_v3.5_two_moment') then ldouble = .true. lsingle = .false. endif call hydro_class_init(lsingle,ldouble,sd) call quickbeam_optics_init() IF (is_master) print*,' just before call COSP_INIT, cosp_init_flag =', cosp_init_flag !$OMP MASTER call COSP_INIT(cfg%Lisccp, cfg%Lmodis, cfg%Lmisr, cfg%Lcloudsat, cfg%Lcalipso, & cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, cfg%Lrttov, & cloudsat_radar_freq, cloudsat_k2, cloudsat_use_gas_abs, & cloudsat_do_ray, isccp_topheight, isccp_topheight_direction, & surface_radar, rcfg_cloudsat, use_vgrid_in, csat_vgrid_in, niv_sorties, & Nlevels, cloudsat_micro_scheme) !$OMP END MASTER !$OMP BARRIER cosp_init_flag = 1 IF (is_master) print*,' just after call COSP_INIT, cosp_init_flag =', cosp_init_flag endif ! cosp_init_flag IF (is_master) print*,' Cles des differents simulateurs cosp a itap :',itap IF (is_master) print*,'cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, & cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov', & cfg%Lcloudsat, cfg%Lcalipso, cfg%LgrLidar532, cfg%Latlid, cfg%Lparasol, & cfg%Lisccp, cfg%Lmisr, cfg%Lmodis, cfg%Lrttov endif !(itap.gt.1).and.(first_write) time_bnds(1) = dtime-dtime/2. time_bnds(2) = dtime+dtime/2. d_time_bnds=time_bnds d_dtime=dtime !------------------------- Fin initialisation de COSP -------------------------- !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! 3) Calculs des champs d'entree COSP a partir des variables LMDZ ! ! 0) Create ptop/ztop for gbx%pf and gbx%zlev are for the the interface, ! also reverse CAM height/pressure values for input into CSOP ! CAM state%pint from top to surface, COSP wants surface to top. ! 0) Altitudes du modele calculees a partir de la variable geopotentiel phi et phis IF (is_master) print*,'Calculs des champs entree COSP a partir des variables LMDZ' zlev = phi/9.81 zlev_half(:,1) = phis(:)/9.81 do k = 2, Nlevels do ip = 1, Npoints zlev_half(ip,k) = phi(ip,k)/9.81 + & (phi(ip,k)-phi(ip,k-1))/9.81 * (ph(ip,k)-p(ip,k)) / (p(ip,k)-p(ip,k-1)) enddo enddo ! 1) Quantite de nuages (couverture?), convectif (=0) et total cca = 0._wp ! convective_cloud_amount (1) tca = tca ! total_cloud_amount (1) ! 2) Humidite relative est donnee tel quel (variable rh) ! 3) Masque terre/mer a partir de la variable fracTerLic do ip = 1, Npoints if (fracTerLic(ip).ge.0.5) then land(ip) = 1. else land(ip) = 0. endif enddo ! A voir l equivalent LMDZ mr_ccliq = 0.0 mr_ccice = 0.0 !!! gbx%mr_hydro(:,:,I_LSCLIQ) = mr_lsliq !mixing_ratio_large_scale_cloud_liquid (kg/kg) !!! gbx%mr_hydro(:,:,I_LSCICE) = mr_lsice !mixing_ratio_large_scale_cloud_ic !!! gbx%mr_hydro(:,:,I_CVCLIQ) = mr_ccliq !mixing_ratio_convective_cloud_liquid !!! gbx%mr_hydro(:,:,I_CVCICE) = mr_ccice !mixing_ratio_convective_cloud_ice ! A revoir fl_lsrain = fl_lsrainI + fl_ccrainI fl_lssnow = fl_lssnowI + fl_ccsnowI !!! gbx%rain_ls = fl_lsrain !flux_large_scale_cloud_rain (kg m^-2 s^-1) !!! gbx%snow_ls = fl_lssnow !flux_large_scale_cloud_snow ! A voir l equivalent LMDZ fl_lsgrpl = 0. fl_ccsnow = 0. fl_ccrain = 0. !!! gbx%grpl_ls = fl_lsgrpl !flux_large_scale_cloud_graupel !!! gbx%rain_cv = fl_ccrain !flux_convective_cloud_rain !!! gbx%snow_cv = fl_ccsnow !flux_convective_cloud_snow ! ISCCP simulator dtau_c = 0. dem_c = 0. ! note: reff_cosp dimensions should be same as cosp (reff_cosp has 9 hydrometeor dimension) Reff(1:Npoints,1:Nlevels,1:N_HYDRO) = 0. Reff(:,:,I_LSCLIQ) = ref_liq*1e-6 Reff(:,:,I_LSCICE) = ref_ice*1e-6 Reff(:,:,I_CVCLIQ) = ref_liq*1e-6 Reff(:,:,I_CVCICE) = ref_ice*1e-6 if (cosp_init_flag .eq. 1) then ! cosp_init_flag = 1 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% !call construct_cosp_outputs(cfg,Npoints,Ncolumns,Nlevels,Nlvgrid,0,cospOUT) IF (is_master) print*,'construct_cosp_outputs' call construct_cosp_outputs(cfg,Npoints,Ncolumns,Nlevels,niv_sorties,rttov_Nchannels,use_vgrid_in,cospOUT) ! 4b) On construit la variable cospstateIN que l'on va remplir avec les champs LMDZ ! Les champ verticaux doivent etre donnes a l'envers, c-a-d : (Nlevels:1) = (TOA:SFC) ! !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IF (is_master) print*,'call construct_cospstateIN' call construct_cospstateIN(Npoints,Nlevels,0,cospstateIN) cospIN%emsfc_lw = emsfc_lw cospstateIN%lat = lat(1:Npoints) cospstateIN%lon = lon(1:Npoints) cospstateIN%at = t(1:Npoints,Nlevels:1:-1) cospstateIN%qv = sh(1:Npoints,Nlevels:1:-1) cospstateIN%o3 = mr_ozone(1:Npoints,Nlevels:1:-1) cospstateIN%sunlit = sunlit(1:Npoints) cospstateIN%skt = skt(1:Npoints) cospstateIN%land = land(1:Npoints) cospstateIN%surfelev = zlev_half(1:Npoints,1) cospstateIN%pfull = p(1:Npoints,Nlevels:1:-1) cospstateIN%phalf(1:Npoints,1) = 0._wp cospstateIN%phalf(1:Npoints,2:Nlevels+1) = ph(1:Npoints,Nlevels:1:-1) cospstateIN%hgt_matrix = zlev(1:Npoints,Nlevels:1:-1) !cospstateIN%hgt_matrix_half(1:Npoints,Nlevels+1) = 0._wp !cospstateIN%hgt_matrix_half(1:Npoints,1:Nlevels) = zlev_half(1:Npoints,Nlevels:1:-1) cospstateIN%hgt_matrix_half(:,1:Nlevels) = zlev_half(:,Nlevels:1:-1) ! km cospIN%rcfg_cloudsat = rcfg_cloudsat !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! ! 4c) On construit la variable cospIN qui contient les proprietes optiques subcolumn ! pour COSP. Elle sera essentiellement remplie dans la subroutine subsample_and_optics ! ou sont appeles SCOPS, PREC_SCOPS et les subroutines qui calculent les signaux ! simules pour chaque simulateur actif. ! !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IF (is_master) print*,'call construct_cospIN' call construct_cospIN(cfg,Npoints,Ncolumns,Nlevels,cospIN) cospIN%emsfc_lw = emsfc_lw if (cfg%Lcloudsat) cospIN%rcfg_cloudsat = rcfg_cloudsat !call cpu_time(driver_time(4)) !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! Generate subcolumns and compute optical inputs. !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IF (is_master) print*,'call subsample_and_optics : Npoints, Nlevels, Ncolumns = ', & Npoints, Nlevels, Ncolumns call subsample_and_optics(cfg, Npoints, Nlevels, Ncolumns, N_HYDRO,overlap, & use_precipitation_fluxes, lidar_ice_type, sd, & tca(1:Npoints,Nlevels:1:-1), cca(1:Npoints,Nlevels:1:-1), & fl_lsrain(1:Npoints,Nlevels:1:-1), & fl_lssnow(1:Npoints,Nlevels:1:-1), & fl_lsgrpl(1:Npoints,Nlevels:1:-1), & fl_ccrain(1:Npoints,Nlevels:1:-1), & fl_ccsnow(1:Npoints,Nlevels:1:-1), & mr_lsliq(1:Npoints,Nlevels:1:-1), & mr_lsice(1:Npoints,Nlevels:1:-1), & mr_ccliq(1:Npoints,Nlevels:1:-1), & mr_ccice(1:Npoints,Nlevels:1:-1), & Reff(1:Npoints,Nlevels:1:-1,:), & dtau_c(1:Npoints,Nlevels:1:-1), & dtau_s(1:Npoints,Nlevels:1:-1), & dem_c(1:Npoints,Nlevels:1:-1), & dem_s(1:Npoints,Nlevels:1:-1), cospstateIN, cospIN) !call cpu_time(driver_time(6)) !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! Call COSP !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% cosp_status = COSP_SIMULATOR(cospIN, cospstateIN, cospOUT,start_idx,end_idx,.false.) endif ! cosp_init_flag = 1 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! Output !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! ! 7a) Ecriture des sorties 1: on cree d'abord les fichiers NCDF pour ecrire les sorties ! en appelant lmdz_cosp_output_open (lors du premier appel de cette interface pour les ! 2 options d'ecriture), ou sont definis les axes et les caracteristiques ! des fichiers de sortie avec les diagnostics. ! !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if (debut_cosp) then !$OMP MASTER IF (is_master) print *, ' Open outpts files and define axis' call lmdz_cosp_output_open(Nlevlmdz, Ncolumns, presnivs, dtime, & use_vgrid_in, niv_sorties, vgrid_z_in, zlev(1,:)) !$OMP END MASTER !$OMP BARRIER debut_cosp=.false. endif ! debut_cosp if (cosp_init_flag .eq. 1) then !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! ! 7b) Ecriture des sorties 2: le remplissage des fichiers de sortie se fait a chaque ! appel de cette interface avec une difference entre les 2 options d'ecriture: ! - AVEC xios, on commence a remplir les fichiers de sortie a partir du DEUXIEME ! appel de cette interface (lorsque cosp_init_flag = 1). ! - SANS xios, on commence a remplir les fichiers de sortie a partir du PREMIER ! appel de cette interface (lorsque cosp_init_flag = 1). ! !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IF (is_master) print *, 'Calling write output' call lmdz_cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, & cfg, niv_sorties, cospOUT) !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! Free up memory !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% call destroy_cosp_outputs(cospOUT) call destroy_cospIN(cospIN) call destroy_cospstateIN(cospstateIN) call cosp_cleanUp() !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% endif ! cosp_init_flag = 1 end subroutine lmdz_cospv2_interface