source: LMDZ5/branches/testing/libf/phylmd/cosp/cosp_output_write_mod.F90 @ 5429

Last change on this file since 5429 was 2886, checked in by Laurent Fairhead, 8 years ago

Merged trunk changes r2865:2885 into testing branch

File size: 28.1 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#endif
185
186   CALL histwrite3d_cosp(o_parasol_refl,stlidar%parasolrefl,nvertp)
187   do k=1,PARASOL_NREFL
188    do ip=1, Npoints
189     if (stlidar%cldlayer(ip,4).gt.0.01.and.stlidar%parasolrefl(ip,k).ne.missing_val) 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   
199   enddo
200   CALL histwrite3d_cosp(o_Ncrefl,Ncref,nvertp)
201   CALL histwrite3d_cosp(o_parasol_crefl,parasolcrefl,nvertp)
202
203#ifdef CPP_XIOS
204   CALL histwrite4d_cosp(o_atb532,sglidar%beta_tot)
205#else
206   do icl=1,Ncolumns
207      CALL histwrite3d_cosp(o_atb532,sglidar%beta_tot(:,icl,:),nvertmcosp,icl)
208   enddo
209#endif
210
211   CALL histwrite3d_cosp(o_beta_mol532,sglidar%beta_mol,nvertmcosp)
212 endif !Lidar
213
214 if (cfg%Lradar_sim) then
215
216#ifdef CPP_XIOS
217   CALL histwrite4d_cosp(o_dbze94,sgradar%Ze_tot)
218   CALL histwrite4d_cosp(o_cfadDbze94,stradar%cfad_ze)
219#else
220   do icl=1,Ncolumns
221      CALL histwrite3d_cosp(o_dbze94,sgradar%Ze_tot(:,icl,:),nvertmcosp,icl)
222   enddo
223   do icl=1,DBZE_BINS
224    CALL histwrite3d_cosp(o_cfadDbze94,stradar%cfad_ze(:,icl,:),nvert,icl)
225   enddo
226#endif
227 endif
228
229 if (cfg%Llidar_sim .and. cfg%Lradar_sim) then
230   where(stradar%lidar_only_freq_cloud == R_UNDEF) &
231                           stradar%lidar_only_freq_cloud = missing_val
232   CALL histwrite3d_cosp(o_clcalipso2,stradar%lidar_only_freq_cloud,nvert)
233   where(stradar%radar_lidar_tcc == R_UNDEF) &
234                           stradar%radar_lidar_tcc = missing_val
235   CALL histwrite2d_cosp(o_cltlidarradar,stradar%radar_lidar_tcc)
236 endif
237
238 if (cfg%Lisccp_sim) then
239
240! Traitement des valeurs indefinies
241   do ip = 1,Npoints
242    if(isccp%totalcldarea(ip).eq.R_UNDEF)then
243      isccp%totalcldarea(ip)=missing_val
244    endif
245    if(isccp%meanptop(ip).eq.R_UNDEF)then
246      isccp%meanptop(ip)=missing_val
247    endif
248    if(isccp%meantaucld(ip).eq.R_UNDEF)then
249      isccp%meantaucld(ip)=missing_val
250    endif
251    if(isccp%meanalbedocld(ip).eq.R_UNDEF)then
252     isccp%meanalbedocld(ip)=missing_val
253    endif
254    if(isccp%meantb(ip).eq.R_UNDEF)then
255     isccp%meantb(ip)=missing_val
256    endif
257    if(isccp%meantbclr(ip).eq.R_UNDEF)then
258       isccp%meantbclr(ip)=missing_val
259    endif
260
261    do k=1,7
262     do ii=1,7
263     if(isccp%fq_isccp(ip,ii,k).eq.R_UNDEF)then
264      isccp%fq_isccp(ip,ii,k)=missing_val
265     endif
266     enddo
267    enddo
268
269    do ii=1,Ncolumns
270     if(isccp%boxtau(ip,ii).eq.R_UNDEF)then
271       isccp%boxtau(ip,ii)=missing_val
272     endif
273    enddo
274
275    do ii=1,Ncolumns
276     if(isccp%boxptop(ip,ii).eq.R_UNDEF)then
277      isccp%boxptop(ip,ii)=missing_val
278     endif
279    enddo
280   enddo
281
282   CALL histwrite2d_cosp(o_sunlit,gbx%sunlit)
283#ifdef CPP_XIOS
284   CALL histwrite4d_cosp(o_clisccp2,isccp%fq_isccp)
285#else
286   do icl=1,7
287   CALL histwrite3d_cosp(o_clisccp2,isccp%fq_isccp(:,icl,:),nvertisccp,icl)
288   enddo
289#endif
290   CALL histwrite3d_cosp(o_boxtauisccp,isccp%boxtau,nvertcol)
291   CALL histwrite3d_cosp(o_boxptopisccp,isccp%boxptop,nvertcol)
292   CALL histwrite2d_cosp(o_tclisccp,isccp%totalcldarea)
293   CALL histwrite2d_cosp(o_ctpisccp,isccp%meanptop)
294   CALL histwrite2d_cosp(o_tauisccp,isccp%meantaucld)
295   CALL histwrite2d_cosp(o_albisccp,isccp%meanalbedocld)
296   CALL histwrite2d_cosp(o_meantbisccp,isccp%meantb)
297   CALL histwrite2d_cosp(o_meantbclrisccp,isccp%meantbclr)
298 endif ! Isccp
299
300! MISR simulator
301 if (cfg%Lmisr_sim) then
302   do ip=1,Npoints
303     do ii=1,7
304       do k=1,MISR_N_CTH
305        if(misr%fq_MISR(ip,ii,k).eq.R_UNDEF)then
306            misr%fq_MISR(ip,ii,k)=missing_val
307        endif
308       enddo
309     enddo
310   enddo
311
312#ifdef CPP_XIOS
313   CALL histwrite4d_cosp(o_clMISR,misr%fq_MISR)
314#else
315   do icl=1,7
316      CALL histwrite3d_cosp(o_clMISR,misr%fq_MISR(:,icl,:),nvertmisr,icl)
317   enddo
318#endif
319 endif
320
321! Modis simulator
322 if (cfg%Lmodis_sim) then
323
324  do ip=1,Npoints
325    if(modis%Cloud_Fraction_Low_Mean(ip).eq.R_UNDEF)then
326      modis%Cloud_Fraction_Low_Mean(ip)=missing_val
327    endif
328    if(modis%Cloud_Fraction_High_Mean(ip).eq.R_UNDEF)then
329       modis%Cloud_Fraction_High_Mean(ip)=missing_val
330    endif
331    if(modis%Cloud_Fraction_Mid_Mean(ip).eq.R_UNDEF)then
332       modis%Cloud_Fraction_Mid_Mean(ip)=missing_val
333    endif
334    if(modis%Cloud_Fraction_Total_Mean(ip).eq.R_UNDEF)then
335       modis%Cloud_Fraction_Total_Mean(ip)=missing_val
336    endif
337    if(modis%Cloud_Fraction_Water_Mean(ip).eq.R_UNDEF)then
338       modis%Cloud_Fraction_Water_Mean(ip)=missing_val
339    endif
340    if(modis%Cloud_Fraction_Ice_Mean(ip).eq.R_UNDEF)then
341       modis%Cloud_Fraction_Ice_Mean(ip)=missing_val
342    endif
343    if(modis%Optical_Thickness_Total_Mean(ip).eq.R_UNDEF)then
344       modis%Optical_Thickness_Total_Mean(ip)=missing_val
345    endif
346    if(modis%Optical_Thickness_Water_Mean(ip).eq.R_UNDEF)then
347       modis%Optical_Thickness_Water_Mean(ip)=missing_val
348    endif
349    if(modis%Optical_Thickness_Ice_Mean(ip).eq.R_UNDEF)then
350       modis%Optical_Thickness_Ice_Mean(ip)=missing_val
351    endif
352    if(modis%Cloud_Particle_Size_Water_Mean(ip).eq.R_UNDEF)then
353       modis%Cloud_Particle_Size_Water_Mean(ip)=missing_val
354    endif
355    if(modis%Cloud_Particle_Size_Ice_Mean(ip).eq.R_UNDEF)then
356       modis%Cloud_Particle_Size_Ice_Mean(ip)=missing_val
357    endif
358    if(modis%Cloud_Top_Pressure_Total_Mean(ip).eq.R_UNDEF)then
359       modis%Cloud_Top_Pressure_Total_Mean(ip)=missing_val
360    endif
361    if(modis%Liquid_Water_Path_Mean(ip).eq.R_UNDEF)then
362       modis%Liquid_Water_Path_Mean(ip)=missing_val
363    endif
364    if(modis%Ice_Water_Path_Mean(ip).eq.R_UNDEF)then
365       modis%Ice_Water_Path_Mean(ip)=missing_val
366    endif
367
368  enddo
369
370    where(modis%Optical_Thickness_Total_LogMean == R_UNDEF) &
371          modis%Optical_Thickness_Total_LogMean = missing_val
372           
373 
374    where(modis%Optical_Thickness_Water_LogMean == R_UNDEF) &
375          modis%Optical_Thickness_Water_LogMean = missing_val
376
377    where(modis%Optical_Thickness_Ice_LogMean == R_UNDEF) &
378          modis%Optical_Thickness_Ice_LogMean = missing_val
379   
380   CALL histwrite2d_cosp(o_cllmodis,modis%Cloud_Fraction_Low_Mean)
381   CALL histwrite2d_cosp(o_clhmodis,modis%Cloud_Fraction_High_Mean)
382   CALL histwrite2d_cosp(o_clmmodis,modis%Cloud_Fraction_Mid_Mean)
383   CALL histwrite2d_cosp(o_cltmodis,modis%Cloud_Fraction_Total_Mean)
384   CALL histwrite2d_cosp(o_clwmodis,modis%Cloud_Fraction_Water_Mean)
385   CALL histwrite2d_cosp(o_climodis,modis%Cloud_Fraction_Ice_Mean)
386   CALL histwrite2d_cosp(o_tautmodis,modis%Optical_Thickness_Total_Mean)
387   CALL histwrite2d_cosp(o_tauwmodis,modis%Optical_Thickness_Water_Mean)
388   CALL histwrite2d_cosp(o_tauimodis,modis%Optical_Thickness_Ice_Mean)
389   CALL histwrite2d_cosp(o_tautlogmodis,modis%Optical_Thickness_Total_LogMean) 
390   CALL histwrite2d_cosp(o_tauwlogmodis,modis%Optical_Thickness_Water_LogMean)
391   CALL histwrite2d_cosp(o_tauilogmodis,modis%Optical_Thickness_Ice_LogMean)
392   CALL histwrite2d_cosp(o_reffclwmodis,modis%Cloud_Particle_Size_Water_Mean)
393   CALL histwrite2d_cosp(o_reffclimodis,modis%Cloud_Particle_Size_Ice_Mean)
394   CALL histwrite2d_cosp(o_pctmodis,modis%Cloud_Top_Pressure_Total_Mean)
395   CALL histwrite2d_cosp(o_lwpmodis,modis%Liquid_Water_Path_Mean)
396   CALL histwrite2d_cosp(o_iwpmodis,modis%Ice_Water_Path_Mean)
397
398   do ip=1,Npoints
399     do ii=1,7
400       do k=1,7
401       if(modis%Optical_Thickness_vs_Cloud_Top_Pressure(ip,ii,k).eq.R_UNDEF)then
402          modis%Optical_Thickness_vs_Cloud_Top_Pressure(ip,ii,k)=missing_val
403        endif
404       enddo
405     enddo
406    enddo
407
408#ifdef CPP_XIOS
409   CALL histwrite4d_cosp(o_clmodis,modis%Optical_Thickness_vs_Cloud_Top_Pressure)
410#else
411   do icl=1,7
412   CALL histwrite3d_cosp(o_clmodis, &
413     modis%Optical_Thickness_vs_Cloud_Top_Pressure(:,icl,:),nvertisccp,icl)           
414   enddo
415#endif
416
417    where(modis%Optical_Thickness_vs_ReffIce == R_UNDEF) &
418          modis%Optical_Thickness_vs_ReffIce = missing_val
419
420    where(modis%Optical_Thickness_vs_ReffLiq == R_UNDEF) &
421          modis%Optical_Thickness_vs_ReffLiq = missing_val
422
423#ifdef CPP_XIOS
424!    print*,'dimension de crimodis=',size(modis%Optical_Thickness_vs_ReffIce,2),&
425!                                    size(modis%Optical_Thickness_vs_ReffIce,3)
426    CALL histwrite4d_cosp(o_crimodis,modis%Optical_Thickness_vs_ReffIce)
427    CALL histwrite4d_cosp(o_crlmodis,modis%Optical_Thickness_vs_ReffLiq)
428#else
429    do icl=1,7
430   CALL histwrite3d_cosp(o_crimodis, &
431     modis%Optical_Thickness_vs_ReffIce(:,icl,:),nvertReffIce,icl)
432   CALL histwrite3d_cosp(o_crlmodis, &
433     modis%Optical_Thickness_vs_ReffLiq(:,icl,:),nvertReffLiq,icl)
434    enddo
435#endif
436 endif
437
438 IF(.NOT.cosp_varsdefined) THEN
439!$OMP MASTER
440#ifndef CPP_IOIPSL_NO_OUTPUT
441            DO iff=1,3
442                IF (cosp_outfilekeys(iff)) THEN
443                  CALL histend(cosp_nidfiles(iff))
444                ENDIF ! cosp_outfilekeys
445            ENDDO !  iff
446#endif
447! Fermeture dans phys_output_write
448!#ifdef CPP_XIOS
449            !On finalise l'initialisation:
450            !CALL wxios_closedef()
451!#endif
452
453!$OMP END MASTER
454!$OMP BARRIER
455            cosp_varsdefined = .TRUE.
456 END IF
457
458    IF(cosp_varsdefined) THEN
459! On synchronise les fichiers pour IOIPSL
460#ifndef CPP_IOIPSL_NO_OUTPUT
461!$OMP MASTER
462     DO iff=1,3
463         IF (ok_sync .AND. cosp_outfilekeys(iff)) THEN
464             CALL histsync(cosp_nidfiles(iff))
465         ENDIF
466     END DO
467!$OMP END MASTER
468#endif
469    ENDIF  !cosp_varsdefined
470
471    END SUBROUTINE cosp_output_write
472
473! ug Routine pour definir itau_iocosp depuis cosp_output_write_mod:
474  SUBROUTINE set_itau_iocosp(ito)
475      IMPLICIT NONE
476      INTEGER, INTENT(IN) :: ito
477      itau_iocosp = ito
478  END SUBROUTINE
479
480  SUBROUTINE histdef2d_cosp (iff,var)
481
482    USE ioipsl
483    USE dimphy
484    use iophy
485    USE mod_phys_lmdz_para
486    USE mod_grid_phy_lmdz, ONLY: nbp_lon
487    USE print_control_mod, ONLY: lunout,prt_level
488#ifdef CPP_XIOS
489  USE wxios
490#endif
491
492    IMPLICIT NONE
493
494    INCLUDE "clesphys.h"
495
496    INTEGER                          :: iff
497    TYPE(ctrl_outcosp)               :: var
498
499    REAL zstophym
500    CHARACTER(LEN=20) :: typeecrit
501
502    ! ug On récupère le type écrit de la structure:
503    !       Assez moche, Ã|  refaire si meilleure méthode...
504    IF (INDEX(var%cosp_typeecrit(iff), "once") > 0) THEN
505       typeecrit = 'once'
506    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_min") > 0) THEN
507       typeecrit = 't_min(X)'
508    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_max") > 0) THEN
509       typeecrit = 't_max(X)'
510    ELSE IF(INDEX(var%cosp_typeecrit(iff), "inst") > 0) THEN
511       typeecrit = 'inst(X)'
512    ELSE
513       typeecrit = cosp_outfiletypes(iff)
514    ENDIF
515
516    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
517       zstophym=zoutm_cosp(iff)
518    ELSE
519       zstophym=zdtimemoy_cosp
520    ENDIF
521
522#ifdef CPP_XIOS
523     IF (.not. ok_all_xml) then
524       IF ( var%cles(iff) ) THEN
525         if (prt_level >= 10) then
526              WRITE(lunout,*)'Appel wxios_add_field_to_file var%name =',var%name
527         endif
528        CALL wxios_add_field_to_file(var%name, 2, cosp_nidfiles(iff), cosp_outfilenames(iff), &
529                                     var%description, var%unit, 1, typeecrit)
530       ENDIF
531     ENDIF
532#endif
533
534#ifndef CPP_IOIPSL_NO_OUTPUT
535       IF ( var%cles(iff) ) THEN
536          CALL histdef (cosp_nidfiles(iff), var%name, var%description, var%unit, &
537               nbp_lon,jj_nb,nhoricosp(iff), 1,1,1, -99, 32, &
538               typeecrit, zstophym,zoutm_cosp(iff))
539       ENDIF
540#endif
541
542  END SUBROUTINE histdef2d_cosp
543
544 SUBROUTINE histdef3d_cosp (iff,var,nvertsave,ncols)
545    USE ioipsl
546    USE dimphy
547    use iophy
548    USE mod_phys_lmdz_para
549    USE mod_grid_phy_lmdz, ONLY: nbp_lon
550    USE print_control_mod, ONLY: lunout,prt_level
551
552#ifdef CPP_XIOS
553  USE wxios
554#endif
555
556
557    IMPLICIT NONE
558
559    INCLUDE "clesphys.h"
560
561    INTEGER                        :: iff, klevs
562    INTEGER, INTENT(IN), OPTIONAL  :: ncols ! ug RUSTINE POUR LES variables 4D
563    INTEGER, INTENT(IN)           :: nvertsave
564    TYPE(ctrl_outcosp)             :: var
565
566    REAL zstophym
567    CHARACTER(LEN=20) :: typeecrit, nomi
568    CHARACTER(LEN=20) :: nom
569    character(len=2) :: str2
570    CHARACTER(len=20) :: nam_axvert
571
572! Axe vertical
573      IF (nvertsave.eq.nvertp(iff)) THEN
574          klevs=PARASOL_NREFL
575          nam_axvert="sza"
576      ELSE IF (nvertsave.eq.nvertisccp(iff)) THEN
577          klevs=7
578          nam_axvert="pressure2"
579      ELSE IF (nvertsave.eq.nvertcol(iff)) THEN
580          klevs=Ncolout
581          nam_axvert="column"
582      ELSE IF (nvertsave.eq.nverttemp(iff)) THEN
583          klevs=LIDAR_NTEMP
584          nam_axvert="temp"
585      ELSE IF (nvertsave.eq.nvertmisr(iff)) THEN
586          klevs=MISR_N_CTH
587          nam_axvert="cth16"
588      ELSE IF (nvertsave.eq.nvertReffIce(iff)) THEN
589          klevs= numMODISReffIceBins
590          nam_axvert="ReffIce"
591      ELSE IF (nvertsave.eq.nvertReffLiq(iff)) THEN
592          klevs= numMODISReffLiqBins
593          nam_axvert="ReffLiq"
594      ELSE
595           klevs=Nlevout
596           nam_axvert="presnivs"
597      ENDIF
598
599! ug RUSTINE POUR LES Champs 4D
600      IF (PRESENT(ncols)) THEN
601               write(str2,'(i2.2)')ncols
602               nomi=var%name
603               nom="c"//str2//"_"//nomi
604      ELSE
605               nom=var%name
606      END IF
607
608    ! ug On récupère le type écrit de la structure:
609    !       Assez moche, Ã|  refaire si meilleure méthode...
610    IF (INDEX(var%cosp_typeecrit(iff), "once") > 0) THEN
611       typeecrit = 'once'
612    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_min") > 0) THEN
613       typeecrit = 't_min(X)'
614    ELSE IF(INDEX(var%cosp_typeecrit(iff), "t_max") > 0) THEN
615       typeecrit = 't_max(X)'
616    ELSE IF(INDEX(var%cosp_typeecrit(iff), "inst") > 0) THEN
617       typeecrit = 'inst(X)'
618    ELSE
619       typeecrit = cosp_outfiletypes(iff)
620    ENDIF
621
622    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
623       zstophym=zoutm_cosp(iff)
624    ELSE
625       zstophym=zdtimemoy_cosp
626    ENDIF
627
628#ifdef CPP_XIOS
629      IF (.not. ok_all_xml) then
630        IF ( var%cles(iff) ) THEN
631          if (prt_level >= 10) then
632              WRITE(lunout,*)'Appel wxios_add_field_to_file 3d nom variable nam_axvert = ',nom, nam_axvert
633          endif
634          CALL wxios_add_field_to_file(nom, 3, cosp_nidfiles(iff), cosp_outfilenames(iff), &
635                                       var%description, var%unit, 1, typeecrit, nam_axvert)
636        ENDIF
637      ENDIF
638#endif
639
640#ifndef CPP_IOIPSL_NO_OUTPUT
641       IF ( var%cles(iff) ) THEN
642          CALL histdef (cosp_nidfiles(iff), nom, var%description, var%unit, &
643               nbp_lon, jj_nb, nhoricosp(iff), klevs, 1, &
644               klevs, nvertsave, 32, typeecrit, &
645               zstophym, zoutm_cosp(iff))
646       ENDIF
647#endif
648
649  END SUBROUTINE histdef3d_cosp
650
651 SUBROUTINE histwrite2d_cosp(var,field)
652  USE dimphy
653  USE mod_phys_lmdz_para
654  USE ioipsl
655  use iophy
656  USE mod_grid_phy_lmdz, ONLY: nbp_lon
657  USE print_control_mod, ONLY: lunout,prt_level
658
659#ifdef CPP_XIOS
660  USE xios, only: xios_send_field
661#endif
662
663  IMPLICIT NONE
664  INCLUDE 'clesphys.h'
665
666    TYPE(ctrl_outcosp), INTENT(IN) :: var
667    REAL, DIMENSION(:), INTENT(IN) :: field
668
669    INTEGER :: iff
670
671    REAL,DIMENSION(klon_mpi) :: buffer_omp
672    INTEGER, allocatable, DIMENSION(:) :: index2d
673    REAL :: Field2d(nbp_lon,jj_nb)
674    CHARACTER(LEN=20) ::  nomi, nom
675    character(len=2) :: str2
676    LOGICAL, SAVE  :: firstx
677!$OMP THREADPRIVATE(firstx)
678
679    IF (prt_level >= 9) WRITE(lunout,*)'Begin histrwrite2d ',var%name
680
681  ! On regarde si on est dans la phase de définition ou d'écriture:
682  IF(.NOT.cosp_varsdefined) THEN
683!$OMP MASTER
684      !Si phase de définition.... on définit
685      CALL conf_cospoutputs(var%name,var%cles)
686      DO iff=1, 3
687         IF (cosp_outfilekeys(iff)) THEN
688            CALL histdef2d_cosp(iff, var)
689         ENDIF
690      ENDDO
691!$OMP END MASTER
692  ELSE
693    !Et sinon on.... écrit
694    IF (SIZE(field)/=klon) &
695  CALL abort_physic('iophy::histwrite2d_cosp','Field first DIMENSION not equal to klon',1)
696
697    CALL Gather_omp(field,buffer_omp)
698!$OMP MASTER
699    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
700
701! La boucle sur les fichiers:
702      firstx=.true.
703      DO iff=1, 3
704           IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
705                ALLOCATE(index2d(nbp_lon*jj_nb))
706#ifndef CPP_IOIPSL_NO_OUTPUT
707        CALL histwrite(cosp_nidfiles(iff),var%name,itau_iocosp,Field2d,nbp_lon*jj_nb,index2d)
708#endif
709                deallocate(index2d)
710#ifdef CPP_XIOS
711              IF (.not. ok_all_xml) then
712                 if (firstx) then
713                  if (prt_level >= 10) then
714                    WRITE(lunout,*)'xios_send_field variable ',var%name
715                  endif
716                  CALL xios_send_field(var%name, Field2d)
717                   firstx=.false.
718                 endif
719              ENDIF
720#endif
721           ENDIF
722      ENDDO
723
724#ifdef CPP_XIOS
725      IF (ok_all_xml) THEN
726        if (prt_level >= 1) then
727              WRITE(lunout,*)'xios_send_field variable ',var%name
728        endif
729       CALL xios_send_field(var%name, Field2d)
730      ENDIF
731#endif
732
733!$OMP END MASTER   
734  ENDIF ! vars_defined
735  IF (prt_level >= 9) WRITE(lunout,*)'End histrwrite2d_cosp ',var%name
736  END SUBROUTINE histwrite2d_cosp
737
738! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
739! AI sept 2013
740  SUBROUTINE histwrite3d_cosp(var, field, nverts, ncols)
741  USE dimphy
742  USE mod_phys_lmdz_para
743  USE ioipsl
744  use iophy
745  USE mod_grid_phy_lmdz, ONLY: nbp_lon
746  USE print_control_mod, ONLY: lunout,prt_level
747
748#ifdef CPP_XIOS
749  USE xios, only: xios_send_field
750#endif
751
752
753  IMPLICIT NONE
754  INCLUDE 'clesphys.h'
755
756    TYPE(ctrl_outcosp), INTENT(IN)    :: var
757    REAL, DIMENSION(:,:), INTENT(IN)  :: field ! --> field(klon,:)
758    INTEGER, INTENT(IN), OPTIONAL     :: ncols ! ug RUSTINE POUR LES Champs 4D.....
759    INTEGER, DIMENSION(3), INTENT(IN) :: nverts
760
761    INTEGER :: iff, k
762
763    REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
764    REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
765    INTEGER :: ip, n, nlev
766    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
767    CHARACTER(LEN=20) ::  nomi, nom
768    character(len=2) :: str2
769    LOGICAL, SAVE  :: firstx
770!$OMP THREADPRIVATE(firstx)
771
772  IF (prt_level >= 9) write(lunout,*)'Begin histrwrite3d ',var%name
773
774! ug RUSTINE POUR LES STD LEVS.....
775      IF (PRESENT(ncols)) THEN
776              write(str2,'(i2.2)')ncols
777              nomi=var%name
778              nom="c"//str2//"_"//nomi
779      ELSE
780               nom=var%name
781      END IF
782  ! On regarde si on est dans la phase de définition ou d'écriture:
783  IF(.NOT.cosp_varsdefined) THEN
784      !Si phase de définition.... on définit
785!$OMP MASTER
786      CALL conf_cospoutputs(var%name,var%cles)
787      DO iff=1, 3
788        IF (cosp_outfilekeys(iff)) THEN
789          CALL histdef3d_cosp(iff, var, nverts(iff), ncols)
790        ENDIF
791      ENDDO
792!$OMP END MASTER
793  ELSE
794    !Et sinon on.... écrit
795    IF (SIZE(field,1)/=klon) &
796   CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)                                 
797    nlev=SIZE(field,2)
798
799
800    CALL Gather_omp(field,buffer_omp)
801!$OMP MASTER
802    CALL grid1Dto2D_mpi(buffer_omp,field3d)
803
804! BOUCLE SUR LES FICHIERS
805     firstx=.true.
806     DO iff=1, 3
807        IF (var%cles(iff) .AND. cosp_outfilekeys(iff)) THEN
808           ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
809#ifndef CPP_IOIPSL_NO_OUTPUT
810    CALL histwrite(cosp_nidfiles(iff),nom,itau_iocosp,Field3d,nbp_lon*jj_nb*nlev,index3d)
811#endif
812
813#ifdef CPP_XIOS
814          IF (.not. ok_all_xml) then
815           IF (firstx) THEN
816               CALL xios_send_field(nom, Field3d(:,:,1:nlev))
817               IF (prt_level >= 9) WRITE(lunout,*)'xios_send_field ',var%name
818               firstx=.FALSE.
819           ENDIF
820          ENDIF
821#endif
822         deallocate(index3d)
823        ENDIF
824      ENDDO
825#ifdef CPP_XIOS
826    IF (ok_all_xml) THEN
827     CALL xios_send_field(nom, Field3d(:,:,1:nlev))
828     IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
829    ENDIF
830#endif
831
832!$OMP END MASTER   
833  ENDIF ! vars_defined
834  IF (prt_level >= 9) write(lunout,*)'End histrwrite3d_cosp ',nom
835  END SUBROUTINE histwrite3d_cosp
836
837! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
838! AI sept 2013
839  SUBROUTINE histwrite4d_cosp(var, field)
840  USE dimphy
841  USE mod_phys_lmdz_para
842  USE ioipsl
843  use iophy
844  USE mod_grid_phy_lmdz, ONLY: nbp_lon
845  USE print_control_mod, ONLY: lunout,prt_level
846
847#ifdef CPP_XIOS
848  USE xios, only: xios_send_field
849#endif
850
851
852  IMPLICIT NONE
853  INCLUDE 'clesphys.h'
854
855    TYPE(ctrl_outcosp), INTENT(IN)    :: var
856    REAL, DIMENSION(:,:,:), INTENT(IN)  :: field ! --> field(klon,:)
857
858    INTEGER :: iff, k
859
860    REAL,DIMENSION(klon_mpi,SIZE(field,2),SIZE(field,3)) :: buffer_omp
861    REAL :: field4d(nbp_lon,jj_nb,SIZE(field,2),SIZE(field,3))
862    INTEGER :: ip, n, nlev, nlev2
863    INTEGER, ALLOCATABLE, DIMENSION(:) :: index4d
864    CHARACTER(LEN=20) ::  nomi, nom
865
866  IF (prt_level >= 9) write(lunout,*)'Begin histrwrite4d ',var%name
867
868  IF(cosp_varsdefined) THEN
869    !Et sinon on.... écrit
870    IF (SIZE(field,1)/=klon) &
871   CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)           
872
873    nlev=SIZE(field,2)
874    nlev2=SIZE(field,3)
875    CALL Gather_omp(field,buffer_omp)
876!$OMP MASTER
877    CALL grid1Dto2D_mpi(buffer_omp,field4d)
878
879#ifdef CPP_XIOS
880    IF (ok_all_xml) THEN
881     CALL xios_send_field(var%name, Field4d(:,:,1:nlev,1:nlev2))
882     IF (prt_level >= 1) WRITE(lunout,*)'xios_send_field ',var%name
883    ENDIF
884#endif
885
886!$OMP END MASTER   
887  ENDIF ! vars_defined
888  IF (prt_level >= 9) write(lunout,*)'End histrwrite4d_cosp ',nom
889  END SUBROUTINE histwrite4d_cosp
890
891  SUBROUTINE conf_cospoutputs(nam_var,cles_var)
892!!! Lecture des noms et cles de sortie des variables dans config.def
893    !   en utilisant les routines getin de IOIPSL 
894    use ioipsl
895    USE print_control_mod, ONLY: lunout,prt_level
896
897    IMPLICIT NONE
898
899   CHARACTER(LEN=20)               :: nam_var, nnam_var
900   LOGICAL, DIMENSION(3)           :: cles_var
901
902! Lecture dans config.def ou output.def de cles_var et name_var
903    CALL getin('cles_'//nam_var,cles_var)
904    CALL getin('name_'//nam_var,nam_var)
905    IF(prt_level>10) WRITE(lunout,*)'nam_var cles_var ',nam_var,cles_var(:)
906
907  END SUBROUTINE conf_cospoutputs
908
909 END MODULE cosp_output_write_mod
Note: See TracBrowser for help on using the repository browser.