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