source: LMDZ5/branches/IPSLCM6.0.10/libf/phylmd/cosp/cosp_output_write_mod.F90

Last change on this file was 2839, checked in by Laurent Fairhead, 8 years ago

Merged trunk changes r2785:2838 into testing branch

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