SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
restart_coupl_topd.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 restart_coupl_topd (UG, U, &
7  hprogram,ki)
8 !###################################################################
9 !
10 !!**** *RESTART_COUPL_TOPDn*
11 !!
12 !! PURPOSE
13 !! -------
14 !! Read all files needed in case of restart
15 !!
16 !! REFERENCE
17 !! ---------
18 !!
19 !! AUTHOR
20 !! ------
21 !! B. Vincendon
22 !!
23 !! MODIFICATIONS
24 !! -------------
25 !! Original 07/06/11
26 !-------------------------------------------------------------------------------
27 !
28 !* 0. DECLARATIONS
29 ! ------------
30 !
31 !
32 !
34 USE modd_surf_atm_n, ONLY : surf_atm_t
35 !
36 USE modd_surf_par, ONLY : xundef,nundef
37 USE modd_isba_par, ONLY : xwgmin
38 !
39 USE modd_topd_par, ONLY : nunit
40 USE modd_topodyn, ONLY : nncat, ccat, nnpt, nline, nnmc, npmax,&
41  nnb_topd_step
42 
43 USE modd_coupling_topd, ONLY : xas_nature, &
44  nnb_stp_stock,nnb_stp_restart,xwtopt,&
45  xrun_torout,xdr_torout
46 !
47 USE modi_read_topd_file
48 USE modi_read_file_isbamap
49 !
50 USE modi_get_luout
51 USE modi_abor1_sfx
54 !
55 USE modi_open_file
56 USE modi_close_file
57 !
58 USE yomhook ,ONLY : lhook, dr_hook
59 USE parkind1 ,ONLY : jprb
60 !
61 IMPLICIT NONE
62 !
63 !* 0.1 declarations of arguments
64 !
65 !
66 TYPE(surf_atm_grid_t), INTENT(INOUT) :: ug
67 TYPE(surf_atm_t), INTENT(INOUT) :: u
68 !
69  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! program calling surf. schemes
70 INTEGER, INTENT(IN) :: ki ! Surfex grid dimension
71 !
72 !
73 !* 0.2 declarations of local variables
74 !
75 INTEGER :: jj
76 INTEGER :: iluout ! unit of output listing file
77 INTEGER :: jstp,jcat,jpix! loop control indexes
78 REAL, DIMENSION(:),ALLOCATABLE :: zas ! Saturated area fraction for each Isba meshes
79 REAL, DIMENSION(:),ALLOCATABLE :: zwtopt ! Initial water content in case of restart
80  CHARACTER(LEN=50), DIMENSION(:),ALLOCATABLE :: yfiletop ! File names
81 LOGICAL :: lstock, lwg, lasat
82 REAL :: zcorr_stock ! used to avoid to lose stock
83 REAL :: zcnt_undef,zsum1,zsum2, zdenom ! used to correct budget
84 REAL(KIND=JPRB) :: zhook_handle
85 !-------------------------------------------------------------------------------
86 IF (lhook) CALL dr_hook('RESTART_COUPL_TOPD',0,zhook_handle)
87 !
88  CALL get_luout(hprogram,iluout)
89 !
90 ! * 1. Read stock files
91 !
92 WRITE(*,*) 'Read STOCK file ',nnb_stp_stock
93 nnb_stp_stock = min(nnb_stp_stock, nnb_topd_step + nnb_stp_restart)
94 !
95 INQUIRE(file='stocks_init.txt', exist=lstock)
96 INQUIRE(file='surfcont_init.map', exist=lasat)
97 !
98 IF (.NOT.lstock) THEN
99  WRITE(iluout,*) 'You asked to run in restart mode but stock file is missing'
100  CALL abor1_sfx("RESTART_COUPL_TOPD_n: stock file is missing")
101 ELSEIF (.NOT.lasat) THEN
102  WRITE(iluout,*) 'You asked to run in restart mode but contributive area file is missing'
103  CALL abor1_sfx("RESTART_COUPL_TOPD_n: contributive area file is missing")
104 ELSE
105  !
106  CALL open_file('ASCII ',nunit,'stocks_init.txt','FORMATTED',haction='READ ')
107  DO jstp=1,nnb_stp_stock
108  READ(nunit,*) xrun_torout(1:nncat,jstp),xdr_torout(1:nncat,jstp)
109  ENDDO
110  CALL close_file('ASCII ',nunit)
111  !
112  ! * 2. Read pixels water content
113  !
114  DO jcat=1,nncat
115  !
116  IF (xrun_torout(jcat,nnb_stp_stock)/=0.) THEN
117  !
118  zcorr_stock = xrun_torout(jcat,nnb_stp_stock) - xrun_torout(jcat,nnb_stp_stock-1)
119  DO jstp = nnb_stp_stock+1,nnb_topd_step
120  xrun_torout(jcat,jstp) = max(0.,xrun_torout(jcat,jstp-1)+zcorr_stock)
121  ENDDO
122  !
123  ENDIF
124  !
125  IF (xdr_torout(jcat,nnb_stp_stock)/=0.) THEN
126  !
127  zcorr_stock = xdr_torout(jcat,nnb_stp_stock) - xdr_torout(jcat,nnb_stp_stock-1)
128  DO jstp = nnb_stp_stock+1,nnb_topd_step
129  xdr_torout(jcat,jstp) = max(0.,xdr_torout(jcat,jstp-1)+zcorr_stock)
130  ENDDO
131  !
132  ENDIF
133  !
134  ENDDO
135  !
136  WRITE(*,*) 'Write pixels water content files'
137  !
138  ALLOCATE(zwtopt(npmax))
139  ALLOCATE(yfiletop(nncat))
140  !
141  DO jcat=1,nncat
142  !
143  yfiletop(jcat)=trim(ccat(jcat))//'_xwtop_init.map'
144  INQUIRE(file=yfiletop(jcat), exist=lwg)
145  IF (.NOT.lwg) THEN
146  !
147  WRITE(iluout,*) 'You asked to run in restart mode but pixels water content file is missing'
148  WRITE(iluout,*) 'for catchment : ',ccat(jcat)
149  CALL abor1_sfx("RESTART_COUPL_TOPD_n: pixels water content file is missing")
150  !
151  ELSE
152  !
153  zsum1=sum(xwtopt(jcat,:),mask=xwtopt(jcat,:)/=xundef)
154  !
155  CALL read_topd_file('ASCII ',yfiletop(jcat),'FORMATTED',nnpt(jcat),zwtopt)
156  !
157  DO jpix=1,SIZE(nline(jcat,:))
158  IF ( nline(jcat,jpix)/=0 .AND. nline(jcat,jpix)/=xundef ) THEN
159  IF (zwtopt(jpix) /= xundef) xwtopt(jcat,nline(jcat,jpix)) = zwtopt(jpix)
160  ENDIF
161  ENDDO
162  !
163  zsum2=sum(xwtopt(jcat,:),mask=xwtopt(jcat,:)<xundef)
164  !
165  IF ( abs(zsum2-zsum1)>100. ) THEN
166  !
167  zcnt_undef = 0.
168  DO jj=1,SIZE(nline,2)
169  IF ( nline(jcat,jj)/=0 ) THEN
170  IF ( xwtopt(jcat,nline(jcat,jj))/=xundef ) zcnt_undef = zcnt_undef + 1.
171  ENDIF
172  ENDDO
173  !
174  IF (zcnt_undef/=0.) THEN
175  zdenom = (zsum2-zsum1)/zcnt_undef
176  DO jj=1,SIZE(nline,2)
177  IF ( nline(jcat,jj)/=0 ) THEN
178  IF ( xwtopt(jcat,nline(jcat,jj))/=xundef ) THEN
179  xwtopt(jcat,nline(jcat,jj)) = xwtopt(jcat,nline(jcat,jj)) - zdenom
180  ENDIF
181  ENDIF
182  ENDDO
183  ENDIF
184  zsum2=sum(xwtopt(jcat,:),mask=xwtopt(jcat,:)<xundef)
185  !
186  ENDIF
187  !
188  ENDIF
189  !
190  ENDDO
191  !
192  ! * 3. Read Asat files
193  !
194  WRITE(*,*) 'Read Asat files'
195  ALLOCATE(zas(ki))
196  CALL open_file('ASCII ',nunit,'surfcont_init.map','FORMATTED',haction='READ ')
197  CALL read_file_isbamap(ug, &
198  nunit,zas,ki)
199  CALL close_file('ASCII ',nunit)
200  CALL pack_same_rank(u%NR_NATURE,zas,xas_nature)
201  !
202 ENDIF
203 !
204 IF (lhook) CALL dr_hook('RESTART_COUPL_TOPD',1,zhook_handle)
205 !-------------------------------------------------------------------------------
206 END SUBROUTINE restart_coupl_topd
subroutine read_topd_file(HPROGRAM, HFILE, HFORM, KNPT, PTOPD_READ)
subroutine read_file_isbamap(UG, KUNIT, PVAR, KI)
subroutine restart_coupl_topd(UG, U, HPROGRAM, KI)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine close_file(HPROGRAM, KUNIT)
Definition: close_file.F90:6
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine open_file(HPROGRAM, KUNIT, HFILE, HFORM, HACTION, HACCESS, KRECL)
Definition: open_file.F90:6