SURFEX v8.1
General documentation of Surfex
write_diag_misc_isban.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 ! #########
6  SUBROUTINE write_diag_misc_isba_n (DTCO, HSELECT, OSNOWDIMNC, U, OPATCH_BUDGET, D, &
7  ND, DM, NDM, IO, S, K, NP, TPSNOW, HPROGRAM)
8 ! #################################
9 !
10 !!**** *WRITE_DIAG_MISC_ISBA* - writes the ISBA diagnostic fields
11 !!
12 !! PURPOSE
13 !! -------
14 !!
15 !!
16 !!** METHOD
17 !! ------
18 !!
19 !! REFERENCE
20 !! ---------
21 !!
22 !!
23 !! AUTHOR
24 !! ------
25 !! P. Le Moigne *Meteo France*
26 !!
27 !! MODIFICATIONS
28 !! -------------
29 !! Original 10/2004
30 !! B. Decharme 2008 Total Albedo, Total SWI and Floodplains
31 !! B. Decharme 06/2009 key to write (or not) patch result
32 !! A.L. Gibelin 04/09 : Add respiration diagnostics
33 !! A.L. Gibelin 05/09 : Add carbon spinup
34 !! A.L. Gibelin 07/09 : Suppress RDK and transform GPP as a diagnostic
35 !! D. Carrer 04/11 : Add FAPAR and effective LAI
36 !! B. Decharme 09/2012 : suppress NWG_LAYER (parallelization problems)
37 !! B. Decharme 09/12 : Carbon fluxes in diag_evap
38 !! B. Decharme 09/12 New diag for DIF:
39 !! F2 stress
40 !! Root zone swi, wg and wgi
41 !! swi, wg and wgi comparable to ISBA-FR-DG2 and DG3 layers
42 !! active layer thickness over permafrost
43 !! frozen layer thickness over non-permafrost
44 !! B. Decharme 06/13 All snow outputs noted SN
45 !! XTSRAD_NAT instead of XAVG_TSRAD
46 !! delete NWG_SIZE
47 !! water table depth
48 !!
49 !-------------------------------------------------------------------------------
50 !
51 !* 0. DECLARATIONS
52 ! ------------
53 !
55 !
57 USE modd_surf_atm_n, ONLY : surf_atm_t
58 USE modd_diag_n, ONLY : diag_t, diag_np_t
62 !
63 USE modd_xios, ONLY : lallow_add_dim
64 !
65 USE modd_surf_par, ONLY : nundef, xundef
66 !
67 USE modd_assim, ONLY : lassim, cassim_isba, nvar, cvar, nobstype, nboutput, cobs
68 !
69 USE modd_agri, ONLY : lagrip
70 !
71 USE modi_init_io_surf_n
73 USE modi_write_field_2d_patch
74 USE modi_write_field_1d_patch
75 USE modi_end_io_surf_n
76 !
77 USE yomhook ,ONLY : lhook, dr_hook
78 USE parkind1 ,ONLY : jprb
79 !
80 IMPLICIT NONE
81 !
82 !* 0.1 Declarations of arguments
83 ! -------------------------
84 !
85 !
86 TYPE(data_cover_t), INTENT(INOUT) :: DTCO
87  CHARACTER(LEN=*), DIMENSION(:), INTENT(IN) :: HSELECT
88 LOGICAL, INTENT(IN) :: OSNOWDIMNC
89 TYPE(surf_atm_t), INTENT(INOUT) :: U
90 LOGICAL, INTENT(IN) :: OPATCH_BUDGET
91 TYPE(diag_t), INTENT(INOUT) :: D
92 TYPE(diag_np_t), INTENT(INOUT) :: ND
93 TYPE(diag_misc_isba_t), INTENT(INOUT) :: DM
94 TYPE(diag_misc_isba_np_t), INTENT(INOUT) :: NDM
95 TYPE(isba_options_t), INTENT(INOUT) :: IO
96 TYPE(isba_s_t), INTENT(INOUT) :: S
97 TYPE(isba_k_t), INTENT(INOUT) :: K
98 TYPE(isba_np_t), INTENT(INOUT) :: NP
99 TYPE(surf_snow), INTENT(IN) :: TPSNOW
100 !
101  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! program calling
102 !
103 !* 0.2 Declarations of local variables
104 ! -------------------------------
105 !
106 INTEGER :: IRESP ! IRESP : return-code if a problem appears
107  CHARACTER(LEN=1) :: YVAR, YOBS, YTIM
108  CHARACTER(LEN=12) :: YRECFM ! Name of the article to be read
109  CHARACTER(LEN=100):: YCOMMENT ! Comment string
110  CHARACTER(LEN=2) :: YLVL
111  CHARACTER(LEN=20) :: YFORM
112 !
113 REAL, DIMENSION(SIZE(DM%XSWI,1)) :: ZMAX
114 INTEGER :: JL, JJ, JVAR, JOBS, JP, JI, JT, JK, ISIZE
115 !
116 REAL(KIND=JPRB) :: ZHOOK_HANDLE
117 !
118 !-------------------------------------------------------------------------------
119 !
120 ! Initialisation for IO
121 !
122 IF (lhook) CALL dr_hook('WRITE_DIAG_MISC_ISBA_N',0,zhook_handle)
123 !
124 IF ( dm%LPROSNOW ) THEN
125  CALL init_io_surf_n(dtco, u, hprogram,'NATURE','ISBA ','WRITE','ISBA_PROGNOSTIC.OUT.nc')
126 ELSE
127  CALL init_io_surf_n(dtco, u, hprogram,'NATURE','ISBA ','WRITE','ISBA_DIAGNOSTICS.OUT.nc')
128 ENDIF
129 !
130 !-------------------------------------------------------------------------------
131 !
132 IF (dm%LSURF_MISC_BUDGET) THEN
133  !
134  !* 2. Miscellaneous fields :
135  !
136  !-------------------------------------------------------------------------------
137  !
138  ! 2.1 Halstead coefficient
139  ! --------------------
140  !
141  yrecfm='HV_ISBA'
142  ycomment='Halstead coefficient averaged over tile nature (-)'
143  CALL write_surf(hselect, hprogram,yrecfm,dm%XHV(:),iresp,hcomment=ycomment)
144  !
145  ! 2.2 Snow fractions
146  ! --------------
147  !
148  yrecfm='PSNG_ISBA'
149  ycomment='snow fraction over ground averaged over tile nature (-)'
150  CALL write_surf(hselect, hprogram,yrecfm,dm%XPSNG(:),iresp,hcomment=ycomment)
151  !
152  yrecfm='PSNV_ISBA'
153  ycomment='snow fraction over vegetation averaged over tile nature (-)'
154  CALL write_surf(hselect, hprogram,yrecfm,dm%XPSNV(:),iresp,hcomment=ycomment)
155  !
156  yrecfm='PSN_ISBA'
157  ycomment='total snow fraction averaged over tile nature (-)'
158  CALL write_surf(hselect, hprogram,yrecfm,dm%XPSN(:),iresp,hcomment=ycomment)
159  !
160  ! 2.3 Total Albedo and surface temperature
161  ! ------------------------------------
162  !
163  IF (tpsnow%SCHEME=='3-L' .OR. tpsnow%SCHEME=='CRO') THEN
164  !
165  yrecfm='TS_ISBA'
166  ycomment='total surface temperature (isba+snow) over tile nature'
167  CALL write_surf(hselect, hprogram,yrecfm,d%XTS(:),iresp,hcomment=ycomment)
168  !
169  yrecfm='TSRAD_ISBA'
170  ycomment='total radiative surface temperature (isba+snow) over tile nature'
171  CALL write_surf(hselect, hprogram,yrecfm,s%XTSRAD_NAT(:),iresp,hcomment=ycomment)
172  !
173  END IF
174  !
175  ! 2.4 Soil Wetness Index, Water content and active layer depth
176  ! --------------------------------------------------------
177  !
178  IF(io%CISBA=='DIF')THEN
179  zmax(:) = 0.
180  !
181  DO jp = 1,io%NPATCH
182  DO ji = 1,np%AL(jp)%NSIZE_P
183  jj = np%AL(jp)%NR_P(ji)
184  !
185  IF (np%AL(jp)%NWG_LAYER(ji)/=nundef.AND.np%AL(jp)%NWG_LAYER(ji)>zmax(jj)) THEN
186  zmax(jj) = np%AL(jp)%NWG_LAYER(ji)
187  ENDIF
188  ENDDO
189  ENDDO
190  !
191  DO jj=1,SIZE(dm%XSWI,1)
192 
193  DO jl = 1,io%NGROUND_LAYER
194  IF(jl>zmax(jj))THEN
195  dm%XSWI (jj,jl) = xundef
196  dm%XTSWI(jj,jl) = xundef
197  ENDIF
198  ENDDO
199 
200  ENDDO
201  ENDIF
202  !
203  DO jl=1,io%NGROUND_LAYER
204  !
205  WRITE(ylvl,'(I2)') jl
206  !
207  yrecfm='SWI'//adjustl(ylvl(:len_trim(ylvl)))
208  yrecfm=yrecfm(:len_trim(yrecfm))//'_ISBA'
209  yform='(A29,I1.1,A4)'
210  IF (jl >= 10) yform='(A29,I2.2,A4)'
211  WRITE(ycomment,fmt=yform) 'soil wetness index for layer ',jl,' (-)'
212  CALL write_surf(hselect, hprogram,yrecfm,dm%XSWI(:,jl),iresp,hcomment=ycomment)
213  !
214  yrecfm='TSWI'//adjustl(ylvl(:len_trim(ylvl)))
215  yrecfm=yrecfm(:len_trim(yrecfm))//'_ISBA'
216  yform='(A29,I1.1,A4)'
217  IF (jl >= 10) yform='(A29,I2.2,A4)'
218  WRITE(ycomment,fmt=yform) 'total swi (liquid+solid) for layer ',jl,' (-)'
219  CALL write_surf(hselect, hprogram,yrecfm,dm%XTSWI(:,jl),iresp,hcomment=ycomment)
220  !
221  END DO
222  !
223  yrecfm='SWI_T_ISBA'
224  ycomment='soil wetness index over the soil column (-)'
225  CALL write_surf(hselect, hprogram,yrecfm,dm%XSOIL_SWI(:),iresp,hcomment=ycomment)
226  !
227  yrecfm='TSWI_T_ISBA'
228  ycomment='total soil wetness index over the soil column (-)'
229  CALL write_surf(hselect, hprogram,yrecfm,dm%XSOIL_TSWI(:),iresp,hcomment=ycomment)
230  !
231  yrecfm='WGTOT_T_ISBA'
232  ycomment='total water content (liquid+solid) over the soil column (kg/m2)'
233  CALL write_surf(hselect, hprogram,yrecfm,dm%XSOIL_TWG(:),iresp,hcomment=ycomment)
234  !
235  yrecfm='WGI_T_ISBA'
236  ycomment='total ice content (solid) over the soil column (kg/m2)'
237  CALL write_surf(hselect, hprogram,yrecfm,dm%XSOIL_TWGI(:),iresp,hcomment=ycomment)
238  !
239  yrecfm='WGTOT_ISBA'
240  ycomment='total volumetric water content (liquid+solid) over the soil column (m3/m3)'
241  CALL write_surf(hselect, hprogram,yrecfm,dm%XSOIL_WG(:),iresp,hcomment=ycomment)
242  !
243  IF (.NOT.lallow_add_dim) THEN
244  yrecfm='WGI_ISBA'
245  ycomment='total volumetric ice content (solid) over the soil column (m3/m3)'
246  CALL write_surf(hselect, hprogram,yrecfm,dm%XSOIL_WGI(:),iresp,hcomment=ycomment)
247  ENDIF
248  !
249  IF(io%CISBA=='DIF') THEN
250  !
251  IF (dm%LSURF_MISC_DIF)THEN
252  !
253  yrecfm='TSWI_D2_ISBA'
254  ycomment='total soil wetness index over comparable FR-DG2 reservoir (-)'
255  CALL write_surf(hselect, hprogram,yrecfm,dm%XFRD2_TSWI(:),iresp,hcomment=ycomment)
256  !
257  yrecfm='WG_D2_ISBA'
258  ycomment='liquid water content over comparable FR-DG2 reservoir (m3/m3)'
259  CALL write_surf(hselect, hprogram,yrecfm,dm%XFRD2_TWG(:),iresp,hcomment=ycomment)
260  !
261  yrecfm='WGI_D2_ISBA'
262  ycomment='ice content over comparable FR-DG2 reservoir (m3/m3)'
263  CALL write_surf(hselect, hprogram,yrecfm,dm%XFRD2_TWGI(:),iresp,hcomment=ycomment)
264  !
265  yrecfm='TSWI_D3_ISBA'
266  ycomment='total soil wetness index over comparable FR-DG3 reservoir (-)'
267  CALL write_surf(hselect, hprogram,yrecfm,dm%XFRD3_TSWI(:),iresp,hcomment=ycomment)
268  !
269  yrecfm='WG_D3_ISBA'
270  ycomment='liquid water content over comparable FR-DG3 reservoir (m3/m3)'
271  CALL write_surf(hselect, hprogram,yrecfm,dm%XFRD3_TWG(:),iresp,hcomment=ycomment)
272  !
273  yrecfm='WGI_D3_ISBA'
274  ycomment='ice content over comparable FR-DG3 reservoir (m3/m3)'
275  CALL write_surf(hselect, hprogram,yrecfm,dm%XFRD3_TWGI(:),iresp,hcomment=ycomment)
276  !
277  ENDIF
278  !
279  yrecfm='ALT_ISBA'
280  ycomment='active layer thickness over permafrost (m)'
281  CALL write_surf(hselect, hprogram,yrecfm,dm%XALT(:),iresp,hcomment=ycomment)
282  !
283  yrecfm='FLT_ISBA'
284  ycomment='frozen layer thickness over non-permafrost (m)'
285  CALL write_surf(hselect, hprogram,yrecfm,dm%XFLT(:),iresp,hcomment=ycomment)
286  !
287  ENDIF
288  !
289  ! 2.5 Snow outputs
290  ! -------------
291  !
292  yrecfm='WSN_T_ISBA'
293  ycomment='Total_snow_reservoir (kg/m2)'
294  CALL write_surf(hselect, hprogram,yrecfm,dm%XTWSNOW(:),iresp,hcomment=ycomment)
295  !
296  yrecfm='DSN_T_ISBA'
297  ycomment='Total_snow_depth (m)'
298  CALL write_surf(hselect, hprogram,yrecfm,dm%XTDSNOW(:),iresp,hcomment=ycomment)
299  !
300  yrecfm='TSN_T_ISBA'
301  ycomment='Total_snow_temperature (K)'
302  CALL write_surf(hselect, hprogram,yrecfm,dm%XTTSNOW(:),iresp,hcomment=ycomment)
303  !
304  IF (tpsnow%SCHEME=='CRO' .AND. dm%LPROSNOW) THEN
305  !
306  ycomment='accumulated snow thickness for past 1 days'
307  CALL write_surf(hselect,hprogram,'SD_1DY_ISBA',dm%XSNDPT_1DY(:),iresp,hcomment=ycomment)
308  !
309  ycomment='accumulated snow thickness for past 3 days'
310  CALL write_surf(hselect,hprogram,'SD_3DY_ISBA',dm%XSNDPT_3DY(:),iresp,hcomment=ycomment)
311  !
312  ycomment='accumulated snow thickness for past 5 days'
313  CALL write_surf(hselect,hprogram,'SD_5DY_ISBA',dm%XSNDPT_5DY(:),iresp,hcomment=ycomment)
314  !
315  ycomment='accumulated snow thickness for past 7 days'
316  CALL write_surf(hselect,hprogram,'SD_7DY_ISBA',dm%XSNDPT_7DY(:),iresp,hcomment=ycomment)
317  !
318  ycomment='accumulated snow water equivalent for past 1 days'
319  CALL write_surf(hselect,hprogram,'SWE_1DY_ISBA',dm%XSNSWE_1DY(:),iresp,hcomment=ycomment)
320  !
321  ycomment='accumulated snow water equivalent for past 3 days'
322  CALL write_surf(hselect,hprogram,'SWE_3DY_ISBA',dm%XSNSWE_3DY(:),iresp,hcomment=ycomment)
323  !
324  ycomment='accumulated snow water equivalent for past 5 days'
325  CALL write_surf(hselect,hprogram,'SWE_5DY_ISBA',dm%XSNSWE_5DY(:),iresp,hcomment=ycomment)
326  !
327  ycomment='accumulated snow water equivalent for past 7 days'
328  CALL write_surf(hselect,hprogram,'SWE_7DY_ISBA',dm%XSNSWE_7DY(:),iresp,hcomment=ycomment)
329  !
330  ycomment='Penetration of ram resistance sensor (2 daN)'
331  CALL write_surf(hselect,hprogram,'RAMSOND_ISBA',dm%XSNRAM_SONDE(:),iresp,hcomment=ycomment)
332  !
333  ycomment='Thickness of wet snow at the top of the snowpack'
334  CALL write_surf(hselect,hprogram,'WET_TH_ISBA',dm%XSN_WETTHCKN(:),iresp,hcomment=ycomment)
335  !
336  ycomment='Thickness of refrozen snow at the top of the snowpack'
337  CALL write_surf(hselect,hprogram,'REFRZTH_ISBA',dm%XSN_REFRZNTHCKN(:),iresp,hcomment=ycomment)
338  !
339  ENDIF
340  !
341  ! 2.6 SGH scheme
342  ! ----------
343  !
344  IF(io%CRUNOFF=='SGH '.OR.io%CRUNOFF=='DT92')THEN
345  yrecfm='FSAT_ISBA'
346  ycomment='Soil saturated fraction (-)'
347  CALL write_surf(hselect, hprogram,yrecfm,dm%XFSAT(:),iresp,hcomment=ycomment)
348  ENDIF
349  !
350  IF(io%CRAIN=='SGH ')THEN
351  yrecfm='MUF_ISBA'
352  ycomment='fraction of the grid cell reached by the rainfall (-)'
353  CALL write_surf(hselect, hprogram,yrecfm,k%XMUF(:),iresp,hcomment=ycomment)
354  ENDIF
355  !
356  ! 2.7 Flooding scheme
357  ! ---------------
358  !
359  IF(io%LFLOOD)THEN
360  !
361  yrecfm='FFG_ISBA'
362  ycomment='flood fraction over ground averaged over tile nature (-)'
363  CALL write_surf(hselect, hprogram,yrecfm,dm%XFFG(:),iresp,hcomment=ycomment)
364  !
365  yrecfm='FFV_ISBA'
366  ycomment='flood fraction over vegetation averaged over tile nature (-)'
367  CALL write_surf(hselect, hprogram,yrecfm,dm%XFFV(:),iresp,hcomment=ycomment)
368  !
369  yrecfm='FF_ISBA'
370  ycomment='total flood fraction averaged over tile nature (-)'
371  CALL write_surf(hselect, hprogram,yrecfm,dm%XFF(:),iresp,hcomment=ycomment)
372  !
373  yrecfm='FFLOOD_ISBA'
374  ycomment='Grid-cell potential flood fraction (-)'
375  CALL write_surf(hselect, hprogram,yrecfm,k%XFFLOOD(:),iresp,hcomment=ycomment)
376  !
377  yrecfm='PIFLOOD_ISBA'
378  ycomment='Grid-cell Potential_floodplain_infiltration (kg/m2/s)'
379  CALL write_surf(hselect, hprogram,yrecfm,k%XPIFLOOD(:),iresp,hcomment=ycomment)
380  !
381  ENDIF
382  !
383  ! 2.8 Total LAI
384  ! ---------
385  !
386  IF(io%CPHOTO/='NON'.OR.io%NPATCH>1)THEN
387  yrecfm='LAI_ISBA'
388  ycomment='leaf area index (m2/m2)'
389  CALL write_surf(hselect, hprogram,yrecfm,dm%XLAI(:),iresp,hcomment=ycomment)
390  ENDIF
391  !
392  ! 2.9 Water table depth
393  ! -----------------
394  !
395  IF(io%LWTD)THEN
396  !
397  yrecfm='FWTD_ISBA'
398  ycomment='grid-cell fraction of water table to rise'
399  CALL write_surf(hselect, hprogram,yrecfm,k%XFWTD(:),iresp,hcomment=ycomment)
400  !
401  yrecfm='WTD_ISBA'
402  ycomment='water table depth from RRM model or observation (m)'
403  CALL write_surf(hselect, hprogram,yrecfm,k%XWTD(:),iresp,hcomment=ycomment)
404  !
405  ENDIF
406  !* 3. Miscellaneous fields for each patch :
407  ! -------------------------------------
408  !
409  isize = u%NSIZE_NATURE
410  !
411  !----------------------------------------------------------------------------
412  !User wants (or not) patch output
413  IF(opatch_budget .AND. io%NPATCH>1)THEN
414  !----------------------------------------------------------------------------
415  !
416  ! 3.1 Soil Wetness Index and active layer depth
417  ! -----------------------------------------
418  !
419  DO jl=1,io%NGROUND_LAYER
420  !
421  WRITE(ylvl,'(I2.0)') jl
422  !
423  yrecfm='SWI'//trim(adjustl(ylvl(:)))//'_'
424  yform='(A39,I1.1,A4)'
425  IF (jl >= 10) yform='(A39,I2.2,A4)'
426  WRITE(ycomment,fmt=yform) 'soil wetness index per patch for layer ',jl,' (-)'
427  DO jp=1,io%NPATCH
428  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
429  np%AL(jp)%NR_P,ndm%AL(jp)%XSWI(:,jl),isize,s%XWORK_WR)
430  ENDDO
431  !
432  yrecfm='TSWI'//trim(adjustl(ylvl(:)))//'_'
433  yform='(A39,I1.1,A4)'
434  IF (jl >= 10) yform='(A39,I2.2,A4)'
435  WRITE(ycomment,fmt=yform) 'total swi (liquid+solid) per patch for layer ',jl,' (-)'
436  DO jp=1,io%NPATCH
437  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
438  np%AL(jp)%NR_P,ndm%AL(jp)%XTSWI(:,jl),isize,s%XWORK_WR)
439  ENDDO
440  !
441  END DO
442  !
443  IF(io%CISBA=='DIF')THEN
444  !
445 
446  yrecfm='ALT_'
447  ycomment='active layer thickness over permafrost per patch (m)'
448  WRITE(ycomment,fmt=yform) 'total swi (liquid+solid) per patch for layer ',jl,' (-)'
449  DO jp=1,io%NPATCH
450  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
451  np%AL(jp)%NR_P,ndm%AL(jp)%XALT(:),isize,s%XWORK_WR)
452  ENDDO
453  !
454  yrecfm='FLT_'
455  ycomment='frozen layer thickness over non-permafrost per patch (m)'
456  DO jp=1,io%NPATCH
457  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
458  np%AL(jp)%NR_P,ndm%AL(jp)%XFLT(:),isize,s%XWORK_WR)
459  ENDDO
460  !
461  ENDIF
462  !
463  ! 3.2 Snow fractions
464  ! --------------
465  !
466  yrecfm='PSNG_'
467  ycomment='snow fraction per patch over ground '
468  DO jp=1,io%NPATCH
469  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
470  np%AL(jp)%NR_P,ndm%AL(jp)%XPSNG(:),isize,s%XWORK_WR)
471  ENDDO
472  !
473  yrecfm='PSNV_'
474  ycomment='snow fraction per patch over vegetation'
475  DO jp=1,io%NPATCH
476  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
477  np%AL(jp)%NR_P,ndm%AL(jp)%XPSNV(:),isize,s%XWORK_WR)
478  ENDDO
479  !
480  yrecfm='PSN_'
481  ycomment='total snow fraction per patch'
482  DO jp=1,io%NPATCH
483  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
484  np%AL(jp)%NR_P,ndm%AL(jp)%XPSN(:),isize,s%XWORK_WR)
485  ENDDO
486  !
487  ! 3.3 SGH scheme
488  ! ----------
489  !
490  IF(io%CRUNOFF=='SGH '.OR.io%CRUNOFF=='DT92')THEN
491  yrecfm='FSAT_'
492  ycomment='Soil saturated fraction per patch (-)'
493  DO jp=1,io%NPATCH
494  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
495  np%AL(jp)%NR_P,ndm%AL(jp)%XFSAT(:),isize,s%XWORK_WR)
496  ENDDO
497  ENDIF
498  !
499  ! 3.3 Flood fractions
500  ! --------------
501  !
502  IF(io%LFLOOD)THEN
503  !
504  yrecfm='FFG_'
505  ycomment='flood fraction per patch over ground '
506  DO jp=1,io%NPATCH
507  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
508  np%AL(jp)%NR_P,ndm%AL(jp)%XFFG(:),isize,s%XWORK_WR)
509  ENDDO
510  !
511  yrecfm='FFV_'
512  ycomment='flood fraction per patch over vegetation'
513  DO jp=1,io%NPATCH
514  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
515  np%AL(jp)%NR_P,ndm%AL(jp)%XFFV(:),isize,s%XWORK_WR)
516  ENDDO
517  !
518  yrecfm='FF_'
519  ycomment='total flood fraction per patch'
520  DO jp=1,io%NPATCH
521  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
522  np%AL(jp)%NR_P,ndm%AL(jp)%XFF(:),isize,s%XWORK_WR)
523  ENDDO
524  !
525  ENDIF
526  !
527  ! 3.4 Total Albedo
528  ! ------------
529  !
530  !
531  IF (tpsnow%SCHEME=='3-L' .OR. tpsnow%SCHEME=='CRO') THEN
532  !
533  yrecfm='TS_'
534  ycomment='total surface temperature (isba+snow) per patch'
535  DO jp=1,io%NPATCH
536  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
537  np%AL(jp)%NR_P,nd%AL(jp)%XTS(:),isize,s%XWORK_WR)
538  ENDDO
539  !
540  yrecfm='TSRAD_'
541  ycomment='total radiative surface temperature (isba+snow) per patch'
542  DO jp=1,io%NPATCH
543  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
544  np%AL(jp)%NR_P,nd%AL(jp)%XTSRAD(:),isize,s%XWORK_WR)
545  ENDDO
546  !
547  ENDIF
548  !
549  ! 3.5 Halstead coefficient
550  ! --------------------
551  !
552  yrecfm='HV_'
553  ycomment='Halstead coefficient per patch'
554  DO jp=1,io%NPATCH
555  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
556  np%AL(jp)%NR_P,ndm%AL(jp)%XHV(:),isize,s%XWORK_WR)
557  ENDDO
558  !
559  ! 3.6 Snow outputs
560  ! -----------------
561  !
562  yrecfm='WSN_T_'
563  ycomment='X_Y_WSNOW_TOT (kg/m2) per patch'
564  DO jp=1,io%NPATCH
565  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
566  np%AL(jp)%NR_P,ndm%AL(jp)%XTWSNOW(:),isize,s%XWORK_WR)
567  ENDDO
568  !
569  yrecfm='DSN_T_'
570  ycomment='X_Y_DSNOW_TOT (m) per patch'
571  DO jp=1,io%NPATCH
572  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
573  np%AL(jp)%NR_P,ndm%AL(jp)%XTDSNOW(:),isize,s%XWORK_WR)
574  ENDDO
575  !
576  yrecfm='TSN_T_'
577  ycomment='X_Y_TSNOW_TOT (k) per patch'
578  DO jp=1,io%NPATCH
579  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
580  np%AL(jp)%NR_P,ndm%AL(jp)%XTTSNOW(:),isize,s%XWORK_WR)
581  ENDDO
582  !
583  IF (tpsnow%SCHEME=='CRO' .AND. dm%LPROSNOW) THEN
584  !
585  ycomment='accumulated snow thickness for past 1 days per patch'
586  DO jp=1,io%NPATCH
587  CALL write_field_1d_patch(hselect,hprogram,'SD_1DY_',ycomment,jp,&
588  np%AL(jp)%NR_P,ndm%AL(jp)%XSNDPT_1DY(:),isize,s%XWORK_WR)
589  ENDDO
590  !
591  ycomment= 'accumulated snow thickness for past 3 days per patch'
592  DO jp=1,io%NPATCH
593  CALL write_field_1d_patch(hselect,hprogram,'SD_3DY_',ycomment,jp,&
594  np%AL(jp)%NR_P,ndm%AL(jp)%XSNDPT_3DY(:),isize,s%XWORK_WR)
595  ENDDO
596  !
597  ycomment= 'accumulated snow thickness for past 5 days per patch'
598  DO jp=1,io%NPATCH
599  CALL write_field_1d_patch(hselect,hprogram,'SD_5DY_',ycomment,jp,&
600  np%AL(jp)%NR_P,ndm%AL(jp)%XSNDPT_5DY(:),isize,s%XWORK_WR)
601  ENDDO
602  !
603  ycomment='accumulated snow thickness for past 7 days per patch'
604  DO jp=1,io%NPATCH
605  CALL write_field_1d_patch(hselect,hprogram,'SD_7DY_',ycomment,jp,&
606  np%AL(jp)%NR_P,ndm%AL(jp)%XSNDPT_7DY(:),isize,s%XWORK_WR)
607  ENDDO
608  !
609  ycomment='accumulated snow water equivalent for past 1 days per patch'
610  DO jp=1,io%NPATCH
611  CALL write_field_1d_patch(hselect,hprogram,'SWE_1DY_',ycomment,jp,&
612  np%AL(jp)%NR_P,ndm%AL(jp)%XSNSWE_1DY(:),isize,s%XWORK_WR)
613  ENDDO
614  !
615  ycomment='accumulated snow water equivalent for past 3 days per patch'
616  DO jp=1,io%NPATCH
617  CALL write_field_1d_patch(hselect,hprogram,'SWE_3DY_',ycomment,jp,&
618  np%AL(jp)%NR_P,ndm%AL(jp)%XSNSWE_3DY(:),isize,s%XWORK_WR)
619  ENDDO
620  !
621  ycomment='accumulated snow water equivalent for past 5 days per patch'
622  DO jp=1,io%NPATCH
623  CALL write_field_1d_patch(hselect,hprogram,'SWE_5DY_',ycomment,jp,&
624  np%AL(jp)%NR_P,ndm%AL(jp)%XSNSWE_5DY(:),isize,s%XWORK_WR)
625  ENDDO
626  !
627  ycomment='accumulated snow water equivalent for past 7 days per patch'
628  DO jp=1,io%NPATCH
629  CALL write_field_1d_patch(hselect,hprogram,'SWE_7DY_',ycomment,jp,&
630  np%AL(jp)%NR_P,ndm%AL(jp)%XSNSWE_7DY(:),isize,s%XWORK_WR)
631  ENDDO
632  !
633  ycomment='Penetration of ram resistance sensor (2 daN) per patch'
634  DO jp=1,io%NPATCH
635  CALL write_field_1d_patch(hselect,hprogram,'RAMSOND_',ycomment,jp,&
636  np%AL(jp)%NR_P,ndm%AL(jp)%XSNRAM_SONDE(:),isize,s%XWORK_WR)
637  ENDDO
638  !
639  ycomment='Thickness of wet snow at the top of the snowpack per patch'
640  DO jp=1,io%NPATCH
641  CALL write_field_1d_patch(hselect,hprogram,'WET_TH_',ycomment,jp,&
642  np%AL(jp)%NR_P,ndm%AL(jp)%XSN_WETTHCKN(:),isize,s%XWORK_WR)
643  ENDDO
644  !
645  ycomment='Thickness of refrozen snow at the top of the snowpack per patch'
646  DO jp=1,io%NPATCH
647  CALL write_field_1d_patch(hselect,hprogram,'REFRZTH_',ycomment,jp,&
648  np%AL(jp)%NR_P,ndm%AL(jp)%XSN_REFRZNTHCKN(:),isize,s%XWORK_WR)
649  ENDDO
650  !
651  ENDIF
652  !
653  ENDIF
654  !
655  IF((opatch_budget.AND. io%NPATCH>1).OR.io%NPATCH==1)THEN
656  !
657  IF ( osnowdimnc ) THEN
658  !
659  IF ( dm%LVOLUMETRIC_SNOWLIQ ) THEN
660  ycomment='snow liquid water (kg m-3)'
661  ELSE
662  ycomment='snow liquid water (m)'
663  ENDIF
664  DO jp=1,io%NPATCH
665  CALL write_field_2d_patch(hselect,hprogram,'SNOWLIQ',ycomment,jp,&
666  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWLIQ(:,:),isize,'snow_layer',s%XWSN_WR)
667  ENDDO
668  !
669  ycomment='snow temperature (K)'
670  DO jp=1,io%NPATCH
671  CALL write_field_2d_patch(hselect,hprogram,'SNOWTEMP',ycomment,jp,&
672  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWTEMP(:,:),isize,'snow_layer',s%XWSN_WR)
673  ENDDO
674  !
675  ycomment= 'snow layer thickness'
676  DO jp=1,io%NPATCH
677  CALL write_field_2d_patch(hselect,hprogram,'SNOWDZ',ycomment,jp,&
678  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWDZ(:,:),isize,'snow_layer',s%XWSN_WR)
679  ENDDO
680  !
681  IF (tpsnow%SCHEME=='CRO' .AND. dm%LPROSNOW) THEN
682  !
683  ycomment= 'snow layer dendricity'
684  DO jp=1,io%NPATCH
685  CALL write_field_2d_patch(hselect,hprogram,'SNOWDEND',ycomment,jp,&
686  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWDEND(:,:),isize,'snow_layer',s%XWSN_WR)
687  ENDDO
688  !
689  ycomment='snow layer sphericity'
690  DO jp=1,io%NPATCH
691  CALL write_field_2d_patch(hselect,hprogram,'SNOWSPHER',ycomment,jp,&
692  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWSPHER(:,:),isize,'snow_layer',s%XWSN_WR)
693  ENDDO
694  !
695  ycomment='snow layer grain size'
696  DO jp=1,io%NPATCH
697  CALL write_field_2d_patch(hselect,hprogram,'SNOWSIZE',ycomment,jp,&
698  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWSIZE(:,:),isize,'snow_layer',s%XWSN_WR)
699  ENDDO
700  !
701  ycomment='snow layer specific surface area'
702  DO jp=1,io%NPATCH
703  CALL write_field_2d_patch(hselect,hprogram,'SNOWSSA',ycomment,jp,&
704  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWSSA(:,:),isize,'snow_layer',s%XWSN_WR)
705  ENDDO
706  !
707  ycomment='snow layer grain type'
708  DO jp=1,io%NPATCH
709  CALL write_field_2d_patch(hselect,hprogram,'SNOWTYPE',ycomment,jp,&
710  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWTYPEMEPRA(:,:),isize,'snow_layer',s%XWSN_WR)
711  ENDDO
712  !
713  ycomment='snow layer ram resistance'
714  DO jp=1,io%NPATCH
715  CALL write_field_2d_patch(hselect,hprogram,'SNOWRAM',ycomment,jp,&
716  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWRAM(:,:),isize,'snow_layer',s%XWSN_WR)
717  ENDDO
718  !
719  ycomment='snow layer shear resistance'
720  DO jp=1,io%NPATCH
721  CALL write_field_2d_patch(hselect,hprogram,'SNOWSHEAR',ycomment,jp,&
722  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWSHEAR(:,:),isize,'snow_layer',s%XWSN_WR)
723  ENDDO
724  !
725  ENDIF
726  !
727  ELSE
728  !
729  DO jl=1,tpsnow%NLAYER
730  !
731  WRITE(ylvl,'(I2)') jl
732  !
733  yrecfm='SNOWLIQ'//adjustl(ylvl(:len_trim(ylvl)))
734  yform='(A18,I1.1,A9)'
735  IF (jl >= 10) yform='(A18,I2.2,A9)'
736  IF ( dm%LVOLUMETRIC_SNOWLIQ ) THEN
737  WRITE(ycomment,yform) 'snow liquid water ',jl,' (kg m-3)'
738  ELSE
739  WRITE(ycomment,yform) 'snow liquid water ',jl,' (m) '
740  ENDIF
741  WRITE(ycomment,fmt=yform) 'snow liquid water',jl,' (m)'
742  DO jp=1,io%NPATCH
743  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
744  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWLIQ(:,jl),isize,s%XWORK_WR)
745  ENDDO
746  !
747  yrecfm='SNOWTEMP'//adjustl(ylvl(:len_trim(ylvl)))
748  yform='(A16,I1.1,A4)'
749  IF (jl >= 10) yform='(A16,I2.2,A4)'
750  WRITE(ycomment,fmt=yform) 'snow temperature',jl,' (K)'
751  DO jp=1,io%NPATCH
752  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
753  np%AL(jp)%NR_P,ndm%AL(jp)%XSNOWTEMP(:,jl),isize,s%XWORK_WR)
754  ENDDO
755  !
756  END DO
757  !
758  ENDIF
759  !
760  ENDIF
761  !
762  IF (lagrip) THEN
763  !
764  ! 2.8 Irrigation threshold
765  ! --------------------
766  !
767  yrecfm='IRRISEUIL'
768  ycomment='irrigation threshold per patch'
769  DO jp=1,io%NPATCH
770  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
771  np%AL(jp)%NR_P,ndm%AL(jp)%XSEUIL(:),isize,s%XWORK_WR)
772  ENDDO
773  !
774  ENDIF
775  !
776  IF (io%LTR_ML) THEN
777  !
778  yrecfm='FAPAR'
779  ycomment='FAPAR (-)'
780  DO jp=1,io%NPATCH
781  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
782  np%AL(jp)%NR_P,ndm%AL(jp)%XFAPAR(:),isize,s%XWORK_WR)
783  ENDDO
784  !
785  yrecfm='FAPIR'
786  ycomment='FAPIR (-)'
787  DO jp=1,io%NPATCH
788  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
789  np%AL(jp)%NR_P,ndm%AL(jp)%XFAPIR(:),isize,s%XWORK_WR)
790  ENDDO
791  !
792  yrecfm='FAPAR_BS'
793  ycomment='FAPAR_BS (-)'
794  DO jp=1,io%NPATCH
795  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
796  np%AL(jp)%NR_P,ndm%AL(jp)%XFAPAR_BS(:),isize,s%XWORK_WR)
797  ENDDO
798  !
799  yrecfm='FAPIR_BS'
800  ycomment='FAPIR_BS (-)'
801  DO jp=1,io%NPATCH
802  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
803  np%AL(jp)%NR_P,ndm%AL(jp)%XFAPIR_BS(:),isize,s%XWORK_WR)
804  ENDDO
805  !
806  yrecfm='DFAPARC'
807  ycomment='DFAPARC (-)'
808  DO jp=1,io%NPATCH
809  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
810  np%AL(jp)%NR_P,ndm%AL(jp)%XDFAPARC(:),isize,s%XWORK_WR)
811  ENDDO
812  !
813  yrecfm='DFAPIRC'
814  ycomment='DFAPIRC (-)'
815  DO jp=1,io%NPATCH
816  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
817  np%AL(jp)%NR_P,ndm%AL(jp)%XDFAPIRC(:),isize,s%XWORK_WR)
818  ENDDO
819  !
820  yrecfm='DLAI_EFFC'
821  ycomment='DLAI_EFFC (m2/m2)'
822  DO jp=1,io%NPATCH
823  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,jp,&
824  np%AL(jp)%NR_P,ndm%AL(jp)%XDLAI_EFFC(:),isize,s%XWORK_WR)
825  ENDDO
826  !
827  ENDIF
828  !
829  IF (lassim .AND. cassim_isba=="EKF ") THEN
830  !
831  CALL end_io_surf_n(hprogram)
832  CALL init_io_surf_n(dtco, u, hprogram,'NATURE','ISBA ','WRITE','ISBA_ANALYSIS.OUT.nc')
833  !
834  DO jvar = 1,nvar
835  WRITE(yvar,fmt='(I1.1)') jvar
836  yrecfm="ANA_INCR"//yvar
837  !YCOMMENT="by patch"
838  ycomment="Analysis increment for control variable "//trim(cvar(jvar))
839  DO jp = 1,io%NPATCH
840  CALL write_field_1d_patch(hselect, hprogram, yrecfm, ycomment, jp,&
841  np%AL(jp)%NR_P,np%AL(jp)%XINCR(1:np%AL(jp)%NSIZE_P,jvar),isize,s%XWORK_WR)
842  ENDDO
843  !
844  WRITE(yvar,fmt='(I1.1)') jvar
845  DO jt = 1,nboutput
846  WRITE(ytim,fmt='(I1.1)') jt
847  DO jobs = 1,nobstype
848  WRITE(yobs,fmt='(I1.1)') jobs
849  yrecfm="HO"//yobs//"_"//yvar//"_"//ytim
850  !YCOMMENT="by patch"
851  ycomment="Jacobian matrix for observation "//trim(cobs(jobs))//" and control variable "//trim(cvar(jvar))
852  jk = (jt-1)*nobstype + jobs
853  DO jp = 1,io%NPATCH
854  CALL write_field_1d_patch(hselect, hprogram, yrecfm, ycomment, jp,&
855  np%AL(jp)%NR_P,np%AL(jp)%XHO(1:np%AL(jp)%NSIZE_P,jk,jvar),isize,s%XWORK_WR)
856  ENDDO
857  ENDDO
858  ENDDO
859  ENDDO
860  !
861  DO jt = 1,nboutput
862  WRITE(ytim,fmt='(I1.1)') jt
863  DO jobs = 1,nobstype
864  WRITE(yobs,fmt='(I1.1)') jobs
865  yrecfm="INNOV"//yobs//"_"//ytim
866  !YCOMMENT="not by patch"
867  ycomment="Innovation for observation "//trim(cobs(jobs))
868  jk = (jt-1)*nobstype + jobs
869  CALL write_surf(hselect,hprogram,yrecfm,s%XINNOV(:,jk),iresp,hcomment=ycomment)
870  ENDDO
871  ENDDO
872  !
873  DO jt = 1,nboutput
874  WRITE(ytim,fmt='(I1.1)') jt
875  DO jobs = 1,nobstype
876  WRITE(yobs,fmt='(I1.1)') jobs
877  yrecfm="RESID"//yobs//"_"//ytim
878  !YCOMMENT="not by patch"
879  ycomment="Residuals for observation "//trim(cobs(jobs))
880  jk = (jt-1)*nobstype + jobs
881  CALL write_surf(hselect,hprogram,yrecfm,s%XRESID(:,jk),iresp,hcomment=ycomment)
882  ENDDO
883  ENDDO
884  !
885  ENDIF
886  !
887 ENDIF
888 ! End of IO
889 !
890 !
891  CALL end_io_surf_n(hprogram)
892 !
893 IF (lhook) CALL dr_hook('WRITE_DIAG_MISC_ISBA_N',1,zhook_handle)
894 !
895 END SUBROUTINE write_diag_misc_isba_n
static const char * trim(const char *name, int *n)
Definition: drhook.c:2383
subroutine write_field_1d_patch(HSELECT, HPROGRAM, HRECFM, HCOMMENT, KP, KMASK, PFIELD_IN, KSIZE, PWORK_WR)
real, parameter xundef
integer, parameter jprb
Definition: parkind1.F90:32
integer, parameter nundef
subroutine write_field_2d_patch(HSELECT, HPROGRAM, HRECFM, HCOMMENT, KP, KMASK, PFIELD_IN, KSIZE, HNAM_DIM, PWORK_WR)
logical lallow_add_dim
Definition: modd_xios.F90:49
subroutine end_io_surf_n(HPROGRAM)
Definition: end_io_surfn.F90:7
subroutine write_diag_misc_isba_n(DTCO, HSELECT, OSNOWDIMNC, U, O
logical lhook
Definition: yomhook.F90:15
subroutine init_io_surf_n(DTCO, U, HPROGRAM, HMASK, HSCHEME, HACTION