source: LMDZ5/branches/testing/libf/phylmd/phys_output_write.h @ 1664

Last change on this file since 1664 was 1664, checked in by Laurent Fairhead, 12 years ago

Version testing basée sur la r1575


Testing release based on r1575

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 72.6 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),clef_stations(iff),
12     $                  o_phis%name,itau_w,pphis)
13       ENDIF
14
15       IF (.NOT.clef_stations(iff)) THEN
16       IF (o_aire%flag(iff)<=lev_files(iff)) THEN
17       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
18     $o_aire%name,itau_w,airephy)
19       ENDIF
20
21       IF (o_contfracATM%flag(iff)<=lev_files(iff)) THEN
22      DO i=1, klon
23       zx_tmp_fi2d(i)=pctsrf(i,is_ter)+pctsrf(i,is_lic)
24      ENDDO
25      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
26     $             o_contfracATM%name,itau_w,zx_tmp_fi2d)
27       ENDIF
28       ENDIF
29
30       IF (o_contfracOR%flag(iff)<=lev_files(iff)) THEN
31      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
32     $                  o_contfracOR%name,itau_w,pctsrf(:,is_ter))
33       ENDIF
34
35       IF (o_aireTER%flag(iff)<=lev_files(iff)) THEN
36      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
37     $                  o_aireTER%name,itau_w,paire_ter)
38       ENDIF
39
40!!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41
42       IF (o_flat%flag(iff)<=lev_files(iff)) THEN
43      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
44     $                  o_flat%name,itau_w,zxfluxlat)
45       ENDIF
46
47       IF (o_slp%flag(iff)<=lev_files(iff)) THEN
48      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
49     $                  o_slp%name,itau_w,slp)
50       ENDIF
51
52       IF (o_tsol%flag(iff)<=lev_files(iff)) THEN
53      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
54     $                  o_tsol%name,itau_w,zxtsol)
55       ENDIF
56
57       IF (o_t2m%flag(iff)<=lev_files(iff)) THEN
58      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
59     $                  o_t2m%name,itau_w,zt2m)
60       ENDIF
61
62      IF (.NOT.clef_stations(iff)) THEN
63       IF (o_t2m_min%flag(iff)<=lev_files(iff)) THEN
64      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
65     $o_t2m_min%name,itau_w,zt2m)
66       ENDIF
67
68       IF (o_t2m_max%flag(iff)<=lev_files(iff)) THEN
69      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
70     $o_t2m_max%name,itau_w,zt2m)
71       ENDIF
72       ENDIF
73
74       IF (o_wind10m%flag(iff)<=lev_files(iff)) THEN
75      DO i=1, klon
76       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
77      ENDDO
78      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
79     s                  o_wind10m%name,itau_w,zx_tmp_fi2d)
80       ENDIF
81
82      IF (.NOT.clef_stations(iff)) THEN
83       IF (o_wind10max%flag(iff)<=lev_files(iff)) THEN
84      DO i=1, klon
85       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
86      ENDDO
87      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
88     $o_wind10max%name,itau_w,zx_tmp_fi2d)
89       ENDIF
90      ENDIF
91
92       IF (o_sicf%flag(iff)<=lev_files(iff)) THEN
93      DO i = 1, klon
94         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
95      ENDDO
96      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
97     $                   o_sicf%name,itau_w,zx_tmp_fi2d)
98       ENDIF
99
100       IF (o_q2m%flag(iff)<=lev_files(iff)) THEN
101      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
102     $o_q2m%name,itau_w,zq2m)
103       ENDIF
104
105       IF (o_u10m%flag(iff)<=lev_files(iff)) THEN
106      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
107     $o_u10m%name,itau_w,zu10m)
108       ENDIF
109
110       IF (o_v10m%flag(iff)<=lev_files(iff)) THEN
111      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
112     $o_v10m%name,itau_w,zv10m)
113       ENDIF
114
115       IF (o_psol%flag(iff)<=lev_files(iff)) THEN
116      DO i = 1, klon
117         zx_tmp_fi2d(i) = paprs(i,1)
118      ENDDO
119      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
120     s                   o_psol%name,itau_w,zx_tmp_fi2d)
121       ENDIF
122
123       IF (o_mass%flag(iff)<=lev_files(iff)) THEN
124      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
125     s                   o_mass%name,itau_w,zmasse)
126        ENDIF
127
128
129       IF (o_qsurf%flag(iff)<=lev_files(iff)) THEN
130      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
131     $o_qsurf%name,itau_w,zxqsurf)
132       ENDIF
133
134       if (.not. ok_veget) then
135         IF (o_qsol%flag(iff)<=lev_files(iff)) THEN
136        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
137     $o_qsol%name,itau_w,qsol)
138         ENDIF
139       endif
140
141      IF (o_precip%flag(iff)<=lev_files(iff)) THEN
142       DO i = 1, klon
143         zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
144       ENDDO
145      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
146     $o_precip%name,itau_w,zx_tmp_fi2d)
147      ENDIF
148
149       IF (o_ndayrain%flag(iff)<=lev_files(iff)) THEN
150      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
151     $o_ndayrain%name,itau_w,nday_rain)
152       ENDIF
153
154      IF (o_plul%flag(iff)<=lev_files(iff)) THEN
155       DO i = 1, klon
156         zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
157       ENDDO
158      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
159     $o_plul%name,itau_w,zx_tmp_fi2d)
160      ENDIF
161
162      IF (o_pluc%flag(iff)<=lev_files(iff)) THEN
163      DO i = 1, klon
164         zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
165      ENDDO
166      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
167     $o_pluc%name,itau_w,zx_tmp_fi2d)
168      ENDIF
169
170       IF (o_snow%flag(iff)<=lev_files(iff)) THEN
171      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
172     $o_snow%name,itau_w,snow_fall)
173       ENDIF
174
175       IF (o_msnow%flag(iff)<=lev_files(iff)) THEN
176      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
177     $o_msnow%name,itau_w,snow_o)
178       ENDIF
179
180       IF (o_fsnow%flag(iff)<=lev_files(iff)) THEN
181      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
182     $o_fsnow%name,itau_w,zfra_o)
183       ENDIF
184
185       IF (o_evap%flag(iff)<=lev_files(iff)) THEN
186      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
187     $o_evap%name,itau_w,evap)
188       ENDIF
189
190       IF (o_tops%flag(iff)<=lev_files(iff)) THEN
191      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
192     $o_tops%name,itau_w,topsw)
193       ENDIF
194
195       IF (o_tops0%flag(iff)<=lev_files(iff)) THEN
196      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
197     $o_tops0%name,itau_w,topsw0)
198       ENDIF
199
200       IF (o_topl%flag(iff)<=lev_files(iff)) THEN
201      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
202     $o_topl%name,itau_w,toplw)
203       ENDIF
204
205       IF (o_topl0%flag(iff)<=lev_files(iff)) THEN
206      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
207     $o_topl0%name,itau_w,toplw0)
208       ENDIF
209
210       IF (o_SWupTOA%flag(iff)<=lev_files(iff)) THEN
211      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
212      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
213     $o_SWupTOA%name,itau_w,zx_tmp_fi2d)
214       ENDIF
215
216       IF (o_SWupTOAclr%flag(iff)<=lev_files(iff)) THEN
217      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
218      CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
219     $                  o_SWupTOAclr%name,itau_w,zx_tmp_fi2d)
220       ENDIF
221
222       IF (o_SWdnTOA%flag(iff)<=lev_files(iff)) THEN
223      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
224      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
225     s                  o_SWdnTOA%name,itau_w,zx_tmp_fi2d)
226       ENDIF
227
228       IF (o_SWdnTOAclr%flag(iff)<=lev_files(iff)) THEN
229      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
230      CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
231     $                  o_SWdnTOAclr%name,itau_w,zx_tmp_fi2d)
232       ENDIF
233
234       IF (o_nettop%flag(iff)<=lev_files(iff)) THEN
235      zx_tmp_fi2d(:) = topsw(:)-toplw(:)
236      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
237     $                  o_nettop%name,itau_w,zx_tmp_fi2d)
238       ENDIF
239
240       IF (o_SWup200%flag(iff)<=lev_files(iff)) THEN
241      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
242     $o_SWup200%name,itau_w,SWup200)
243       ENDIF
244
245       IF (o_SWup200clr%flag(iff)<=lev_files(iff)) THEN
246      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
247     s                   o_SWup200clr%name,itau_w,SWup200clr)
248       ENDIF
249
250       IF (o_SWdn200%flag(iff)<=lev_files(iff)) THEN
251      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
252     $o_SWdn200%name,itau_w,SWdn200)
253       ENDIF
254
255       IF (o_SWdn200clr%flag(iff)<=lev_files(iff)) THEN
256      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
257     s                o_SWdn200clr%name,itau_w,SWdn200clr)
258       ENDIF
259
260       IF (o_LWup200%flag(iff)<=lev_files(iff)) THEN
261      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
262     $o_LWup200%name,itau_w,LWup200)
263       ENDIF
264
265       IF (o_LWup200clr%flag(iff)<=lev_files(iff)) THEN
266      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
267     s                   o_LWup200clr%name,itau_w,LWup200clr)
268       ENDIF
269
270       IF (o_LWdn200%flag(iff)<=lev_files(iff)) THEN
271      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
272     s                   o_LWdn200%name,itau_w,LWdn200)
273       ENDIF
274
275       IF (o_LWdn200clr%flag(iff)<=lev_files(iff)) THEN
276      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
277     s                  o_LWdn200clr%name,itau_w,LWdn200clr)
278       ENDIF
279
280       IF (o_sols%flag(iff)<=lev_files(iff)) THEN
281      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
282     $o_sols%name,itau_w,solsw)
283       ENDIF
284
285       IF (o_sols0%flag(iff)<=lev_files(iff)) THEN
286      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
287     $o_sols0%name,itau_w,solsw0)
288       ENDIF
289
290       IF (o_soll%flag(iff)<=lev_files(iff)) THEN
291      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
292     $o_soll%name,itau_w,sollw)
293       ENDIF
294
295       IF (o_radsol%flag(iff)<=lev_files(iff)) THEN
296      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
297     $o_radsol%name,itau_w,radsol)
298       ENDIF
299
300       IF (o_soll0%flag(iff)<=lev_files(iff)) THEN
301      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
302     $o_soll0%name,itau_w,sollw0)
303       ENDIF
304
305       IF (o_SWupSFC%flag(iff)<=lev_files(iff)) THEN
306      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
307      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
308     s               o_SWupSFC%name,itau_w,zx_tmp_fi2d)
309       ENDIF
310
311       IF (o_SWupSFCclr%flag(iff)<=lev_files(iff)) THEN
312      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 1 )
313      CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
314     $                   o_SWupSFCclr%name,itau_w,zx_tmp_fi2d)
315       ENDIF
316
317       IF (o_SWdnSFC%flag(iff)<=lev_files(iff)) THEN
318      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
319      CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
320     $                   o_SWdnSFC%name,itau_w,zx_tmp_fi2d)
321       ENDIF
322
323       IF (o_SWdnSFCclr%flag(iff)<=lev_files(iff)) THEN
324      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 1 )
325      CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
326     $                  o_SWdnSFCclr%name,itau_w,zx_tmp_fi2d)
327       ENDIF
328
329       IF (o_LWupSFC%flag(iff)<=lev_files(iff)) THEN
330      zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
331      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
332     $                    o_LWupSFC%name,itau_w,zx_tmp_fi2d)
333       ENDIF
334
335       IF (o_LWdnSFC%flag(iff)<=lev_files(iff)) THEN
336      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
337     $                   o_LWdnSFC%name,itau_w,sollwdown)
338       ENDIF
339
340       sollwdownclr(1:klon) = -1.*lwdn0(1:klon,1)
341       IF (o_LWupSFCclr%flag(iff)<=lev_files(iff)) THEN
342      zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
343      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
344     $                   o_LWupSFCclr%name,itau_w,zx_tmp_fi2d)
345       ENDIF
346
347       IF (o_LWdnSFCclr%flag(iff)<=lev_files(iff)) THEN
348      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
349     $                   o_LWdnSFCclr%name,itau_w,sollwdownclr)
350       ENDIF
351
352       IF (o_bils%flag(iff)<=lev_files(iff)) THEN
353      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
354     $o_bils%name,itau_w,bils)
355       ENDIF
356
357       IF (o_sens%flag(iff)<=lev_files(iff)) THEN
358      zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
359      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
360     $o_sens%name,itau_w,zx_tmp_fi2d)
361       ENDIF
362
363       IF (o_fder%flag(iff)<=lev_files(iff)) THEN
364      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
365     $o_fder%name,itau_w,fder)
366       ENDIF
367
368       IF (o_ffonte%flag(iff)<=lev_files(iff)) THEN
369       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
370     $o_ffonte%name,itau_w,zxffonte)
371       ENDIF
372
373       IF (o_fqcalving%flag(iff)<=lev_files(iff)) THEN
374       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
375     $                    o_fqcalving%name,itau_w,zxfqcalving)
376       ENDIF
377
378       IF (o_fqfonte%flag(iff)<=lev_files(iff)) THEN
379       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
380     $                   o_fqfonte%name,itau_w,zxfqfonte)
381       ENDIF
382
383       IF (o_taux%flag(iff)<=lev_files(iff)) THEN
384         zx_tmp_fi2d=0.
385         do nsrf=1,nbsrf
386          zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxu(:,1,nsrf)
387         enddo
388         CALL histwrite_phy(nid_files(iff),clef_stations(iff),
389     $                   o_taux%name,itau_w,zx_tmp_fi2d)
390       ENDIF
391
392       IF (o_tauy%flag(iff)<=lev_files(iff)) THEN
393         zx_tmp_fi2d=0.
394         do nsrf=1,nbsrf
395          zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxv(:,1,nsrf)
396         enddo
397         CALL histwrite_phy(nid_files(iff),clef_stations(iff),
398     $                   o_tauy%name,itau_w,zx_tmp_fi2d)
399       ENDIF
400
401         DO nsrf = 1, nbsrf
402!           IF(nsrf.GE.2) THEN
403            IF (o_pourc_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
404            zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
405            CALL histwrite_phy(nid_files(iff),
406     $                     clef_stations(iff),
407     $                     o_pourc_srf(nsrf)%name,itau_w,
408     $                     zx_tmp_fi2d)
409            ENDIF
410
411          IF (o_fract_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
412          zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
413          CALL histwrite_phy(nid_files(iff),clef_stations(iff),
414     $                  o_fract_srf(nsrf)%name,itau_w,
415     $                  zx_tmp_fi2d)
416          ENDIF
417!         ENDIF !nsrf.GT.2
418
419        IF (o_taux_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
420        zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
421        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
422     $                     o_taux_srf(nsrf)%name,itau_w,
423     $                     zx_tmp_fi2d)
424        ENDIF
425
426        IF (o_tauy_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN           
427        zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
428        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
429     $                    o_tauy_srf(nsrf)%name,itau_w,
430     $                    zx_tmp_fi2d)
431        ENDIF
432
433        IF (o_tsol_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
434        zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
435        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
436     $                   o_tsol_srf(nsrf)%name,itau_w,
437     $      zx_tmp_fi2d)
438        ENDIF
439
440      IF (o_u10m_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
441      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, nsrf)
442      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
443     $o_u10m_srf(nsrf)%name,
444     $                 itau_w,zx_tmp_fi2d)
445      ENDIF
446
447      IF (o_v10m_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
448      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, nsrf)
449      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
450     $o_v10m_srf(nsrf)%name,
451     $              itau_w,zx_tmp_fi2d)
452      ENDIF
453 
454      IF (o_t2m_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
455      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, nsrf)
456      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
457     $o_t2m_srf(nsrf)%name,
458     $           itau_w,zx_tmp_fi2d)
459      ENDIF
460
461      IF (o_evap_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
462      zx_tmp_fi2d(1 : klon) = fevap(1 : klon, nsrf)
463      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
464     $o_evap_srf(nsrf)%name,
465     $           itau_w,zx_tmp_fi2d)
466      ENDIF
467
468       IF (o_sens_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
469       zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
470       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
471     $                    o_sens_srf(nsrf)%name,itau_w,
472     $      zx_tmp_fi2d)
473       ENDIF
474
475        IF (o_lat_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
476        zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
477        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
478     $                 o_lat_srf(nsrf)%name,itau_w,
479     $                                   zx_tmp_fi2d)
480          ENDIF
481
482        IF (o_flw_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
483        zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
484        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
485     $                     o_flw_srf(nsrf)%name,itau_w,
486     $      zx_tmp_fi2d)
487        ENDIF
488
489        IF (o_fsw_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
490        zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
491        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
492     $                   o_fsw_srf(nsrf)%name,itau_w,
493     $      zx_tmp_fi2d)
494        ENDIF
495
496        IF (o_wbils_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
497        zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
498        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
499     $                   o_wbils_srf(nsrf)%name,itau_w,
500     $      zx_tmp_fi2d)
501        ENDIF
502
503        IF (o_wbilo_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
504        zx_tmp_fi2d(1 : klon) = wfbilo( 1 : klon, nsrf)
505        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
506     $                    o_wbilo_srf(nsrf)%name,itau_w,
507     $      zx_tmp_fi2d)
508        ENDIF
509
510       if (iflag_pbl>1 .and. lev_histday.gt.10 ) then
511        IF (o_tke_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
512        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
513     $                   o_tke_srf(nsrf)%name,itau_w,
514     $                    pbl_tke(:,1:klev,nsrf))
515       ENDIF
516
517      IF (.NOT.clef_stations(iff)) THEN
518        IF (o_tke_max_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
519        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
520     $                    o_tke_max_srf(nsrf)%name,itau_w,
521     $      pbl_tke(:,1:klev,nsrf))
522        ENDIF
523      ENDIF
524       endif
525      ENDDO
526
527        IF (o_cdrm%flag(iff)<=lev_files(iff)) THEN
528      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
529     $o_cdrm%name,itau_w,cdragm)
530        ENDIF
531
532        IF (o_cdrh%flag(iff)<=lev_files(iff)) THEN
533      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
534     $o_cdrh%name,itau_w,cdragh)
535        ENDIF
536
537        IF (o_cldl%flag(iff)<=lev_files(iff)) THEN
538      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
539     $o_cldl%name,itau_w,cldl)
540        ENDIF
541
542        IF (o_cldm%flag(iff)<=lev_files(iff)) THEN
543      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
544     $o_cldm%name,itau_w,cldm)
545        ENDIF
546
547        IF (o_cldh%flag(iff)<=lev_files(iff)) THEN
548      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
549     $o_cldh%name,itau_w,cldh)
550        ENDIF
551
552        IF (o_cldt%flag(iff)<=lev_files(iff)) THEN
553      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
554     $o_cldt%name, 
555     &                   itau_w,cldt)
556        ENDIF
557
558        IF (o_cldq%flag(iff)<=lev_files(iff)) THEN
559      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
560     $o_cldq%name,itau_w,cldq)
561        ENDIF
562
563        IF (o_lwp%flag(iff)<=lev_files(iff)) THEN
564      zx_tmp_fi2d(1:klon) = flwp(1:klon)
565      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
566     s                   o_lwp%name,itau_w,zx_tmp_fi2d)
567        ENDIF
568
569        IF (o_iwp%flag(iff)<=lev_files(iff)) THEN
570      zx_tmp_fi2d(1:klon) = fiwp(1:klon)
571      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
572     s                    o_iwp%name,itau_w,zx_tmp_fi2d)
573        ENDIF
574
575        IF (o_ue%flag(iff)<=lev_files(iff)) THEN
576      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
577     $o_ue%name,itau_w,ue)
578        ENDIF
579
580        IF (o_ve%flag(iff)<=lev_files(iff)) THEN
581      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
582     $o_ve%name,itau_w,ve)
583        ENDIF
584
585        IF (o_uq%flag(iff)<=lev_files(iff)) THEN
586      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
587     $o_uq%name,itau_w,uq)
588        ENDIF
589
590        IF (o_vq%flag(iff)<=lev_files(iff)) THEN
591      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
592     $o_vq%name,itau_w,vq)
593        ENDIF
594
595      IF(iflag_con.GE.3) THEN ! sb
596        IF (o_cape%flag(iff)<=lev_files(iff)) THEN
597      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
598     $o_cape%name,itau_w,cape)
599        ENDIF
600
601        IF (o_pbase%flag(iff)<=lev_files(iff)) THEN
602      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
603     $o_pbase%name,itau_w,ema_pcb)
604        ENDIF
605
606        IF (o_ptop%flag(iff)<=lev_files(iff)) THEN
607      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
608     $o_ptop%name,itau_w,ema_pct)
609        ENDIF
610
611        IF (o_fbase%flag(iff)<=lev_files(iff)) THEN
612      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
613     $o_fbase%name,itau_w,ema_cbmf)
614        ENDIF
615
616        if (iflag_con /= 30) then
617           if (o_plcl%flag(iff)<=lev_files(iff)) THEN
618              CALL histwrite_phy(nid_files(iff),clef_stations(iff),
619     $             o_plcl%name,itau_w,plcl)
620           ENDIF
621
622           IF (o_plfc%flag(iff)<=lev_files(iff)) THEN
623              CALL histwrite_phy(nid_files(iff),clef_stations(iff),
624     $             o_plfc%name,itau_w,plfc)
625           ENDIF
626
627           IF (o_wbeff%flag(iff)<=lev_files(iff)) THEN
628              CALL histwrite_phy(nid_files(iff),clef_stations(iff),
629     $             o_wbeff%name,itau_w,wbeff)
630           ENDIF
631        end if
632
633        IF (o_prw%flag(iff)<=lev_files(iff)) THEN
634      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
635     $o_prw%name,itau_w,prw)
636        ENDIF
637
638      IF (.NOT.clef_stations(iff)) THEN
639      IF (o_cape_max%flag(iff)<=lev_files(iff)) THEN
640      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
641     $o_cape_max%name,itau_w,cape)
642      ENDIF
643      ENDIF
644
645       IF (o_upwd%flag(iff)<=lev_files(iff)) THEN
646      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
647     $o_upwd%name,itau_w,upwd)
648       ENDIF
649
650       IF (o_Ma%flag(iff)<=lev_files(iff)) THEN
651      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
652     $o_Ma%name,itau_w,Ma)
653       ENDIF
654
655       IF (o_dnwd%flag(iff)<=lev_files(iff)) THEN
656      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
657     $o_dnwd%name,itau_w,dnwd)
658       ENDIF
659
660       IF (o_dnwd0%flag(iff)<=lev_files(iff)) THEN
661      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
662     $o_dnwd0%name,itau_w,dnwd0)
663       ENDIF
664
665       IF (o_ftime_con%flag(iff)<=lev_files(iff)) THEN
666        zx_tmp_fi2d=float(itau_con)/float(itap)
667      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
668     $o_ftime_con%name,
669     s                   itau_w,zx_tmp_fi2d)
670       ENDIF
671
672       IF (o_mc%flag(iff)<=lev_files(iff)) THEN
673        if(iflag_thermals.gt.1)then
674         zx_tmp_fi3d=dnwd+dnwd0+upwd+fm_therm(:,1:klev)
675        else
676         zx_tmp_fi3d=dnwd+dnwd0+upwd
677        endif
678      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
679     $o_mc%name,itau_w,zx_tmp_fi3d)
680       ENDIF
681     
682      ENDIF !iflag_con .GE. 3
683
684        IF (o_s_pblh%flag(iff)<=lev_files(iff)) THEN
685      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
686     $o_s_pblh%name,itau_w,s_pblh)
687        ENDIF
688
689        IF (o_s_pblt%flag(iff)<=lev_files(iff)) THEN
690      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
691     $o_s_pblt%name,itau_w,s_pblt)
692        ENDIF
693
694        IF (o_s_lcl%flag(iff)<=lev_files(iff)) THEN
695      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
696     $o_s_lcl%name,itau_w,s_lcl)
697        ENDIF
698
699        IF (o_s_therm%flag(iff)<=lev_files(iff)) THEN
700      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
701     $o_s_therm%name,itau_w,s_therm)
702        ENDIF
703
704!IM : Les champs suivants (s_capCL, s_oliqCL, s_cteiCL, s_trmb1, s_trmb2, s_trmb3) ne sont pas definis dans HBTM.F
705!       IF (o_s_capCL%flag(iff)<=lev_files(iff)) THEN
706!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
707!    $o_s_capCL%name,itau_w,s_capCL)
708!       ENDIF
709
710!       IF (o_s_oliqCL%flag(iff)<=lev_files(iff)) THEN
711!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
712!    $o_s_oliqCL%name,itau_w,s_oliqCL)
713!       ENDIF
714
715!       IF (o_s_cteiCL%flag(iff)<=lev_files(iff)) THEN
716!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
717!    $o_s_cteiCL%name,itau_w,s_cteiCL)
718!       ENDIF
719
720!       IF (o_s_trmb1%flag(iff)<=lev_files(iff)) THEN
721!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
722!    $o_s_trmb1%name,itau_w,s_trmb1)
723!       ENDIF
724
725!       IF (o_s_trmb2%flag(iff)<=lev_files(iff)) THEN
726!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
727!    $o_s_trmb2%name,itau_w,s_trmb2)
728!       ENDIF
729
730!       IF (o_s_trmb3%flag(iff)<=lev_files(iff)) THEN
731!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
732!    $o_s_trmb3%name,itau_w,s_trmb3)
733!       ENDIF
734
735! Champs interpolles sur des niveaux de pression
736
737        ll=0
738        DO k=1, nlevSTD
739         bb2=clevSTD(k) 
740         IF(bb2.EQ."850".OR.bb2.EQ."700".OR.
741     $      bb2.EQ."500".OR.bb2.EQ."200".OR.
742     $      bb2.EQ."100".OR.
743     $      bb2.EQ."50".OR.bb2.EQ."10") THEN
744
745! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
746          ll=ll+1
747       IF (o_uSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
748       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
749     $o_uSTDlevs(ll)%name,
750     &                    itau_w,uwriteSTD(:,k,iff))
751       ENDIF
752
753       IF (o_vSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
754      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
755     $o_vSTDlevs(ll)%name, 
756     &                   itau_w,vwriteSTD(:,k,iff))
757       ENDIF
758
759       IF (o_wSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
760      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
761     $o_wSTDlevs(ll)%name,
762     &                    itau_w,wwriteSTD(:,k,iff))
763       ENDIF
764
765       IF (o_zSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
766      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
767     $o_zSTDlevs(ll)%name,
768     &               itau_w,phiwriteSTD(:,k,iff))
769       ENDIF
770
771       IF (o_qSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
772      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
773     $o_qSTDlevs(ll)%name,
774     &                   itau_w, qwriteSTD(:,k,iff))
775       ENDIF
776
777       IF (o_tSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
778      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
779     $o_tSTDlevs(ll)%name,
780     &                   itau_w, twriteSTD(:,k,iff))
781       ENDIF
782
783       ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
784       ENDDO
785
786      IF (o_t_oce_sic%flag(iff)<=lev_files(iff)) THEN
787      DO i=1, klon
788       IF (pctsrf(i,is_oce).GT.epsfra.OR.
789     $     pctsrf(i,is_sic).GT.epsfra) THEN
790        zx_tmp_fi2d(i) = (ftsol(i, is_oce) * pctsrf(i,is_oce)+
791     $                   ftsol(i, is_sic) * pctsrf(i,is_sic))/
792     $                   (pctsrf(i,is_oce)+pctsrf(i,is_sic))
793       ELSE
794        zx_tmp_fi2d(i) = 273.15
795       ENDIF
796      ENDDO
797      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
798     s                   o_t_oce_sic%name,itau_w,zx_tmp_fi2d)
799      ENDIF
800
801! Couplage convection-couche limite
802      IF (iflag_con.GE.3) THEN
803      IF (iflag_coupl>=1) THEN
804       IF (o_ale_bl%flag(iff)<=lev_files(iff)) THEN
805       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
806     $o_ale_bl%name,itau_w,ale_bl)
807       ENDIF
808       IF (o_alp_bl%flag(iff)<=lev_files(iff)) THEN
809       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
810     $o_alp_bl%name,itau_w,alp_bl)
811       ENDIF
812      ENDIF !iflag_coupl>=1
813      ENDIF !(iflag_con.GE.3)
814
815! Wakes
816      IF (iflag_con.EQ.3) THEN
817      IF (iflag_wake>=1) THEN
818       IF (o_ale_wk%flag(iff)<=lev_files(iff)) THEN
819       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
820     $o_ale_wk%name,itau_w,ale_wake)
821       ENDIF
822       IF (o_alp_wk%flag(iff)<=lev_files(iff)) THEN
823       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
824     $o_alp_wk%name,itau_w,alp_wake)
825       ENDIF
826
827       IF (o_ale%flag(iff)<=lev_files(iff)) THEN
828       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
829     $o_ale%name,itau_w,ale)
830       ENDIF
831       IF (o_alp%flag(iff)<=lev_files(iff)) THEN
832       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
833     $o_alp%name,itau_w,alp)
834       ENDIF
835       IF (o_cin%flag(iff)<=lev_files(iff)) THEN
836       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
837     $o_cin%name,itau_w,cin)
838       ENDIF
839       IF (o_wape%flag(iff)<=lev_files(iff)) THEN
840       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
841     $o_WAPE%name,itau_w,wake_pe)
842       ENDIF
843       IF (o_wake_h%flag(iff)<=lev_files(iff)) THEN
844      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
845     $o_wake_h%name,itau_w,wake_h)
846       ENDIF
847
848       IF (o_wake_s%flag(iff)<=lev_files(iff)) THEN
849      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
850     $o_wake_s%name,itau_w,wake_s)
851       ENDIF
852
853        IF (o_wake_deltat%flag(iff)<=lev_files(iff)) THEN
854       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
855     $o_wake_deltat%name,
856     $                     itau_w,wake_deltat)
857        ENDIF
858
859        IF (o_wake_deltaq%flag(iff)<=lev_files(iff)) THEN
860       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
861     $o_wake_deltaq%name,
862     $                    itau_w,wake_deltaq)
863        ENDIF
864
865        IF (o_wake_omg%flag(iff)<=lev_files(iff)) THEN
866       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
867     s                    o_wake_omg%name,itau_w,wake_omg)
868        ENDIF
869
870         IF (o_dtwak%flag(iff)<=lev_files(iff)) THEN
871           zx_tmp_fi3d(1:klon,1:klev)=d_t_wake(1:klon,1:klev)
872     &                                        /pdtphys
873           CALL histwrite_phy(nid_files(iff),
874     $clef_stations(iff),
875     &                       o_dtwak%name,itau_w,zx_tmp_fi3d)
876         ENDIF
877
878        IF (o_dqwak%flag(iff)<=lev_files(iff)) THEN
879        zx_tmp_fi3d(1:klon,1:klev)=d_q_wake(1:klon,1:klev)/pdtphys
880        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
881     &                     o_dqwak%name,itau_w,zx_tmp_fi3d)
882        ENDIF
883      ENDIF ! iflag_wake>=1
884
885        IF (o_Vprecip%flag(iff)<=lev_files(iff)) THEN
886       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
887     $o_Vprecip%name,itau_w,Vprecip)
888        ENDIF
889
890        IF (o_ftd%flag(iff)<=lev_files(iff)) THEN
891       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
892     $o_ftd%name,itau_w,ftd)
893        ENDIF
894
895        IF (o_fqd%flag(iff)<=lev_files(iff)) THEN
896       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
897     $o_fqd%name,itau_w,fqd)
898        ENDIF
899      ENDIF !(iflag_con.EQ.3) 
900 
901      IF (type_ocean=='slab ') THEN
902      IF ( o_slab_bils%flag(iff)<=lev_files(iff)) 
903     $     CALL histwrite_phy(
904     $     nid_files(iff),clef_stations(iff),
905     $o_slab_bils%name,itau_w,slab_wfbils)
906
907      ENDIF !type_ocean == force/slab
908
909      IF (o_weakinv%flag(iff)<=lev_files(iff)) THEN
910      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
911     s                  o_weakinv%name,itau_w,weak_inversion)
912      ENDIF
913
914      IF (o_dthmin%flag(iff)<=lev_files(iff)) THEN
915      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
916     $o_dthmin%name,itau_w,dthmin)
917      ENDIF
918
919       IF (o_cldtau%flag(iff)<=lev_files(iff)) THEN
920       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
921     $o_cldtau%name,itau_w,cldtau)
922       ENDIF
923
924       IF (o_cldemi%flag(iff)<=lev_files(iff)) THEN
925       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
926     $o_cldemi%name,itau_w,cldemi)
927       ENDIF
928
929      IF (o_pr_con_l%flag(iff)<=lev_files(iff)) THEN
930      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
931     s         o_pr_con_l%name,itau_w,pmflxr(:,1:klev))
932      ENDIF
933
934      IF (o_pr_con_i%flag(iff)<=lev_files(iff)) THEN
935      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
936     s         o_pr_con_i%name,itau_w,pmflxs(:,1:klev))
937      ENDIF
938
939      IF (o_pr_lsc_l%flag(iff)<=lev_files(iff)) THEN
940      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
941     s        o_pr_lsc_l%name,itau_w,prfl(:,1:klev))
942      ENDIF
943
944      IF (o_pr_lsc_i%flag(iff)<=lev_files(iff)) THEN
945      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
946     s        o_pr_lsc_i%name,itau_w,psfl(:,1:klev))
947      ENDIF
948
949      IF (o_re%flag(iff)<=lev_files(iff)) THEN
950      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
951     $o_re%name,itau_w,re)
952      ENDIF
953
954      IF (o_fl%flag(iff)<=lev_files(iff)) THEN
955      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
956     $o_fl%name,itau_w,fl)
957      ENDIF
958
959
960
961      IF (o_rh2m%flag(iff)<=lev_files(iff)) THEN
962      DO i=1, klon
963       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
964      ENDDO
965      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
966     $o_rh2m%name,itau_w,zx_tmp_fi2d)
967      ENDIF
968
969      IF (.NOT.clef_stations(iff)) THEN
970      IF (o_rh2m_min%flag(iff)<=lev_files(iff)) THEN
971      DO i=1, klon
972       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
973      ENDDO
974      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
975     $o_rh2m_min%name,
976     s               itau_w,zx_tmp_fi2d)
977      ENDIF
978
979      IF (o_rh2m_max%flag(iff)<=lev_files(iff)) THEN
980      DO i=1, klon
981       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
982      ENDDO
983      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
984     $o_rh2m_max%name,
985     s              itau_w,zx_tmp_fi2d)
986      ENDIF
987      ENDIF
988
989
990      IF (o_qsat2m%flag(iff)<=lev_files(iff)) THEN
991      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
992     $o_qsat2m%name,itau_w,qsat2m)
993      ENDIF
994
995      IF (o_tpot%flag(iff)<=lev_files(iff)) THEN
996      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
997     $o_tpot%name,itau_w,tpot)
998      ENDIF
999
1000       IF (o_tpote%flag(iff)<=lev_files(iff)) THEN
1001      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1002     $o_tpote%name,itau_w,tpote)
1003       ENDIF
1004
1005      IF (o_SWnetOR%flag(iff)<=lev_files(iff)) THEN
1006      zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, is_ter)
1007      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1008     s                   o_SWnetOR%name,itau_w, zx_tmp_fi2d)
1009      ENDIF
1010
1011      IF (o_SWdownOR%flag(iff)<=lev_files(iff)) THEN
1012      zx_tmp_fi2d(1:klon) = solsw(1:klon)/(1.-albsol1(1:klon))
1013      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1014     s                   o_SWdownOR%name,itau_w, zx_tmp_fi2d)
1015      ENDIF
1016
1017      IF (o_LWdownOR%flag(iff)<=lev_files(iff)) THEN
1018      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1019     s                  o_LWdownOR%name,itau_w,sollwdown)
1020      ENDIF
1021
1022      IF (o_snowl%flag(iff)<=lev_files(iff)) THEN
1023      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1024     $o_snowl%name,itau_w,snow_lsc)
1025      ENDIF
1026
1027      IF (o_solldown%flag(iff)<=lev_files(iff)) THEN
1028      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1029     s                   o_solldown%name,itau_w,sollwdown)
1030      ENDIF
1031
1032      IF (o_dtsvdfo%flag(iff)<=lev_files(iff)) THEN
1033      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1034     s                 o_dtsvdfo%name,itau_w,d_ts(:,is_oce))
1035      ENDIF
1036
1037      IF (o_dtsvdft%flag(iff)<=lev_files(iff)) THEN
1038      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1039     s                   o_dtsvdft%name,itau_w,d_ts(:,is_ter))
1040      ENDIF
1041
1042       IF (o_dtsvdfg%flag(iff)<=lev_files(iff)) THEN
1043        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1044     $                   o_dtsvdfg%name,itau_w, d_ts(:,is_lic))
1045       ENDIF
1046
1047       IF (o_dtsvdfi%flag(iff)<=lev_files(iff)) THEN
1048      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1049     s                   o_dtsvdfi%name,itau_w,d_ts(:,is_sic))
1050       ENDIF
1051
1052       IF (o_rugs%flag(iff)<=lev_files(iff)) THEN
1053      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1054     $o_rugs%name,itau_w,zxrugs)
1055       ENDIF
1056
1057! OD550 per species
1058      IF (new_aod .and. (.not. aerosol_couple)) THEN
1059          IF (ok_ade.OR.ok_aie) THEN
1060
1061          IF (o_od550aer%flag(iff)<=lev_files(iff)) THEN
1062             CALL histwrite_phy(nid_files(iff),
1063     $clef_stations(iff),
1064     $o_od550aer%name,itau_w,
1065     $            od550aer)
1066          ENDIF
1067          IF (o_od865aer%flag(iff)<=lev_files(iff)) THEN
1068             CALL histwrite_phy(nid_files(iff),
1069     $clef_stations(iff),
1070     $o_od865aer%name,itau_w,
1071     $            od865aer)
1072          ENDIF
1073          IF (o_absvisaer%flag(iff)<=lev_files(iff)) THEN
1074             CALL histwrite_phy(nid_files(iff),
1075     $clef_stations(iff),
1076     $o_absvisaer%name,itau_w,
1077     $            absvisaer)
1078          ENDIF
1079          IF (o_od550lt1aer%flag(iff)<=lev_files(iff)) THEN
1080            CALL histwrite_phy(nid_files(iff),
1081     $clef_stations(iff),
1082     $o_od550lt1aer%name,itau_w,
1083     $            od550lt1aer)
1084          ENDIF
1085
1086          IF (o_sconcso4%flag(iff)<=lev_files(iff)) THEN
1087              CALL histwrite_phy(nid_files(iff),
1088     $clef_stations(iff),
1089     $o_sconcso4%name,itau_w,
1090     $            sconcso4)
1091          ENDIF
1092          IF (o_sconcoa%flag(iff)<=lev_files(iff)) THEN
1093              CALL histwrite_phy(nid_files(iff),
1094     $clef_stations(iff),
1095     $o_sconcoa%name,itau_w,
1096     $            sconcoa)
1097          ENDIF
1098          IF (o_sconcbc%flag(iff)<=lev_files(iff)) THEN
1099              CALL histwrite_phy(nid_files(iff),
1100     $clef_stations(iff),
1101     $o_sconcbc%name,itau_w,
1102     $            sconcbc)
1103          ENDIF
1104          IF (o_sconcss%flag(iff)<=lev_files(iff)) THEN
1105              CALL histwrite_phy(nid_files(iff),
1106     $clef_stations(iff),
1107     $o_sconcss%name,itau_w,
1108     $            sconcss)
1109          ENDIF
1110          IF (o_sconcdust%flag(iff)<=lev_files(iff)) THEN
1111              CALL histwrite_phy(nid_files(iff),
1112     $clef_stations(iff),
1113     $o_sconcdust%name,itau_w,
1114     $            sconcdust)
1115          ENDIF
1116         
1117          IF (o_concso4%flag(iff)<=lev_files(iff)) THEN
1118              CALL histwrite_phy(nid_files(iff),
1119     $clef_stations(iff),
1120     $o_concso4%name,itau_w,
1121     $            concso4)
1122          ENDIF
1123          IF (o_concoa%flag(iff)<=lev_files(iff)) THEN
1124              CALL histwrite_phy(nid_files(iff),
1125     $clef_stations(iff),
1126     $o_concoa%name,itau_w,
1127     $            concoa)
1128          ENDIF
1129          IF (o_concbc%flag(iff)<=lev_files(iff)) THEN
1130              CALL histwrite_phy(nid_files(iff),
1131     $clef_stations(iff),
1132     $o_concbc%name,itau_w,
1133     $            concbc)
1134          ENDIF
1135          IF (o_concss%flag(iff)<=lev_files(iff)) THEN
1136              CALL histwrite_phy(nid_files(iff),
1137     $clef_stations(iff),
1138     $o_concss%name,itau_w,
1139     $            concss)
1140          ENDIF
1141          IF (o_concdust%flag(iff)<=lev_files(iff)) THEN
1142              CALL histwrite_phy(nid_files(iff),
1143     $clef_stations(iff),
1144     $o_concdust%name,itau_w,
1145     $            concdust)
1146          ENDIF
1147         
1148          IF (o_loadso4%flag(iff)<=lev_files(iff)) THEN
1149              CALL histwrite_phy(nid_files(iff),
1150     $clef_stations(iff),
1151     $o_loadso4%name,itau_w,
1152     $            loadso4)
1153          ENDIF
1154          IF (o_loadoa%flag(iff)<=lev_files(iff)) THEN
1155              CALL histwrite_phy(nid_files(iff),
1156     $clef_stations(iff),
1157     $o_loadoa%name,itau_w,
1158     $            loadoa)
1159          ENDIF
1160          IF (o_loadbc%flag(iff)<=lev_files(iff)) THEN
1161              CALL histwrite_phy(nid_files(iff),
1162     $clef_stations(iff),
1163     $o_loadbc%name,itau_w,
1164     $            loadbc)
1165          ENDIF
1166          IF (o_loadss%flag(iff)<=lev_files(iff)) THEN
1167              CALL histwrite_phy(nid_files(iff),
1168     $clef_stations(iff),
1169     $o_loadss%name,itau_w,
1170     $            loadss)
1171          ENDIF
1172          IF (o_loaddust%flag(iff)<=lev_files(iff)) THEN
1173              CALL histwrite_phy(nid_files(iff),
1174     $clef_stations(iff),
1175     $o_loaddust%name,itau_w,
1176     $            loaddust)
1177          ENDIF
1178         
1179          DO naero = 1, naero_spc
1180            IF (o_tausumaero(naero)%flag(iff)<=lev_files(iff)) THEN
1181                CALL histwrite_phy(nid_files(iff),
1182     $clef_stations(iff),
1183     $              o_tausumaero(naero)%name,itau_w,
1184     $              tausum_aero(:,2,naero) )
1185            ENDIF
1186          END DO
1187          endif
1188      ENDIF
1189     
1190       IF (ok_ade) THEN
1191          IF (o_topswad%flag(iff)<=lev_files(iff)) THEN
1192             CALL histwrite_phy(nid_files(iff),
1193     $clef_stations(iff),
1194     $o_topswad%name,itau_w,
1195     $            topswad_aero)
1196          ENDIF
1197          IF (o_solswad%flag(iff)<=lev_files(iff)) THEN
1198             CALL histwrite_phy(nid_files(iff),
1199     $clef_stations(iff),
1200     $o_solswad%name,itau_w,
1201     $            solswad_aero)
1202          ENDIF
1203
1204!====MS forcing diagnostics
1205        if (new_aod) then             
1206        IF (o_swtoaas_nat%flag(iff)<=lev_files(iff)) THEN
1207        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1208     $o_swtoaas_nat%name,itau_w,
1209     $      topsw_aero(:,1))
1210        ENDIF
1211
1212        IF (o_swsrfas_nat%flag(iff)<=lev_files(iff)) THEN
1213        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1214     $o_swsrfas_nat%name,itau_w,
1215     $      solsw_aero(:,1))
1216        ENDIF
1217
1218        IF (o_swtoacs_nat%flag(iff)<=lev_files(iff)) THEN
1219        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1220     $o_swtoacs_nat%name,itau_w,
1221     $      topsw0_aero(:,1))
1222        ENDIF
1223
1224        IF (o_swsrfcs_nat%flag(iff)<=lev_files(iff)) THEN
1225        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1226     $o_swsrfcs_nat%name,itau_w,
1227     $      solsw0_aero(:,1))
1228        ENDIF
1229 
1230!ant
1231        IF (o_swtoaas_ant%flag(iff)<=lev_files(iff)) THEN
1232        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1233     $o_swtoaas_ant%name,itau_w,
1234     $      topsw_aero(:,2))
1235        ENDIF
1236
1237        IF (o_swsrfas_ant%flag(iff)<=lev_files(iff)) THEN
1238        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1239     $o_swsrfas_ant%name,itau_w,
1240     $      solsw_aero(:,2))
1241        ENDIF
1242
1243        IF (o_swtoacs_ant%flag(iff)<=lev_files(iff)) THEN
1244        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1245     $o_swtoacs_ant%name,itau_w,
1246     $      topsw0_aero(:,2))
1247        ENDIF
1248
1249        IF (o_swsrfcs_ant%flag(iff)<=lev_files(iff)) THEN
1250        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1251     $o_swsrfcs_ant%name,itau_w,
1252     $      solsw0_aero(:,2))
1253        ENDIF
1254
1255!cf
1256
1257        if (.not. aerosol_couple) then
1258        IF (o_swtoacf_nat%flag(iff)<=lev_files(iff)) THEN
1259        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1260     $o_swtoacf_nat%name,itau_w,
1261     $      topswcf_aero(:,1))
1262        ENDIF
1263
1264        IF (o_swsrfcf_nat%flag(iff)<=lev_files(iff)) THEN
1265        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1266     $o_swsrfcf_nat%name,itau_w,
1267     $      solswcf_aero(:,1))
1268        ENDIF
1269
1270        IF (o_swtoacf_ant%flag(iff)<=lev_files(iff)) THEN
1271        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1272     $o_swtoacf_ant%name,itau_w,
1273     $      topswcf_aero(:,2))
1274        ENDIF
1275
1276        IF (o_swsrfcf_ant%flag(iff)<=lev_files(iff)) THEN
1277        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1278     $o_swsrfcf_ant%name,itau_w,
1279     $      solswcf_aero(:,2))
1280        ENDIF
1281
1282        IF (o_swtoacf_zero%flag(iff)<=lev_files(iff)) THEN
1283        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1284     $o_swtoacf_zero%name,itau_w,
1285     $      topswcf_aero(:,3))
1286        ENDIF
1287
1288        IF (o_swsrfcf_zero%flag(iff)<=lev_files(iff)) THEN
1289        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1290     $o_swsrfcf_zero%name,itau_w,
1291     $      solswcf_aero(:,3))
1292        ENDIF
1293        endif
1294
1295        endif ! new_aod
1296!====MS forcing diagnostics
1297
1298       ENDIF
1299
1300       IF (ok_aie) THEN
1301          IF (o_topswai%flag(iff)<=lev_files(iff)) THEN
1302             CALL histwrite_phy(nid_files(iff),
1303     $clef_stations(iff),
1304     $o_topswai%name,itau_w,
1305     $            topswai_aero)
1306          ENDIF
1307          IF (o_solswai%flag(iff)<=lev_files(iff)) THEN
1308             CALL histwrite_phy(nid_files(iff),
1309     $clef_stations(iff),
1310     $o_solswai%name,itau_w,
1311     $            solswai_aero)
1312          ENDIF
1313          IF (o_scdnc%flag(iff)<=lev_files(iff)) THEN
1314             CALL histwrite_phy(nid_files(iff),
1315     $clef_stations(iff),
1316     $o_scdnc%name,itau_w,
1317     $            scdnc)
1318          ENDIF
1319          IF (o_cldncl%flag(iff)<=lev_files(iff)) THEN
1320             CALL histwrite_phy(nid_files(iff),
1321     $clef_stations(iff),
1322     $o_cldncl%name,itau_w,
1323     $            cldncl)
1324          ENDIF
1325         IF (o_reffclws%flag(iff)<=lev_files(iff)) THEN
1326            CALL histwrite_phy(nid_files(iff),
1327     $clef_stations(iff),
1328     $o_reffclws%name,itau_w,
1329     $            reffclws)
1330         ENDIF
1331         IF (o_reffclwc%flag(iff)<=lev_files(iff)) THEN
1332            CALL histwrite_phy(nid_files(iff),
1333     $clef_stations(iff),
1334     $o_reffclwc%name,itau_w,
1335     $            reffclwc)
1336         ENDIF
1337          IF (o_cldnvi%flag(iff)<=lev_files(iff)) THEN
1338             CALL histwrite_phy(nid_files(iff),
1339     $clef_stations(iff),
1340     $o_cldnvi%name,itau_w,
1341     $            cldnvi)
1342          ENDIF
1343          IF (o_lcc%flag(iff)<=lev_files(iff)) THEN
1344             CALL histwrite_phy(nid_files(iff),
1345     $clef_stations(iff),
1346     $o_lcc%name,itau_w,
1347     $            lcc)
1348          ENDIF
1349          IF (o_lcc3d%flag(iff)<=lev_files(iff)) THEN
1350             CALL histwrite_phy(nid_files(iff),
1351     $clef_stations(iff),
1352     $o_lcc3d%name,itau_w,
1353     $            lcc3d)
1354          ENDIF
1355          IF (o_lcc3dcon%flag(iff)<=lev_files(iff)) THEN
1356             CALL histwrite_phy(nid_files(iff),
1357     $clef_stations(iff),
1358     $o_lcc3dcon%name,itau_w,
1359     $            lcc3dcon)
1360          ENDIF
1361          IF (o_lcc3dstra%flag(iff)<=lev_files(iff)) THEN
1362             CALL histwrite_phy(nid_files(iff),
1363     $clef_stations(iff),
1364     $o_lcc3dstra%name,itau_w,
1365     $            lcc3dstra)
1366          ENDIF
1367          IF (o_reffclwtop%flag(iff)<=lev_files(iff)) THEN
1368             CALL histwrite_phy(nid_files(iff),
1369     $clef_stations(iff),
1370     $o_reffclwtop%name,itau_w,
1371     $            reffclwtop)
1372          ENDIF
1373       ENDIF
1374
1375! Champs 3D:
1376       IF (ok_ade .OR. ok_aie) then
1377          IF (o_ec550aer%flag(iff)<=lev_files(iff)) THEN
1378             CALL histwrite_phy(nid_files(iff),
1379     $clef_stations(iff),
1380     $o_ec550aer%name,itau_w,
1381     &            ec550aer)
1382          ENDIF
1383       ENDIF
1384
1385       IF (o_lwcon%flag(iff)<=lev_files(iff)) THEN
1386      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1387     $o_lwcon%name,itau_w,flwc)
1388       ENDIF
1389
1390       IF (o_iwcon%flag(iff)<=lev_files(iff)) THEN
1391      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1392     $o_iwcon%name,itau_w,fiwc)
1393       ENDIF
1394
1395       IF (o_temp%flag(iff)<=lev_files(iff)) THEN
1396      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1397     $o_temp%name,itau_w,t_seri)
1398       ENDIF
1399
1400       IF (o_theta%flag(iff)<=lev_files(iff)) THEN
1401      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1402     $o_theta%name,itau_w,theta)
1403       ENDIF
1404
1405       IF (o_ovapinit%flag(iff)<=lev_files(iff)) THEN
1406      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1407     $o_ovapinit%name,itau_w,
1408     $ qx(:,:,ivap))
1409       ENDIF
1410
1411       IF (o_ovap%flag(iff)<=lev_files(iff)) THEN
1412      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1413     $                   o_ovap%name,itau_w,q_seri)
1414       ENDIF
1415
1416       IF (o_geop%flag(iff)<=lev_files(iff)) THEN
1417      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1418     $o_geop%name,itau_w,zphi)
1419       ENDIF
1420
1421       IF (o_vitu%flag(iff)<=lev_files(iff)) THEN
1422      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1423     $o_vitu%name,itau_w,u_seri)
1424       ENDIF
1425
1426       IF (o_vitv%flag(iff)<=lev_files(iff)) THEN
1427      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1428     $o_vitv%name,itau_w,v_seri)
1429       ENDIF
1430
1431       IF (o_vitw%flag(iff)<=lev_files(iff)) THEN
1432      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1433     $o_vitw%name,itau_w,omega)
1434       ENDIF
1435
1436        IF (o_pres%flag(iff)<=lev_files(iff)) THEN
1437      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1438     $o_pres%name,itau_w,pplay)
1439        ENDIF
1440
1441        IF (o_paprs%flag(iff)<=lev_files(iff)) THEN
1442      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1443     $o_paprs%name,
1444     s                    itau_w,paprs(:,1:klev))
1445        ENDIF
1446
1447        IF (o_zfull%flag(iff)<=lev_files(iff)) THEN
1448         DO i=1, klon
1449          zx_tmp_fi3d1(i,1)= pphis(i)/RG
1450!020611   zx_tmp_fi3d(i,1)= pphis(i)/RG
1451         ENDDO
1452         DO k=1, klev
1453!020611        DO k=1, klev-1
1454         DO i=1, klon
1455!020611         zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - (t_seri(i,k) *RD * 
1456          zx_tmp_fi3d1(i,k+1)= zx_tmp_fi3d1(i,k) - (t_seri(i,k) *RD * 
1457     $    (paprs(i,k+1) - paprs(i,k))) / ( pplay(i,k) * RG ) 
1458         ENDDO
1459         ENDDO
1460      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1461     $o_zfull%name,itau_w,zx_tmp_fi3d1(:,2:klevp1))
1462!020611    $o_zfull%name,itau_w,zx_tmp_fi3d)
1463        ENDIF
1464
1465        IF (o_zhalf%flag(iff)<=lev_files(iff)) THEN
1466         DO i=1, klon
1467          zx_tmp_fi3d(i,1)= pphis(i)/RG - (
1468     $    (t_seri(i,1)+zxtsol(i))/2. *RD *
1469     $    (pplay(i,1) - paprs(i,1)))/( (paprs(i,1)+pplay(i,1))/2. * RG)
1470         ENDDO
1471         DO k=1, klev-1
1472         DO i=1, klon
1473          zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - (
1474     $    (t_seri(i,k)+t_seri(i,k+1))/2. *RD * 
1475     $    (pplay(i,k+1) - pplay(i,k))) / ( paprs(i,k) * RG ) 
1476         ENDDO
1477         ENDDO
1478      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1479     $o_zhalf%name,itau_w,zx_tmp_fi3d)
1480        ENDIF
1481
1482       IF (o_rneb%flag(iff)<=lev_files(iff)) THEN
1483      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1484     $o_rneb%name,itau_w,cldfra)
1485       ENDIF
1486
1487       IF (o_rnebcon%flag(iff)<=lev_files(iff)) THEN
1488      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1489     $o_rnebcon%name,itau_w,rnebcon)
1490       ENDIF
1491
1492       IF (o_rhum%flag(iff)<=lev_files(iff)) THEN
1493      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1494     $o_rhum%name,itau_w,zx_rh)
1495       ENDIF
1496
1497      IF (o_ozone%flag(iff)<=lev_files(iff)) THEN
1498         CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
1499     $o_ozone%name, itau_w,
1500     $        wo(:, :, 1) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
1501      ENDIF
1502
1503      IF (o_ozone_light%flag(iff)<=lev_files(iff) .and.
1504     $     read_climoz == 2) THEN
1505         CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
1506     $o_ozone_light%name, itau_w,
1507     $        wo(:, :, 2) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
1508      ENDIF
1509
1510       IF (o_dtphy%flag(iff)<=lev_files(iff)) THEN
1511      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1512     $o_dtphy%name,itau_w,d_t)
1513       ENDIF
1514
1515       IF (o_dqphy%flag(iff)<=lev_files(iff)) THEN
1516      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1517     s                  o_dqphy%name,itau_w, d_qx(:,:,ivap))
1518       ENDIF
1519
1520        DO nsrf=1, nbsrf
1521        IF (o_albe_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
1522        zx_tmp_fi2d(1 : klon) = falb1( 1 : klon, nsrf)
1523        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1524     s                    o_albe_srf(nsrf)%name,itau_w,
1525     $                     zx_tmp_fi2d)
1526        ENDIF
1527
1528        IF (o_rugs_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN 
1529        zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
1530        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1531     s                     o_rugs_srf(nsrf)%name,itau_w,
1532     $      zx_tmp_fi2d)
1533        ENDIF
1534
1535        IF (o_ages_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
1536        zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
1537        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1538     s                     o_ages_srf(nsrf)%name,itau_w
1539     $    ,zx_tmp_fi2d)
1540        ENDIF
1541        ENDDO !nsrf=1, nbsrf
1542
1543       IF (o_alb1%flag(iff)<=lev_files(iff)) THEN
1544      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1545     $o_alb1%name,itau_w,albsol1)
1546       ENDIF
1547
1548       IF (o_alb2%flag(iff)<=lev_files(iff)) THEN
1549      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1550     $o_alb2%name,itau_w,albsol2)
1551       ENDIF
1552
1553!FH Sorties pour la couche limite
1554      if (iflag_pbl>1) then
1555      zx_tmp_fi3d=0.
1556      do nsrf=1,nbsrf
1557         do k=1,klev
1558          zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k)
1559     $    +pctsrf(:,nsrf)*pbl_tke(:,k,nsrf)
1560         enddo
1561      enddo
1562       IF (o_tke%flag(iff)<=lev_files(iff)) THEN
1563      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1564     $o_tke%name,itau_w,zx_tmp_fi3d)
1565       ENDIF
1566
1567      IF (.NOT.clef_stations(iff)) THEN
1568       IF (o_tke_max%flag(iff)<=lev_files(iff)) THEN
1569      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1570     s                   o_tke_max%name,itau_w,zx_tmp_fi3d)
1571       ENDIF
1572      ENDIF
1573      endif
1574
1575       IF (o_kz%flag(iff)<=lev_files(iff)) THEN
1576      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1577     $o_kz%name,itau_w,coefh)
1578       ENDIF
1579
1580      IF (.NOT.clef_stations(iff)) THEN
1581       IF (o_kz_max%flag(iff)<=lev_files(iff)) THEN
1582      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1583     $o_kz_max%name,itau_w,coefh)
1584       ENDIF
1585      ENDIF
1586
1587       IF (o_clwcon%flag(iff)<=lev_files(iff)) THEN
1588      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1589     $o_clwcon%name,itau_w,clwcon0)
1590       ENDIF
1591
1592       IF (o_dtdyn%flag(iff)<=lev_files(iff)) THEN
1593      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1594     $o_dtdyn%name,itau_w,d_t_dyn)
1595       ENDIF
1596
1597       IF (o_dqdyn%flag(iff)<=lev_files(iff)) THEN
1598      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1599     $o_dqdyn%name,itau_w,d_q_dyn)
1600       ENDIF
1601
1602       IF (o_dudyn%flag(iff)<=lev_files(iff)) THEN
1603      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1604     $o_dudyn%name,itau_w,d_u_dyn)
1605       ENDIF                                                   
1606
1607       IF (o_dvdyn%flag(iff)<=lev_files(iff)) THEN                 
1608      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1609     $o_dvdyn%name,itau_w,d_v_dyn) 
1610       ENDIF                                                     
1611
1612       IF (o_dtcon%flag(iff)<=lev_files(iff)) THEN
1613      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys
1614      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1615     $o_dtcon%name,itau_w,zx_tmp_fi3d)
1616      ENDIF                                                     
1617
1618      if(iflag_thermals.eq.1)then
1619      IF (o_tntc%flag(iff)<=lev_files(iff)) THEN
1620      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys +
1621     $                           d_t_ajsb(1:klon,1:klev)/pdtphys
1622      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1623     $o_tntc%name,itau_w,zx_tmp_fi3d)
1624      ENDIF
1625      else if(iflag_thermals.gt.1.and.iflag_wake.EQ.1)then
1626      IF (o_tntc%flag(iff)<=lev_files(iff)) THEN
1627      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys +
1628     $                           d_t_ajs(1:klon,1:klev)/pdtphys +
1629     $                           d_t_wake(1:klon,1:klev)/pdtphys
1630      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1631     $o_tntc%name,itau_w,zx_tmp_fi3d)
1632      ENDIF
1633      endif
1634
1635       IF (o_ducon%flag(iff)<=lev_files(iff)) THEN
1636      zx_tmp_fi3d(1:klon,1:klev)=d_u_con(1:klon,1:klev)/pdtphys
1637      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1638     $o_ducon%name,itau_w,zx_tmp_fi3d)
1639       ENDIF
1640
1641       IF (o_dqcon%flag(iff)<=lev_files(iff)) THEN
1642      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
1643      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1644     $o_dqcon%name,itau_w,zx_tmp_fi3d)
1645       ENDIF
1646
1647      if(iflag_thermals.eq.1)then
1648       IF (o_tnhusc%flag(iff)<=lev_files(iff)) THEN
1649      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
1650      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1651     $o_tnhusc%name,itau_w,zx_tmp_fi3d)
1652       ENDIF
1653      else if(iflag_thermals.gt.1.and.iflag_wake.EQ.1)then
1654      IF (o_tnhusc%flag(iff)<=lev_files(iff)) THEN
1655      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys +
1656     $                           d_q_ajs(1:klon,1:klev)/pdtphys +
1657     $                           d_q_wake(1:klon,1:klev)/pdtphys
1658      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1659     $o_tnhusc%name,itau_w,zx_tmp_fi3d)
1660      ENDIF
1661      endif
1662
1663       IF (o_dtlsc%flag(iff)<=lev_files(iff)) THEN
1664      zx_tmp_fi3d(1:klon,1:klev)=d_t_lsc(1:klon,1:klev)/pdtphys
1665      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1666     $o_dtlsc%name,itau_w,zx_tmp_fi3d)
1667       ENDIF
1668
1669       IF (o_dtlschr%flag(iff)<=lev_files(iff)) THEN
1670      zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+
1671     $                           d_t_eva(1:klon,1:klev))/pdtphys
1672      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1673     s                   o_dtlschr%name,itau_w,zx_tmp_fi3d)
1674       ENDIF
1675
1676       IF (o_dqlsc%flag(iff)<=lev_files(iff)) THEN
1677      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
1678      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1679     $o_dqlsc%name,itau_w,zx_tmp_fi3d)
1680       ENDIF
1681
1682!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1683! Sorties specifiques a la separation thermiques/non thermiques
1684       if (iflag_thermals>1) then
1685
1686       IF (o_dtlscth%flag(iff)<=lev_files(iff)) THEN
1687      zx_tmp_fi3d(1:klon,1:klev)=d_t_lscth(1:klon,1:klev)/pdtphys
1688      CALL
1689     s histwrite_phy(nid_files(iff),clef_stations(iff),
1690     $o_dtlscth%name,itau_w,zx_tmp_fi3d)
1691       ENDIF
1692
1693       IF (o_dtlscst%flag(iff)<=lev_files(iff)) THEN
1694      zx_tmp_fi3d(1:klon,1:klev)=d_t_lscst(1:klon,1:klev)/pdtphys
1695      CALL
1696     s histwrite_phy(nid_files(iff),clef_stations(iff),
1697     $o_dtlscst%name,itau_w,zx_tmp_fi3d)
1698       ENDIF
1699
1700       IF (o_dqlscth%flag(iff)<=lev_files(iff)) THEN
1701      zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
1702      CALL
1703     s histwrite_phy(nid_files(iff),clef_stations(iff),
1704     $o_dqlscth%name,itau_w,zx_tmp_fi3d)
1705       ENDIF
1706
1707       IF (o_dqlscst%flag(iff)<=lev_files(iff)) THEN
1708      zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
1709      CALL
1710     s histwrite_phy(nid_files(iff),clef_stations(iff),
1711     $o_dqlscst%name,itau_w,zx_tmp_fi3d)
1712       ENDIF
1713
1714       IF (o_plulth%flag(iff)<=lev_files(iff)) THEN
1715      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1716     $o_plulth%name,itau_w,plul_th)
1717       ENDIF
1718
1719       IF (o_plulst%flag(iff)<=lev_files(iff)) THEN
1720      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1721     $o_plulst%name,itau_w,plul_st)
1722       ENDIF
1723
1724      do k=1,klev
1725      do i=1,klon
1726          if (ptconvth(i,k)) then
1727           zx_tmp_fi3d(i,k)=1.
1728          else
1729           zx_tmp_fi3d(i,k)=0.
1730          endif
1731      enddo
1732      enddo
1733       IF (o_ptconvth%flag(iff)<=lev_files(iff)) THEN
1734      CALL
1735     s  histwrite_phy(nid_files(iff),clef_stations(iff),
1736     $o_ptconvth%name,itau_w,zx_tmp_fi3d)
1737       ENDIF
1738
1739      do i=1,klon
1740           zx_tmp_fi2d(1:klon)=lmax_th(:)
1741      enddo
1742       IF (o_ptconvth%flag(iff)<=lev_files(iff)) THEN
1743      CALL
1744     s histwrite_phy(nid_files(iff),clef_stations(iff),
1745     $o_lmaxth%name,itau_w,zx_tmp_fi2d)
1746       ENDIF
1747
1748      endif ! iflag_thermals>1
1749
1750!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1751
1752       IF (o_dtvdf%flag(iff)<=lev_files(iff)) THEN
1753      zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
1754      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1755     $o_dtvdf%name,itau_w,zx_tmp_fi3d)
1756       ENDIF
1757
1758       IF (o_dqvdf%flag(iff)<=lev_files(iff)) THEN
1759      zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
1760      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1761     $o_dqvdf%name,itau_w,zx_tmp_fi3d)
1762       ENDIF
1763
1764       IF (o_dteva%flag(iff)<=lev_files(iff)) THEN
1765      zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
1766      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1767     $o_dteva%name,itau_w,zx_tmp_fi3d)
1768       ENDIF
1769
1770       IF (o_dqeva%flag(iff)<=lev_files(iff)) THEN
1771      zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
1772      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1773     $o_dqeva%name,itau_w,zx_tmp_fi3d)
1774       ENDIF
1775
1776       IF (o_ptconv%flag(iff)<=lev_files(iff)) THEN
1777      zpt_conv = 0.
1778      where (ptconv) zpt_conv = 1.
1779      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1780     $o_ptconv%name,itau_w,zpt_conv)
1781       ENDIF
1782
1783       IF (o_ratqs%flag(iff)<=lev_files(iff)) THEN
1784      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1785     $o_ratqs%name,itau_w,ratqs)
1786       ENDIF
1787
1788       IF (o_dtthe%flag(iff)<=lev_files(iff)) THEN
1789      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajs(1:klon,1:klev)/pdtphys -
1790     $                           d_t_ajsb(1:klon,1:klev)/pdtphys
1791      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1792     $o_dtthe%name,itau_w,zx_tmp_fi3d)
1793       ENDIF
1794
1795       IF (iflag_thermals.gt.1) THEN
1796        IF (o_ftime_th%flag(iff)<=lev_files(iff)) THEN
1797! Pour l instant 0 a y reflichir pour les thermiques
1798         zx_tmp_fi2d=0. 
1799        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1800     $o_ftime_th%name,
1801     s                     itau_w,zx_tmp_fi2d)
1802        ENDIF
1803
1804        IF (o_f_th%flag(iff)<=lev_files(iff)) THEN
1805        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1806     $o_f_th%name,itau_w,fm_therm)
1807        ENDIF
1808
1809        IF (o_e_th%flag(iff)<=lev_files(iff)) THEN
1810        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1811     $o_e_th%name,itau_w,entr_therm)
1812        ENDIF
1813
1814        IF (o_w_th%flag(iff)<=lev_files(iff)) THEN
1815        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1816     $o_w_th%name,itau_w,zw2)
1817        ENDIF
1818
1819        IF (o_q_th%flag(iff)<=lev_files(iff)) THEN
1820        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1821     $o_q_th%name,itau_w,zqasc)
1822        ENDIF
1823
1824        IF (o_lambda_th%flag(iff)<=lev_files(iff)) THEN
1825        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1826     s                     o_lambda_th%name,itau_w,lambda_th)
1827        ENDIF
1828
1829        IF (o_a_th%flag(iff)<=lev_files(iff)) THEN
1830        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1831     $o_a_th%name,itau_w,fraca)
1832        ENDIF
1833
1834       IF (o_d_th%flag(iff)<=lev_files(iff)) THEN
1835       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1836     $o_d_th%name,itau_w,detr_therm)
1837       ENDIF
1838
1839       IF (o_f0_th%flag(iff)<=lev_files(iff)) THEN
1840      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1841     $o_f0_th%name,itau_w,f0)
1842       ENDIF
1843
1844       IF (o_zmax_th%flag(iff)<=lev_files(iff)) THEN
1845       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1846     $o_zmax_th%name,itau_w,zmax_th)
1847       ENDIF
1848
1849       IF (o_dqthe%flag(iff)<=lev_files(iff)) THEN
1850      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys -
1851     $                           d_q_ajsb(1:klon,1:klev)/pdtphys
1852      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1853     $o_dqthe%name,itau_w,zx_tmp_fi3d)
1854       ENDIF
1855
1856      ENDIF !iflag_thermals
1857
1858       IF (o_dtajs%flag(iff)<=lev_files(iff)) THEN
1859      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajsb(1:klon,1:klev)/pdtphys
1860      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1861     $o_dtajs%name,itau_w,zx_tmp_fi3d)
1862       ENDIF
1863
1864       IF (o_dqajs%flag(iff)<=lev_files(iff)) THEN
1865      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
1866      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1867     $o_dqajs%name,itau_w,zx_tmp_fi3d)
1868       ENDIF
1869
1870       IF (o_dtswr%flag(iff)<=lev_files(iff)) THEN
1871      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY
1872      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1873     $o_dtswr%name,itau_w,zx_tmp_fi3d)
1874       ENDIF
1875
1876       IF (o_dtsw0%flag(iff)<=lev_files(iff)) THEN
1877      zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
1878      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1879     $o_dtsw0%name,itau_w,zx_tmp_fi3d)
1880       ENDIF
1881
1882       IF (o_dtlwr%flag(iff)<=lev_files(iff)) THEN
1883      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
1884      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1885     $o_dtlwr%name,itau_w,zx_tmp_fi3d)
1886       ENDIF
1887
1888       IF (o_dtlw0%flag(iff)<=lev_files(iff)) THEN
1889      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
1890      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1891     $o_dtlw0%name,itau_w,zx_tmp_fi3d)
1892       ENDIF
1893
1894       IF (o_dtec%flag(iff)<=lev_files(iff)) THEN
1895      zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)
1896      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1897     $o_dtec%name,itau_w,zx_tmp_fi3d)
1898       ENDIF
1899
1900       IF (o_duvdf%flag(iff)<=lev_files(iff)) THEN
1901      zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
1902      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1903     $o_duvdf%name,itau_w,zx_tmp_fi3d)
1904       ENDIF
1905
1906       IF (o_dvvdf%flag(iff)<=lev_files(iff)) THEN
1907      zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
1908      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1909     $o_dvvdf%name,itau_w,zx_tmp_fi3d)
1910       ENDIF
1911
1912       IF (ok_orodr) THEN
1913      IF (o_duoro%flag(iff)<=lev_files(iff)) THEN
1914      zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
1915      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1916     $o_duoro%name,itau_w,zx_tmp_fi3d)
1917       ENDIF
1918
1919      IF (o_dvoro%flag(iff)<=lev_files(iff)) THEN
1920      zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
1921      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1922     $o_dvoro%name,itau_w,zx_tmp_fi3d)
1923      ENDIF
1924
1925      IF (o_dtoro%flag(iff)<=lev_files(iff)) THEN
1926      zx_tmp_fi3d(1:klon,1:klev)=d_t_oro(1:klon,1:klev)/pdtphys
1927      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1928     $o_dtoro%name,itau_w,zx_tmp_fi3d)
1929      ENDIF
1930       ENDIF
1931
1932        IF (ok_orolf) THEN
1933       IF (o_dulif%flag(iff)<=lev_files(iff)) THEN
1934      zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
1935      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1936     $o_dulif%name,itau_w,zx_tmp_fi3d)
1937       ENDIF
1938
1939        IF (o_dvlif%flag(iff)<=lev_files(iff)) THEN
1940      zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
1941      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1942     $o_dvlif%name,itau_w,zx_tmp_fi3d)
1943       ENDIF
1944
1945        IF (o_dtlif%flag(iff)<=lev_files(iff)) THEN
1946      zx_tmp_fi3d(1:klon,1:klev)=d_t_lif(1:klon,1:klev)/pdtphys
1947      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1948     $o_dtlif%name,itau_w,zx_tmp_fi3d)
1949       ENDIF
1950        ENDIF
1951
1952       IF (ok_hines) THEN
1953       IF (o_duhin%flag(iff)<=lev_files(iff)) THEN
1954      zx_tmp_fi3d(1:klon,1:klev)=d_u_hin(1:klon,1:klev)/pdtphys
1955      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1956     $o_duhin%name,itau_w,zx_tmp_fi3d)
1957       ENDIF
1958
1959
1960        IF (o_dvhin%flag(iff)<=lev_files(iff)) THEN
1961      zx_tmp_fi3d(1:klon,1:klev)=d_v_hin(1:klon,1:klev)/pdtphys
1962      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1963     $o_dvhin%name,itau_w,zx_tmp_fi3d)
1964       ENDIF
1965
1966        IF (o_dthin%flag(iff)<=lev_files(iff)) THEN
1967      zx_tmp_fi3d(1:klon,1:klev)=d_t_hin(1:klon,1:klev)/pdtphys
1968      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1969     $o_dthin%name,itau_w,zx_tmp_fi3d)
1970       ENDIF
1971        ENDIF
1972
1973       IF (o_rsu%flag(iff)<=lev_files(iff)) THEN
1974      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1975     $o_rsu%name,itau_w,swup)
1976       ENDIF
1977       IF (o_rsd%flag(iff)<=lev_files(iff)) THEN
1978      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1979     $o_rsd%name,itau_w,swdn)
1980       ENDIF
1981       IF (o_rlu%flag(iff)<=lev_files(iff)) THEN
1982      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1983     $o_rlu%name,itau_w,lwup)
1984       ENDIF
1985       IF (o_rld%flag(iff)<=lev_files(iff)) THEN
1986      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1987     $o_rld%name,itau_w,lwdn)
1988       ENDIF
1989
1990       IF (o_rsucs%flag(iff)<=lev_files(iff)) THEN
1991      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1992     $o_rsucs%name,itau_w,swup0)
1993       ENDIF
1994       IF (o_rsdcs%flag(iff)<=lev_files(iff)) THEN
1995      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
1996     $o_rsdcs%name,itau_w,swdn0)
1997       ENDIF
1998       IF (o_rlucs%flag(iff)<=lev_files(iff)) THEN
1999      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2000     $o_rlucs%name,itau_w,lwup0)
2001       ENDIF
2002       IF (o_rldcs%flag(iff)<=lev_files(iff)) THEN
2003      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2004     $o_rldcs%name,itau_w,lwdn0)
2005       ENDIF
2006
2007       IF (o_tnt%flag(iff)<=lev_files(iff)) THEN
2008      zx_tmp_fi3d(1:klon,1:klev)=d_t(1:klon,1:klev)+
2009     $d_t_dyn(1:klon,1:klev)
2010      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2011     $o_tnt%name,itau_w,zx_tmp_fi3d)
2012       ENDIF
2013
2014       IF (o_tntr%flag(iff)<=lev_files(iff)) THEN
2015      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY -
2016     $cool(1:klon,1:klev)/RDAY
2017      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2018     $o_tntr%name,itau_w,zx_tmp_fi3d)
2019       ENDIF
2020
2021       IF (o_tntscpbl%flag(iff)<=lev_files(iff)) THEN
2022      zx_tmp_fi3d(1:klon,1:klev)= (d_t_lsc(1:klon,1:klev)+
2023     $                             d_t_eva(1:klon,1:klev)+
2024     $                             d_t_vdf(1:klon,1:klev))/pdtphys
2025      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2026     $o_tntscpbl%name,itau_w,zx_tmp_fi3d)
2027       ENDIF
2028
2029       IF (o_tnhus%flag(iff)<=lev_files(iff)) THEN
2030      zx_tmp_fi3d(1:klon,1:klev)=d_qx(1:klon,1:klev,ivap)+
2031     $d_q_dyn(1:klon,1:klev)
2032      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2033     $o_tnhus%name,itau_w,zx_tmp_fi3d)
2034       ENDIF
2035
2036       IF (o_tnhusscpbl%flag(iff)<=lev_files(iff)) THEN
2037      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys+
2038     $                           d_q_eva(1:klon,1:klev)/pdtphys
2039      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2040     $o_tnhusscpbl%name,itau_w,zx_tmp_fi3d)
2041       ENDIF
2042
2043       IF (o_evu%flag(iff)<=lev_files(iff)) THEN
2044      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2045     $o_evu%name,itau_w,coefm)
2046       ENDIF
2047
2048       IF (o_h2o%flag(iff)<=lev_files(iff)) THEN
2049      zx_tmp_fi3d(1:klon,1:klev)=q_seri(1:klon,1:klev)+
2050     $                           ql_seri(1:klon,1:klev) 
2051      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2052     $o_h2o%name,itau_w,zx_tmp_fi3d)
2053       ENDIF
2054
2055       IF (o_mcd%flag(iff)<=lev_files(iff)) THEN
2056      zx_tmp_fi3d(1:klon,1:klev)=-1 * (dnwd(1:klon,1:klev)+
2057     $                                 dnwd0(1:klon,1:klev)) 
2058      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2059     $o_mcd%name,itau_w,zx_tmp_fi3d)
2060       ENDIF
2061
2062       IF (o_dmc%flag(iff)<=lev_files(iff)) THEN
2063      zx_tmp_fi3d(1:klon,1:klev)=upwd(1:klon,1:klev) +
2064     $  dnwd(1:klon,1:klev)+ dnwd0(1:klon,1:klev) 
2065      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2066     $o_dmc%name,itau_w,zx_tmp_fi3d)
2067       ENDIF
2068
2069       IF (o_ref_liq%flag(iff)<=lev_files(iff)) THEN
2070      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2071     $o_ref_liq%name,itau_w,ref_liq)
2072       ENDIF
2073
2074       IF (o_ref_ice%flag(iff)<=lev_files(iff)) THEN
2075      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2076     $o_ref_ice%name,itau_w,ref_ice)
2077       ENDIF
2078
2079      if (RCO2_per.NE.RCO2_act.OR.RCH4_per.NE.RCH4_act.OR.
2080     $ RN2O_per.NE.RN2O_act.OR.RCFC11_per.NE.RCFC11_act.OR.
2081     $ RCFC12_per.NE.RCFC12_act) THEN
2082
2083       IF (o_rsut4co2%flag(iff)<=lev_files(iff)) THEN
2084      zx_tmp_fi2d(1 : klon) = swupp ( 1 : klon, klevp1 )
2085      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2086     $o_rsut4co2%name,itau_w,zx_tmp_fi2d)
2087       ENDIF
2088
2089       IF (o_rlut4co2%flag(iff)<=lev_files(iff)) THEN
2090      zx_tmp_fi2d(1 : klon) = lwupp ( 1 : klon, klevp1 )
2091      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2092     $o_rlut4co2%name,itau_w,zx_tmp_fi2d)
2093       ENDIF
2094
2095       IF (o_rsutcs4co2%flag(iff)<=lev_files(iff)) THEN
2096      zx_tmp_fi2d(1 : klon) = swup0p ( 1 : klon, klevp1 )
2097      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2098     $o_rsutcs4co2%name,itau_w,zx_tmp_fi2d)
2099       ENDIF
2100
2101       IF (o_rlutcs4co2%flag(iff)<=lev_files(iff)) THEN
2102      zx_tmp_fi2d(1 : klon) = lwup0p ( 1 : klon, klevp1 )
2103      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2104     $o_rlutcs4co2%name,itau_w,zx_tmp_fi2d)
2105       ENDIF
2106
2107       IF (o_rsu4co2%flag(iff)<=lev_files(iff)) THEN
2108      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2109     $o_rsu4co2%name,itau_w,swupp)
2110       ENDIF
2111
2112       IF (o_rlu4co2%flag(iff)<=lev_files(iff)) THEN
2113      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2114     $o_rlu4co2%name,itau_w,lwupp)
2115       ENDIF
2116
2117       IF (o_rsucs4co2%flag(iff)<=lev_files(iff)) THEN
2118      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2119     $o_rsucs4co2%name,itau_w,swup0p)
2120       ENDIF
2121
2122       IF (o_rlucs4co2%flag(iff)<=lev_files(iff)) THEN
2123      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2124     $o_rlucs4co2%name,itau_w,lwup0p)
2125       ENDIF
2126
2127       IF (o_rsd4co2%flag(iff)<=lev_files(iff)) THEN
2128      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2129     $o_rsd4co2%name,itau_w,swdnp)
2130       ENDIF
2131
2132       IF (o_rld4co2%flag(iff)<=lev_files(iff)) THEN
2133      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2134     $o_rld4co2%name,itau_w,lwdnp)
2135       ENDIF
2136
2137       IF (o_rsdcs4co2%flag(iff)<=lev_files(iff)) THEN
2138      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2139     $o_rsdcs4co2%name,itau_w,swdn0p)
2140       ENDIF
2141
2142       IF (o_rldcs4co2%flag(iff)<=lev_files(iff)) THEN
2143      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2144     $o_rldcs4co2%name,itau_w,lwdn0p)
2145       ENDIF
2146
2147      endif
2148
2149        if (nqtot.GE.3) THEN
2150         DO iq=3,nqtot
2151       IF (o_trac(iq-2)%flag(iff)<=lev_files(iff)) THEN
2152         CALL histwrite_phy(nid_files(iff),clef_stations(iff),
2153     s                  o_trac(iq-2)%name,itau_w,qx(:,:,iq))
2154       ENDIF
2155         ENDDO
2156        endif
2157
2158      if (ok_sync) then
2159c$OMP MASTER
2160      call histsync(nid_files(iff))
2161c$OMP END MASTER
2162      endif
2163
2164       ENDIF ! clef_files
2165
2166      ENDDO ! iff=1,nfiles
Note: See TracBrowser for help on using the repository browser.