source: LMDZ6/branches/Amaury_dev/libf/phylmd/cosp/cosp_output_write_mod.F90

Last change on this file was 5185, checked in by abarral, 2 months ago

Replace REPROBUS CPP KEY by logical using handmade wonky wrapper

File size: 30.9 KB
Line 
1!!!! Abderrahmane Idelkadi aout 2013 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2! Module pour definir (au 1er appel) et ecrire les variables dans les fichiers de sortie cosp
3!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4   MODULE cosp_output_write_mod
5
6   USE cosp_output_mod
7
8   IMPLICIT NONE
9
10   INTEGER, SAVE  :: itau_iocosp
11!$OMP THREADPRIVATE(itau_iocosp)
12   INTEGER, save        :: Nlevout, Ncolout
13!$OMP THREADPRIVATE(Nlevout, Ncolout)
14
15!  INTERFACE histwrite_cosp
16!    MODULE PROCEDURE histwrite2d_cosp,histwrite3d_cosp
17!  END INTERFACE
18
19   CONTAINS
20
21  SUBROUTINE cosp_output_write(Nlevlmdz, Npoints, Ncolumns, itap, dtime, freq_COSP, missing_cosp, &
22                               cfg, gbx, vgrid, sglidar, sgradar, stlidar, stradar, &
23                               isccp, misr, modis)
24
25    USE ioipsl
26    USE time_phylmdz_mod, ONLY: itau_phy, start_time, day_step_phy
27    USE lmdz_print_control, ONLY: lunout,prt_level
28    USE lmdz_wxios, only: wxios_closedef
29    USE lmdz_xios, only: xios_update_calendar, xios_field_is_active, using_xios
30  IMPLICIT NONE
31!!! Variables d'entree
32  integer               :: itap, Nlevlmdz, Ncolumns, Npoints
33  REAL                  :: freq_COSP, dtime, missing_val, missing_cosp
34  type(cosp_config)     :: cfg     ! Control outputs
35  type(cosp_gridbox)    :: gbx     ! Gridbox information. Input for COSP
36  type(cosp_sglidar)    :: sglidar ! Output from lidar simulator
37  type(cosp_sgradar)    :: sgradar ! Output from radar simulator
38  type(cosp_isccp)      :: isccp   ! Output from ISCCP simulator
39  type(cosp_lidarstats) :: stlidar ! Summary statistics from lidar simulator
40  type(cosp_radarstats) :: stradar
41  type(cosp_misr)       :: misr    ! Output from MISR
42  type(cosp_modis)      :: modis   ! Outputs from Modis
43  type(cosp_vgrid)      :: vgrid   ! Information on vertical grid of stats
44
45!!! Variables locales
46  integer               :: icl,k,ip
47  logical               :: ok_sync
48  integer               :: itau_wcosp, iff
49  real, dimension(Npoints,PARASOL_NREFL) :: parasolcrefl, Ncref
50
51! Variables locals intermidiaires pour inverser les axes des champs 4D
52! Compatibilite avec sorties CMIP
53  real, dimension(Npoints,Nlevout,SR_BINS) :: tmp_fi4da_cfadL
54  real, dimension(Npoints,Nlevout,DBZE_BINS) :: tmp_fi4da_cfadR
55  real, dimension(Npoints,MISR_N_CTH,7) :: tmp_fi4da_misr
56
57  IF (using_xios) THEN
58    missing_val=missing_cosp
59  ELSE
60    missing_val=0.
61  ENDIF
62
63  Nlevout = vgrid%Nlvgrid
64  Ncolout = Ncolumns
65
66! A refaire
67       itau_wcosp = itau_phy + itap + start_time * day_step_phy
68        if (prt_level >= 10) then
69             WRITE(lunout,*)'itau_wcosp, itap, start_time, day_step_phy =', &
70                             itau_wcosp, itap, start_time, day_step_phy
71        endif
72
73! On le donne a  cosp_output_write_mod pour que les histwrite y aient acces:
74       CALL set_itau_iocosp(itau_wcosp)
75        if (prt_level >= 10) then
76              WRITE(lunout,*)'itau_iocosp =',itau_iocosp
77        endif
78
79    ok_sync = .TRUE.
80
81!DO iinit=1, iinitend
82! AI sept 2014 cette boucle supprimee
83! On n'ecrit pas quand itap=1 (cosp)
84
85!   if (prt_level >= 10) then
86!         WRITE(lunout,*)'DO iinit=1, iinitend ',iinitend
87!   endif
88
89!!IF (using_xios) THEN
90! !$OMP MASTER
91!IF (cosp_varsdefined) THEN
92!   if (prt_level >= 10) then
93!         WRITE(lunout,*)'Apell xios_update_calendar cosp_varsdefined iinitend ', &
94!                         cosp_varsdefined,iinitend
95!   endif
96!    CALL xios_update_calendar(itau_wcosp)
97!ENDIF
98!  !$OMP END MASTER
99!  !$OMP BARRIER
100!!ENDIF
101
102!!!! Sorties Calipso
103 if (cfg%Llidar_sim) then
104!!! AI 02 2018
105! Traitement missing_val
106   where(stlidar%lidarcld == R_UNDEF) stlidar%lidarcld = missing_val
107   where(stlidar%proftemp == R_UNDEF) stlidar%proftemp = missing_val   !TIBO
108   where(stlidar%profSR == R_UNDEF) stlidar%profSR = missing_val       !TIBO2
109   where(sglidar%beta_mol == R_UNDEF) sglidar%beta_mol = missing_val
110   where(sglidar%beta_tot == R_UNDEF) sglidar%beta_tot = missing_val
111   where(stlidar%cldlayer == R_UNDEF) stlidar%cldlayer = missing_val
112   where(stlidar%cldtype == R_UNDEF) stlidar%cldtype = missing_val     !OPAQ
113   where(stlidar%cfad_sr == R_UNDEF) stlidar%cfad_sr = missing_val
114! AI 11 / 2015
115   where(stlidar%parasolrefl == R_UNDEF) stlidar%parasolrefl = missing_val
116   where(stlidar%lidarcldtmp == R_UNDEF) stlidar%lidarcldtmp = missing_val
117   where(stlidar%cldlayerphase == R_UNDEF) stlidar%cldlayerphase = missing_val
118   where(stlidar%lidarcldphase == R_UNDEF) stlidar%lidarcldphase = missing_val
119   where(stlidar%lidarcldtype == R_UNDEF) stlidar%lidarcldtype = missing_val   !OPAQ
120   where(stlidar%lidarcldtmp == R_UNDEF) stlidar%lidarcldtmp = missing_val
121
122!   print*,'Appel histwrite2d_cosp'
123   if (cfg%Lcllcalipso) CALL histwrite2d_cosp(o_cllcalipso,stlidar%cldlayer(:,1))
124   if (cfg%Lclhcalipso) CALL histwrite2d_cosp(o_clhcalipso,stlidar%cldlayer(:,3))
125   if (cfg%Lclmcalipso) CALL histwrite2d_cosp(o_clmcalipso,stlidar%cldlayer(:,2))
126   if (cfg%Lcltcalipso) CALL histwrite2d_cosp(o_cltcalipso,stlidar%cldlayer(:,4))
127   if (cfg%Lclcalipso) CALL histwrite3d_cosp(o_clcalipso,stlidar%lidarcld,nvert)
128   if (cfg%Lclcalipsotmp) CALL histwrite3d_cosp(o_clcalipsotmp,stlidar%lidarcldtmp(:,:,1),nverttemp)
129
130   if (cfg%Lcllcalipsoice) CALL histwrite2d_cosp(o_cllcalipsoice,stlidar%cldlayerphase(:,1,1))
131   if (cfg%Lclhcalipsoice) CALL histwrite2d_cosp(o_clhcalipsoice,stlidar%cldlayerphase(:,3,1))
132   if (cfg%Lclmcalipsoice) CALL histwrite2d_cosp(o_clmcalipsoice,stlidar%cldlayerphase(:,2,1))
133   if (cfg%Lcltcalipsoice) CALL histwrite2d_cosp(o_cltcalipsoice,stlidar%cldlayerphase(:,4,1))
134   if (cfg%Lclcalipsoice) CALL histwrite3d_cosp(o_clcalipsoice,stlidar%lidarcldphase(:,:,1),nvert)
135   if (cfg%Lclcalipsotmpice) CALL histwrite3d_cosp(o_clcalipsotmpice,stlidar%lidarcldtmp(:,:,2),nverttemp)
136
137   if (cfg%Lcllcalipsoliq) CALL histwrite2d_cosp(o_cllcalipsoliq,stlidar%cldlayerphase(:,1,2))
138   if (cfg%Lclhcalipsoliq) CALL histwrite2d_cosp(o_clhcalipsoliq,stlidar%cldlayerphase(:,3,2))
139   if (cfg%Lclmcalipsoliq) CALL histwrite2d_cosp(o_clmcalipsoliq,stlidar%cldlayerphase(:,2,2))
140   if (cfg%Lcltcalipsoliq) CALL histwrite2d_cosp(o_cltcalipsoliq,stlidar%cldlayerphase(:,4,2))
141   if (cfg%Lclcalipsoliq) CALL histwrite3d_cosp(o_clcalipsoliq,stlidar%lidarcldphase(:,:,2),nvert)
142   if (cfg%Lclcalipsotmpliq) CALL histwrite3d_cosp(o_clcalipsotmpliq,stlidar%lidarcldtmp(:,:,3),nverttemp)
143
144   if (cfg%Lcllcalipsoun) CALL histwrite2d_cosp(o_cllcalipsoun,stlidar%cldlayerphase(:,1,3))
145   if (cfg%Lclhcalipsoun) CALL histwrite2d_cosp(o_clhcalipsoun,stlidar%cldlayerphase(:,3,3))
146   if (cfg%Lclmcalipsoun) CALL histwrite2d_cosp(o_clmcalipsoun,stlidar%cldlayerphase(:,2,3))
147   if (cfg%Lcltcalipsoun) CALL histwrite2d_cosp(o_cltcalipsoun,stlidar%cldlayerphase(:,4,3))
148   if (cfg%Lclcalipsoun) CALL histwrite3d_cosp(o_clcalipsoun,stlidar%lidarcldphase(:,:,3),nvert)
149   if (cfg%Lclcalipsotmpun) CALL histwrite3d_cosp(o_clcalipsotmpun,stlidar%lidarcldtmp(:,:,4),nverttemp)
150
151   if (cfg%Lclopaquecalipso) CALL histwrite2d_cosp(o_clopaquecalipso,stlidar%cldtype(:,1))               !OPAQ
152   if (cfg%Lclthincalipso) CALL histwrite2d_cosp(o_clthincalipso,stlidar%cldtype(:,2))                 !OPAQ
153   if (cfg%Lclzopaquecalipso) CALL histwrite2d_cosp(o_clzopaquecalipso,stlidar%cldtype(:,3))              !OPAQ
154
155   if (cfg%Lclcalipsoopaque) CALL histwrite3d_cosp(o_clcalipsoopaque,stlidar%lidarcldtype(:,:,1),nvert)  !OPAQ
156   if (cfg%Lclcalipsothin) CALL histwrite3d_cosp(o_clcalipsothin,stlidar%lidarcldtype(:,:,2),nvert)    !OPAQ
157   if (cfg%Lclcalipsozopaque) CALL histwrite3d_cosp(o_clcalipsozopaque,stlidar%lidarcldtype(:,:,3),nvert) !OPAQ
158   if (cfg%Lclcalipsoopacity) CALL histwrite3d_cosp(o_clcalipsoopacity,stlidar%lidarcldtype(:,:,4),nvert) !OPAQ
159
160   if (cfg%Lproftemp) CALL histwrite3d_cosp(o_proftemp,stlidar%proftemp,nvert)                    !TIBO
161
162   IF (using_xios) THEN
163     DO icl=1,SR_BINS
164        tmp_fi4da_cfadL(:,:,icl)=stlidar%cfad_sr(:,icl,:)
165     enddo
166  !   if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr)
167     if (cfg%LcfadLidarsr532) CALL histwrite4d_cosp(o_cfad_lidarsr532,tmp_fi4da_cfadL)
168     if (cfg%LprofSR) CALL histwrite4d_cosp(o_profSR,stlidar%profSR)                              !TIBO
169   ELSE
170     if (cfg%LcfadLidarsr532) then
171       DO icl=1,SR_BINS
172          CALL histwrite3d_cosp(o_cfad_lidarsr532,stlidar%cfad_sr(:,icl,:),nvert,icl)
173       enddo
174     endif
175     if (cfg%LprofSR) then
176       DO icl=1,Ncolumns                                                              !TIBO
177          CALL histwrite3d_cosp(o_profSR,stlidar%profSR(:,icl,:),nvert,icl)           !TIBO
178       enddo                                                                          !TIBO
179      endif
180   ENDIF
181
182   if (cfg%LparasolRefl) CALL histwrite3d_cosp(o_parasol_refl,stlidar%parasolrefl,nvertp)
183
184  if (cfg%LparasolRefl) then
185    DO k=1,PARASOL_NREFL
186     DO ip=1, Npoints
187      if (stlidar%cldlayer(ip,4).gt.0.01.AND.stlidar%parasolrefl(ip,k).ne.missing_val) then
188        parasolcrefl(ip,k)=(stlidar%parasolrefl(ip,k)-0.03*(1.-stlidar%cldlayer(ip,4)))/ &
189                             stlidar%cldlayer(ip,4)
190         Ncref(ip,k) = 1.
191      else
192         parasolcrefl(ip,k)=missing_val
193         Ncref(ip,k) = 0.
194      endif
195     enddo
196    enddo
197    CALL histwrite3d_cosp(o_Ncrefl,Ncref,nvertp)
198    CALL histwrite3d_cosp(o_parasol_crefl,parasolcrefl,nvertp)
199  endif
200
201   IF (using_xios) THEN
202     if (cfg%Latb532) CALL histwrite4d_cosp(o_atb532,sglidar%beta_tot)
203   ELSE
204     if (cfg%Latb532) then
205       DO icl=1,Ncolumns
206          CALL histwrite3d_cosp(o_atb532,sglidar%beta_tot(:,icl,:),nvertmcosp,icl)
207       enddo
208     endif
209   ENDIF
210
211   if (cfg%LlidarBetaMol532) CALL histwrite3d_cosp(o_beta_mol532,sglidar%beta_mol,nvertmcosp)
212
213 endif !Lidar
214
215!!! Sorties Cloudsat
216 if (cfg%Lradar_sim) then
217
218   where(stradar%cfad_ze == R_UNDEF) stradar%cfad_ze = missing_val
219   IF (using_xios) THEN
220     DO icl=1,DBZE_BINS
221       tmp_fi4da_cfadR(:,:,icl)=stradar%cfad_ze(:,icl,:)
222     enddo
223     if (cfg%Ldbze94) CALL histwrite4d_cosp(o_dbze94,sgradar%Ze_tot)
224  !  if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,stradar%cfad_ze)
225     if (cfg%LcfadDbze94) CALL histwrite4d_cosp(o_cfadDbze94,tmp_fi4da_cfadR)
226   ELSE
227     if (cfg%Ldbze94) then
228       DO icl=1,Ncolumns
229         CALL histwrite3d_cosp(o_dbze94,sgradar%Ze_tot(:,icl,:),nvert,icl)
230       enddo
231     endif
232     if (cfg%LcfadDbze94) then
233       DO icl=1,DBZE_BINS
234         CALL histwrite3d_cosp(o_cfadDbze94,stradar%cfad_ze(:,icl,:),nvert,icl)
235       enddo
236     endif
237   ENDIF
238 endif
239! endif pour radar
240
241!!! Sorties combinees Cloudsat et Calipso
242 if (cfg%Llidar_sim .AND. cfg%Lradar_sim) then
243   where(stradar%lidar_only_freq_cloud == R_UNDEF) &
244                           stradar%lidar_only_freq_cloud = missing_val
245   if (cfg%Lclcalipso) CALL histwrite3d_cosp(o_clcalipso2,stradar%lidar_only_freq_cloud,nvert)
246   where(stradar%radar_lidar_tcc == R_UNDEF) &
247                           stradar%radar_lidar_tcc = missing_val
248   if (cfg%Lcltlidarradar) CALL histwrite2d_cosp(o_cltlidarradar,stradar%radar_lidar_tcc)
249 endif
250
251!!! Sorties Isccp
252 if (cfg%Lisccp_sim) then
253  where(isccp%totalcldarea == R_UNDEF) isccp%totalcldarea = missing_val
254  where(isccp%meanptop == R_UNDEF) isccp%meanptop = missing_val
255  where(isccp%meantaucld == R_UNDEF) isccp%meantaucld = missing_val
256  where(isccp%meanalbedocld == R_UNDEF) isccp%meanalbedocld = missing_val
257  where(isccp%meantb == R_UNDEF) isccp%meantb = missing_val
258  where(isccp%meantbclr == R_UNDEF) isccp%meantbclr = missing_val
259  where(isccp%fq_isccp == R_UNDEF) isccp%fq_isccp = missing_val
260  where(isccp%boxtau == R_UNDEF) isccp%boxtau = missing_val
261  where(isccp%boxptop == R_UNDEF) isccp%boxptop = missing_val
262
263   CALL histwrite2d_cosp(o_sunlit,gbx%sunlit)
264   IF (using_xios) THEN
265     if (cfg%Lclisccp) CALL histwrite4d_cosp(o_clisccp2,isccp%fq_isccp)
266   ELSE
267     if (cfg%Lclisccp) then
268       DO icl=1,7
269         CALL histwrite3d_cosp(o_clisccp2,isccp%fq_isccp(:,icl,:),nvertisccp,icl)
270       enddo
271     endif
272   ENDIF
273
274   if (cfg%Lboxtauisccp) CALL histwrite3d_cosp(o_boxtauisccp,isccp%boxtau,nvertcol)
275   if (cfg%Lboxptopisccp) CALL histwrite3d_cosp(o_boxptopisccp,isccp%boxptop,nvertcol)
276   if (cfg%Lcltisccp) CALL histwrite2d_cosp(o_tclisccp,isccp%totalcldarea)
277   if (cfg%Lpctisccp) CALL histwrite2d_cosp(o_ctpisccp,isccp%meanptop)
278   if (cfg%Ltauisccp) CALL histwrite2d_cosp(o_tauisccp,isccp%meantaucld)
279   if (cfg%Lalbisccp) CALL histwrite2d_cosp(o_albisccp,isccp%meanalbedocld)
280   if (cfg%Lmeantbisccp) CALL histwrite2d_cosp(o_meantbisccp,isccp%meantb)
281   if (cfg%Lmeantbclrisccp) CALL histwrite2d_cosp(o_meantbclrisccp,isccp%meantbclr)
282 endif ! Isccp
283
284!!! MISR simulator
285 if (cfg%Lmisr_sim) then
286   where(misr%fq_MISR == R_UNDEF) misr%fq_MISR = missing_val
287
288   IF (using_xios) THEN
289     DO icl=1,MISR_N_CTH
290        tmp_fi4da_misr(:,icl,:)=misr%fq_MISR(:,:,icl)
291     enddo
292  !   if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,misr%fq_MISR)
293     if (cfg%LclMISR) CALL histwrite4d_cosp(o_clMISR,tmp_fi4da_misr)
294   ELSE
295     if (cfg%LclMISR) then
296      DO icl=1,7
297        CALL histwrite3d_cosp(o_clMISR,misr%fq_MISR(:,icl,:),nvertmisr,icl)
298      enddo
299     endif
300   ENDIF
301 endif
302! endif pour Misr
303
304!!! Modis simulator
305 if (cfg%Lmodis_sim) then
306  where(modis%Cloud_Fraction_Low_Mean == R_UNDEF) &
307        modis%Cloud_Fraction_Low_Mean = missing_val
308  where(modis%Cloud_Fraction_High_Mean == R_UNDEF) &
309        modis%Cloud_Fraction_High_Mean = missing_val
310  where(modis%Cloud_Fraction_Mid_Mean == R_UNDEF) &
311        modis%Cloud_Fraction_Mid_Mean = missing_val
312  where(modis%Cloud_Fraction_Total_Mean == R_UNDEF) &
313        modis%Cloud_Fraction_Total_Mean = missing_val
314  where(modis%Cloud_Fraction_Water_Mean == R_UNDEF) &
315        modis%Cloud_Fraction_Water_Mean = missing_val
316  where(modis%Cloud_Fraction_Ice_Mean == R_UNDEF) &
317        modis%Cloud_Fraction_Ice_Mean = missing_val
318  where(modis%Optical_Thickness_Total_Mean == R_UNDEF) &
319        modis%Optical_Thickness_Total_Mean = missing_val
320  where(modis%Optical_Thickness_Water_Mean == R_UNDEF) &
321        modis%Optical_Thickness_Water_Mean = missing_val
322  where(modis%Optical_Thickness_Ice_Mean == R_UNDEF) &
323        modis%Optical_Thickness_Ice_Mean = missing_val
324  where(modis%Cloud_Particle_Size_Water_Mean == R_UNDEF) &
325        modis%Cloud_Particle_Size_Water_Mean = missing_val
326  where(modis%Cloud_Particle_Size_Ice_Mean == R_UNDEF) &
327        modis%Cloud_Particle_Size_Ice_Mean = missing_val
328  where(modis%Cloud_Top_Pressure_Total_Mean == R_UNDEF) &
329        modis%Cloud_Top_Pressure_Total_Mean = missing_val
330  where(modis%Liquid_Water_Path_Mean == R_UNDEF) &
331        modis%Liquid_Water_Path_Mean = missing_val
332  where(modis%Ice_Water_Path_Mean == R_UNDEF) &
333        modis%Ice_Water_Path_Mean = missing_val
334
335  where(modis%Optical_Thickness_Total_LogMean == R_UNDEF) &
336          modis%Optical_Thickness_Total_LogMean = missing_val
337
338  where(modis%Optical_Thickness_Water_LogMean == R_UNDEF) &
339          modis%Optical_Thickness_Water_LogMean = missing_val
340
341  where(modis%Optical_Thickness_Ice_LogMean == R_UNDEF) &
342          modis%Optical_Thickness_Ice_LogMean = missing_val
343
344  if (cfg%Lcllmodis) CALL histwrite2d_cosp(o_cllmodis,modis%Cloud_Fraction_Low_Mean)
345  if (cfg%Lclhmodis) CALL histwrite2d_cosp(o_clhmodis,modis%Cloud_Fraction_High_Mean)
346  if (cfg%Lclmmodis) CALL histwrite2d_cosp(o_clmmodis,modis%Cloud_Fraction_Mid_Mean)
347  if (cfg%Lcltmodis) CALL histwrite2d_cosp(o_cltmodis,modis%Cloud_Fraction_Total_Mean)
348  if (cfg%Lclwmodis) CALL histwrite2d_cosp(o_clwmodis,modis%Cloud_Fraction_Water_Mean)
349  if (cfg%Lclimodis) CALL histwrite2d_cosp(o_climodis,modis%Cloud_Fraction_Ice_Mean)
350  if (cfg%Ltautmodis)  CALL histwrite2d_cosp(o_tautmodis,modis%Optical_Thickness_Total_Mean)
351  if (cfg%Ltauwmodis) CALL histwrite2d_cosp(o_tauwmodis,modis%Optical_Thickness_Water_Mean)
352  if (cfg%Ltauimodis) CALL histwrite2d_cosp(o_tauimodis,modis%Optical_Thickness_Ice_Mean)
353  if (cfg%Ltautlogmodis) CALL histwrite2d_cosp(o_tautlogmodis,modis%Optical_Thickness_Total_LogMean)
354  if (cfg%Ltauwlogmodis) CALL histwrite2d_cosp(o_tauwlogmodis,modis%Optical_Thickness_Water_LogMean)
355  if (cfg%Ltauilogmodis) CALL histwrite2d_cosp(o_tauilogmodis,modis%Optical_Thickness_Ice_LogMean)
356  if (cfg%Lreffclwmodis) CALL histwrite2d_cosp(o_reffclwmodis,modis%Cloud_Particle_Size_Water_Mean)
357  if (cfg%Lreffclimodis) CALL histwrite2d_cosp(o_reffclimodis,modis%Cloud_Particle_Size_Ice_Mean)
358  if (cfg%Lpctmodis) CALL histwrite2d_cosp(o_pctmodis,modis%Cloud_Top_Pressure_Total_Mean)
359  if (cfg%Llwpmodis) CALL histwrite2d_cosp(o_lwpmodis,modis%Liquid_Water_Path_Mean)
360  if (cfg%Liwpmodis) CALL histwrite2d_cosp(o_iwpmodis,modis%Ice_Water_Path_Mean)
361
362    where(modis%Optical_Thickness_vs_Cloud_Top_Pressure == R_UNDEF) &
363          modis%Optical_Thickness_vs_Cloud_Top_Pressure = missing_val
364
365   IF (using_xios) THEN
366     if (cfg%Lclmodis) CALL histwrite4d_cosp(o_clmodis,modis%Optical_Thickness_vs_Cloud_Top_Pressure)
367   ELSE
368     if (cfg%Lclmodis) then
369       DO icl=1,7
370         CALL histwrite3d_cosp(o_clmodis, &
371         modis%Optical_Thickness_vs_Cloud_Top_Pressure(:,icl,:),nvertisccp,icl)
372       enddo
373      endif
374   ENDIF
375
376    where(modis%Optical_Thickness_vs_ReffIce == R_UNDEF) &
377          modis%Optical_Thickness_vs_ReffIce = missing_val
378
379    where(modis%Optical_Thickness_vs_ReffLiq == R_UNDEF) &
380          modis%Optical_Thickness_vs_ReffLiq = missing_val
381
382   IF (using_xios) THEN
383     if (cfg%Lcrimodis) CALL histwrite4d_cosp(o_crimodis,modis%Optical_Thickness_vs_ReffIce)
384     if (cfg%Lcrlmodis) CALL histwrite4d_cosp(o_crlmodis,modis%Optical_Thickness_vs_ReffLiq)
385   ELSE
386     if (cfg%Lcrimodis) then
387       DO icl=1,7
388         CALL histwrite3d_cosp(o_crimodis, &
389            modis%Optical_Thickness_vs_ReffIce(:,icl,:),nvertReffIce,icl)
390       enddo
391     endif
392     if (cfg%Lcrlmodis) then
393       DO icl=1,7
394         CALL histwrite3d_cosp(o_crlmodis, &
395            modis%Optical_Thickness_vs_ReffLiq(:,icl,:),nvertReffLiq,icl)
396       enddo
397     endif
398   ENDIF
399 endif !modis
400
401 IF(.NOT.cosp_varsdefined) THEN
402!$OMP MASTER
403#ifndef CPP_IOIPSL_NO_OUTPUT
404            DO iff=1,3
405                IF (cosp_outfilekeys(iff)) THEN
406                  CALL histend(cosp_nidfiles(iff))
407                ENDIF ! cosp_outfilekeys
408            ENDDO !  iff
409#endif
410
411!$OMP END MASTER
412!$OMP BARRIER
413            cosp_varsdefined = .TRUE.
414 END IF
415
416    IF(cosp_varsdefined) THEN
417! On synchronise les fichiers pour IOIPSL
418#ifndef CPP_IOIPSL_NO_OUTPUT
419!$OMP MASTER
420     DO iff=1,3
421         IF (ok_sync .AND. cosp_outfilekeys(iff)) THEN
422             CALL histsync(cosp_nidfiles(iff))
423         ENDIF
424     END DO
425!$OMP END MASTER
426#endif
427    ENDIF  !cosp_varsdefined
428
429    END SUBROUTINE cosp_output_write
430
431! ug Routine pour definir itau_iocosp depuis cosp_output_write_mod:
432  SUBROUTINE set_itau_iocosp(ito)
433      IMPLICIT NONE
434      INTEGER, INTENT(IN) :: ito
435      itau_iocosp = ito
436  END SUBROUTINE
437
438  SUBROUTINE histdef2d_cosp (iff,var)
439
440    USE ioipsl
441    USE dimphy
442    use iophy
443    USE lmdz_phys_para
444    USE lmdz_grid_phy, ONLY: nbp_lon
445    USE lmdz_print_control, ONLY: lunout,prt_level
446    USE lmdz_wxios
447    USE lmdz_clesphys
448
449    IMPLICIT NONE
450
451    INTEGER                          :: iff
452    TYPE(ctrl_outcosp)               :: var
453
454    REAL zstophym
455    CHARACTER(LEN=20) :: typeecrit
456
457    ! ug On récupère le type écrit de la structure:
458    !       Assez moche, �|  refaire si meilleure méthode...
459    IF (INDEX(var%cosp_typeecrit(iff), "once") > 0) THEN
460       typeecrit = 'once'
461    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_min") > 0) THEN
462       typeecrit = 't_min(X)'
463    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_max") > 0) THEN
464       typeecrit = 't_max(X)'
465    ELSE IF(INDEX(var%cosp_typeecrit(iff), "inst") > 0) THEN
466       typeecrit = 'inst(X)'
467    ELSE
468       typeecrit = cosp_outfiletypes(iff)
469    ENDIF
470
471    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
472       zstophym=zoutm_cosp(iff)
473    ELSE
474       zstophym=zdtimemoy_cosp
475    ENDIF
476
477    IF (using_xios) THEN
478      IF (.not. ok_all_xml) then
479        IF ( var%cles(iff) ) THEN
480          if (prt_level >= 10) then
481            WRITE(lunout,*)'Appel wxios_add_field_to_file var%name =',var%name
482          endif
483          CALL wxios_add_field_to_file(var%name, 2, cosp_nidfiles(iff), cosp_outfilenames(iff), &
484                                     var%description, var%unit, 1, typeecrit)
485        ENDIF
486      ENDIF
487    ENDIF
488
489#ifndef CPP_IOIPSL_NO_OUTPUT
490       IF ( var%cles(iff) ) THEN
491          CALL histdef (cosp_nidfiles(iff), var%name, var%description, var%unit, &
492               nbp_lon,jj_nb,nhoricosp(iff), 1,1,1, -99, 32, &
493               typeecrit, zstophym,zoutm_cosp(iff))
494       ENDIF
495#endif
496
497  END SUBROUTINE histdef2d_cosp
498
499 SUBROUTINE histdef3d_cosp (iff,var,nvertsave,ncols)
500    USE ioipsl
501    USE dimphy
502    use iophy
503    USE lmdz_phys_para
504    USE lmdz_grid_phy, ONLY: nbp_lon
505    USE lmdz_print_control, ONLY: lunout,prt_level
506    USE lmdz_wxios
507    USE lmdz_clesphys
508
509    IMPLICIT NONE
510
511    INTEGER                        :: iff, klevs
512    INTEGER, INTENT(IN), OPTIONAL  :: ncols ! ug RUSTINE POUR LES variables 4D
513    INTEGER, INTENT(IN)           :: nvertsave
514    TYPE(ctrl_outcosp)             :: var
515
516    REAL zstophym
517    CHARACTER(LEN=20) :: typeecrit, nomi
518    CHARACTER(LEN=20) :: nom
519    character(len=2) :: str2
520    CHARACTER(len=20) :: nam_axvert
521
522! Axe vertical
523      IF (nvertsave.eq.nvertp(iff)) THEN
524          klevs=PARASOL_NREFL
525          nam_axvert="sza"
526      ELSE IF (nvertsave.eq.nvertisccp(iff)) THEN
527          klevs=7
528          nam_axvert="pressure2"
529      ELSE IF (nvertsave.eq.nvertcol(iff)) THEN
530          klevs=Ncolout
531          nam_axvert="column"
532      ELSE IF (nvertsave.eq.nverttemp(iff)) THEN
533          klevs=LIDAR_NTEMP
534          nam_axvert="temp"
535      ELSE IF (nvertsave.eq.nvertmisr(iff)) THEN
536          klevs=MISR_N_CTH
537          nam_axvert="cth16"
538      ELSE IF (nvertsave.eq.nvertReffIce(iff)) THEN
539          klevs= numMODISReffIceBins
540          nam_axvert="ReffIce"
541      ELSE IF (nvertsave.eq.nvertReffLiq(iff)) THEN
542          klevs= numMODISReffLiqBins
543          nam_axvert="ReffLiq"
544      ELSE
545           klevs=Nlevout
546           nam_axvert="presnivs"
547      ENDIF
548
549! ug RUSTINE POUR LES Champs 4D
550      IF (PRESENT(ncols)) THEN
551               write(str2,'(i2.2)')ncols
552               nomi=var%name
553               nom="c"//str2//"_"//nomi
554      ELSE
555               nom=var%name
556      END IF
557
558    ! ug On récupère le type écrit de la structure:
559    !       Assez moche, �|  refaire si meilleure méthode...
560    IF (INDEX(var%cosp_typeecrit(iff), "once") > 0) THEN
561       typeecrit = 'once'
562    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_min") > 0) THEN
563       typeecrit = 't_min(X)'
564    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_max") > 0) THEN
565       typeecrit = 't_max(X)'
566    ELSE IF(INDEX(var%cosp_typeecrit(iff), "inst") > 0) THEN
567       typeecrit = 'inst(X)'
568    ELSE
569       typeecrit = cosp_outfiletypes(iff)
570    ENDIF
571
572    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
573       zstophym=zoutm_cosp(iff)
574    ELSE
575       zstophym=zdtimemoy_cosp
576    ENDIF
577
578    IF (using_xios) THEN
579      IF (.not. ok_all_xml) then
580        IF ( var%cles(iff) ) THEN
581          if (prt_level >= 10) then
582              WRITE(lunout,*)'Appel wxios_add_field_to_file 3d nom variable nam_axvert = ',nom, nam_axvert
583          endif
584          CALL wxios_add_field_to_file(nom, 3, cosp_nidfiles(iff), cosp_outfilenames(iff), &
585                                       var%description, var%unit, 1, typeecrit, nam_axvert)
586        ENDIF
587      ENDIF
588    ENDIF
589
590#ifndef CPP_IOIPSL_NO_OUTPUT
591       IF ( var%cles(iff) ) THEN
592          CALL histdef (cosp_nidfiles(iff), nom, var%description, var%unit, &
593               nbp_lon, jj_nb, nhoricosp(iff), klevs, 1, &
594               klevs, nvertsave, 32, typeecrit, &
595               zstophym, zoutm_cosp(iff))
596       ENDIF
597#endif
598
599  END SUBROUTINE histdef3d_cosp
600
601 SUBROUTINE histwrite2d_cosp(var,field)
602  USE dimphy
603  USE lmdz_phys_para
604  USE ioipsl
605  use iophy
606  USE lmdz_grid_phy, ONLY: nbp_lon
607  USE lmdz_print_control, ONLY: lunout,prt_level
608  USE lmdz_xios, only: xios_send_field, using_xios
609  USE lmdz_abort_physic, ONLY: abort_physic
610  USE lmdz_clesphys
611
612  IMPLICIT NONE
613
614    TYPE(ctrl_outcosp), INTENT(IN) :: var
615    REAL, DIMENSION(:), INTENT(IN) :: field
616
617    INTEGER :: iff
618
619    REAL,DIMENSION(klon_mpi) :: buffer_omp
620    INTEGER, allocatable, DIMENSION(:) :: index2d
621    REAL :: Field2d(nbp_lon,jj_nb)
622    CHARACTER(LEN=20) ::  nomi, nom
623    character(len=2) :: str2
624    LOGICAL, SAVE  :: firstx
625!$OMP THREADPRIVATE(firstx)
626
627    IF (prt_level >= 9) WRITE(lunout,*)'Begin histrwrite2d ',var%name
628
629  ! On regarde si on est dans la phase de définition ou d'écriture:
630  IF(.NOT.cosp_varsdefined) THEN
631!$OMP MASTER
632      !Si phase de définition.... on définit
633      CALL conf_cospoutputs(var%name,var%cles)
634      DO iff=1, 3
635         IF (cosp_outfilekeys(iff)) THEN
636            CALL histdef2d_cosp(iff, var)
637         ENDIF
638      ENDDO
639!$OMP END MASTER
640  ELSE
641    !Et sinon on.... écrit
642    IF (SIZE(field)/=klon) &
643  CALL abort_physic('iophy::histwrite2d_cosp','Field first DIMENSION not equal to klon',1)
644
645    CALL Gather_omp(field,buffer_omp)
646!$OMP MASTER
647    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
648
649! La boucle sur les fichiers:
650      firstx=.true.
651      DO iff=1, 3
652           IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
653                ALLOCATE(index2d(nbp_lon*jj_nb))
654#ifndef CPP_IOIPSL_NO_OUTPUT
655        CALL histwrite(cosp_nidfiles(iff),var%name,itau_iocosp,Field2d,nbp_lon*jj_nb,index2d)
656#endif
657            deallocate(index2d)
658            IF (using_xios) THEN
659              IF (.not. ok_all_xml) then
660                 if (firstx) then
661                  if (prt_level >= 10) then
662                    WRITE(lunout,*)'xios_send_field variable ',var%name
663                  endif
664                  CALL xios_send_field(var%name, Field2d)
665                   firstx=.false.
666                 endif
667              ENDIF
668            ENDIF
669          ENDIF
670      ENDDO
671
672    IF (using_xios) THEN
673      IF (ok_all_xml) THEN
674        if (prt_level >= 1) then
675              WRITE(lunout,*)'xios_send_field variable ',var%name
676        endif
677       CALL xios_send_field(var%name, Field2d)
678      ENDIF
679    ENDIF
680
681!$OMP END MASTER
682  ENDIF ! vars_defined
683  IF (prt_level >= 9) WRITE(lunout,*)'End histrwrite2d_cosp ',var%name
684  END SUBROUTINE histwrite2d_cosp
685
686! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
687! AI sept 2013
688  SUBROUTINE histwrite3d_cosp(var, field, nverts, ncols)
689  USE dimphy
690  USE lmdz_phys_para
691  USE ioipsl
692  use iophy
693  USE lmdz_grid_phy, ONLY: nbp_lon
694  USE lmdz_print_control, ONLY: lunout,prt_level
695  USE lmdz_xios, only: xios_send_field, using_xios
696  USE lmdz_abort_physic, ONLY: abort_physic
697  USE lmdz_clesphys
698
699  IMPLICIT NONE
700
701    TYPE(ctrl_outcosp), INTENT(IN)    :: var
702    REAL, DIMENSION(:,:), INTENT(IN)  :: field ! --> field(klon,:)
703    INTEGER, INTENT(IN), OPTIONAL     :: ncols ! ug RUSTINE POUR LES Champs 4D.....
704    INTEGER, DIMENSION(3), INTENT(IN) :: nverts
705
706    INTEGER :: iff, k
707
708    REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
709    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
710    INTEGER :: ip, n, nlev
711    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
712    CHARACTER(LEN=20) ::  nomi, nom
713    character(len=2) :: str2
714    LOGICAL, SAVE  :: firstx
715!$OMP THREADPRIVATE(firstx)
716
717  IF (prt_level >= 9) write(lunout,*)'Begin histrwrite3d ',var%name
718
719! ug RUSTINE POUR LES STD LEVS.....
720      IF (PRESENT(ncols)) THEN
721              write(str2,'(i2.2)')ncols
722              nomi=var%name
723              nom="c"//str2//"_"//nomi
724      ELSE
725               nom=var%name
726      END IF
727  ! On regarde si on est dans la phase de définition ou d'écriture:
728  IF(.NOT.cosp_varsdefined) THEN
729      !Si phase de définition.... on définit
730!$OMP MASTER
731      CALL conf_cospoutputs(var%name,var%cles)
732      DO iff=1, 3
733        IF (cosp_outfilekeys(iff)) THEN
734          CALL histdef3d_cosp(iff, var, nverts(iff), ncols)
735        ENDIF
736      ENDDO
737!$OMP END MASTER
738  ELSE
739    !Et sinon on.... écrit
740    IF (SIZE(field,1)/=klon) &
741   CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
742    nlev=SIZE(field,2)
743
744
745    CALL Gather_omp(field,buffer_omp)
746!$OMP MASTER
747    CALL grid1Dto2D_mpi(buffer_omp,field3d)
748
749! BOUCLE SUR LES FICHIERS
750     firstx=.true.
751     DO iff=1, 3
752        IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
753           ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
754#ifndef CPP_IOIPSL_NO_OUTPUT
755    CALL histwrite(cosp_nidfiles(iff),nom,itau_iocosp,Field3d,nbp_lon*jj_nb*nlev,index3d)
756#endif
757
758        IF (using_xios) THEN
759          IF (.not. ok_all_xml) then
760           IF (firstx) THEN
761               CALL xios_send_field(nom, Field3d(:,:,1:nlev))
762               IF (prt_level >= 9) WRITE(lunout,*)'xios_send_field ',var%name
763               firstx=.FALSE.
764           ENDIF
765          ENDIF
766        ENDIF
767         deallocate(index3d)
768        ENDIF
769      ENDDO
770
771  IF (using_xios) THEN
772    IF (ok_all_xml) THEN
773     CALL xios_send_field(nom, Field3d(:,:,1:nlev))
774     IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
775    ENDIF
776  ENDIF
777
778!$OMP END MASTER
779  ENDIF ! vars_defined
780  IF (prt_level >= 9) write(lunout,*)'End histrwrite3d_cosp ',nom
781  END SUBROUTINE histwrite3d_cosp
782
783! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
784! AI sept 2013
785  SUBROUTINE histwrite4d_cosp(var, field)
786  USE dimphy
787  USE lmdz_phys_para
788  USE ioipsl
789  use iophy
790  USE lmdz_grid_phy, ONLY: nbp_lon
791  USE lmdz_print_control, ONLY: lunout,prt_level
792  USE lmdz_xios, only: xios_send_field, using_xios
793  USE lmdz_abort_physic, ONLY: abort_physic
794  USE lmdz_clesphys
795
796  IMPLICIT NONE
797
798    TYPE(ctrl_outcosp), INTENT(IN)    :: var
799    REAL, DIMENSION(:,:,:), INTENT(IN)  :: field ! --> field(klon,:)
800
801    INTEGER :: iff, k
802
803    REAL,DIMENSION(klon_mpi,SIZE(field,2),SIZE(field,3)) :: buffer_omp
804    REAL :: field4d(nbp_lon,jj_nb,SIZE(field,2),SIZE(field,3))
805    INTEGER :: ip, n, nlev, nlev2
806    INTEGER, ALLOCATABLE, DIMENSION(:) :: index4d
807    CHARACTER(LEN=20) ::  nomi, nom
808
809  IF (prt_level >= 9) write(lunout,*)'Begin histrwrite4d ',var%name
810
811  IF(cosp_varsdefined) THEN
812    !Et sinon on.... écrit
813    IF (SIZE(field,1)/=klon) &
814   CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
815
816    nlev=SIZE(field,2)
817    nlev2=SIZE(field,3)
818    CALL Gather_omp(field,buffer_omp)
819!$OMP MASTER
820    CALL grid1Dto2D_mpi(buffer_omp,field4d)
821
822   IF (using_xios) THEN
823!    IF (ok_all_xml) THEN
824     CALL xios_send_field(var%name, Field4d(:,:,1:nlev,1:nlev2))
825     IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
826!    ENDIF
827   ENDIF
828
829!$OMP END MASTER
830  ENDIF ! vars_defined
831  IF (prt_level >= 9) write(lunout,*)'End histrwrite4d_cosp ',nom
832  END SUBROUTINE histwrite4d_cosp
833
834  SUBROUTINE conf_cospoutputs(nam_var,cles_var)
835!!! Lecture des noms et cles de sortie des variables dans config.def
836    !   en utilisant les routines getin de IOIPSL 
837    use ioipsl
838    USE lmdz_print_control, ONLY: lunout,prt_level
839
840    IMPLICIT NONE
841
842   CHARACTER(LEN=20)               :: nam_var, nnam_var
843   LOGICAL, DIMENSION(3)           :: cles_var
844
845! Lecture dans config.def ou output.def de cles_var et name_var
846    CALL getin('cles_'//nam_var,cles_var)
847    CALL getin('name_'//nam_var,nam_var)
848    IF(prt_level>10) WRITE(lunout,*)'nam_var cles_var ',nam_var,cles_var(:)
849
850  END SUBROUTINE conf_cospoutputs
851
852 END MODULE cosp_output_write_mod
Note: See TracBrowser for help on using the repository browser.