source: LMDZ6/branches/Amaury_dev/libf/phylmd/iophy.F90 @ 5133

Last change on this file since 5133 was 5123, checked in by abarral, 5 months ago

Correct various minor mistakes from previous commits

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 52.6 KB
Line 
1
2! $Id: iophy.F90 5123 2024-07-25 06:45:50Z abarral $
3
4MODULE iophy
5    USE lmdz_abort_physic, ONLY: abort_physic
6
7! abd  REAL,PRIVATE,ALLOCATABLE,DIMENSION(:),save :: io_lat
8! abd  REAL,PRIVATE,ALLOCATABLE,DIMENSION(:),save :: io_lon
9  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: io_lat
10  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: io_lon
11  INTEGER, SAVE :: phys_domain_id
12  INTEGER, SAVE :: npstn
13  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE :: nptabij
14  INTEGER, SAVE :: itau_iophy
15  LOGICAL :: check_dim = .FALSE.
16
17!$OMP THREADPRIVATE(itau_iophy)
18
19  INTERFACE histwrite_phy
20    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old,histwrite2d_xios,histwrite3d_xios,histwrite0d_xios
21  END INTERFACE
22
23  INTERFACE histbeg_phy_all
24    MODULE PROCEDURE histbeg_phy,histbeg_phyxios,histbeg_phy_points
25  END INTERFACE
26
27
28CONTAINS
29
30! ug Routine pour définir itau_iophy depuis phys_output_write_mod:
31  SUBROUTINE set_itau_iophy(ito)
32    IMPLICIT NONE
33    INTEGER, INTENT(IN) :: ito
34    itau_iophy = ito
35  END SUBROUTINE
36
37  SUBROUTINE init_iophy_new(rlat,rlon)
38
39    USE dimphy, ONLY: klon
40    USE lmdz_phys_para, ONLY: gather, bcast, &
41                                  jj_nb, jj_begin, jj_end, ii_begin, ii_end, &
42                                  mpi_size, mpi_rank, klon_mpi, &
43                                is_sequential, is_south_pole_dyn
44  USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat, klon_glo, grid_type, unstructured
45  USE lmdz_print_control, ONLY: prt_level,lunout
46    USE ioipsl, ONLY: flio_dom_set
47  USE lmdz_wxios, ONLY: wxios_domain_param, wxios_domain_param_unstructured, wxios_context_init, using_xios
48    IMPLICIT NONE
49    REAL,DIMENSION(klon),INTENT(IN) :: rlon
50    REAL,DIMENSION(klon),INTENT(IN) :: rlat
51
52    REAL,DIMENSION(klon_glo)        :: rlat_glo
53    REAL,DIMENSION(klon_glo)        :: rlon_glo
54   
55    INTEGER,DIMENSION(2) :: ddid
56    INTEGER,DIMENSION(2) :: dsg
57    INTEGER,DIMENSION(2) :: dsl
58    INTEGER,DIMENSION(2) :: dpf
59    INTEGER,DIMENSION(2) :: dpl
60    INTEGER,DIMENSION(2) :: dhs
61    INTEGER,DIMENSION(2) :: dhe
62    INTEGER :: i   
63    INTEGER :: data_ibegin, data_iend
64
65    IF (using_xios)  CALL wxios_context_init
66   
67
68    IF (grid_type==unstructured) THEN
69   
70      CALL wxios_domain_param_unstructured("dom_glo")
71
72    ELSE
73
74      CALL gather(rlat,rlat_glo)
75      CALL bcast(rlat_glo)
76      CALL gather(rlon,rlon_glo)
77      CALL bcast(rlon_glo)
78   
79!$OMP MASTER 
80    ALLOCATE(io_lat(nbp_lat))
81    IF (klon_glo == 1) THEN
82      io_lat(1)=rlat_glo(1)
83    ELSE
84      io_lat(1)=rlat_glo(1)
85      io_lat(nbp_lat)=rlat_glo(klon_glo)
86      DO i=2,nbp_lat-1
87        io_lat(i)=rlat_glo(2+(i-2)*nbp_lon)
88      ENDDO
89    ENDIF
90
91    ALLOCATE(io_lon(nbp_lon))
92    IF (klon_glo == 1) THEN
93      io_lon(1)=rlon_glo(1)
94    ELSE
95      io_lon(1:nbp_lon)=rlon_glo(2:nbp_lon+1)
96    ENDIF
97
98!! (I) dtnb   : total number of domains
99!! (I) dnb    : domain number
100!! (I) did(:) : distributed dimensions identifiers
101!!              (up to 5 dimensions are supported)
102!! (I) dsg(:) : total number of points for each dimension
103!! (I) dsl(:) : local number of points for each dimension
104!! (I) dpf(:) : position of first local point for each dimension
105!! (I) dpl(:) : position of last local point for each dimension
106!! (I) dhs(:) : start halo size for each dimension
107!! (I) dhe(:) : end halo size for each dimension
108!! (C) cdnm   : Model domain definition name.
109!!              The names actually supported are :
110!!              "BOX", "APPLE", "ORANGE".
111!!              These names are case insensitive.
112
113    ddid=(/ 1,2 /)
114    dsg=(/ nbp_lon, nbp_lat /)
115    dsl=(/ nbp_lon, jj_nb /)
116    dpf=(/ 1,jj_begin /)
117    dpl=(/ nbp_lon, jj_end /)
118    dhs=(/ ii_begin-1,0 /)
119    IF (mpi_rank==mpi_size-1) THEN
120      dhe=(/0,0/)
121    ELSE
122      dhe=(/ nbp_lon-ii_end,0 /) 
123    ENDIF
124
125#ifndef CPP_IOIPSL_NO_OUTPUT   
126    CALL flio_dom_set(mpi_size,mpi_rank,ddid,dsg,dsl,dpf,dpl,dhs,dhe, &
127                      'APPLE',phys_domain_id)
128#endif
129    IF (using_xios) THEN 
130      ! Set values for the mask:
131      IF (mpi_rank == 0) THEN
132          data_ibegin = 0
133      ELSE
134          data_ibegin = ii_begin - 1
135      END IF
136
137      IF (mpi_rank == mpi_size-1) THEN
138          data_iend = nbp_lon
139      ELSE
140          data_iend = ii_end + 1
141      END IF
142
143      IF (prt_level>=10) THEN
144        WRITE(lunout,*) "init_iophy_new: mpirank=",mpi_rank," iibegin=",ii_begin , " ii_end=",ii_end," jjbegin=",jj_begin," jj_nb=",jj_nb," jj_end=",jj_end
145        WRITE(lunout,*) "init_iophy_new: mpirank=",mpi_rank," nbp_lon=",nbp_lon," nbp_lat=",nbp_lat
146        WRITE(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
147        WRITE(lunout,*) "init_iophy_new: mpirank=",mpi_rank," data_ibegin=",data_ibegin," data_iend=",data_iend
148        WRITE(lunout,*) "init_iophy_new: mpirank=",mpi_rank," is_south_pole_dyn=",is_south_pole_dyn
149      ENDIF
150
151      ! Initialize the XIOS domain coreesponding to this process:
152    ENDIF
153!$OMP END MASTER
154
155      IF (using_xios) CALL wxios_domain_param("dom_glo")
156     
157    ENDIF
158     
159  END SUBROUTINE init_iophy_new
160
161
162  SUBROUTINE init_iophy(lat,lon)
163
164    USE lmdz_phys_para, ONLY: jj_begin, jj_end, ii_begin, ii_end, jj_nb, &
165                                  mpi_size, mpi_rank
166    USE ioipsl, ONLY: flio_dom_set
167    USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat
168
169    IMPLICIT NONE
170
171    REAL,DIMENSION(nbp_lon),INTENT(IN) :: lon
172    REAL,DIMENSION(nbp_lat),INTENT(IN) :: lat
173
174    INTEGER,DIMENSION(2) :: ddid
175    INTEGER,DIMENSION(2) :: dsg
176    INTEGER,DIMENSION(2) :: dsl
177    INTEGER,DIMENSION(2) :: dpf
178    INTEGER,DIMENSION(2) :: dpl
179    INTEGER,DIMENSION(2) :: dhs
180    INTEGER,DIMENSION(2) :: dhe
181
182!$OMP MASTER 
183    ALLOCATE(io_lat(nbp_lat))
184    io_lat(:)=lat(:)
185    ALLOCATE(io_lon(nbp_lon))
186    io_lon(:)=lon(:)
187   
188    ddid=(/ 1,2 /)
189    dsg=(/ nbp_lon, nbp_lat /)
190    dsl=(/ nbp_lon, jj_nb /)
191    dpf=(/ 1,jj_begin /)
192    dpl=(/ nbp_lon, jj_end /)
193    dhs=(/ ii_begin-1,0 /)
194    IF (mpi_rank==mpi_size-1) THEN
195      dhe=(/0,0/)
196    ELSE
197      dhe=(/ nbp_lon-ii_end,0 /) 
198    ENDIF
199   
200#ifndef CPP_IOIPSL_NO_OUTPUT
201    CALL flio_dom_set(mpi_size,mpi_rank,ddid,dsg,dsl,dpf,dpl,dhs,dhe, &
202                      'APPLE',phys_domain_id)
203#endif
204!$OMP END MASTER
205     
206  END SUBROUTINE init_iophy
207
208 SUBROUTINE histbeg_phyxios(name,itau0,zjulian,dtime,ffreq,lev,nhori,nid_day)
209!  USE dimphy
210  USE lmdz_phys_para, ONLY: is_sequential, is_using_mpi, is_mpi_root, &
211                                jj_begin, jj_end, jj_nb
212  USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat
213  USE ioipsl, ONLY: histbeg
214  USE lmdz_wxios, ONLY: wxios_add_file, using_xios
215  IMPLICIT NONE
216  INCLUDE 'clesphys.h'
217   
218  CHARACTER*(*), INTENT(IN) :: name
219  INTEGER, INTENT(IN) :: itau0
220  REAL,INTENT(IN) :: zjulian
221  REAL,INTENT(IN) :: dtime
222  CHARACTER(LEN=*), INTENT(IN) :: ffreq
223  INTEGER,INTENT(IN) :: lev
224  INTEGER,INTENT(OUT) :: nhori
225  INTEGER,INTENT(OUT) :: nid_day
226
227!$OMP MASTER   
228  IF (is_sequential) THEN
229    CALL histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
230                 1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
231  ELSE
232    CALL histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
233                 1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
234  ENDIF
235
236  IF (using_xios) THEN 
237    ! ug OMP en chantier...
238    IF((.NOT. is_using_mpi) .OR. is_mpi_root) THEN
239        ! ug Création du fichier
240      IF (.NOT. ok_all_xml) THEN
241        CALL wxios_add_file(name, ffreq, lev)
242      ENDIF
243    ENDIF
244  ENDIF
245!$OMP END MASTER
246 
247  END SUBROUTINE histbeg_phyxios
248 
249  SUBROUTINE histbeg_phy(name,itau0,zjulian,dtime,nhori,nid_day)
250
251  USE lmdz_phys_para, ONLY: jj_begin, jj_end, jj_nb, is_sequential
252  USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat
253  USE ioipsl, ONLY: histbeg
254
255  IMPLICIT NONE
256   
257    CHARACTER*(*), INTENT(IN) :: name
258    INTEGER, INTENT(IN) :: itau0
259    REAL,INTENT(IN) :: zjulian
260    REAL,INTENT(IN) :: dtime
261    INTEGER,INTENT(OUT) :: nhori
262    INTEGER,INTENT(OUT) :: nid_day
263
264!$OMP MASTER   
265#ifndef CPP_IOIPSL_NO_OUTPUT
266    IF (is_sequential) THEN
267      CALL histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
268                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day)
269    ELSE
270      CALL histbeg(name,nbp_lon,io_lon, jj_nb,io_lat(jj_begin:jj_end), &
271                   1,nbp_lon,1,jj_nb,itau0, zjulian, dtime, nhori, nid_day,phys_domain_id)
272    ENDIF
273#endif
274!$OMP END MASTER
275 
276  END SUBROUTINE histbeg_phy
277
278
279  SUBROUTINE histbeg_phy_points(rlon,rlat,pim,tabij,ipt,jpt, &
280             plon,plat,plon_bounds,plat_bounds, &
281             nname,itau0,zjulian,dtime,nnhori,nnid_day)
282  USE dimphy, ONLY: klon
283  USE lmdz_phys_para, ONLY: gather, bcast, &
284                                is_sequential, klon_mpi_begin, klon_mpi_end, &
285                                mpi_rank
286  USE lmdz_grid_phy, ONLY: klon_glo, nbp_lon, nbp_lat, grid1dTo2d_glo
287  USE ioipsl, ONLY: histbeg
288
289  IMPLICIT NONE
290
291    REAL,DIMENSION(klon),INTENT(IN) :: rlon
292    REAL,DIMENSION(klon),INTENT(IN) :: rlat
293    INTEGER, INTENT(IN) :: itau0
294    REAL,INTENT(IN) :: zjulian
295    REAL,INTENT(IN) :: dtime
296    INTEGER, INTENT(IN) :: pim
297    INTEGER, INTENT(OUT) :: nnhori
298    CHARACTER(len=20), INTENT(IN) :: nname
299    INTEGER, INTENT(OUT) :: nnid_day
300    INTEGER :: i
301    REAL,DIMENSION(klon_glo)        :: rlat_glo
302    REAL,DIMENSION(klon_glo)        :: rlon_glo
303    INTEGER, DIMENSION(pim), INTENT(IN)  :: tabij
304    REAL,DIMENSION(pim), INTENT(IN) :: plat, plon
305    INTEGER,DIMENSION(pim), INTENT(IN) :: ipt, jpt
306    REAL,DIMENSION(pim,2), INTENT(OUT) :: plat_bounds, plon_bounds
307
308    INTEGER, SAVE :: tabprocbeg, tabprocend
309!$OMP THREADPRIVATE(tabprocbeg, tabprocend)
310    INTEGER :: ip
311    INTEGER, PARAMETER :: nip=1
312    INTEGER :: npproc
313    REAL, ALLOCATABLE, DIMENSION(:) :: npplat, npplon
314    REAL, ALLOCATABLE, DIMENSION(:,:) :: npplat_bounds, npplon_bounds
315    REAL, DIMENSION(nbp_lon,nbp_lat) :: zx_lon, zx_lat
316
317    CALL gather(rlat,rlat_glo)
318    CALL bcast(rlat_glo)
319    CALL gather(rlon,rlon_glo)
320    CALL bcast(rlon_glo)
321
322!$OMP MASTER
323    DO i=1,pim
324
325!    PRINT*,'CFMIP_iophy i tabij lon lat',i,tabij(i),plon(i),plat(i)
326
327     plon_bounds(i,1)=rlon_glo(tabij(i)-1)
328     plon_bounds(i,2)=rlon_glo(tabij(i)+1)
329     IF (plon_bounds(i,2)<=0..AND.plon_bounds(i,1)>=0.) THEN
330      IF (rlon_glo(tabij(i))>=0.) THEN
331       plon_bounds(i,2)=-1*plon_bounds(i,2)
332      ENDIF
333     ENDIF
334     IF (plon_bounds(i,2)>=0..AND.plon_bounds(i,1)<=0.) THEN
335      IF (rlon_glo(tabij(i))<=0.) THEN
336       plon_bounds(i,2)=-1*plon_bounds(i,2)
337      ENDIF
338     ENDIF
339
340     IF ( tabij(i)<=nbp_lon) THEN
341      plat_bounds(i,1)=rlat_glo(tabij(i))
342     ELSE
343      plat_bounds(i,1)=rlat_glo(tabij(i)-nbp_lon)
344     ENDIF
345     plat_bounds(i,2)=rlat_glo(tabij(i)+nbp_lon)
346
347!    PRINT*,'CFMIP_iophy point i lon lon_bds',i,plon_bounds(i,1),rlon_glo(tabij(i)),plon_bounds(i,2)
348!    PRINT*,'CFMIP_iophy point i lat lat_bds',i,plat_bounds(i,1),rlat_glo(tabij(i)),plat_bounds(i,2)
349
350    ENDDO
351    IF (is_sequential) THEN
352     npstn=pim
353     IF(.NOT. ALLOCATED(nptabij)) THEN
354      ALLOCATE(nptabij(pim))
355     ENDIF
356     DO i=1,pim
357      nptabij(i)=tabij(i)
358     ENDDO
359
360       CALL grid1dTo2d_glo(rlon_glo,zx_lon)
361       IF ((nbp_lon*nbp_lat)>1) THEN
362       DO i = 1, nbp_lon
363         zx_lon(i,1) = rlon_glo(i+1)
364         zx_lon(i,nbp_lat) = rlon_glo(i+1)
365       ENDDO
366       ENDIF
367       CALL grid1dTo2d_glo(rlat_glo,zx_lat)
368
369    DO i=1,pim
370!    PRINT*,'CFMIP_iophy i tabij lon lat',i,tabij(i),plon(i),plat(i)
371
372     plon_bounds(i,1)=zx_lon(ipt(i)-1,jpt(i))
373     plon_bounds(i,2)=zx_lon(ipt(i)+1,jpt(i))
374
375     IF (ipt(i)==1) THEN
376      plon_bounds(i,1)=zx_lon(nbp_lon,jpt(i))
377      plon_bounds(i,2)=360.+zx_lon(ipt(i)+1,jpt(i))
378     ENDIF
379 
380     IF (ipt(i)==nbp_lon) THEN
381      plon_bounds(i,2)=360.+zx_lon(1,jpt(i))
382     ENDIF
383
384     plat_bounds(i,1)=zx_lat(ipt(i),jpt(i)-1)
385     plat_bounds(i,2)=zx_lat(ipt(i),jpt(i)+1)
386
387     IF (jpt(i)==1) THEN
388      plat_bounds(i,1)=zx_lat(ipt(i),1)+0.001
389      plat_bounds(i,2)=zx_lat(ipt(i),1)-0.001
390     ENDIF
391 
392     IF (jpt(i)==nbp_lat) THEN
393      plat_bounds(i,1)=zx_lat(ipt(i),nbp_lat)+0.001
394      plat_bounds(i,2)=zx_lat(ipt(i),nbp_lat)-0.001
395     ENDIF
396
397!    PRINT*,'CFMIP_iophy point i lon lon_bds',i,plon_bounds(i,1),rlon(tabij(i)),plon_bounds(i,2)
398!    PRINT*,'CFMIP_iophy point i lat lat_bds',i,plat_bounds(i,1),rlat(tabij(i)),plat_bounds(i,2)
399
400    ENDDO
401
402#ifndef CPP_IOIPSL_NO_OUTPUT
403     CALL histbeg(nname,pim,plon,plon_bounds, &
404                           plat,plat_bounds, &
405                           itau0, zjulian, dtime, nnhori, nnid_day)
406#endif
407    ELSE
408     npproc=0
409     DO ip=1, pim
410      tabprocbeg=klon_mpi_begin
411      tabprocend=klon_mpi_end
412      IF(tabij(ip)>=tabprocbeg.AND.tabij(ip)<=tabprocend) THEN
413       npproc=npproc+1
414       npstn=npproc
415      ENDIF
416     ENDDO
417!    PRINT*,'CFMIP_iophy mpi_rank npstn',mpi_rank,npstn
418     IF(.NOT. ALLOCATED(nptabij)) THEN
419      ALLOCATE(nptabij(npstn))
420      ALLOCATE(npplon(npstn), npplat(npstn))
421      ALLOCATE(npplon_bounds(npstn,2), npplat_bounds(npstn,2))
422     ENDIF
423     npproc=0
424     DO ip=1, pim
425      IF(tabij(ip)>=tabprocbeg.AND.tabij(ip)<=tabprocend) THEN
426       npproc=npproc+1
427       nptabij(npproc)=tabij(ip)
428!      PRINT*,'mpi_rank npproc ip plon plat tabij=',mpi_rank,npproc,ip, &
429!      plon(ip),plat(ip),tabij(ip)
430       npplon(npproc)=plon(ip)
431       npplat(npproc)=plat(ip)
432       npplon_bounds(npproc,1)=plon_bounds(ip,1)
433       npplon_bounds(npproc,2)=plon_bounds(ip,2)
434       npplat_bounds(npproc,1)=plat_bounds(ip,1)
435       npplat_bounds(npproc,2)=plat_bounds(ip,2)
436!!!
437!!! print qui sert a reordonner les points stations selon l'ordre CFMIP
438!!! ne pas enlever
439        PRINT*,'iophy_mpi rank ip lon lat',mpi_rank,ip,plon(ip),plat(ip)
440!!!
441      ENDIF
442     ENDDO
443#ifndef CPP_IOIPSL_NO_OUTPUT
444     CALL histbeg(nname,npstn,npplon,npplon_bounds, &
445                            npplat,npplat_bounds, &
446                            itau0,zjulian,dtime,nnhori,nnid_day,phys_domain_id)
447#endif
448    ENDIF
449!$OMP END MASTER
450
451  END SUBROUTINE histbeg_phy_points
452
453
454  SUBROUTINE histdef2d_old(iff,lpoint,flag_var,nomvar,titrevar,unitvar)
455
456    USE ioipsl, ONLY: histdef
457    USE lmdz_phys_para, ONLY: jj_nb, is_master
458    USE phys_output_var_mod, ONLY: type_ecri, zoutm, zdtime_moy, lev_files, &
459                                   nid_files, nhorim, swaero_diag, dryaod_diag, nfiles, &
460                                   ok_4xCO2atm
461    USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat
462    USE aero_mod, ONLY: naero_tot, name_aero_tau
463    USE lmdz_print_control, ONLY: prt_level,lunout
464
465    IMPLICIT NONE
466
467    INCLUDE "clesphys.h"
468
469    INTEGER                          :: iff
470    INTEGER                          :: naero
471    LOGICAL                          :: lpoint
472    INTEGER, DIMENSION(nfiles)       :: flag_var
473    CHARACTER(LEN=20)                :: nomvar
474    CHARACTER(LEN=*)                 :: titrevar
475    CHARACTER(LEN=*)                 :: unitvar
476
477    REAL zstophym
478
479    IF (type_ecri(iff)=='inst(X)'.OR.type_ecri(iff)=='once') THEN
480       zstophym=zoutm(iff)
481    ELSE
482       zstophym=zdtime_moy
483    ENDIF
484    IF (check_dim .AND. is_master) WRITE(lunout,*)'histdef2d_old for ', nomvar
485    ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
486    CALL conf_physoutputs(nomvar,flag_var)
487
488    IF(.NOT.lpoint) THEN 
489       IF ( flag_var(iff)<=lev_files(iff) ) THEN
490          CALL histdef (nid_files(iff),nomvar,titrevar,unitvar, &
491               nbp_lon,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
492               type_ecri(iff), zstophym,zoutm(iff))               
493       ENDIF
494    ELSE
495       IF ( flag_var(iff)<=lev_files(iff) ) THEN
496          CALL histdef (nid_files(iff),nomvar,titrevar,unitvar, &
497               npstn,1,nhorim(iff), 1,1,1, -99, 32, &
498               type_ecri(iff), zstophym,zoutm(iff))               
499       ENDIF
500    ENDIF
501
502    ! Set swaero_diag=true if at least one of the concerned variables are defined
503    IF (nomvar=='topswad' .OR. nomvar=='topswad0' .OR. nomvar=='solswad' .OR. nomvar=='solswad0' .OR. &
504        nomvar=='toplwad' .OR. nomvar=='toplwad0' .OR. nomvar=='sollwad' .OR. nomvar=='sollwad0' .OR. &
505        nomvar=='topswai' .OR. nomvar=='solswai' ) THEN
506       IF  ( flag_var(iff)<=lev_files(iff) ) swaero_diag=.TRUE.
507    ENDIF
508
509    ! Set dryaod_diag=true if at least one of the concerned variables are defined
510    IF (nomvar=='dryod550aer') THEN
511      IF  ( flag_var(iff)<=lev_files(iff) ) dryaod_diag=.TRUE.
512    ENDIF
513    DO naero = 1, naero_tot-1
514      IF (nomvar=='dryod550_'//name_aero_tau(naero)) THEN
515        IF  ( flag_var(iff)<=lev_files(iff) ) dryaod_diag=.TRUE.
516      ENDIF
517    ENDDO
518
519    ! Set ok_4xCO2atm=true if at least one of the concerned variables are
520    ! defined
521    IF (nomvar=='rsut4co2'.OR.nomvar=='rlut4co2'.OR.nomvar=='rsutcs4co2' &
522        .OR. nomvar=='rlutcs4co2'.OR.nomvar=='rsu4co2'.OR.nomvar=='rsucs4co2' &
523        .OR.nomvar=='rsu4co2'.OR.nomvar=='rsucs4co2'.OR.nomvar=='rsd4co2'.OR. &
524        nomvar=='rsdcs4co2'.OR.nomvar=='rlu4co2'.OR.nomvar=='rlucs4co2'.OR.&
525        nomvar=='rld4co2'.OR.nomvar=='rldcs4co2') THEN
526        IF ( flag_var(iff)<=lev_files(iff) ) ok_4xCO2atm=.TRUE.
527    ENDIF
528  END SUBROUTINE histdef2d_old
529
530  SUBROUTINE histdef3d_old(iff,lpoint,flag_var,nomvar,titrevar,unitvar)
531
532    USE ioipsl, ONLY: histdef
533    USE dimphy, ONLY: klev
534    USE lmdz_phys_para, ONLY: jj_nb, is_master
535    USE phys_output_var_mod, ONLY: type_ecri, zoutm, lev_files, nid_files, &
536                                   nhorim, zdtime_moy, levmin, levmax, &
537                                   nvertm, nfiles
538    USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat
539    USE lmdz_print_control, ONLY: prt_level,lunout
540    IMPLICIT NONE
541
542    INCLUDE "clesphys.h"
543
544    INTEGER                          :: iff
545    LOGICAL                          :: lpoint
546    INTEGER, DIMENSION(nfiles)       :: flag_var
547    CHARACTER(LEN=20)                 :: nomvar
548    CHARACTER(LEN=*)                 :: titrevar
549    CHARACTER(LEN=*)                 :: unitvar
550
551    REAL zstophym
552
553    ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
554    CALL conf_physoutputs(nomvar,flag_var)
555
556    IF (check_dim .AND. is_master) WRITE(lunout,*)'histdef3d_old for ', nomvar
557
558    IF (type_ecri(iff)=='inst(X)'.OR.type_ecri(iff)=='once') THEN
559       zstophym=zoutm(iff)
560    ELSE
561       zstophym=zdtime_moy
562    ENDIF
563
564    IF(.NOT.lpoint) THEN
565       IF ( flag_var(iff)<=lev_files(iff) ) THEN
566          CALL histdef (nid_files(iff), nomvar, titrevar, unitvar, &
567               nbp_lon, jj_nb, nhorim(iff), klev, levmin(iff), &
568               levmax(iff)-levmin(iff)+1, nvertm(iff), 32, type_ecri(iff), &
569               zstophym, zoutm(iff))
570       ENDIF
571    ELSE
572       IF ( flag_var(iff)<=lev_files(iff) ) THEN
573          CALL histdef (nid_files(iff), nomvar, titrevar, unitvar, &
574               npstn,1,nhorim(iff), klev, levmin(iff), &
575               levmax(iff)-levmin(iff)+1, nvertm(iff), 32, &
576               type_ecri(iff), zstophym,zoutm(iff))
577       ENDIF
578    ENDIF
579  END SUBROUTINE histdef3d_old
580
581  SUBROUTINE histdef2d(iff,var)
582
583    USE ioipsl, ONLY: histdef
584    USE lmdz_phys_para, ONLY: jj_nb, is_master
585    USE phys_output_var_mod, ONLY: ctrl_out, type_ecri_files, zoutm, zdtime_moy, &
586                                   clef_stations, phys_out_filenames, lev_files, &
587                                   nid_files, nhorim, swaerofree_diag, swaero_diag, dryaod_diag,&
588                                   ok_4xCO2atm
589    USE lmdz_print_control, ONLY: prt_level,lunout
590    USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat
591    USE aero_mod, ONLY: naero_tot, name_aero_tau
592    USE lmdz_wxios, ONLY: wxios_add_field_to_file, using_xios
593    USE lmdz_print_control, ONLY: prt_level,lunout
594    IMPLICIT NONE
595
596    INCLUDE "clesphys.h"
597
598    INTEGER                          :: iff
599    INTEGER                          :: naero
600    TYPE(ctrl_out)                   :: var
601
602    REAL zstophym
603    CHARACTER(LEN=20) :: typeecrit
604
605    IF (check_dim .AND. is_master) WRITE(lunout,*)'histdef2d for ', var%name
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%type_ecrit(iff), "once") > 0) THEN
610       typeecrit = 'once'
611    ELSE IF(INDEX(var%type_ecrit(iff), "t_min") > 0) THEN
612       typeecrit = 't_min(X)'
613    ELSE IF(INDEX(var%type_ecrit(iff), "t_max") > 0) THEN
614       typeecrit = 't_max(X)'
615    ELSE IF(INDEX(var%type_ecrit(iff), "inst") > 0) THEN
616       typeecrit = 'inst(X)'
617    ELSE
618       typeecrit = type_ecri_files(iff)
619    ENDIF
620
621    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
622       zstophym=zoutm(iff)
623    ELSE
624       zstophym=zdtime_moy
625    ENDIF
626
627    ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
628    CALL conf_physoutputs(var%name, var%flag)
629
630    IF(.NOT.clef_stations(iff)) THEN 
631
632      IF (using_xios) THEN 
633        IF (.NOT. ok_all_xml) THEN
634          IF ( var%flag(iff)<=lev_files(iff) ) THEN
635            CALL wxios_add_field_to_file(var%name, 2, iff, phys_out_filenames(iff), &
636            var%description, var%unit, var%flag(iff), typeecrit)
637            IF (prt_level >= 10) THEN
638              WRITE(lunout,*) 'histdef2d: CALL wxios_add_field_to_file var%name iff: ', &
639                              trim(var%name),iff
640            ENDIF
641          ENDIF
642        ENDIF
643      ENDIF
644#ifndef CPP_IOIPSL_NO_OUTPUT
645
646       IF ( var%flag(iff)<=lev_files(iff) ) THEN
647          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
648               nbp_lon,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
649               typeecrit, zstophym,zoutm(iff))               
650       ENDIF
651    ELSE
652       IF ( var%flag(iff)<=lev_files(iff)) THEN
653          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
654               npstn,1,nhorim(iff), 1,1,1, -99, 32, &
655               typeecrit, zstophym,zoutm(iff))               
656       ENDIF
657#endif
658    ENDIF
659
660    ! Set swaero_diag=true if at least one of the concerned variables are defined
661    !--OB 30/05/2016 use wider set of variables
662    IF ( var%name=='topswad' .OR. var%name=='topswad0' .OR. var%name=='solswad' .OR. var%name=='solswad0' .OR. &
663         var%name=='topswai' .OR. var%name=='solswai'  .OR. ( iflag_rrtm==1 .AND. (                            &
664         var%name=='toplwad' .OR. var%name=='toplwad0' .OR. var%name=='sollwad' .OR. var%name=='sollwad0' .OR. &
665         var%name=='toplwai' .OR. var%name=='sollwai'  ) ) ) THEN
666       IF  ( var%flag(iff)<=lev_files(iff) ) swaero_diag=.TRUE.
667    ENDIF
668
669    ! Set swaerofree_diag=true if at least one of the concerned variables are defined
670    IF (var%name=='SWupTOAcleanclr' .OR. var%name=='SWupSFCcleanclr' .OR. var%name=='SWdnSFCcleanclr' .OR. &
671        var%name=='LWupTOAcleanclr' .OR. var%name=='LWdnSFCcleanclr' ) THEN
672       IF  ( var%flag(iff)<=lev_files(iff) ) swaerofree_diag=.TRUE.
673    ENDIF
674
675    ! set dryaod_dry=true if at least one of the concerned variables are defined
676    IF (var%name=='dryod550aer') THEN
677      IF  ( var%flag(iff)<=lev_files(iff) ) dryaod_diag=.TRUE.
678    ENDIF
679
680    DO naero = 1, naero_tot-1
681      IF (var%name=='dryod550_'//name_aero_tau(naero)) THEN
682        IF  ( var%flag(iff)<=lev_files(iff) ) dryaod_diag=.TRUE.
683      ENDIF
684    ENDDO
685    ! Set ok_4xCO2atm=true if at least one of the concerned variables are
686    ! defined
687    IF (var%name=='rsut4co2'.OR.var%name=='rlut4co2'.OR.var%name=='rsutcs4co2' &
688        .OR. var%name=='rlutcs4co2'.OR.var%name=='rsu4co2'.OR.var%name=='rsucs4co2' &
689        .OR.var%name=='rsu4co2'.OR.var%name=='rsucs4co2'.OR.var%name=='rsd4co2'.OR. &
690        var%name=='rsdcs4co2'.OR.var%name=='rlu4co2'.OR.var%name=='rlucs4co2'.OR.&
691        var%name=='rld4co2'.OR.var%name=='rldcs4co2') THEN
692        IF ( var%flag(iff)<=lev_files(iff) ) ok_4xCO2atm=.TRUE.
693    ENDIF
694  END SUBROUTINE histdef2d
695
696  SUBROUTINE histdef3d(iff,var)
697
698    USE ioipsl, ONLY: histdef
699    USE dimphy, ONLY: klev
700    USE lmdz_phys_para, ONLY: jj_nb, is_master
701    USE phys_output_var_mod, ONLY: ctrl_out, type_ecri_files, zoutm, zdtime_moy, &
702                                   clef_stations, phys_out_filenames, lev_files, &
703                                   nid_files, nhorim, swaerofree_diag, levmin, &
704                                   levmax, nvertm
705    USE lmdz_print_control, ONLY: prt_level,lunout
706    USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat
707    USE lmdz_wxios, ONLY: wxios_add_field_to_file, using_xios
708    USE lmdz_print_control, ONLY: prt_level,lunout
709    IMPLICIT NONE
710
711    INCLUDE "clesphys.h"
712
713    INTEGER                          :: iff
714    TYPE(ctrl_out)                   :: var
715
716    REAL zstophym
717    CHARACTER(LEN=20) :: typeecrit
718
719    IF (check_dim .AND. is_master) WRITE(lunout,*)'histdef3d for ', var%name
720
721    ! ug On récupère le type écrit de la structure:
722    !       Assez moche, à refaire si meilleure méthode...
723    IF (INDEX(var%type_ecrit(iff), "once") > 0) THEN
724       typeecrit = 'once'
725    ELSE IF(INDEX(var%type_ecrit(iff), "t_min") > 0) THEN
726       typeecrit = 't_min(X)'
727    ELSE IF(INDEX(var%type_ecrit(iff), "t_max") > 0) THEN
728       typeecrit = 't_max(X)'
729    ELSE IF(INDEX(var%type_ecrit(iff), "inst") > 0) THEN
730       typeecrit = 'inst(X)'
731    ELSE
732       typeecrit = type_ecri_files(iff)
733    ENDIF
734
735    ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
736    CALL conf_physoutputs(var%name,var%flag)
737
738    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
739       zstophym=zoutm(iff)
740    ELSE
741       zstophym=zdtime_moy
742    ENDIF
743
744    IF(.NOT.clef_stations(iff)) THEN
745
746      IF (using_xios) THEN 
747
748        IF (.NOT. ok_all_xml) THEN
749          IF ( var%flag(iff)<=lev_files(iff) ) THEN
750          CALL wxios_add_field_to_file(var%name, 3, iff, phys_out_filenames(iff), &
751          var%description, var%unit, var%flag(iff), typeecrit)
752            IF (prt_level >= 10) THEN
753              WRITE(lunout,*) 'histdef3d: CALL wxios_add_field_to_file var%name iff: ', &
754                              trim(var%name),iff
755            ENDIF
756          ENDIF
757        ENDIF
758      ENDIF
759#ifndef CPP_IOIPSL_NO_OUTPUT
760
761       IF ( var%flag(iff)<=lev_files(iff) ) THEN
762          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
763               nbp_lon, jj_nb, nhorim(iff), klev, levmin(iff), &
764               levmax(iff)-levmin(iff)+1, nvertm(iff), 32, typeecrit, &
765               zstophym, zoutm(iff))
766       ENDIF
767    ELSE
768       IF ( var%flag(iff)<=lev_files(iff)) THEN
769          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
770               npstn,1,nhorim(iff), klev, levmin(iff), &
771               levmax(iff)-levmin(iff)+1, nvertm(iff), 32, &
772               typeecrit, zstophym,zoutm(iff))
773       ENDIF
774#endif
775    ENDIF
776
777    ! Set swaerofree_diag=true if at least one of the concerned variables are defined
778    IF (var%name=='rsucsaf' .OR. var%name=='rsdcsaf') THEN
779       IF  ( var%flag(iff)<=lev_files(iff) ) swaerofree_diag=.TRUE.
780    ENDIF
781
782  END SUBROUTINE histdef3d
783
784  SUBROUTINE conf_physoutputs(nam_var,flag_var)
785!!! Lecture des noms et niveau de sortie des variables dans output.def
786    !   en utilisant les routines getin de IOIPSL 
787    USE ioipsl, ONLY: getin
788    USE phys_output_var_mod, ONLY: nfiles
789    USE lmdz_print_control, ONLY: prt_level,lunout
790    IMPLICIT NONE
791
792    CHARACTER(LEN=*), INTENT(INOUT) :: nam_var
793    INTEGER,          INTENT(INOUT) :: flag_var(nfiles)
794
795    IF(prt_level>10) WRITE(lunout,*)'Avant getin: nam_var flag_var ',nam_var,flag_var(:)
796    CALL getin('flag_'//nam_var,flag_var)
797    CALL getin('name_'//nam_var,nam_var)
798    IF(prt_level>10) WRITE(lunout,*)'Apres getin: nam_var flag_var ',nam_var,flag_var(:)
799
800  END SUBROUTINE conf_physoutputs
801
802 
803  SUBROUTINE histwrite2d_phy_old(nid,lpoint,name,itau,field)
804
805    USE dimphy, ONLY: klon
806    USE lmdz_phys_para, ONLY: Gather_omp, grid1Dto2D_mpi, &
807                                  is_sequential, klon_mpi_begin, klon_mpi_end, &
808                                  jj_nb, klon_mpi, is_master
809    USE ioipsl, ONLY: histwrite
810    USE lmdz_print_control, ONLY: prt_level,lunout
811    USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat
812
813    IMPLICIT NONE
814   
815    INTEGER,INTENT(IN) :: nid
816    LOGICAL,INTENT(IN) :: lpoint
817    CHARACTER*(*), INTENT(IN) :: name
818    INTEGER, INTENT(IN) :: itau
819    REAL,DIMENSION(:),INTENT(IN) :: field
820    REAL,DIMENSION(klon_mpi) :: buffer_omp
821    INTEGER, ALLOCATABLE, DIMENSION(:) :: index2d
822    REAL :: Field2d(nbp_lon,jj_nb)
823
824    INTEGER :: ip
825    REAL,ALLOCATABLE,DIMENSION(:) :: fieldok
826
827    IF (size(field)/=klon) CALL abort_physic('iophy::histwrite2d','Field first DIMENSION not equal to klon',1)
828    IF (check_dim .AND. is_master) WRITE(lunout,*)'histwrite2d_phy_old for ', name
829
830    CALL Gather_omp(field,buffer_omp)   
831!$OMP MASTER
832    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
833    IF (.NOT.lpoint) THEN
834     ALLOCATE(index2d(nbp_lon*jj_nb))
835     ALLOCATE(fieldok(nbp_lon*jj_nb))
836     IF (prt_level >= 10) WRITE(lunout,*)'Sending ',name,' to IOIPSL'
837     CALL histwrite(nid,name,itau,Field2d,nbp_lon*jj_nb,index2d)
838     IF (prt_level >= 10) WRITE(lunout,*)'Finished sending ',name,' to IOIPSL'
839    ELSE
840     ALLOCATE(fieldok(npstn))
841     ALLOCATE(index2d(npstn))
842
843     IF (is_sequential) THEN
844!     klon_mpi_begin=1
845!     klon_mpi_end=klon
846      DO ip=1, npstn
847       fieldok(ip)=buffer_omp(nptabij(ip))
848      ENDDO
849     ELSE
850      DO ip=1, npstn
851!     PRINT*,'histwrite2d is_sequential npstn ip name nptabij',npstn,ip,name,nptabij(ip)
852       IF(nptabij(ip)>=klon_mpi_begin.AND. &
853          nptabij(ip)<=klon_mpi_end) THEN
854         fieldok(ip)=buffer_omp(nptabij(ip)-klon_mpi_begin+1)
855       ENDIF
856      ENDDO
857     ENDIF
858     IF (prt_level >= 10) WRITE(lunout,*)'Sending ',name,' to IOIPSL'
859     CALL histwrite(nid,name,itau,fieldok,npstn,index2d)
860     IF (prt_level >= 10) WRITE(lunout,*)'Finished sending ',name,' to IOIPSL'
861
862    ENDIF
863    DEALLOCATE(index2d)
864    DEALLOCATE(fieldok)
865!$OMP END MASTER   
866
867 
868  END SUBROUTINE histwrite2d_phy_old
869
870  SUBROUTINE histwrite3d_phy_old(nid,lpoint,name,itau,field)
871
872    USE dimphy, ONLY: klon
873    USE lmdz_phys_para, ONLY: Gather_omp, grid1Dto2D_mpi, &
874                                  is_sequential, klon_mpi_begin, klon_mpi_end, &
875                                  jj_nb, klon_mpi, is_master
876    USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat
877    USE ioipsl, ONLY: histwrite
878    USE lmdz_print_control, ONLY: prt_level,lunout
879
880    IMPLICIT NONE
881   
882    INTEGER,INTENT(IN) :: nid
883    LOGICAL,INTENT(IN) :: lpoint
884    CHARACTER*(*), INTENT(IN) :: name
885    INTEGER, INTENT(IN) :: itau
886    REAL,DIMENSION(:,:),INTENT(IN) :: field  ! --> field(klon,:)
887    REAL,DIMENSION(klon_mpi,size(field,2)) :: buffer_omp
888    REAL :: Field3d(nbp_lon,jj_nb,size(field,2))
889    INTEGER :: ip, n, nlev
890    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
891    REAL,ALLOCATABLE, DIMENSION(:,:) :: fieldok
892
893    IF (check_dim .AND. is_master) WRITE(lunout,*)'histwrite3d_phy_old for ', name
894
895    IF (size(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
896    nlev=size(field,2)
897
898    CALL Gather_omp(field,buffer_omp)
899!$OMP MASTER
900    CALL grid1Dto2D_mpi(buffer_omp,field3d)
901    IF (.NOT.lpoint) THEN
902      ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
903      ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
904      IF (prt_level >= 10) WRITE(lunout,*)'Sending ',name,' to IOIPSL'
905      CALL histwrite(nid,name,itau,Field3d,nbp_lon*jj_nb*nlev,index3d)
906      IF (prt_level >= 10) WRITE(lunout,*)'Finished sending ',name,' to IOIPSL'
907    ELSE
908      nlev=size(field,2)
909      ALLOCATE(index3d(npstn*nlev))
910      ALLOCATE(fieldok(npstn,nlev))
911
912      IF (is_sequential) THEN
913!       klon_mpi_begin=1
914!       klon_mpi_end=klon
915        DO n=1, nlev
916        DO ip=1, npstn
917          fieldok(ip,n)=buffer_omp(nptabij(ip),n)
918        ENDDO
919        ENDDO
920      ELSE
921        DO n=1, nlev
922        DO ip=1, npstn
923          IF(nptabij(ip)>=klon_mpi_begin.AND. &
924           nptabij(ip)<=klon_mpi_end) THEN
925           fieldok(ip,n)=buffer_omp(nptabij(ip)-klon_mpi_begin+1,n)
926          ENDIF
927        ENDDO
928        ENDDO
929      ENDIF
930      IF (prt_level >= 10) WRITE(lunout,*)'Sending ',name,' to IOIPSL'
931      CALL histwrite(nid,name,itau,fieldok,npstn*nlev,index3d)
932      IF (prt_level >= 10) WRITE(lunout,*)'Finished sending ',name,' to IOIPSL'
933    ENDIF
934    DEALLOCATE(index3d)
935    DEALLOCATE(fieldok)
936!$OMP END MASTER   
937
938  END SUBROUTINE histwrite3d_phy_old
939
940
941! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
942  SUBROUTINE histwrite2d_phy(var,field, STD_iff)
943
944  USE lmdz_phys_omp_transfert, ONLY: bcast_omp
945  USE dimphy, ONLY: klon, klev
946  USE lmdz_phys_para, ONLY: gather_omp, grid1dto2d_mpi, &
947                                jj_nb, klon_mpi, klon_mpi_begin, &
948                                klon_mpi_end, is_sequential, is_master
949  USE ioipsl, ONLY: histwrite
950  USE phys_output_var_mod, ONLY: ctrl_out, clef_files, lev_files, &
951                                 nfiles, vars_defined, clef_stations, &
952                                 nid_files, swaerofree_diag, swaero_diag, dryaod_diag, ok_4xCO2atm
953  USE lmdz_print_control, ONLY: prt_level,lunout
954  USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat, grid_type, unstructured, regular_lonlat
955  USE lmdz_xios, ONLY: xios_send_field, xios_field_is_active, using_xios
956  USE lmdz_print_control, ONLY: lunout, prt_level
957
958  IMPLICIT NONE
959  INCLUDE 'clesphys.h'
960
961  TYPE(ctrl_out), INTENT(IN) :: var
962  REAL, DIMENSION(:), INTENT(IN) :: field
963  INTEGER, INTENT(IN), OPTIONAL :: STD_iff ! ug RUSTINE POUR LES STD LEVS.....
964     
965  INTEGER :: iff, iff_beg, iff_end
966  LOGICAL, SAVE  :: firstx
967!$OMP THREADPRIVATE(firstx)
968
969  REAL,DIMENSION(klon_mpi) :: buffer_omp
970  INTEGER, ALLOCATABLE, DIMENSION(:) :: index2d
971  REAL :: Field2d(nbp_lon,jj_nb)
972
973  INTEGER :: ip
974  REAL, ALLOCATABLE, DIMENSION(:) :: fieldok
975  logical, save :: is_active = .TRUE.
976
977  IF (check_dim .AND. is_master) WRITE(lunout,*)'histwrite2d_phy for ',trim(var%name)
978
979  IF (prt_level >= 10) THEN
980    WRITE(lunout,*)'Begin histwrite2d_phy for ',trim(var%name)
981  ENDIF
982
983! ug RUSTINE POUR LES STD LEVS.....
984  IF (PRESENT(STD_iff)) THEN
985        iff_beg = STD_iff
986        iff_end = STD_iff
987  ELSE
988        iff_beg = 1
989        iff_end = nfiles
990  ENDIF
991
992  ! On regarde si on est dans la phase de définition ou d'écriture:
993  IF (.NOT.vars_defined) THEN
994!$OMP MASTER
995      !Si phase de définition.... on définit
996      IF (.NOT. ok_all_xml) THEN
997      IF (prt_level >= 10) THEN
998      WRITE(lunout,*)"histwrite2d_phy: .NOT.vars_defined ; time to define ", &
999                     trim(var%name)
1000      ENDIF
1001      DO iff=iff_beg, iff_end
1002         IF (clef_files(iff)) THEN
1003            CALL histdef2d(iff, var)
1004         ENDIF
1005      ENDDO
1006      ENDIF
1007!$OMP END MASTER
1008!--broadcasting the flags that have been changed in histdef2d on OMP masters
1009      CALL bcast_omp(swaero_diag)
1010      CALL bcast_omp(swaerofree_diag)
1011      CALL bcast_omp(dryaod_diag)
1012      CALL bcast_omp(ok_4xCO2atm)
1013
1014  ELSE
1015    IF (using_xios) THEN
1016      IF (ok_all_xml) THEN
1017        !$omp barrier
1018        !$omp master
1019        is_active = xios_field_is_active(var%name, at_current_timestep_arg=.FALSE.)
1020        !$omp end master
1021        !$omp barrier
1022        IF(.NOT. is_active) RETURN
1023      ENDIF
1024    ENDIF
1025
1026    !Et sinon on.... écrit
1027    IF (SIZE(field)/=klon .AND. SIZE(field)/=klev .AND. SIZE(field)/=klev+1) &
1028         CALL abort_physic('iophy::histwrite2d_phy',&
1029         'Field first DIMENSION not equal to klon/klev',1)
1030    IF (prt_level >= 10) THEn
1031      WRITE (lunout,*)"histwrite2d_phy: .NOT.vars_defined ; time to gather and write ", trim(var%name)
1032    ENDIF
1033   
1034   
1035    IF (SIZE(field) == klon) THEN
1036        CALL Gather_omp(field,buffer_omp)
1037    ELSE
1038        buffer_omp(:)=0.
1039    ENDIF
1040!$OMP MASTER
1041    IF (grid_type==regular_lonlat) CALL grid1Dto2D_mpi(buffer_omp,Field2d)
1042
1043! La boucle sur les fichiers:
1044      firstx=.TRUE.
1045
1046      IF (ok_all_xml) THEN
1047        IF (using_xios) THEN 
1048          IF (prt_level >= 10) THEN
1049             WRITE(lunout,*)'Dans iophy histwrite2D,var%name ', trim(var%name)
1050          ENDIF
1051         
1052          IF (grid_type==regular_lonlat) THEN
1053            IF (SIZE(field) == klon) THEN
1054              CALL xios_send_field(var%name, Field2d)
1055            ELSE
1056               CALL xios_send_field(var%name, field)
1057            ENDIF
1058          ELSE IF (grid_type==unstructured) THEN
1059            IF (SIZE(field) == klon) THEN
1060              CALL xios_send_field(var%name, buffer_omp)
1061            ELSE
1062               CALL xios_send_field(var%name, field)
1063            ENDIF
1064
1065          ENDIF
1066          IF (prt_level >= 10) THEN
1067             WRITE(lunout,*)'Dans iophy histwrite2D,var%name apres xios_send ',&
1068                             trim(var%name)                       
1069          ENDIF
1070        ELSE
1071          CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
1072        ENDIF
1073      ELSE 
1074        DO iff=iff_beg, iff_end
1075            IF (var%flag(iff) <= lev_files(iff) .AND. clef_files(iff)) THEN
1076
1077              IF (using_xios) THEN
1078                IF (firstx) THEN
1079                   IF (prt_level >= 10) THEN
1080                      WRITE(lunout,*)'Dans iophy histwrite2D,iff,var%name ',&
1081                                     iff,trim(var%name)                       
1082                      WRITE(lunout,*)"histwrite2d_phy:.NOT.clef_stations(iff)and iff==iff_beg, CALL xios_send_field"
1083                   ENDIF
1084                   IF (grid_type==regular_lonlat) THEN
1085                     IF (SIZE(field) == klon) THEN
1086                        CALL xios_send_field(var%name, Field2d)
1087                     ELSE
1088                        CALL xios_send_field(var%name, field)
1089                     ENDIF
1090                   ELSE IF (grid_type==unstructured) THEN
1091                     IF (SIZE(field) == klon) THEN
1092                       CALL xios_send_field(var%name, buffer_omp)
1093                     ELSE
1094                       CALL xios_send_field(var%name, field)
1095                     ENDIF
1096                   ENDIF
1097
1098                   firstx=.FALSE.
1099                ENDIF
1100              ENDIF
1101
1102                  IF (.NOT.clef_stations(iff)) THEN
1103                        ALLOCATE(index2d(nbp_lon*jj_nb))
1104                        ALLOCATE(fieldok(nbp_lon*jj_nb))
1105#ifndef CPP_IOIPSL_NO_OUTPUT
1106                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field2d,nbp_lon*jj_nb,index2d)
1107#endif
1108!    IF (using_xios) THEN 
1109!                        IF (iff == iff_beg) THEN
1110!                          IF (prt_level >= 10) THEN
1111!                            WRITE(lunout,*)"histwrite2d_phy: .NOT.clef_stations(iff) and iff==iff_beg, CALL xios_send_field"
1112!                          ENDIF
1113!                          CALL xios_send_field(var%name, Field2d)
1114!                        ENDIF
1115!    ENDIF
1116                  ELSE
1117                        ALLOCATE(fieldok(npstn))
1118                        ALLOCATE(index2d(npstn))
1119
1120                        IF (is_sequential) THEN
1121                          DO ip=1, npstn
1122                            fieldok(ip)=buffer_omp(nptabij(ip))
1123                          ENDDO
1124                        ELSE
1125                              DO ip=1, npstn
1126                                WRITE(lunout,*)'histwrite2d_phy is_sequential npstn ip namenptabij',npstn,ip,var%name,nptabij(ip)
1127                                     IF(nptabij(ip)>=klon_mpi_begin.AND. &
1128                                        nptabij(ip)<=klon_mpi_end) THEN
1129                                       fieldok(ip)=buffer_omp(nptabij(ip)-klon_mpi_begin+1)
1130                                     ENDIF
1131                              ENDDO
1132                       ENDIF ! of IF (is_sequential)
1133#ifndef CPP_IOIPSL_NO_OUTPUT
1134                       IF (prt_level >= 10) THEN
1135                         WRITE(lunout,*)"histwrite2d_phy: clef_stations(iff) and iff==iff_beg, CALL wxios_write_2D"
1136                       ENDIF
1137                       CALL histwrite(nid_files(iff),var%name,itau_iophy,fieldok,npstn,index2d)
1138#endif
1139                  ENDIF ! of IF(.NOT.clef_stations(iff))
1140                 
1141                DEALLOCATE(index2d)
1142                DEALLOCATE(fieldok)
1143            ENDIF !levfiles
1144        ENDDO ! of DO iff=iff_beg, iff_end
1145      ENDIF
1146!$OMP END MASTER   
1147  ENDIF ! vars_defined
1148
1149  IF (prt_level >= 10) WRITE(lunout,*)'End histwrite2d_phy ',trim(var%name)
1150
1151  END SUBROUTINE histwrite2d_phy
1152
1153
1154! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
1155  SUBROUTINE histwrite3d_phy(var, field, STD_iff)
1156
1157  USE lmdz_phys_omp_transfert, ONLY: bcast_omp
1158  USE dimphy, ONLY: klon, klev
1159  USE lmdz_phys_para, ONLY: gather_omp, grid1dto2d_mpi, &
1160                                jj_nb, klon_mpi, klon_mpi_begin, &
1161                                klon_mpi_end, is_sequential, is_master
1162  USE ioipsl, ONLY: histwrite
1163  USE phys_output_var_mod, ONLY: ctrl_out, clef_files, lev_files, &
1164                                 nfiles, vars_defined, clef_stations, &
1165                                 nid_files, swaerofree_diag
1166  USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat, grid_type, regular_lonlat, unstructured
1167  USE lmdz_xios, ONLY: xios_send_field, xios_field_is_active, using_xios
1168  USE lmdz_print_control, ONLY: prt_level,lunout
1169
1170  IMPLICIT NONE
1171  INCLUDE 'clesphys.h'
1172
1173  TYPE(ctrl_out), INTENT(IN) :: var
1174  REAL, DIMENSION(:,:), INTENT(IN) :: field ! --> field(klon,:)
1175  INTEGER, INTENT(IN), OPTIONAL :: STD_iff ! ug RUSTINE POUR LES STD LEVS.....
1176     
1177  INTEGER :: iff, iff_beg, iff_end
1178  LOGICAL, SAVE  :: firstx
1179!$OMP THREADPRIVATE(firstx)
1180  REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
1181  REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
1182  INTEGER :: ip, n, nlev, nlevx
1183  INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
1184  REAL,ALLOCATABLE, DIMENSION(:,:) :: fieldok
1185  logical, save :: is_active = .TRUE.
1186
1187  IF (check_dim .AND. is_master) WRITE(lunout,*)'histwrite3d_phy for ', trim(var%name)
1188
1189  IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite3d ',var%name
1190
1191! ug RUSTINE POUR LES STD LEVS.....
1192      IF (PRESENT(STD_iff)) THEN
1193            iff_beg = STD_iff
1194            iff_end = STD_iff
1195      ELSE
1196            iff_beg = 1
1197            iff_end = nfiles
1198      ENDIF
1199
1200  ! On regarde si on est dans la phase de définition ou d'écriture:
1201  IF (.NOT.vars_defined) THEN
1202      !Si phase de définition.... on définit
1203!$OMP MASTER
1204      DO iff=iff_beg, iff_end
1205        IF (clef_files(iff)) THEN
1206          CALL histdef3d(iff, var)
1207        ENDIF
1208      ENDDO
1209!$OMP END MASTER
1210!--broadcasting the flag that have been changed in histdef3d on OMP masters
1211      CALL bcast_omp(swaerofree_diag)
1212  ELSE
1213    IF (using_xios) THEN 
1214      IF (ok_all_xml) THEN
1215        !$omp barrier
1216        !$omp master
1217        is_active = xios_field_is_active(var%name, at_current_timestep_arg=.FALSE.)
1218        !$omp end master
1219        !$omp barrier
1220        IF(.NOT. is_active) RETURN
1221      ENDIF
1222    ENDIF
1223
1224    !Et sinon on.... écrit
1225    IF (SIZE(field,1)/=klon .AND. SIZE(field,1)/=klev &
1226         .AND. SIZE(field,1)/=klev+1) &
1227         CALL abort_physic('iophy::histwrite3d_phy', &
1228         'Field first DIMENSION not equal to klon/klev',1)
1229
1230    nlev=SIZE(field,2)
1231    nlevx=nlev
1232!    IF (nlev.EQ.klev+1) THEN
1233!        nlevx=klev
1234!    ELSE
1235!        nlevx=nlev
1236!    ENDIF
1237
1238    IF (SIZE(field,1) == klon) THEN
1239        CALL Gather_omp(field,buffer_omp)
1240    ELSE
1241        buffer_omp(:,:)=0.
1242    ENDIF
1243!$OMP MASTER
1244    IF (grid_type==regular_lonlat) CALL grid1Dto2D_mpi(buffer_omp,field3d)
1245
1246! BOUCLE SUR LES FICHIERS
1247    firstx=.TRUE.
1248
1249    IF (ok_all_xml) THEN
1250      IF (using_xios) THEN 
1251          IF (prt_level >= 10) THEN
1252             WRITE(lunout,*)'Dans iophy histwrite3D,var%name ',&
1253                             trim(var%name)                       
1254          ENDIF
1255          IF (grid_type==regular_lonlat) THEN
1256            IF (SIZE(field,1) == klon) THEN
1257               CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
1258            ELSE
1259               CALL xios_send_field(var%name, field)
1260            ENDIF
1261          ELSE IF (grid_type==unstructured) THEN
1262            IF (SIZE(field,1) == klon) THEN
1263               CALL xios_send_field(var%name, buffer_omp(:,1:nlevx))
1264            ELSE
1265               CALL xios_send_field(var%name, field)
1266            ENDIF
1267        ENDIF
1268
1269      ELSE
1270        CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
1271      ENDIF
1272    ELSE 
1273
1274      DO iff=iff_beg, iff_end
1275          IF (var%flag(iff) <= lev_files(iff) .AND. clef_files(iff)) THEN
1276            IF (using_xios) THEN 
1277              IF (firstx) THEN
1278                IF (prt_level >= 10) THEN
1279                  WRITE(lunout,*)'Dans iophy, histwrite3D iff nlev klev firstx', &
1280                                  iff,nlev,klev, firstx                       
1281                  WRITE(lunout,*)'histwrite3d_phy: CALL xios_send_field for ', &
1282                                  trim(var%name), ' with iim jjm nlevx = ', &
1283                                  nbp_lon,jj_nb,nlevx
1284                ENDIF
1285                IF (grid_type==regular_lonlat) THEN
1286                  IF (SIZE(field,1) == klon) THEN
1287                      CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
1288                  ELSE
1289                       CALL xios_send_field(var%name, field)
1290                  ENDIF
1291                ELSE IF (grid_type==unstructured) THEN
1292                  IF (SIZE(field,1) == klon) THEN
1293                     CALL xios_send_field(var%name, buffer_omp(:,1:nlevx))
1294                  ELSE
1295                     CALL xios_send_field(var%name, field)
1296                  ENDIF
1297                ENDIF
1298
1299                firstx=.FALSE.
1300              ENDIF
1301            ENDIF
1302           
1303            IF (.NOT.clef_stations(iff)) THEN
1304                      ALLOCATE(index3d(nbp_lon*jj_nb*nlev))
1305                      ALLOCATE(fieldok(nbp_lon*jj_nb,nlev))
1306
1307#ifndef CPP_IOIPSL_NO_OUTPUT
1308                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field3d,nbp_lon*jj_nb*nlev,index3d)
1309#endif
1310
1311!    IF (using_xios) THEN 
1312!                        IF (iff == 1) THEN
1313!                              CALL xios_send_field(var%name, Field3d(:,:,1:klev))
1314!                        ENDIF
1315!    ENDIF
1316
1317              ELSE
1318                        nlev=size(field,2)
1319                        ALLOCATE(index3d(npstn*nlev))
1320                        ALLOCATE(fieldok(npstn,nlev))
1321
1322                        IF (is_sequential) THEN
1323                              DO n=1, nlev
1324                                    DO ip=1, npstn
1325                                          fieldok(ip,n)=buffer_omp(nptabij(ip),n)
1326                                    ENDDO
1327                              ENDDO
1328                        ELSE
1329                              DO n=1, nlev
1330                                    DO ip=1, npstn
1331                                                IF(nptabij(ip)>=klon_mpi_begin.AND. &
1332                                                      nptabij(ip)<=klon_mpi_end) THEN
1333                                                fieldok(ip,n)=buffer_omp(nptabij(ip)-klon_mpi_begin+1,n)
1334                                          ENDIF
1335                                    ENDDO
1336                              ENDDO
1337                        ENDIF
1338#ifndef CPP_IOIPSL_NO_OUTPUT
1339                        CALL histwrite(nid_files(iff),var%name,itau_iophy,fieldok,npstn*nlev,index3d)
1340#endif
1341              ENDIF
1342              DEALLOCATE(index3d)
1343              DEALLOCATE(fieldok)
1344          ENDIF
1345      ENDDO
1346    ENDIF
1347!$OMP END MASTER   
1348  ENDIF ! vars_defined
1349
1350  IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite3d ',var%name
1351
1352  END SUBROUTINE histwrite3d_phy
1353 
1354
1355! VERSION DES HISTWRITE DEDIEES AU TOUT-XIOS-XML DEJA UTILISEE DANS PHYDEV
1356  SUBROUTINE histwrite2d_xios(field_name,field)
1357
1358  USE dimphy, ONLY: klon, klev
1359  USE lmdz_phys_para, ONLY: gather_omp, grid1Dto2D_mpi, &
1360                                is_sequential, klon_mpi_begin, klon_mpi_end, &
1361                                jj_nb, klon_mpi, is_master
1362  USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat, grid_type, unstructured
1363  USE lmdz_xios, ONLY: xios_send_field
1364  USE lmdz_print_control, ONLY: prt_level,lunout
1365
1366  IMPLICIT NONE
1367
1368  CHARACTER(LEN=*), INTENT(IN) :: field_name
1369  REAL, DIMENSION(:), INTENT(IN) :: field
1370     
1371  REAL,DIMENSION(klon_mpi) :: buffer_omp
1372  INTEGER, ALLOCATABLE, DIMENSION(:) :: index2d
1373  REAL :: Field2d(nbp_lon,jj_nb)
1374
1375  INTEGER :: ip
1376  REAL, ALLOCATABLE, DIMENSION(:) :: fieldok
1377
1378  IF (check_dim .AND. is_master) WRITE(lunout,*)'histwrite2d_xios for ', field_name
1379
1380  IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite2d_xios ',field_name
1381
1382    !Et sinon on.... écrit
1383    IF (SIZE(field)/=klon .AND. SIZE(field)/=klev .AND. SIZE(field)/=klev+1) CALL abort_physic('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon/klev',1)
1384    IF (SIZE(field) == klev .OR. SIZE(field) == klev+1) THEN
1385!$OMP MASTER
1386
1387        CALL xios_send_field(field_name,field)
1388!$OMP END MASTER   
1389  ELSE
1390        CALL Gather_omp(field,buffer_omp)   
1391!$OMP MASTER
1392
1393      IF (grid_type==unstructured) THEN
1394 
1395        CALL xios_send_field(field_name, buffer_omp)
1396
1397      ELSE
1398
1399        CALL grid1Dto2D_mpi(buffer_omp,Field2d)
1400   
1401!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1402!ATTENTION, STATIONS PAS GEREES !
1403!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1404    !IF(.NOT.clef_stations(iff)) THEN
1405        IF (.TRUE.) THEN
1406   
1407            CALL xios_send_field(field_name, Field2d)
1408   
1409        ELSE
1410            ALLOCATE(fieldok(npstn))
1411            ALLOCATE(index2d(npstn))
1412   
1413            IF (is_sequential) THEN
1414                DO ip=1, npstn
1415                    fieldok(ip)=buffer_omp(nptabij(ip))
1416                ENDDO
1417            ELSE
1418                DO ip=1, npstn
1419                    PRINT*,'histwrite2d_xios is_sequential npstn ip namenptabij',npstn,ip,field_name,nptabij(ip)
1420                    IF(nptabij(ip)>=klon_mpi_begin.AND. &
1421                    nptabij(ip)<=klon_mpi_end) THEN
1422                        fieldok(ip)=buffer_omp(nptabij(ip)-klon_mpi_begin+1)
1423                    ENDIF
1424                ENDDO
1425            ENDIF
1426            DEALLOCATE(index2d)
1427            DEALLOCATE(fieldok)
1428   
1429        ENDIF                 
1430      ENDIF
1431!$OMP END MASTER   
1432  ENDIF
1433
1434  IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite2d_xios ',field_name
1435  END SUBROUTINE histwrite2d_xios
1436
1437
1438! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
1439  SUBROUTINE histwrite3d_xios(field_name, field)
1440
1441  USE dimphy, ONLY: klon, klev
1442  USE lmdz_phys_para, ONLY: gather_omp, grid1Dto2D_mpi, &
1443                                is_sequential, klon_mpi_begin, klon_mpi_end, &
1444                                jj_nb, klon_mpi, is_master
1445  USE lmdz_xios, ONLY: xios_send_field
1446  USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat, grid_type, unstructured
1447  USE lmdz_print_control, ONLY: prt_level,lunout
1448
1449  IMPLICIT NONE
1450
1451  CHARACTER(LEN=*), INTENT(IN) :: field_name
1452  REAL, DIMENSION(:,:), INTENT(IN) :: field ! --> field(klon,:)
1453
1454  REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
1455  REAL :: Field3d(nbp_lon,jj_nb,SIZE(field,2))
1456  INTEGER :: ip, n, nlev
1457  INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
1458  REAL,ALLOCATABLE, DIMENSION(:,:) :: fieldok
1459
1460  IF (check_dim .AND. is_master) WRITE(lunout,*)'histwrite3d_xios for ', field_name
1461
1462  IF (prt_level >= 10) WRITE(lunout,*)'Begin histrwrite3d_xios ',field_name
1463
1464    !Et on.... écrit
1465    IF (SIZE(field,1)/=klon .AND. SIZE(field,1)/=klev .AND. SIZE(field,1)/=klev+1) THEN
1466      WRITE(lunout,*)' histrwrite3d_xios ', field_name, SIZE(field)
1467      CALL abort_physic('iophy::histwrite3d_xios','Field first DIMENSION not equal to klon/klev',1)
1468    ENDIF
1469   
1470    IF (SIZE(field,1) == klev .OR. SIZE(field,1) == klev+1) THEN
1471!$OMP MASTER
1472        CALL xios_send_field(field_name,field)
1473!$OMP END MASTER   
1474  ELSE
1475        nlev=SIZE(field,2)
1476
1477
1478        CALL Gather_omp(field,buffer_omp)
1479!$OMP MASTER
1480
1481    IF (grid_type==unstructured) THEN
1482
1483      CALL xios_send_field(field_name, buffer_omp(:,1:nlev))
1484
1485    ELSE
1486        CALL grid1Dto2D_mpi(buffer_omp,field3d)
1487
1488!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1489!ATTENTION, STATIONS PAS GEREES !
1490!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1491    !IF (.NOT.clef_stations(iff)) THEN
1492        IF(.TRUE.)THEN
1493
1494           CALL xios_send_field(field_name, Field3d(:,:,1:nlev))
1495                           
1496        ELSE
1497            nlev=size(field,2)
1498            ALLOCATE(index3d(npstn*nlev))
1499            ALLOCATE(fieldok(npstn,nlev))
1500   
1501            IF (is_sequential) THEN
1502                DO n=1, nlev
1503                    DO ip=1, npstn
1504                        fieldok(ip,n)=buffer_omp(nptabij(ip),n)
1505                    ENDDO
1506                ENDDO
1507            ELSE
1508                DO n=1, nlev
1509                    DO ip=1, npstn
1510                        IF(nptabij(ip)>=klon_mpi_begin.AND. &
1511                        nptabij(ip)<=klon_mpi_end) THEN
1512                            fieldok(ip,n)=buffer_omp(nptabij(ip)-klon_mpi_begin+1,n)
1513                        ENDIF
1514                    ENDDO
1515                ENDDO
1516            ENDIF
1517            DEALLOCATE(index3d)
1518            DEALLOCATE(fieldok)
1519        ENDIF
1520      ENDIF
1521!$OMP END MASTER   
1522  ENDIF
1523
1524  IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite3d_xios ',field_name
1525
1526  END SUBROUTINE histwrite3d_xios
1527
1528  SUBROUTINE histwrite0d_xios(field_name, field)
1529  USE lmdz_xios, ONLY: xios_send_field
1530  USE lmdz_phys_para, ONLY: is_master
1531  USE lmdz_print_control, ONLY: prt_level,lunout
1532  USE phys_output_var_mod, ONLY: vars_defined
1533
1534  IMPLICIT NONE
1535
1536  CHARACTER(LEN=*), INTENT(IN) :: field_name
1537  REAL, INTENT(IN) :: field ! --> scalar
1538
1539  IF (check_dim .AND. is_master) WRITE(lunout,*)'histwrite0d_xios for ', field_name
1540
1541  IF (vars_defined) THEN
1542!$OMP MASTER
1543    CALL xios_send_field(field_name, field)
1544!$OMP END MASTER
1545  ENDIF
1546
1547  END SUBROUTINE histwrite0d_xios
1548
1549END MODULE iophy
Note: See TracBrowser for help on using the repository browser.