source: LMDZ5/branches/LMDZ5V2.0-dev/libf/phylmd/phys_output_write.h @ 5452

Last change on this file since 5452 was 1491, checked in by musat, 14 years ago

Couplage Thermiques/Emanuel? seulement si T<0 avec iflag_coupl==2 (FH)
Correction bug initialisation ptconvth (FH/JYG)
Correction dimensions tableau paprs_glo definition ZPM1R pour le 1D (JYG)
IM

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 52.2 KB
Line 
1      itau_w = itau_phy + itap
2
3      DO iff=1,nfiles
4
5       IF (clef_files(iff)) THEN
6             ndex2d = 0
7             ndex3d = 0
8
9!!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10       IF (o_phis%flag(iff)<=lev_files(iff)) THEN
11         CALL histwrite_phy(nid_files(iff),
12     $                      o_phis%name,itau_w,pphis)
13       ENDIF
14
15       IF (o_aire%flag(iff)<=lev_files(iff)) THEN
16       CALL histwrite_phy(nid_files(iff),o_aire%name,itau_w,airephy)
17       ENDIF
18
19       IF (o_contfracATM%flag(iff)<=lev_files(iff)) THEN
20      DO i=1, klon
21       zx_tmp_fi2d(i)=pctsrf(i,is_ter)+pctsrf(i,is_lic)
22      ENDDO
23      CALL histwrite_phy(nid_files(iff),
24     $             o_contfracATM%name,itau_w,zx_tmp_fi2d)
25       ENDIF
26
27       IF (o_contfracOR%flag(iff)<=lev_files(iff)) THEN
28      CALL histwrite_phy(nid_files(iff),o_contfracOR%name,itau_w,
29     $                   pctsrf(:,is_ter))
30       ENDIF
31
32       IF (o_aireTER%flag(iff)<=lev_files(iff)) THEN
33      CALL histwrite_phy(nid_files(iff),
34     $                  o_aireTER%name,itau_w,paire_ter)
35       ENDIF
36
37!!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
38
39       IF (o_flat%flag(iff)<=lev_files(iff)) THEN
40      CALL histwrite_phy(nid_files(iff),o_flat%name,itau_w,zxfluxlat)
41       ENDIF
42
43       IF (o_slp%flag(iff)<=lev_files(iff)) THEN
44      CALL histwrite_phy(nid_files(iff),o_slp%name,itau_w,slp)
45       ENDIF
46
47       IF (o_tsol%flag(iff)<=lev_files(iff)) THEN
48      CALL histwrite_phy(nid_files(iff),o_tsol%name,itau_w,zxtsol)
49       ENDIF
50
51       IF (o_t2m%flag(iff)<=lev_files(iff)) THEN
52      CALL histwrite_phy(nid_files(iff),o_t2m%name,itau_w,zt2m)
53       ENDIF
54
55       IF (o_t2m_min%flag(iff)<=lev_files(iff)) THEN
56      CALL histwrite_phy(nid_files(iff),o_t2m_min%name,itau_w,zt2m)
57       ENDIF
58
59       IF (o_t2m_max%flag(iff)<=lev_files(iff)) THEN
60      CALL histwrite_phy(nid_files(iff),o_t2m_max%name,itau_w,zt2m)
61       ENDIF
62
63       IF (o_wind10m%flag(iff)<=lev_files(iff)) THEN
64      DO i=1, klon
65       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
66      ENDDO
67      CALL histwrite_phy(nid_files(iff),
68     s                  o_wind10m%name,itau_w,zx_tmp_fi2d)
69       ENDIF
70
71       IF (o_wind10max%flag(iff)<=lev_files(iff)) THEN
72      DO i=1, klon
73       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
74      ENDDO
75      CALL histwrite_phy(nid_files(iff),o_wind10max%name, 
76     $                   itau_w,zx_tmp_fi2d)
77       ENDIF
78
79       IF (o_sicf%flag(iff)<=lev_files(iff)) THEN
80      DO i = 1, klon
81         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
82      ENDDO
83      CALL histwrite_phy(nid_files(iff),
84     $                   o_sicf%name,itau_w,zx_tmp_fi2d)
85       ENDIF
86
87       IF (o_q2m%flag(iff)<=lev_files(iff)) THEN
88      CALL histwrite_phy(nid_files(iff),o_q2m%name,itau_w,zq2m)
89       ENDIF
90
91       IF (o_u10m%flag(iff)<=lev_files(iff)) THEN
92      CALL histwrite_phy(nid_files(iff),o_u10m%name,itau_w,zu10m)
93       ENDIF
94
95       IF (o_v10m%flag(iff)<=lev_files(iff)) THEN
96      CALL histwrite_phy(nid_files(iff),o_v10m%name,itau_w,zv10m)
97       ENDIF
98
99       IF (o_psol%flag(iff)<=lev_files(iff)) THEN
100      DO i = 1, klon
101         zx_tmp_fi2d(i) = paprs(i,1)
102      ENDDO
103      CALL histwrite_phy(nid_files(iff),
104     s                   o_psol%name,itau_w,zx_tmp_fi2d)
105       ENDIF
106
107       IF (o_mass%flag(iff)<=lev_files(iff)) THEN
108      CALL histwrite_phy(nid_files(iff),o_mass%name,itau_w,zmasse)
109        ENDIF
110
111
112       IF (o_qsurf%flag(iff)<=lev_files(iff)) THEN
113      CALL histwrite_phy(nid_files(iff),o_qsurf%name,itau_w,zxqsurf)
114       ENDIF
115
116       if (.not. ok_veget) then
117         IF (o_qsol%flag(iff)<=lev_files(iff)) THEN
118        CALL histwrite_phy(nid_files(iff),o_qsol%name,itau_w,qsol)
119         ENDIF
120       endif
121
122      IF (o_precip%flag(iff)<=lev_files(iff)) THEN
123       DO i = 1, klon
124         zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
125       ENDDO
126      CALL histwrite_phy(nid_files(iff),o_precip%name,
127     s                   itau_w,zx_tmp_fi2d)
128      ENDIF
129
130       IF (o_ndayrain%flag(iff)<=lev_files(iff)) THEN
131      CALL histwrite_phy(nid_files(iff),o_ndayrain%name,
132     s                   itau_w,nday_rain)
133       ENDIF
134
135      IF (o_plul%flag(iff)<=lev_files(iff)) THEN
136       DO i = 1, klon
137         zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
138       ENDDO
139      CALL histwrite_phy(nid_files(iff),o_plul%name,itau_w,zx_tmp_fi2d)
140      ENDIF
141
142      IF (o_pluc%flag(iff)<=lev_files(iff)) THEN
143      DO i = 1, klon
144         zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
145      ENDDO
146      CALL histwrite_phy(nid_files(iff),o_pluc%name,itau_w,zx_tmp_fi2d)
147      ENDIF
148
149       IF (o_snow%flag(iff)<=lev_files(iff)) THEN
150      CALL histwrite_phy(nid_files(iff),o_snow%name,itau_w,snow_fall)
151       ENDIF
152
153       IF (o_msnow%flag(iff)<=lev_files(iff)) THEN
154      CALL histwrite_phy(nid_files(iff),o_msnow%name,itau_w,snow_o)
155       ENDIF
156
157       IF (o_fsnow%flag(iff)<=lev_files(iff)) THEN
158      CALL histwrite_phy(nid_files(iff),o_fsnow%name,itau_w,zfra_o)
159       ENDIF
160
161       IF (o_evap%flag(iff)<=lev_files(iff)) THEN
162      CALL histwrite_phy(nid_files(iff),o_evap%name,itau_w,evap)
163       ENDIF
164
165       IF (o_tops%flag(iff)<=lev_files(iff)) THEN
166      CALL histwrite_phy(nid_files(iff),o_tops%name,itau_w,topsw)
167       ENDIF
168
169       IF (o_tops0%flag(iff)<=lev_files(iff)) THEN
170      CALL histwrite_phy(nid_files(iff),o_tops0%name,itau_w,topsw0)
171       ENDIF
172
173       IF (o_topl%flag(iff)<=lev_files(iff)) THEN
174      CALL histwrite_phy(nid_files(iff),o_topl%name,itau_w,toplw)
175       ENDIF
176
177       IF (o_topl0%flag(iff)<=lev_files(iff)) THEN
178      CALL histwrite_phy(nid_files(iff),o_topl0%name,itau_w,toplw0)
179       ENDIF
180
181       IF (o_SWupTOA%flag(iff)<=lev_files(iff)) THEN
182      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
183      CALL histwrite_phy(nid_files(iff),o_SWupTOA%name,
184     s                     itau_w,zx_tmp_fi2d)
185       ENDIF
186
187       IF (o_SWupTOAclr%flag(iff)<=lev_files(iff)) THEN
188      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
189      CALL histwrite_phy(nid_files(iff), 
190     $                  o_SWupTOAclr%name,itau_w,zx_tmp_fi2d)
191       ENDIF
192
193       IF (o_SWdnTOA%flag(iff)<=lev_files(iff)) THEN
194      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
195      CALL histwrite_phy(nid_files(iff),
196     s                  o_SWdnTOA%name,itau_w,zx_tmp_fi2d)
197       ENDIF
198
199       IF (o_SWdnTOAclr%flag(iff)<=lev_files(iff)) THEN
200      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
201      CALL histwrite_phy(nid_files(iff), 
202     $                  o_SWdnTOAclr%name,itau_w,zx_tmp_fi2d)
203       ENDIF
204
205       IF (o_nettop%flag(iff)<=lev_files(iff)) THEN
206      zx_tmp_fi2d(:) = topsw(:)-toplw(:)
207      CALL histwrite_phy(nid_files(iff),
208     $                  o_nettop%name,itau_w,zx_tmp_fi2d)
209       ENDIF
210
211       IF (o_SWup200%flag(iff)<=lev_files(iff)) THEN
212      CALL histwrite_phy(nid_files(iff),o_SWup200%name,itau_w,SWup200)
213       ENDIF
214
215       IF (o_SWup200clr%flag(iff)<=lev_files(iff)) THEN
216      CALL histwrite_phy(nid_files(iff),
217     s                   o_SWup200clr%name,itau_w,SWup200clr)
218       ENDIF
219
220       IF (o_SWdn200%flag(iff)<=lev_files(iff)) THEN
221      CALL histwrite_phy(nid_files(iff),o_SWdn200%name,itau_w,SWdn200)
222       ENDIF
223
224       IF (o_SWdn200clr%flag(iff)<=lev_files(iff)) THEN
225      CALL histwrite_phy(nid_files(iff),
226     s                o_SWdn200clr%name,itau_w,SWdn200clr)
227       ENDIF
228
229       IF (o_LWup200%flag(iff)<=lev_files(iff)) THEN
230      CALL histwrite_phy(nid_files(iff),o_LWup200%name,itau_w,LWup200)
231       ENDIF
232
233       IF (o_LWup200clr%flag(iff)<=lev_files(iff)) THEN
234      CALL histwrite_phy(nid_files(iff),
235     s                   o_LWup200clr%name,itau_w,LWup200clr)
236       ENDIF
237
238       IF (o_LWdn200%flag(iff)<=lev_files(iff)) THEN
239      CALL histwrite_phy(nid_files(iff),
240     s                   o_LWdn200%name,itau_w,LWdn200)
241       ENDIF
242
243       IF (o_LWdn200clr%flag(iff)<=lev_files(iff)) THEN
244      CALL histwrite_phy(nid_files(iff),
245     s                  o_LWdn200clr%name,itau_w,LWdn200clr)
246       ENDIF
247
248       IF (o_sols%flag(iff)<=lev_files(iff)) THEN
249      CALL histwrite_phy(nid_files(iff),o_sols%name,itau_w,solsw)
250       ENDIF
251
252       IF (o_sols0%flag(iff)<=lev_files(iff)) THEN
253      CALL histwrite_phy(nid_files(iff),o_sols0%name,itau_w,solsw0)
254       ENDIF
255
256       IF (o_soll%flag(iff)<=lev_files(iff)) THEN
257      CALL histwrite_phy(nid_files(iff),o_soll%name,itau_w,sollw)
258       ENDIF
259
260       IF (o_radsol%flag(iff)<=lev_files(iff)) THEN
261      CALL histwrite_phy(nid_files(iff),o_radsol%name,itau_w,radsol)
262       ENDIF
263
264       IF (o_soll0%flag(iff)<=lev_files(iff)) THEN
265      CALL histwrite_phy(nid_files(iff),o_soll0%name,itau_w,sollw0)
266       ENDIF
267
268       IF (o_SWupSFC%flag(iff)<=lev_files(iff)) THEN
269      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
270      CALL histwrite_phy(nid_files(iff),
271     s               o_SWupSFC%name,itau_w,zx_tmp_fi2d)
272       ENDIF
273
274       IF (o_SWupSFCclr%flag(iff)<=lev_files(iff)) THEN
275      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 1 )
276      CALL histwrite_phy(nid_files(iff), 
277     $                   o_SWupSFCclr%name,itau_w,zx_tmp_fi2d)
278       ENDIF
279
280       IF (o_SWdnSFC%flag(iff)<=lev_files(iff)) THEN
281      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
282      CALL histwrite_phy(nid_files(iff), 
283     $                   o_SWdnSFC%name,itau_w,zx_tmp_fi2d)
284       ENDIF
285
286       IF (o_SWdnSFCclr%flag(iff)<=lev_files(iff)) THEN
287      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 1 )
288      CALL histwrite_phy(nid_files(iff), 
289     $                  o_SWdnSFCclr%name,itau_w,zx_tmp_fi2d)
290       ENDIF
291
292       IF (o_LWupSFC%flag(iff)<=lev_files(iff)) THEN
293      zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
294      CALL histwrite_phy(nid_files(iff),
295     $                    o_LWupSFC%name,itau_w,zx_tmp_fi2d)
296       ENDIF
297
298       IF (o_LWdnSFC%flag(iff)<=lev_files(iff)) THEN
299      CALL histwrite_phy(nid_files(iff),
300     $                   o_LWdnSFC%name,itau_w,sollwdown)
301       ENDIF
302
303       sollwdownclr(1:klon) = -1.*lwdn0(1:klon,1)
304       IF (o_LWupSFCclr%flag(iff)<=lev_files(iff)) THEN
305      zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
306      CALL histwrite_phy(nid_files(iff),
307     $                   o_LWupSFCclr%name,itau_w,zx_tmp_fi2d)
308       ENDIF
309
310       IF (o_LWdnSFCclr%flag(iff)<=lev_files(iff)) THEN
311      CALL histwrite_phy(nid_files(iff),
312     $                   o_LWdnSFCclr%name,itau_w,sollwdownclr)
313       ENDIF
314
315       IF (o_bils%flag(iff)<=lev_files(iff)) THEN
316      CALL histwrite_phy(nid_files(iff),o_bils%name,itau_w,bils)
317       ENDIF
318
319       IF (o_sens%flag(iff)<=lev_files(iff)) THEN
320      zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
321      CALL histwrite_phy(nid_files(iff),o_sens%name,itau_w,zx_tmp_fi2d)
322       ENDIF
323
324       IF (o_fder%flag(iff)<=lev_files(iff)) THEN
325      CALL histwrite_phy(nid_files(iff),o_fder%name,itau_w,fder)
326       ENDIF
327
328       IF (o_ffonte%flag(iff)<=lev_files(iff)) THEN
329       CALL histwrite_phy(nid_files(iff),o_ffonte%name,itau_w,zxffonte)
330       ENDIF
331
332       IF (o_fqcalving%flag(iff)<=lev_files(iff)) THEN
333       CALL histwrite_phy(nid_files(iff),
334     $                    o_fqcalving%name,itau_w,zxfqcalving)
335       ENDIF
336
337       IF (o_fqfonte%flag(iff)<=lev_files(iff)) THEN
338       CALL histwrite_phy(nid_files(iff),
339     $                   o_fqfonte%name,itau_w,zxfqfonte)
340       ENDIF
341
342       IF (o_taux%flag(iff)<=lev_files(iff)) THEN
343         zx_tmp_fi2d=0.
344         do nsrf=1,nbsrf
345          zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxu(:,1,nsrf)
346         enddo
347         CALL histwrite_phy(nid_files(iff),
348     $                   o_taux%name,itau_w,zx_tmp_fi2d)
349       ENDIF
350
351       IF (o_tauy%flag(iff)<=lev_files(iff)) THEN
352         zx_tmp_fi2d=0.
353         do nsrf=1,nbsrf
354          zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxv(:,1,nsrf)
355         enddo
356         CALL histwrite_phy(nid_files(iff),
357     $                   o_tauy%name,itau_w,zx_tmp_fi2d)
358       ENDIF
359
360         DO nsrf = 1, nbsrf
361!           IF(nsrf.GE.2) THEN
362            IF (o_pourc_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
363            zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
364            CALL histwrite_phy(nid_files(iff),
365     $                     o_pourc_srf(nsrf)%name,itau_w,
366     $                     zx_tmp_fi2d)
367            ENDIF
368
369          IF (o_fract_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
370          zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
371          CALL histwrite_phy(nid_files(iff),
372     $                  o_fract_srf(nsrf)%name,itau_w,
373     $                  zx_tmp_fi2d)
374          ENDIF
375!         ENDIF !nsrf.GT.2
376
377        IF (o_taux_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
378        zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
379        CALL histwrite_phy(nid_files(iff),
380     $                     o_taux_srf(nsrf)%name,itau_w,
381     $                     zx_tmp_fi2d)
382        ENDIF
383
384        IF (o_tauy_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN           
385        zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
386        CALL histwrite_phy(nid_files(iff),
387     $                    o_tauy_srf(nsrf)%name,itau_w,
388     $                    zx_tmp_fi2d)
389        ENDIF
390
391        IF (o_tsol_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
392        zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
393        CALL histwrite_phy(nid_files(iff),
394     $                   o_tsol_srf(nsrf)%name,itau_w,
395     $      zx_tmp_fi2d)
396        ENDIF
397
398      IF (o_u10m_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
399      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, nsrf)
400      CALL histwrite_phy(nid_files(iff),o_u10m_srf(nsrf)%name,
401     $                 itau_w,zx_tmp_fi2d)
402      ENDIF
403
404      IF (o_v10m_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
405      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, nsrf)
406      CALL histwrite_phy(nid_files(iff),o_v10m_srf(nsrf)%name,
407     $              itau_w,zx_tmp_fi2d)
408      ENDIF
409 
410      IF (o_t2m_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
411      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, nsrf)
412      CALL histwrite_phy(nid_files(iff),o_t2m_srf(nsrf)%name,
413     $           itau_w,zx_tmp_fi2d)
414      ENDIF
415
416      IF (o_evap_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
417      zx_tmp_fi2d(1 : klon) = fevap(1 : klon, nsrf)
418      CALL histwrite_phy(nid_files(iff),o_evap_srf(nsrf)%name,
419     $           itau_w,zx_tmp_fi2d)
420      ENDIF
421
422       IF (o_sens_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
423       zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
424       CALL histwrite_phy(nid_files(iff),
425     $                    o_sens_srf(nsrf)%name,itau_w,
426     $      zx_tmp_fi2d)
427       ENDIF
428
429        IF (o_lat_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
430        zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
431        CALL histwrite_phy(nid_files(iff),
432     $                 o_lat_srf(nsrf)%name,itau_w,
433     $                                   zx_tmp_fi2d)
434          ENDIF
435
436        IF (o_flw_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
437        zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
438        CALL histwrite_phy(nid_files(iff),
439     $                     o_flw_srf(nsrf)%name,itau_w,
440     $      zx_tmp_fi2d)
441        ENDIF
442
443        IF (o_fsw_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
444        zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
445        CALL histwrite_phy(nid_files(iff),
446     $                   o_fsw_srf(nsrf)%name,itau_w,
447     $      zx_tmp_fi2d)
448        ENDIF
449
450        IF (o_wbils_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
451        zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
452        CALL histwrite_phy(nid_files(iff),
453     $                   o_wbils_srf(nsrf)%name,itau_w,
454     $      zx_tmp_fi2d)
455        ENDIF
456
457        IF (o_wbilo_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
458        zx_tmp_fi2d(1 : klon) = wfbilo( 1 : klon, nsrf)
459        CALL histwrite_phy(nid_files(iff),
460     $                    o_wbilo_srf(nsrf)%name,itau_w,
461     $      zx_tmp_fi2d)
462        ENDIF
463
464       if (iflag_pbl>1 .and. lev_histday.gt.10 ) then
465        IF (o_tke_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
466        CALL histwrite_phy(nid_files(iff),
467     $                   o_tke_srf(nsrf)%name,itau_w,
468     $                    pbl_tke(:,1:klev,nsrf))
469       ENDIF
470
471        IF (o_tke_max_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
472        CALL histwrite_phy(nid_files(iff),
473     $                    o_tke_max_srf(nsrf)%name,itau_w,
474     $      pbl_tke(:,1:klev,nsrf))
475        ENDIF
476       endif
477      ENDDO
478
479        IF (o_cdrm%flag(iff)<=lev_files(iff)) THEN
480      CALL histwrite_phy(nid_files(iff),o_cdrm%name,itau_w,cdragm)
481        ENDIF
482
483        IF (o_cdrh%flag(iff)<=lev_files(iff)) THEN
484      CALL histwrite_phy(nid_files(iff),o_cdrh%name,itau_w,cdragh)
485        ENDIF
486
487        IF (o_cldl%flag(iff)<=lev_files(iff)) THEN
488      CALL histwrite_phy(nid_files(iff),o_cldl%name,itau_w,cldl)
489        ENDIF
490
491        IF (o_cldm%flag(iff)<=lev_files(iff)) THEN
492      CALL histwrite_phy(nid_files(iff),o_cldm%name,itau_w,cldm)
493        ENDIF
494
495        IF (o_cldh%flag(iff)<=lev_files(iff)) THEN
496      CALL histwrite_phy(nid_files(iff),o_cldh%name,itau_w,cldh)
497        ENDIF
498
499        IF (o_cldt%flag(iff)<=lev_files(iff)) THEN
500      CALL histwrite_phy(nid_files(iff),o_cldt%name, 
501     &                   itau_w,cldt)
502        ENDIF
503
504        IF (o_cldq%flag(iff)<=lev_files(iff)) THEN
505      CALL histwrite_phy(nid_files(iff),o_cldq%name,itau_w,cldq)
506        ENDIF
507
508        IF (o_lwp%flag(iff)<=lev_files(iff)) THEN
509      zx_tmp_fi2d(1:klon) = flwp(1:klon)
510      CALL histwrite_phy(nid_files(iff),
511     s                   o_lwp%name,itau_w,zx_tmp_fi2d)
512        ENDIF
513
514        IF (o_iwp%flag(iff)<=lev_files(iff)) THEN
515      zx_tmp_fi2d(1:klon) = fiwp(1:klon)
516      CALL histwrite_phy(nid_files(iff),
517     s                    o_iwp%name,itau_w,zx_tmp_fi2d)
518        ENDIF
519
520        IF (o_ue%flag(iff)<=lev_files(iff)) THEN
521      CALL histwrite_phy(nid_files(iff),o_ue%name,itau_w,ue)
522        ENDIF
523
524        IF (o_ve%flag(iff)<=lev_files(iff)) THEN
525      CALL histwrite_phy(nid_files(iff),o_ve%name,itau_w,ve)
526        ENDIF
527
528        IF (o_uq%flag(iff)<=lev_files(iff)) THEN
529      CALL histwrite_phy(nid_files(iff),o_uq%name,itau_w,uq)
530        ENDIF
531
532        IF (o_vq%flag(iff)<=lev_files(iff)) THEN
533      CALL histwrite_phy(nid_files(iff),o_vq%name,itau_w,vq)
534        ENDIF
535
536      IF(iflag_con.GE.3) THEN ! sb
537        IF (o_cape%flag(iff)<=lev_files(iff)) THEN
538      CALL histwrite_phy(nid_files(iff),o_cape%name,itau_w,cape)
539        ENDIF
540
541        IF (o_pbase%flag(iff)<=lev_files(iff)) THEN
542      CALL histwrite_phy(nid_files(iff),o_pbase%name,itau_w,ema_pcb)
543        ENDIF
544
545        IF (o_ptop%flag(iff)<=lev_files(iff)) THEN
546      CALL histwrite_phy(nid_files(iff),o_ptop%name,itau_w,ema_pct)
547        ENDIF
548
549        IF (o_fbase%flag(iff)<=lev_files(iff)) THEN
550      CALL histwrite_phy(nid_files(iff),o_fbase%name,itau_w,ema_cbmf)
551        ENDIF
552
553        IF (o_prw%flag(iff)<=lev_files(iff)) THEN
554      CALL histwrite_phy(nid_files(iff),o_prw%name,itau_w,prw)
555        ENDIF
556
557      IF (o_cape_max%flag(iff)<=lev_files(iff)) THEN
558      CALL histwrite_phy(nid_files(iff),o_cape_max%name,itau_w,cape)
559      ENDIF
560
561       IF (o_upwd%flag(iff)<=lev_files(iff)) THEN
562      CALL histwrite_phy(nid_files(iff),o_upwd%name,itau_w,upwd)
563       ENDIF
564
565       IF (o_Ma%flag(iff)<=lev_files(iff)) THEN
566      CALL histwrite_phy(nid_files(iff),o_Ma%name,itau_w,Ma)
567       ENDIF
568
569       IF (o_dnwd%flag(iff)<=lev_files(iff)) THEN
570      CALL histwrite_phy(nid_files(iff),o_dnwd%name,itau_w,dnwd)
571       ENDIF
572
573       IF (o_dnwd0%flag(iff)<=lev_files(iff)) THEN
574      CALL histwrite_phy(nid_files(iff),o_dnwd0%name,itau_w,dnwd0)
575       ENDIF
576
577       IF (o_ftime_con%flag(iff)<=lev_files(iff)) THEN
578        zx_tmp_fi2d=float(itau_con)/float(itap)
579      CALL histwrite_phy(nid_files(iff),o_ftime_con%name,
580     s                   itau_w,zx_tmp_fi2d)
581       ENDIF
582
583       IF (o_mc%flag(iff)<=lev_files(iff)) THEN
584        if(iflag_thermals.gt.1)then
585         zx_tmp_fi3d=dnwd+dnwd0+upwd+fm_therm
586        else
587         zx_tmp_fi3d=dnwd+dnwd0+upwd
588        endif
589      CALL histwrite_phy(nid_files(iff),o_mc%name,itau_w,zx_tmp_fi3d)
590       ENDIF
591     
592      ENDIF !iflag_con .GE. 3
593
594        IF (o_s_pblh%flag(iff)<=lev_files(iff)) THEN
595      CALL histwrite_phy(nid_files(iff),o_s_pblh%name,itau_w,s_pblh)
596        ENDIF
597
598        IF (o_s_pblt%flag(iff)<=lev_files(iff)) THEN
599      CALL histwrite_phy(nid_files(iff),o_s_pblt%name,itau_w,s_pblt)
600        ENDIF
601
602        IF (o_s_lcl%flag(iff)<=lev_files(iff)) THEN
603      CALL histwrite_phy(nid_files(iff),o_s_lcl%name,itau_w,s_lcl)
604        ENDIF
605
606        IF (o_s_therm%flag(iff)<=lev_files(iff)) THEN
607      CALL histwrite_phy(nid_files(iff),o_s_therm%name,itau_w,s_therm)
608        ENDIF
609
610!IM : Les champs suivants (s_capCL, s_oliqCL, s_cteiCL, s_trmb1, s_trmb2, s_trmb3) ne sont pas definis dans HBTM.F
611!       IF (o_s_capCL%flag(iff)<=lev_files(iff)) THEN
612!     CALL histwrite_phy(nid_files(iff),o_s_capCL%name,itau_w,s_capCL)
613!       ENDIF
614
615!       IF (o_s_oliqCL%flag(iff)<=lev_files(iff)) THEN
616!     CALL histwrite_phy(nid_files(iff),o_s_oliqCL%name,itau_w,s_oliqCL)
617!       ENDIF
618
619!       IF (o_s_cteiCL%flag(iff)<=lev_files(iff)) THEN
620!     CALL histwrite_phy(nid_files(iff),o_s_cteiCL%name,itau_w,s_cteiCL)
621!       ENDIF
622
623!       IF (o_s_trmb1%flag(iff)<=lev_files(iff)) THEN
624!     CALL histwrite_phy(nid_files(iff),o_s_trmb1%name,itau_w,s_trmb1)
625!       ENDIF
626
627!       IF (o_s_trmb2%flag(iff)<=lev_files(iff)) THEN
628!     CALL histwrite_phy(nid_files(iff),o_s_trmb2%name,itau_w,s_trmb2)
629!       ENDIF
630
631!       IF (o_s_trmb3%flag(iff)<=lev_files(iff)) THEN
632!     CALL histwrite_phy(nid_files(iff),o_s_trmb3%name,itau_w,s_trmb3)
633!       ENDIF
634
635! Champs interpolles sur des niveaux de pression
636
637        ll=0
638        DO k=1, nlevSTD
639!         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
640!         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
641         bb2=clevSTD(k) 
642         IF(bb2.EQ."850".OR.bb2.EQ."700".OR.
643     $      bb2.EQ."500".OR.bb2.EQ."200".OR.
644     $      bb2.EQ."50".OR.bb2.EQ."10") THEN
645
646! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
647          ll=ll+1
648       IF (o_uSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
649       CALL histwrite_phy(nid_files(iff),o_uSTDlevs(ll)%name,
650     &                    itau_w,uwriteSTD(:,k,iff))
651       ENDIF
652
653       IF (o_vSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
654      CALL histwrite_phy(nid_files(iff),o_vSTDlevs(ll)%name, 
655     &                   itau_w,vwriteSTD(:,k,iff))
656       ENDIF
657
658       IF (o_wSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
659      CALL histwrite_phy(nid_files(iff),o_wSTDlevs(ll)%name,
660     &                    itau_w,wwriteSTD(:,k,iff))
661       ENDIF
662
663       IF (o_zSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
664      CALL histwrite_phy(nid_files(iff),o_zSTDlevs(ll)%name,
665     &               itau_w,phiwriteSTD(:,k,iff))
666       ENDIF
667
668       IF (o_qSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
669      CALL histwrite_phy(nid_files(iff),o_qSTDlevs(ll)%name,
670     &                   itau_w, qwriteSTD(:,k,iff))
671       ENDIF
672
673       IF (o_tSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
674      CALL histwrite_phy(nid_files(iff),o_tSTDlevs(ll)%name,
675     &                   itau_w, twriteSTD(:,k,iff))
676       ENDIF
677
678       ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
679       ENDDO
680
681      IF (o_t_oce_sic%flag(iff)<=lev_files(iff)) THEN
682      DO i=1, klon
683       IF (pctsrf(i,is_oce).GT.epsfra.OR.
684     $     pctsrf(i,is_sic).GT.epsfra) THEN
685        zx_tmp_fi2d(i) = (ftsol(i, is_oce) * pctsrf(i,is_oce)+
686     $                   ftsol(i, is_sic) * pctsrf(i,is_sic))/
687     $                   (pctsrf(i,is_oce)+pctsrf(i,is_sic))
688       ELSE
689        zx_tmp_fi2d(i) = 273.15
690       ENDIF
691      ENDDO
692      CALL histwrite_phy(nid_files(iff),
693     s                   o_t_oce_sic%name,itau_w,zx_tmp_fi2d)
694      ENDIF
695
696! Couplage convection-couche limite
697      IF (iflag_con.GE.3) THEN
698      IF (iflag_coupl>=1) THEN
699       IF (o_ale_bl%flag(iff)<=lev_files(iff)) THEN
700       CALL histwrite_phy(nid_files(iff),o_ale_bl%name,itau_w,ale_bl)
701       ENDIF
702       IF (o_alp_bl%flag(iff)<=lev_files(iff)) THEN
703       CALL histwrite_phy(nid_files(iff),o_alp_bl%name,itau_w,alp_bl)
704       ENDIF
705      ENDIF !iflag_coupl>=1
706      ENDIF !(iflag_con.GE.3)
707
708! Wakes
709      IF (iflag_con.EQ.3) THEN
710      IF (iflag_wake.EQ.1) THEN
711       IF (o_ale_wk%flag(iff)<=lev_files(iff)) THEN
712       CALL histwrite_phy(nid_files(iff),o_ale_wk%name,itau_w,ale_wake)
713       ENDIF
714       IF (o_alp_wk%flag(iff)<=lev_files(iff)) THEN
715       CALL histwrite_phy(nid_files(iff),o_alp_wk%name,itau_w,alp_wake)
716       ENDIF
717
718       IF (o_ale%flag(iff)<=lev_files(iff)) THEN
719       CALL histwrite_phy(nid_files(iff),o_ale%name,itau_w,ale)
720       ENDIF
721       IF (o_alp%flag(iff)<=lev_files(iff)) THEN
722       CALL histwrite_phy(nid_files(iff),o_alp%name,itau_w,alp)
723       ENDIF
724       IF (o_cin%flag(iff)<=lev_files(iff)) THEN
725       CALL histwrite_phy(nid_files(iff),o_cin%name,itau_w,cin)
726       ENDIF
727       IF (o_wape%flag(iff)<=lev_files(iff)) THEN
728       CALL histwrite_phy(nid_files(iff),o_WAPE%name,itau_w,wake_pe)
729       ENDIF
730       IF (o_wake_h%flag(iff)<=lev_files(iff)) THEN
731      CALL histwrite_phy(nid_files(iff),o_wake_h%name,itau_w,wake_h)
732       ENDIF
733
734       IF (o_wake_s%flag(iff)<=lev_files(iff)) THEN
735      CALL histwrite_phy(nid_files(iff),o_wake_s%name,itau_w,wake_s)
736       ENDIF
737
738        IF (o_wake_deltat%flag(iff)<=lev_files(iff)) THEN
739       CALL histwrite_phy(nid_files(iff),o_wake_deltat%name,
740     $                     itau_w,wake_deltat)
741        ENDIF
742
743        IF (o_wake_deltaq%flag(iff)<=lev_files(iff)) THEN
744       CALL histwrite_phy(nid_files(iff),o_wake_deltaq%name,
745     $                    itau_w,wake_deltaq)
746        ENDIF
747
748        IF (o_wake_omg%flag(iff)<=lev_files(iff)) THEN
749       CALL histwrite_phy(nid_files(iff),
750     s                    o_wake_omg%name,itau_w,wake_omg)
751        ENDIF
752
753         IF (o_dtwak%flag(iff)<=lev_files(iff)) THEN
754           zx_tmp_fi3d(1:klon,1:klev)=d_t_wake(1:klon,1:klev)
755     &                                        /pdtphys
756           CALL histwrite_phy(nid_files(iff),
757     &                       o_dtwak%name,itau_w,zx_tmp_fi3d)
758         ENDIF
759
760        IF (o_dqwak%flag(iff)<=lev_files(iff)) THEN
761        zx_tmp_fi3d(1:klon,1:klev)=d_q_wake(1:klon,1:klev)/pdtphys
762        CALL histwrite_phy(nid_files(iff),
763     &                     o_dqwak%name,itau_w,zx_tmp_fi3d)
764        ENDIF
765      ENDIF ! iflag_wake.EQ.1
766
767        IF (o_Vprecip%flag(iff)<=lev_files(iff)) THEN
768       CALL histwrite_phy(nid_files(iff),o_Vprecip%name,itau_w,Vprecip)
769        ENDIF
770
771        IF (o_ftd%flag(iff)<=lev_files(iff)) THEN
772       CALL histwrite_phy(nid_files(iff),o_ftd%name,itau_w,ftd)
773        ENDIF
774
775        IF (o_fqd%flag(iff)<=lev_files(iff)) THEN
776       CALL histwrite_phy(nid_files(iff),o_fqd%name,itau_w,fqd)
777        ENDIF
778      ENDIF !(iflag_con.EQ.3) 
779 
780      IF (type_ocean=='slab ') THEN
781      IF ( o_slab_bils%flag(iff)<=lev_files(iff)) 
782     $     CALL histwrite_phy(
783     $     nid_files(iff),o_slab_bils%name,itau_w,slab_wfbils)
784
785      ENDIF !type_ocean == force/slab
786
787      IF (o_weakinv%flag(iff)<=lev_files(iff)) THEN
788      CALL histwrite_phy(nid_files(iff),
789     s                  o_weakinv%name,itau_w,weak_inversion)
790      ENDIF
791
792      IF (o_dthmin%flag(iff)<=lev_files(iff)) THEN
793      CALL histwrite_phy(nid_files(iff),o_dthmin%name,itau_w,dthmin)
794      ENDIF
795
796       IF (o_cldtau%flag(iff)<=lev_files(iff)) THEN
797       CALL histwrite_phy(nid_files(iff),o_cldtau%name,itau_w,cldtau)
798       ENDIF
799
800       IF (o_cldemi%flag(iff)<=lev_files(iff)) THEN
801       CALL histwrite_phy(nid_files(iff),o_cldemi%name,itau_w,cldemi)
802       ENDIF
803
804      IF (o_pr_con_l%flag(iff)<=lev_files(iff)) THEN
805      CALL histwrite_phy(nid_files(iff),
806     s         o_pr_con_l%name,itau_w,pmflxr(:,1:klev))
807      ENDIF
808
809      IF (o_pr_con_i%flag(iff)<=lev_files(iff)) THEN
810      CALL histwrite_phy(nid_files(iff),
811     s         o_pr_con_i%name,itau_w,pmflxs(:,1:klev))
812      ENDIF
813
814      IF (o_pr_lsc_l%flag(iff)<=lev_files(iff)) THEN
815      CALL histwrite_phy(nid_files(iff),
816     s        o_pr_lsc_l%name,itau_w,prfl(:,1:klev))
817      ENDIF
818
819      IF (o_pr_lsc_i%flag(iff)<=lev_files(iff)) THEN
820      CALL histwrite_phy(nid_files(iff),
821     s        o_pr_lsc_i%name,itau_w,psfl(:,1:klev))
822      ENDIF
823
824      IF (o_re%flag(iff)<=lev_files(iff)) THEN
825      CALL histwrite_phy(nid_files(iff),o_re%name,itau_w,re)
826      ENDIF
827
828      IF (o_fl%flag(iff)<=lev_files(iff)) THEN
829      CALL histwrite_phy(nid_files(iff),o_fl%name,itau_w,fl)
830      ENDIF
831
832
833
834      IF (o_rh2m%flag(iff)<=lev_files(iff)) THEN
835      DO i=1, klon
836       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
837      ENDDO
838      CALL histwrite_phy(nid_files(iff),o_rh2m%name,itau_w,zx_tmp_fi2d)
839      ENDIF
840
841      IF (o_rh2m_min%flag(iff)<=lev_files(iff)) THEN
842      DO i=1, klon
843       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
844      ENDDO
845      CALL histwrite_phy(nid_files(iff),o_rh2m_min%name,
846     s               itau_w,zx_tmp_fi2d)
847      ENDIF
848
849      IF (o_rh2m_max%flag(iff)<=lev_files(iff)) THEN
850      DO i=1, klon
851       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
852      ENDDO
853      CALL histwrite_phy(nid_files(iff),o_rh2m_max%name,
854     s              itau_w,zx_tmp_fi2d)
855      ENDIF
856
857
858      IF (o_qsat2m%flag(iff)<=lev_files(iff)) THEN
859      CALL histwrite_phy(nid_files(iff),o_qsat2m%name,itau_w,qsat2m)
860      ENDIF
861
862      IF (o_tpot%flag(iff)<=lev_files(iff)) THEN
863      CALL histwrite_phy(nid_files(iff),o_tpot%name,itau_w,tpot)
864      ENDIF
865
866       IF (o_tpote%flag(iff)<=lev_files(iff)) THEN
867      CALL histwrite_phy(nid_files(iff),o_tpote%name,itau_w,tpote)
868       ENDIF
869
870      IF (o_SWnetOR%flag(iff)<=lev_files(iff)) THEN
871      zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, is_ter)
872      CALL histwrite_phy(nid_files(iff),
873     s                   o_SWnetOR%name,itau_w, zx_tmp_fi2d)
874      ENDIF
875
876      IF (o_SWdownOR%flag(iff)<=lev_files(iff)) THEN
877      zx_tmp_fi2d(1:klon) = solsw(1:klon)/(1.-albsol1(1:klon))
878      CALL histwrite_phy(nid_files(iff),
879     s                   o_SWdownOR%name,itau_w, zx_tmp_fi2d)
880      ENDIF
881
882      IF (o_LWdownOR%flag(iff)<=lev_files(iff)) THEN
883      CALL histwrite_phy(nid_files(iff),
884     s                  o_LWdownOR%name,itau_w,sollwdown)
885      ENDIF
886
887      IF (o_snowl%flag(iff)<=lev_files(iff)) THEN
888      CALL histwrite_phy(nid_files(iff),o_snowl%name,itau_w,snow_lsc)
889      ENDIF
890
891      IF (o_solldown%flag(iff)<=lev_files(iff)) THEN
892      CALL histwrite_phy(nid_files(iff),
893     s                   o_solldown%name,itau_w,sollwdown)
894      ENDIF
895
896      IF (o_dtsvdfo%flag(iff)<=lev_files(iff)) THEN
897      CALL histwrite_phy(nid_files(iff),
898     s                 o_dtsvdfo%name,itau_w,d_ts(:,is_oce))
899      ENDIF
900
901      IF (o_dtsvdft%flag(iff)<=lev_files(iff)) THEN
902      CALL histwrite_phy(nid_files(iff),
903     s                   o_dtsvdft%name,itau_w,d_ts(:,is_ter))
904      ENDIF
905
906       IF (o_dtsvdfg%flag(iff)<=lev_files(iff)) THEN
907        CALL histwrite_phy(nid_files(iff),
908     $                   o_dtsvdfg%name,itau_w, d_ts(:,is_lic))
909       ENDIF
910
911       IF (o_dtsvdfi%flag(iff)<=lev_files(iff)) THEN
912      CALL histwrite_phy(nid_files(iff),
913     s                   o_dtsvdfi%name,itau_w,d_ts(:,is_sic))
914       ENDIF
915
916       IF (o_rugs%flag(iff)<=lev_files(iff)) THEN
917      CALL histwrite_phy(nid_files(iff),o_rugs%name,itau_w,zxrugs)
918       ENDIF
919
920! OD550 per species
921      IF (new_aod .and. (.not. aerosol_couple)) THEN
922          IF (ok_ade.OR.ok_aie) THEN
923
924          IF (o_od550aer%flag(iff)<=lev_files(iff)) THEN
925             CALL histwrite_phy(nid_files(iff),o_od550aer%name,itau_w,
926     $            od550aer)
927          ENDIF
928          IF (o_od865aer%flag(iff)<=lev_files(iff)) THEN
929             CALL histwrite_phy(nid_files(iff),o_od865aer%name,itau_w,
930     $            od865aer)
931          ENDIF
932          IF (o_absvisaer%flag(iff)<=lev_files(iff)) THEN
933             CALL histwrite_phy(nid_files(iff),o_absvisaer%name,itau_w,
934     $            absvisaer)
935          ENDIF
936          IF (o_od550lt1aer%flag(iff)<=lev_files(iff)) THEN
937            CALL histwrite_phy(nid_files(iff),o_od550lt1aer%name,itau_w,
938     $            od550lt1aer)
939          ENDIF
940
941          IF (o_sconcso4%flag(iff)<=lev_files(iff)) THEN
942              CALL histwrite_phy(nid_files(iff),o_sconcso4%name,itau_w,
943     $            sconcso4)
944          ENDIF
945          IF (o_sconcoa%flag(iff)<=lev_files(iff)) THEN
946              CALL histwrite_phy(nid_files(iff),o_sconcoa%name,itau_w,
947     $            sconcoa)
948          ENDIF
949          IF (o_sconcbc%flag(iff)<=lev_files(iff)) THEN
950              CALL histwrite_phy(nid_files(iff),o_sconcbc%name,itau_w,
951     $            sconcbc)
952          ENDIF
953          IF (o_sconcss%flag(iff)<=lev_files(iff)) THEN
954              CALL histwrite_phy(nid_files(iff),o_sconcss%name,itau_w,
955     $            sconcss)
956          ENDIF
957          IF (o_sconcdust%flag(iff)<=lev_files(iff)) THEN
958              CALL histwrite_phy(nid_files(iff),o_sconcdust%name,itau_w,
959     $            sconcdust)
960          ENDIF
961         
962          IF (o_concso4%flag(iff)<=lev_files(iff)) THEN
963              CALL histwrite_phy(nid_files(iff),o_concso4%name,itau_w,
964     $            concso4)
965          ENDIF
966          IF (o_concoa%flag(iff)<=lev_files(iff)) THEN
967              CALL histwrite_phy(nid_files(iff),o_concoa%name,itau_w,
968     $            concoa)
969          ENDIF
970          IF (o_concbc%flag(iff)<=lev_files(iff)) THEN
971              CALL histwrite_phy(nid_files(iff),o_concbc%name,itau_w,
972     $            concbc)
973          ENDIF
974          IF (o_concss%flag(iff)<=lev_files(iff)) THEN
975              CALL histwrite_phy(nid_files(iff),o_concss%name,itau_w,
976     $            concss)
977          ENDIF
978          IF (o_concdust%flag(iff)<=lev_files(iff)) THEN
979              CALL histwrite_phy(nid_files(iff),o_concdust%name,itau_w,
980     $            concdust)
981          ENDIF
982         
983          IF (o_loadso4%flag(iff)<=lev_files(iff)) THEN
984              CALL histwrite_phy(nid_files(iff),o_loadso4%name,itau_w,
985     $            loadso4)
986          ENDIF
987          IF (o_loadoa%flag(iff)<=lev_files(iff)) THEN
988              CALL histwrite_phy(nid_files(iff),o_loadoa%name,itau_w,
989     $            loadoa)
990          ENDIF
991          IF (o_loadbc%flag(iff)<=lev_files(iff)) THEN
992              CALL histwrite_phy(nid_files(iff),o_loadbc%name,itau_w,
993     $            loadbc)
994          ENDIF
995          IF (o_loadss%flag(iff)<=lev_files(iff)) THEN
996              CALL histwrite_phy(nid_files(iff),o_loadss%name,itau_w,
997     $            loadss)
998          ENDIF
999          IF (o_loaddust%flag(iff)<=lev_files(iff)) THEN
1000              CALL histwrite_phy(nid_files(iff),o_loaddust%name,itau_w,
1001     $            loaddust)
1002          ENDIF
1003         
1004          DO naero = 1, naero_spc
1005            IF (o_tausumaero(naero)%flag(iff)<=lev_files(iff)) THEN
1006                CALL histwrite_phy(nid_files(iff),
1007     $              o_tausumaero(naero)%name,itau_w,
1008     $              tausum_aero(:,2,naero) )
1009            ENDIF
1010          END DO
1011          endif
1012      ENDIF
1013     
1014       IF (ok_ade) THEN
1015          IF (o_topswad%flag(iff)<=lev_files(iff)) THEN
1016             CALL histwrite_phy(nid_files(iff),o_topswad%name,itau_w,
1017     $            topswad_aero)
1018          ENDIF
1019          IF (o_solswad%flag(iff)<=lev_files(iff)) THEN
1020             CALL histwrite_phy(nid_files(iff),o_solswad%name,itau_w,
1021     $            solswad_aero)
1022          ENDIF
1023
1024!====MS forcing diagnostics
1025        if (new_aod) then             
1026        IF (o_swtoaas_nat%flag(iff)<=lev_files(iff)) THEN
1027        CALL histwrite_phy(nid_files(iff),o_swtoaas_nat%name,itau_w,
1028     $      topsw_aero(:,1))
1029        ENDIF
1030
1031        IF (o_swsrfas_nat%flag(iff)<=lev_files(iff)) THEN
1032        CALL histwrite_phy(nid_files(iff),o_swsrfas_nat%name,itau_w,
1033     $      solsw_aero(:,1))
1034        ENDIF
1035
1036        IF (o_swtoacs_nat%flag(iff)<=lev_files(iff)) THEN
1037        CALL histwrite_phy(nid_files(iff),o_swtoacs_nat%name,itau_w,
1038     $      topsw0_aero(:,1))
1039        ENDIF
1040
1041        IF (o_swsrfcs_nat%flag(iff)<=lev_files(iff)) THEN
1042        CALL histwrite_phy(nid_files(iff),o_swsrfcs_nat%name,itau_w,
1043     $      solsw0_aero(:,1))
1044        ENDIF
1045 
1046!ant
1047        IF (o_swtoaas_ant%flag(iff)<=lev_files(iff)) THEN
1048        CALL histwrite_phy(nid_files(iff),o_swtoaas_ant%name,itau_w,
1049     $      topsw_aero(:,2))
1050        ENDIF
1051
1052        IF (o_swsrfas_ant%flag(iff)<=lev_files(iff)) THEN
1053        CALL histwrite_phy(nid_files(iff),o_swsrfas_ant%name,itau_w,
1054     $      solsw_aero(:,2))
1055        ENDIF
1056
1057        IF (o_swtoacs_ant%flag(iff)<=lev_files(iff)) THEN
1058        CALL histwrite_phy(nid_files(iff),o_swtoacs_ant%name,itau_w,
1059     $      topsw0_aero(:,2))
1060        ENDIF
1061
1062        IF (o_swsrfcs_ant%flag(iff)<=lev_files(iff)) THEN
1063        CALL histwrite_phy(nid_files(iff),o_swsrfcs_ant%name,itau_w,
1064     $      solsw0_aero(:,2))
1065        ENDIF
1066
1067!cf
1068
1069        if (.not. aerosol_couple) then
1070        IF (o_swtoacf_nat%flag(iff)<=lev_files(iff)) THEN
1071        CALL histwrite_phy(nid_files(iff),o_swtoacf_nat%name,itau_w,
1072     $      topswcf_aero(:,1))
1073        ENDIF
1074
1075        IF (o_swsrfcf_nat%flag(iff)<=lev_files(iff)) THEN
1076        CALL histwrite_phy(nid_files(iff),o_swsrfcf_nat%name,itau_w,
1077     $      solswcf_aero(:,1))
1078        ENDIF
1079
1080        IF (o_swtoacf_ant%flag(iff)<=lev_files(iff)) THEN
1081        CALL histwrite_phy(nid_files(iff),o_swtoacf_ant%name,itau_w,
1082     $      topswcf_aero(:,2))
1083        ENDIF
1084
1085        IF (o_swsrfcf_ant%flag(iff)<=lev_files(iff)) THEN
1086        CALL histwrite_phy(nid_files(iff),o_swsrfcf_ant%name,itau_w,
1087     $      solswcf_aero(:,2))
1088        ENDIF
1089
1090        IF (o_swtoacf_zero%flag(iff)<=lev_files(iff)) THEN
1091        CALL histwrite_phy(nid_files(iff),o_swtoacf_zero%name,itau_w,
1092     $      topswcf_aero(:,3))
1093        ENDIF
1094
1095        IF (o_swsrfcf_zero%flag(iff)<=lev_files(iff)) THEN
1096        CALL histwrite_phy(nid_files(iff),o_swsrfcf_zero%name,itau_w,
1097     $      solswcf_aero(:,3))
1098        ENDIF
1099        endif
1100
1101        endif ! new_aod
1102!====MS forcing diagnostics
1103
1104       ENDIF
1105
1106       IF (ok_aie) THEN
1107          IF (o_topswai%flag(iff)<=lev_files(iff)) THEN
1108             CALL histwrite_phy(nid_files(iff),o_topswai%name,itau_w,
1109     $            topswai_aero)
1110          ENDIF
1111          IF (o_solswai%flag(iff)<=lev_files(iff)) THEN
1112             CALL histwrite_phy(nid_files(iff),o_solswai%name,itau_w,
1113     $            solswai_aero)
1114          ENDIF
1115          IF (o_scdnc%flag(iff)<=lev_files(iff)) THEN
1116             CALL histwrite_phy(nid_files(iff),o_scdnc%name,itau_w,
1117     $            scdnc)
1118          ENDIF
1119          IF (o_cldncl%flag(iff)<=lev_files(iff)) THEN
1120             CALL histwrite_phy(nid_files(iff),o_cldncl%name,itau_w,
1121     $            cldncl)
1122          ENDIF
1123          IF (o_reffclws%flag(iff)<=lev_files(iff)) THEN
1124             CALL histwrite_phy(nid_files(iff),o_reffclws%name,itau_w,
1125     $            reffclws)
1126          ENDIF
1127          IF (o_reffclwc%flag(iff)<=lev_files(iff)) THEN
1128             CALL histwrite_phy(nid_files(iff),o_reffclwc%name,itau_w,
1129     $            reffclwc)
1130          ENDIF
1131          IF (o_cldnvi%flag(iff)<=lev_files(iff)) THEN
1132             CALL histwrite_phy(nid_files(iff),o_cldnvi%name,itau_w,
1133     $            cldnvi)
1134          ENDIF
1135          IF (o_lcc%flag(iff)<=lev_files(iff)) THEN
1136             CALL histwrite_phy(nid_files(iff),o_lcc%name,itau_w,
1137     $            lcc)
1138          ENDIF
1139          IF (o_lcc3d%flag(iff)<=lev_files(iff)) THEN
1140             CALL histwrite_phy(nid_files(iff),o_lcc3d%name,itau_w,
1141     $            lcc3d)
1142          ENDIF
1143          IF (o_lcc3dcon%flag(iff)<=lev_files(iff)) THEN
1144             CALL histwrite_phy(nid_files(iff),o_lcc3dcon%name,itau_w,
1145     $            lcc3dcon)
1146          ENDIF
1147          IF (o_lcc3dstra%flag(iff)<=lev_files(iff)) THEN
1148             CALL histwrite_phy(nid_files(iff),o_lcc3dstra%name,itau_w,
1149     $            lcc3dstra)
1150          ENDIF
1151          IF (o_reffclwtop%flag(iff)<=lev_files(iff)) THEN
1152             CALL histwrite_phy(nid_files(iff),o_reffclwtop%name,itau_w,
1153     $            reffclwtop)
1154          ENDIF
1155       ENDIF
1156
1157! Champs 3D:
1158       IF (ok_ade .OR. ok_aie) then
1159          IF (o_ec550aer%flag(iff)<=lev_files(iff)) THEN
1160             CALL histwrite_phy(nid_files(iff),o_ec550aer%name,itau_w,
1161     &            ec550aer)
1162          ENDIF
1163       ENDIF
1164
1165       IF (o_lwcon%flag(iff)<=lev_files(iff)) THEN
1166      CALL histwrite_phy(nid_files(iff),o_lwcon%name,itau_w,flwc)
1167       ENDIF
1168
1169       IF (o_iwcon%flag(iff)<=lev_files(iff)) THEN
1170      CALL histwrite_phy(nid_files(iff),o_iwcon%name,itau_w,fiwc)
1171       ENDIF
1172
1173       IF (o_temp%flag(iff)<=lev_files(iff)) THEN
1174      CALL histwrite_phy(nid_files(iff),o_temp%name,itau_w,t_seri)
1175       ENDIF
1176
1177       IF (o_theta%flag(iff)<=lev_files(iff)) THEN
1178      CALL histwrite_phy(nid_files(iff),o_theta%name,itau_w,theta)
1179       ENDIF
1180
1181       IF (o_ovapinit%flag(iff)<=lev_files(iff)) THEN
1182      CALL histwrite_phy(nid_files(iff),o_ovapinit%name,itau_w,
1183     $ qx(:,:,ivap))
1184       ENDIF
1185
1186       IF (o_ovap%flag(iff)<=lev_files(iff)) THEN
1187      CALL histwrite_phy(nid_files(iff),
1188     $                   o_ovap%name,itau_w,q_seri)
1189       ENDIF
1190
1191       IF (o_geop%flag(iff)<=lev_files(iff)) THEN
1192      CALL histwrite_phy(nid_files(iff),o_geop%name,itau_w,zphi)
1193       ENDIF
1194
1195       IF (o_vitu%flag(iff)<=lev_files(iff)) THEN
1196      CALL histwrite_phy(nid_files(iff),o_vitu%name,itau_w,u_seri)
1197       ENDIF
1198
1199       IF (o_vitv%flag(iff)<=lev_files(iff)) THEN
1200      CALL histwrite_phy(nid_files(iff),o_vitv%name,itau_w,v_seri)
1201       ENDIF
1202
1203       IF (o_vitw%flag(iff)<=lev_files(iff)) THEN
1204      CALL histwrite_phy(nid_files(iff),o_vitw%name,itau_w,omega)
1205       ENDIF
1206
1207        IF (o_pres%flag(iff)<=lev_files(iff)) THEN
1208      CALL histwrite_phy(nid_files(iff),o_pres%name,itau_w,pplay)
1209        ENDIF
1210
1211        IF (o_paprs%flag(iff)<=lev_files(iff)) THEN
1212      CALL histwrite_phy(nid_files(iff),o_paprs%name,
1213     s                    itau_w,paprs(:,1:klev))
1214        ENDIF
1215
1216       IF (o_rneb%flag(iff)<=lev_files(iff)) THEN
1217      CALL histwrite_phy(nid_files(iff),o_rneb%name,itau_w,cldfra)
1218       ENDIF
1219
1220       IF (o_rnebcon%flag(iff)<=lev_files(iff)) THEN
1221      CALL histwrite_phy(nid_files(iff),o_rnebcon%name,itau_w,rnebcon)
1222       ENDIF
1223
1224       IF (o_rhum%flag(iff)<=lev_files(iff)) THEN
1225      CALL histwrite_phy(nid_files(iff),o_rhum%name,itau_w,zx_rh)
1226       ENDIF
1227
1228      IF (o_ozone%flag(iff)<=lev_files(iff)) THEN
1229         CALL histwrite_phy(nid_files(iff), o_ozone%name, itau_w,
1230     $        wo(:, :, 1) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
1231      ENDIF
1232
1233      IF (o_ozone_light%flag(iff)<=lev_files(iff) .and.
1234     $     read_climoz == 2) THEN
1235         CALL histwrite_phy(nid_files(iff), o_ozone_light%name, itau_w,
1236     $        wo(:, :, 2) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
1237      ENDIF
1238
1239       IF (o_dtphy%flag(iff)<=lev_files(iff)) THEN
1240      CALL histwrite_phy(nid_files(iff),o_dtphy%name,itau_w,d_t)
1241       ENDIF
1242
1243       IF (o_dqphy%flag(iff)<=lev_files(iff)) THEN
1244      CALL histwrite_phy(nid_files(iff),
1245     s                  o_dqphy%name,itau_w, d_qx(:,:,ivap))
1246       ENDIF
1247
1248        DO nsrf=1, nbsrf
1249        IF (o_albe_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
1250        zx_tmp_fi2d(1 : klon) = falb1( 1 : klon, nsrf)
1251        CALL histwrite_phy(nid_files(iff),
1252     s                    o_albe_srf(nsrf)%name,itau_w,
1253     $                     zx_tmp_fi2d)
1254        ENDIF
1255
1256        IF (o_rugs_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN 
1257        zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
1258        CALL histwrite_phy(nid_files(iff),
1259     s                     o_rugs_srf(nsrf)%name,itau_w,
1260     $      zx_tmp_fi2d)
1261        ENDIF
1262
1263        IF (o_ages_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
1264        zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
1265        CALL histwrite_phy(nid_files(iff),
1266     s                     o_ages_srf(nsrf)%name,itau_w
1267     $    ,zx_tmp_fi2d)
1268        ENDIF
1269        ENDDO !nsrf=1, nbsrf
1270
1271       IF (o_alb1%flag(iff)<=lev_files(iff)) THEN
1272      CALL histwrite_phy(nid_files(iff),o_alb1%name,itau_w,albsol1)
1273       ENDIF
1274
1275       IF (o_alb2%flag(iff)<=lev_files(iff)) THEN
1276      CALL histwrite_phy(nid_files(iff),o_alb2%name,itau_w,albsol2)
1277       ENDIF
1278
1279!FH Sorties pour la couche limite
1280      if (iflag_pbl>1) then
1281      zx_tmp_fi3d=0.
1282      do nsrf=1,nbsrf
1283         do k=1,klev
1284          zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k)
1285     $    +pctsrf(:,nsrf)*pbl_tke(:,k,nsrf)
1286         enddo
1287      enddo
1288       IF (o_tke%flag(iff)<=lev_files(iff)) THEN
1289      CALL histwrite_phy(nid_files(iff),o_tke%name,itau_w,zx_tmp_fi3d)
1290       ENDIF
1291
1292       IF (o_tke_max%flag(iff)<=lev_files(iff)) THEN
1293      CALL histwrite_phy(nid_files(iff),
1294     s                   o_tke_max%name,itau_w,zx_tmp_fi3d)
1295       ENDIF
1296      endif
1297
1298       IF (o_kz%flag(iff)<=lev_files(iff)) THEN
1299      CALL histwrite_phy(nid_files(iff),o_kz%name,itau_w,coefh)
1300       ENDIF
1301
1302       IF (o_kz_max%flag(iff)<=lev_files(iff)) THEN
1303      CALL histwrite_phy(nid_files(iff),o_kz_max%name,itau_w,coefh)
1304       ENDIF
1305
1306       IF (o_clwcon%flag(iff)<=lev_files(iff)) THEN
1307      CALL histwrite_phy(nid_files(iff),o_clwcon%name,itau_w,clwcon0)
1308       ENDIF
1309
1310       IF (o_dtdyn%flag(iff)<=lev_files(iff)) THEN
1311      CALL histwrite_phy(nid_files(iff),o_dtdyn%name,itau_w,d_t_dyn)
1312       ENDIF
1313
1314       IF (o_dqdyn%flag(iff)<=lev_files(iff)) THEN
1315      CALL histwrite_phy(nid_files(iff),o_dqdyn%name,itau_w,d_q_dyn)
1316       ENDIF
1317
1318       IF (o_dudyn%flag(iff)<=lev_files(iff)) THEN
1319      CALL histwrite_phy(nid_files(iff),o_dudyn%name,itau_w,d_u_dyn)
1320       ENDIF                                                   
1321
1322       IF (o_dvdyn%flag(iff)<=lev_files(iff)) THEN                 
1323      CALL histwrite_phy(nid_files(iff),o_dvdyn%name,itau_w,d_v_dyn) 
1324       ENDIF                                                     
1325
1326       IF (o_dtcon%flag(iff)<=lev_files(iff)) THEN
1327      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys
1328      CALL histwrite_phy(nid_files(iff),o_dtcon%name,itau_w,zx_tmp_fi3d)
1329       ENDIF
1330
1331       IF (o_ducon%flag(iff)<=lev_files(iff)) THEN
1332      zx_tmp_fi3d(1:klon,1:klev)=d_u_con(1:klon,1:klev)/pdtphys
1333      CALL histwrite_phy(nid_files(iff),o_ducon%name,itau_w,zx_tmp_fi3d)
1334       ENDIF
1335
1336       IF (o_dqcon%flag(iff)<=lev_files(iff)) THEN
1337      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
1338      CALL histwrite_phy(nid_files(iff),o_dqcon%name,itau_w,zx_tmp_fi3d)
1339       ENDIF
1340
1341       IF (o_dtlsc%flag(iff)<=lev_files(iff)) THEN
1342      zx_tmp_fi3d(1:klon,1:klev)=d_t_lsc(1:klon,1:klev)/pdtphys
1343      CALL histwrite_phy(nid_files(iff),o_dtlsc%name,itau_w,zx_tmp_fi3d)
1344       ENDIF
1345
1346       IF (o_dtlschr%flag(iff)<=lev_files(iff)) THEN
1347      zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+
1348     $                           d_t_eva(1:klon,1:klev))/pdtphys
1349      CALL histwrite_phy(nid_files(iff),
1350     s                   o_dtlschr%name,itau_w,zx_tmp_fi3d)
1351       ENDIF
1352
1353       IF (o_dqlsc%flag(iff)<=lev_files(iff)) THEN
1354      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
1355      CALL histwrite_phy(nid_files(iff),o_dqlsc%name,itau_w,zx_tmp_fi3d)
1356       ENDIF
1357
1358       IF (o_dtvdf%flag(iff)<=lev_files(iff)) THEN
1359      zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
1360      CALL histwrite_phy(nid_files(iff),o_dtvdf%name,itau_w,zx_tmp_fi3d)
1361       ENDIF
1362
1363       IF (o_dqvdf%flag(iff)<=lev_files(iff)) THEN
1364      zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
1365      CALL histwrite_phy(nid_files(iff),o_dqvdf%name,itau_w,zx_tmp_fi3d)
1366       ENDIF
1367
1368       IF (o_dteva%flag(iff)<=lev_files(iff)) THEN
1369      zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
1370      CALL histwrite_phy(nid_files(iff),o_dteva%name,itau_w,zx_tmp_fi3d)
1371       ENDIF
1372
1373       IF (o_dqeva%flag(iff)<=lev_files(iff)) THEN
1374      zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
1375      CALL histwrite_phy(nid_files(iff),o_dqeva%name,itau_w,zx_tmp_fi3d)
1376       ENDIF
1377
1378       IF (o_ptconv%flag(iff)<=lev_files(iff)) THEN
1379      zpt_conv = 0.
1380      where (ptconv) zpt_conv = 1.
1381      CALL histwrite_phy(nid_files(iff),o_ptconv%name,itau_w,zpt_conv)
1382       ENDIF
1383
1384       IF (o_ratqs%flag(iff)<=lev_files(iff)) THEN
1385      CALL histwrite_phy(nid_files(iff),o_ratqs%name,itau_w,ratqs)
1386       ENDIF
1387
1388       IF (o_dtthe%flag(iff)<=lev_files(iff)) THEN
1389      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajs(1:klon,1:klev)/pdtphys
1390      CALL histwrite_phy(nid_files(iff),o_dtthe%name,itau_w,zx_tmp_fi3d)
1391       ENDIF
1392
1393       IF (iflag_thermals.gt.1) THEN
1394        IF (o_ftime_th%flag(iff)<=lev_files(iff)) THEN
1395! Pour l instant 0 a y reflichir pour les thermiques
1396         zx_tmp_fi2d=0. 
1397        CALL histwrite_phy(nid_files(iff),o_ftime_th%name,
1398     s                     itau_w,zx_tmp_fi2d)
1399        ENDIF
1400
1401        IF (o_f_th%flag(iff)<=lev_files(iff)) THEN
1402        CALL histwrite_phy(nid_files(iff),o_f_th%name,itau_w,fm_therm)
1403        ENDIF
1404
1405        IF (o_e_th%flag(iff)<=lev_files(iff)) THEN
1406        CALL histwrite_phy(nid_files(iff),o_e_th%name,itau_w,entr_therm)
1407        ENDIF
1408
1409        IF (o_w_th%flag(iff)<=lev_files(iff)) THEN
1410        CALL histwrite_phy(nid_files(iff),o_w_th%name,itau_w,zw2)
1411        ENDIF
1412
1413        IF (o_q_th%flag(iff)<=lev_files(iff)) THEN
1414        CALL histwrite_phy(nid_files(iff),o_q_th%name,itau_w,zqasc)
1415        ENDIF
1416
1417        IF (o_lambda_th%flag(iff)<=lev_files(iff)) THEN
1418        CALL histwrite_phy(nid_files(iff),
1419     s                     o_lambda_th%name,itau_w,lambda_th)
1420        ENDIF
1421
1422        IF (o_a_th%flag(iff)<=lev_files(iff)) THEN
1423        CALL histwrite_phy(nid_files(iff),o_a_th%name,itau_w,fraca)
1424        ENDIF
1425
1426       IF (o_d_th%flag(iff)<=lev_files(iff)) THEN
1427       CALL histwrite_phy(nid_files(iff),o_d_th%name,itau_w,detr_therm)
1428       ENDIF
1429
1430
1431       IF (o_f0_th%flag(iff)<=lev_files(iff)) THEN
1432      CALL histwrite_phy(nid_files(iff),o_f0_th%name,itau_w,f0)
1433       ENDIF
1434
1435       IF (o_f0_th%flag(iff)<=lev_files(iff)) THEN
1436      CALL histwrite_phy(nid_files(iff),o_zmax_th%name,itau_w,zmax0)
1437       ENDIF
1438
1439       IF (o_dqthe%flag(iff)<=lev_files(iff)) THEN
1440      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys
1441      CALL histwrite_phy(nid_files(iff),o_dqthe%name,itau_w,zx_tmp_fi3d)
1442       ENDIF
1443
1444      ENDIF !iflag_thermals
1445
1446       IF (o_dtajs%flag(iff)<=lev_files(iff)) THEN
1447      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajsb(1:klon,1:klev)/pdtphys
1448      CALL histwrite_phy(nid_files(iff),o_dtajs%name,itau_w,zx_tmp_fi3d)
1449       ENDIF
1450
1451       IF (o_dqajs%flag(iff)<=lev_files(iff)) THEN
1452      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
1453      CALL histwrite_phy(nid_files(iff),o_dqajs%name,itau_w,zx_tmp_fi3d)
1454       ENDIF
1455
1456       IF (o_dtswr%flag(iff)<=lev_files(iff)) THEN
1457      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY
1458      CALL histwrite_phy(nid_files(iff),o_dtswr%name,itau_w,zx_tmp_fi3d)
1459       ENDIF
1460
1461       IF (o_dtsw0%flag(iff)<=lev_files(iff)) THEN
1462      zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
1463      CALL histwrite_phy(nid_files(iff),o_dtsw0%name,itau_w,zx_tmp_fi3d)
1464       ENDIF
1465
1466       IF (o_dtlwr%flag(iff)<=lev_files(iff)) THEN
1467      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
1468      CALL histwrite_phy(nid_files(iff),o_dtlwr%name,itau_w,zx_tmp_fi3d)
1469       ENDIF
1470
1471       IF (o_dtlw0%flag(iff)<=lev_files(iff)) THEN
1472      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
1473      CALL histwrite_phy(nid_files(iff),o_dtlw0%name,itau_w,zx_tmp_fi3d)
1474       ENDIF
1475
1476       IF (o_dtec%flag(iff)<=lev_files(iff)) THEN
1477      zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)
1478      CALL histwrite_phy(nid_files(iff),o_dtec%name,itau_w,zx_tmp_fi3d)
1479       ENDIF
1480
1481       IF (o_duvdf%flag(iff)<=lev_files(iff)) THEN
1482      zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
1483      CALL histwrite_phy(nid_files(iff),o_duvdf%name,itau_w,zx_tmp_fi3d)
1484       ENDIF
1485
1486       IF (o_dvvdf%flag(iff)<=lev_files(iff)) THEN
1487      zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
1488      CALL histwrite_phy(nid_files(iff),o_dvvdf%name,itau_w,zx_tmp_fi3d)
1489       ENDIF
1490
1491       IF (ok_orodr) THEN
1492      IF (o_duoro%flag(iff)<=lev_files(iff)) THEN
1493      zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
1494      CALL histwrite_phy(nid_files(iff),o_duoro%name,itau_w,zx_tmp_fi3d)
1495       ENDIF
1496
1497      IF (o_dvoro%flag(iff)<=lev_files(iff)) THEN
1498      zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
1499      CALL histwrite_phy(nid_files(iff),o_dvoro%name,itau_w,zx_tmp_fi3d)
1500      ENDIF
1501       ENDIF
1502
1503        IF (ok_orolf) THEN
1504       IF (o_dulif%flag(iff)<=lev_files(iff)) THEN
1505      zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
1506      CALL histwrite_phy(nid_files(iff),o_dulif%name,itau_w,zx_tmp_fi3d)
1507       ENDIF
1508
1509        IF (o_dvlif%flag(iff)<=lev_files(iff)) THEN
1510      zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
1511      CALL histwrite_phy(nid_files(iff),o_dvlif%name,itau_w,zx_tmp_fi3d)
1512       ENDIF
1513        ENDIF
1514
1515        if (nqtot.GE.3) THEN
1516         DO iq=3,nqtot
1517       IF (o_trac(iq-2)%flag(iff)<=lev_files(iff)) THEN
1518         CALL histwrite_phy(nid_files(iff),
1519     s                  o_trac(iq-2)%name,itau_w,qx(:,:,iq))
1520       ENDIF
1521         ENDDO
1522        endif
1523
1524      if (ok_sync) then
1525c$OMP MASTER
1526        call histsync(nid_files(iff))
1527c$OMP END MASTER
1528      endif
1529
1530       ENDIF ! clef_files
1531
1532      ENDDO ! iff=1,nfiles
Note: See TracBrowser for help on using the repository browser.