Juan 24/05/2017: add MPPDB_CHECK on SURFEX routine for reprod check with MNH_PARALLEL key
[MNH-git_open_source-lfs.git] / src / SURFEX / zoom_pgd_orography.F90
1 !SURFEX_LIC Copyright 1994-2014 Meteo-France 
2 !SURFEX_LIC This is part of the SURFEX software governed by the CeCILL-C  licence
3 !SURFEX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SURFEX_LIC for details. version 1.
5 !     #########
6       SUBROUTINE ZOOM_PGD_OROGRAPHY(HPROGRAM,PSEA,PWATER,HINIFILE,HINIFILETYPE)
7 !     ###########################################################
8
9 !!
10 !!    PURPOSE
11 !!    -------
12 !!   This program prepares the physiographic data fields.
13 !!
14 !!    METHOD
15 !!    ------
16 !!   
17 !!    EXTERNAL
18 !!    --------
19 !!
20 !!
21 !!    IMPLICIT ARGUMENTS
22 !!    ------------------
23 !!
24 !!
25 !!    REFERENCE
26 !!    ---------
27 !!
28 !!    AUTHOR
29 !!    ------
30 !!
31 !!    V. Masson                   Meteo-France
32 !!
33 !!    MODIFICATION
34 !!    ------------
35 !!
36 !!    Original     13/10/03
37 !----------------------------------------------------------------------------
38 !
39 !*    0.     DECLARATION
40 !            -----------
41 !
42 USE MODD_DATA_COVER_PAR,   ONLY : JPCOVER
43 USE MODD_SURF_ATM_n,       ONLY : XZS, NSIZE_FULL!, XSEA, XWATER
44 USE MODD_SURF_ATM_GRID_n,  ONLY : XLAT, XLON, CGRID, XGRID_PAR
45 USE MODD_SURF_ATM_SSO_n,   ONLY : XSSO_STDEV, XAVG_ZS, XSIL_ZS, XMIN_ZS, XMAX_ZS,&
46                                     XSSO_ANIS, XSSO_DIR, XSSO_SLOPE,               &
47                                     XAOSIP, XAOSIM, XAOSJP, XAOSJM,                &
48                                     XHO2IP, XHO2IM, XHO2JP, XHO2JM  
49 USE MODD_PREP,             ONLY : CINGRID_TYPE, CINTERP_TYPE, LINTERP
50 USE MODD_SURF_PAR,         ONLY : XUNDEF
51 !
52 USE MODI_OPEN_AUX_IO_SURF
53 USE MODI_READ_SURF
54 USE MODI_CLOSE_AUX_IO_SURF
55 USE MODI_PREP_GRID_EXTERN
56 USE MODI_HOR_INTERPOL
57 USE MODI_PREP_OUTPUT_GRID
58 !
59 USE MODI_GOTO_MODEL_MNH
60 !
61 USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
62 USE PARKIND1  ,ONLY : JPRB
63 !
64 USE MODI_CLEAN_PREP_OUTPUT_GRID
65 !
66 USE MODI_GET_LUOUT
67 #ifdef MNH_PARALLEL
68 !
69 USE MODE_MPPDB
70 !
71 #endif
72 IMPLICIT NONE
73 !
74 !*    0.1    Declaration of dummy arguments
75 !            ------------------------------
76 !
77  CHARACTER(LEN=6),     INTENT(IN)  :: HPROGRAM    ! program calling
78  REAL, DIMENSION(:),   INTENT(IN)  :: PSEA        ! sea fraction
79  REAL, DIMENSION(:),   INTENT(IN)  :: PWATER      ! inland water fraction
80  CHARACTER(LEN=28),    INTENT(IN)  :: HINIFILE    ! input atmospheric file name
81  CHARACTER(LEN=6),     INTENT(IN)  :: HINIFILETYPE! input atmospheric file type
82 !
83 !
84 !*    0.2    Declaration of local variables
85 !            ------------------------------
86 !
87 INTEGER :: IRESP
88 INTEGER :: ILUOUT
89 INTEGER :: INI     ! total 1D dimension (input field)
90 INTEGER :: IL      ! total 1D dimension (output field)
91 REAL, DIMENSION(:), POINTER :: ZZS
92 REAL, DIMENSION(:), POINTER :: ZAVG_ZS
93 REAL, DIMENSION(:), POINTER :: ZSIL_ZS
94 REAL, DIMENSION(:), POINTER :: ZSSO_STDEV
95 REAL, DIMENSION(:), POINTER :: ZMIN_ZS
96 REAL, DIMENSION(:), POINTER :: ZMAX_ZS
97 REAL, DIMENSION(:), POINTER :: ZSSO_ANIS
98 REAL, DIMENSION(:), POINTER :: ZSSO_DIR
99 REAL, DIMENSION(:), POINTER :: ZSSO_SLOPE
100 REAL, DIMENSION(:), POINTER :: ZAOSIP
101 REAL, DIMENSION(:), POINTER :: ZAOSIM
102 REAL, DIMENSION(:), POINTER :: ZAOSJP
103 REAL, DIMENSION(:), POINTER :: ZAOSJM
104 REAL, DIMENSION(:), POINTER :: ZHO2IP
105 REAL, DIMENSION(:), POINTER :: ZHO2IM
106 REAL, DIMENSION(:), POINTER :: ZHO2JP
107 REAL, DIMENSION(:), POINTER :: ZHO2JM
108  CHARACTER(LEN=LEN_HREC) :: YRECFM         ! Name of the article to be read
109 REAL(KIND=JPRB) :: ZHOOK_HANDLE
110 INTEGER :: IINFO_ll
111 !------------------------------------------------------------------------------
112 IF (LHOOK) CALL DR_HOOK('ZOOM_PGD_OROGRAPHY',0,ZHOOK_HANDLE)
113  CALL GET_LUOUT(HPROGRAM,ILUOUT)
114 !
115 !*      1.     Preparation of IO for reading in the file
116 !              -----------------------------------------
117 !
118 !* Note that all points are read, even those without physical meaning.
119 !  These points will not be used during the horizontal interpolation step.
120 !  Their value must be defined as XUNDEF.
121 !
122 ! get the local sizes of model 1
123 CALL GOTO_MODEL_MNH(HPROGRAM, 1, IINFO_ll)
124 !CALL GOTO_MODEL_SURFEX(1, .TRUE.)   ! cette routine plante don je me demerde sans
125  CALL OPEN_AUX_IO_SURF(HINIFILE,HINIFILETYPE,'FULL  ')
126 !
127 !------------------------------------------------------------------------------
128 !
129 !*      2.     Reading of grid
130 !              ---------------
131 !
132  CALL PREP_GRID_EXTERN(HINIFILETYPE,ILUOUT,CINGRID_TYPE,CINTERP_TYPE,INI)
133 !
134  CALL PREP_OUTPUT_GRID(ILUOUT,CGRID,XGRID_PAR,XLAT,XLON)
135 #ifdef MNH_PARALLEL
136  CALL MPPDB_CHECK_SURFEX2D(XLAT,"ZOOM_PGD_OROGRAPHY:XLAT",PRECISION,ILUOUT)
137  CALL MPPDB_CHECK_SURFEX2D(XLON,"ZOOM_PGD_OROGRAPHY:XLON",PRECISION,ILUOUT)
138 #endif
139 !
140 !------------------------------------------------------------------------------
141 !
142 !*      3.     Reading of orographic parameters
143 !              --------------------------------
144 !
145 ALLOCATE(ZZS        (INI))
146 !
147 ALLOCATE(ZAVG_ZS    (INI))
148 ALLOCATE(ZSIL_ZS    (INI))
149 ALLOCATE(ZSSO_STDEV (INI))
150 ALLOCATE(ZMIN_ZS    (INI))
151 ALLOCATE(ZMAX_ZS    (INI))
152 !
153 ALLOCATE(ZSSO_ANIS  (INI))
154 ALLOCATE(ZSSO_DIR   (INI))
155 ALLOCATE(ZSSO_SLOPE (INI))
156 !
157 ALLOCATE(ZAOSIP     (INI))
158 ALLOCATE(ZAOSIM     (INI))
159 ALLOCATE(ZAOSJP     (INI))
160 ALLOCATE(ZAOSJM     (INI))
161 ALLOCATE(ZHO2IP     (INI))
162 ALLOCATE(ZHO2IM     (INI))
163 ALLOCATE(ZHO2JP     (INI))
164 ALLOCATE(ZHO2JM     (INI))
165 !
166 YRECFM='ZS'
167  CALL READ_SURF(HPROGRAM,YRECFM,ZZS,IRESP,HDIR='A')
168 !
169 YRECFM='AVG_ZS'
170  CALL READ_SURF(HPROGRAM,YRECFM,ZAVG_ZS,IRESP,HDIR='A')
171 YRECFM='SIL_ZS'
172  CALL READ_SURF(HPROGRAM,YRECFM,ZSIL_ZS,IRESP,HDIR='A')
173 YRECFM='SSO_STDEV'
174  CALL READ_SURF(HPROGRAM,YRECFM,ZSSO_STDEV,IRESP,HDIR='A')
175 YRECFM='MIN_ZS'
176  CALL READ_SURF(HPROGRAM,YRECFM,ZMIN_ZS,IRESP,HDIR='A')
177 YRECFM='MAX_ZS'
178  CALL READ_SURF(HPROGRAM,YRECFM,ZMAX_ZS,IRESP,HDIR='A')
179 !
180 YRECFM='SSO_ANIS'
181  CALL READ_SURF(HPROGRAM,YRECFM,ZSSO_ANIS,IRESP,HDIR='A')
182 YRECFM='SSO_DIR'
183  CALL READ_SURF(HPROGRAM,YRECFM,ZSSO_DIR,IRESP,HDIR='A')
184 YRECFM='SSO_SLOPE'
185  CALL READ_SURF(HPROGRAM,YRECFM,ZSSO_SLOPE,IRESP,HDIR='A')
186 !
187 YRECFM='AOSIP'
188  CALL READ_SURF(HPROGRAM,YRECFM,ZAOSIP,IRESP,HDIR='A')
189 YRECFM='AOSIM'
190  CALL READ_SURF(HPROGRAM,YRECFM,ZAOSIM,IRESP,HDIR='A')
191 YRECFM='AOSJP'
192  CALL READ_SURF(HPROGRAM,YRECFM,ZAOSJP,IRESP,HDIR='A')
193 YRECFM='AOSJM'
194  CALL READ_SURF(HPROGRAM,YRECFM,ZAOSJM,IRESP,HDIR='A')
195 YRECFM='HO2IP'
196  CALL READ_SURF(HPROGRAM,YRECFM,ZHO2IP,IRESP,HDIR='A')
197 YRECFM='HO2IM'
198  CALL READ_SURF(HPROGRAM,YRECFM,ZHO2IM,IRESP,HDIR='A')
199 YRECFM='HO2JP'
200  CALL READ_SURF(HPROGRAM,YRECFM,ZHO2JP,IRESP,HDIR='A')
201 YRECFM='HO2JM'
202  CALL READ_SURF(HPROGRAM,YRECFM,ZHO2JM,IRESP,HDIR='A')
203 !
204  CALL CLOSE_AUX_IO_SURF(HINIFILE,HINIFILETYPE)
205 !------------------------------------------------------------------------------
206 !
207 !*      4.     Interpolations
208 !              --------------
209 !
210 IL = SIZE(XLAT)   !size of local child model
211 !
212 ALLOCATE(XZS        (IL))
213 !
214 ALLOCATE(XAVG_ZS    (IL))
215 ALLOCATE(XSIL_ZS    (IL))
216 ALLOCATE(XSSO_STDEV (IL))
217 ALLOCATE(XMIN_ZS    (IL))
218 ALLOCATE(XMAX_ZS    (IL))
219 !
220 ALLOCATE(XSSO_ANIS  (IL))
221 ALLOCATE(XSSO_DIR   (IL))
222 ALLOCATE(XSSO_SLOPE (IL))
223 !
224 ALLOCATE(XAOSIP     (IL))
225 ALLOCATE(XAOSIM     (IL))
226 ALLOCATE(XAOSJP     (IL))
227 ALLOCATE(XAOSJM     (IL))
228 ALLOCATE(XHO2IP     (IL))
229 ALLOCATE(XHO2IM     (IL))
230 ALLOCATE(XHO2JP     (IL))
231 ALLOCATE(XHO2JM     (IL))
232 !
233  CALL ZOOM(ILUOUT,ZZS,XZS)
234  CALL ZOOM(ILUOUT,ZAVG_ZS,XAVG_ZS)
235  CALL ZOOM(ILUOUT,ZSIL_ZS,XSIL_ZS)
236  CALL ZOOM(ILUOUT,ZMIN_ZS,XMIN_ZS)
237  CALL ZOOM(ILUOUT,ZMAX_ZS,XMAX_ZS)
238 !
239 LINTERP(:)=(PSEA(:)<1.)
240  CALL ZOOM(ILUOUT,ZSSO_STDEV,XSSO_STDEV)
241  CALL ZOOM(ILUOUT,ZSSO_ANIS,XSSO_ANIS)
242  CALL ZOOM(ILUOUT,ZSSO_DIR,XSSO_DIR)
243  CALL ZOOM(ILUOUT,ZSSO_SLOPE,XSSO_SLOPE)
244  CALL ZOOM(ILUOUT,ZAOSIP,XAOSIP)
245  CALL ZOOM(ILUOUT,ZAOSIM,XAOSIM)
246  CALL ZOOM(ILUOUT,ZAOSJP,XAOSJP)
247  CALL ZOOM(ILUOUT,ZAOSJM,XAOSJM)
248  CALL ZOOM(ILUOUT,ZHO2IP,XHO2IP)
249  CALL ZOOM(ILUOUT,ZHO2IM,XHO2IM)
250  CALL ZOOM(ILUOUT,ZHO2JP,XHO2JP)
251  CALL ZOOM(ILUOUT,ZHO2JM,XHO2JM)
252 !
253 !* coherence with land sea mask
254 !
255 WHERE(PSEA==1.) XZS=0.
256 WHERE(PSEA(:)==1.) XSSO_STDEV(:) = XUNDEF
257 WHERE(PWATER(:)==1.) XSSO_STDEV(:) = 0.
258 WHERE(PSEA(:)>0.) XMIN_ZS(:) = 0.
259 WHERE(PSEA(:)==1.) XMAX_ZS(:) = 0.
260 !
261 WHERE (PSEA(:)==1.)
262   XSSO_ANIS (:) = XUNDEF
263   XSSO_DIR  (:) = XUNDEF
264   XSSO_SLOPE(:) = XUNDEF
265 END WHERE
266 !
267 WHERE (PWATER(:)==1.)
268   XSSO_ANIS (:) = 1.
269   XSSO_DIR  (:) = 0.
270   XSSO_SLOPE(:) = 0.
271 END WHERE
272 !
273 WHERE (PSEA(:)==1.)
274   XHO2IP(:) = XUNDEF
275   XHO2IM(:) = XUNDEF
276   XHO2JP(:) = XUNDEF
277   XHO2JM(:) = XUNDEF
278   XAOSIP(:) = XUNDEF
279   XAOSIM(:) = XUNDEF
280   XAOSJP(:) = XUNDEF
281   XAOSJM(:) = XUNDEF
282 END WHERE
283 !
284 WHERE (PWATER(:)==1.)
285   XHO2IP(:) = 0.
286   XHO2IM(:) = 0.
287   XHO2JP(:) = 0.
288   XHO2JM(:) = 0.
289   XAOSIP(:) = 0.
290   XAOSIM(:) = 0.
291   XAOSJP(:) = 0.
292   XAOSJM(:) = 0.
293 END WHERE
294 #ifdef MNH_PARALLEL
295 CALL MPPDB_CHECK_SURFEX2D(XZS,"ZOOM_PGD_OROGRAPHY:XZS",PRECISION,ILUOUT)
296 CALL MPPDB_CHECK_SURFEX2D(XAVG_ZS,"ZOOM_PGD_OROGRAPHY:XAVG_ZS",PRECISION,ILUOUT)
297 CALL MPPDB_CHECK_SURFEX2D(XSIL_ZS,"ZOOM_PGD_OROGRAPHY:XSIL_ZS",PRECISION,ILUOUT)
298 CALL MPPDB_CHECK_SURFEX2D(XSSO_STDEV,"ZOOM_PGD_OROGRAPHY:XSSO_STDEV",PRECISION,ILUOUT)
299 CALL MPPDB_CHECK_SURFEX2D(XMIN_ZS,"ZOOM_PGD_OROGRAPHY:XMIN_ZS",PRECISION,ILUOUT)
300 CALL MPPDB_CHECK_SURFEX2D(XMAX_ZS,"ZOOM_PGD_OROGRAPHY:XMAX_ZS",PRECISION,ILUOUT)
301 CALL MPPDB_CHECK_SURFEX2D(XSSO_ANIS,"ZOOM_PGD_OROGRAPHY:XSSO_ANIS",PRECISION,ILUOUT)
302 CALL MPPDB_CHECK_SURFEX2D(XSSO_DIR,"ZOOM_PGD_OROGRAPHY:XSSO_DIR",PRECISION,ILUOUT)
303 CALL MPPDB_CHECK_SURFEX2D(XSSO_SLOPE,"ZOOM_PGD_OROGRAPHY:XSSO_SLOPE",PRECISION,ILUOUT)
304 CALL MPPDB_CHECK_SURFEX2D(XAOSIP,"ZOOM_PGD_OROGRAPHY:XAOSIP",PRECISION,ILUOUT)
305 CALL MPPDB_CHECK_SURFEX2D(XAOSIM,"ZOOM_PGD_OROGRAPHY:XAOSIM",PRECISION,ILUOUT)
306 CALL MPPDB_CHECK_SURFEX2D(XAOSJP,"ZOOM_PGD_OROGRAPHY:XAOSJP",PRECISION,ILUOUT)
307 CALL MPPDB_CHECK_SURFEX2D(XAOSJM,"ZOOM_PGD_OROGRAPHY:XAOSJM",PRECISION,ILUOUT)
308 CALL MPPDB_CHECK_SURFEX2D(XHO2IP,"ZOOM_PGD_OROGRAPHY:XHO2IP",PRECISION,ILUOUT)
309 CALL MPPDB_CHECK_SURFEX2D(XHO2IM,"ZOOM_PGD_OROGRAPHY:XHO2IM",PRECISION,ILUOUT)
310 CALL MPPDB_CHECK_SURFEX2D(XHO2JP,"ZOOM_PGD_OROGRAPHY:XHO2JP",PRECISION,ILUOUT)
311 CALL MPPDB_CHECK_SURFEX2D(XHO2JM,"ZOOM_PGD_OROGRAPHY:XHO2JM",PRECISION,ILUOUT)
312 #endif
313 !
314 ! go back to child model
315 !CALL GOTO_MODEL_SURFEX(2, .TRUE.)   ! cette routine plante
316 CALL GOTO_MODEL_MNH(HPROGRAM, 2, IINFO_ll)
317 !_______________________________________________________________________________
318 DEALLOCATE(ZZS        )
319 !
320 DEALLOCATE(ZAVG_ZS    )
321 DEALLOCATE(ZSIL_ZS    )
322 DEALLOCATE(ZSSO_STDEV )
323 DEALLOCATE(ZMIN_ZS    )
324 DEALLOCATE(ZMAX_ZS    )
325 !
326 DEALLOCATE(ZSSO_ANIS  )
327 DEALLOCATE(ZSSO_DIR   )
328 DEALLOCATE(ZSSO_SLOPE )
329 !
330 DEALLOCATE(ZAOSIP     )
331 DEALLOCATE(ZAOSIM     )
332 DEALLOCATE(ZAOSJP     )
333 DEALLOCATE(ZAOSJM     )
334 DEALLOCATE(ZHO2IP     )
335 DEALLOCATE(ZHO2IM     )
336 DEALLOCATE(ZHO2JP     )
337 DEALLOCATE(ZHO2JM     )
338 !_______________________________________________________________________________
339  CALL CLEAN_PREP_OUTPUT_GRID
340 !_______________________________________________________________________________
341 IF (LHOOK) CALL DR_HOOK('ZOOM_PGD_OROGRAPHY',1,ZHOOK_HANDLE)
342 CONTAINS
343 !
344 SUBROUTINE ZOOM(KLUOUT,PFIELDIN,PFIELDOUT)
345 INTEGER, INTENT(IN)             :: KLUOUT
346 REAL, DIMENSION(:), POINTER     :: PFIELDIN
347 REAL, DIMENSION(:), INTENT(OUT) :: PFIELDOUT
348 REAL, DIMENSION(:,:), POINTER   :: ZFIELDIN
349 REAL, DIMENSION(:,:), POINTER   :: ZFIELDOUT
350 REAL(KIND=JPRB) :: ZHOOK_HANDLE
351 IF (LHOOK) CALL DR_HOOK('ZOOM',0,ZHOOK_HANDLE)
352 ALLOCATE(ZFIELDIN (SIZE(PFIELDIN, 1),1))
353 ALLOCATE(ZFIELDOUT(SIZE(PFIELDOUT,1),1))
354 ZFIELDIN(:,1) = PFIELDIN(:)
355  CALL HOR_INTERPOL(KLUOUT,ZFIELDIN,ZFIELDOUT)
356 PFIELDOUT(:) = ZFIELDOUT(:,1)
357 DEALLOCATE(ZFIELDIN )
358 DEALLOCATE(ZFIELDOUT)
359 IF (LHOOK) CALL DR_HOOK('ZOOM',1,ZHOOK_HANDLE)
360
361 END SUBROUTINE ZOOM
362 !
363 END SUBROUTINE ZOOM_PGD_OROGRAPHY