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 / pgd_surf_atm.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 PGD_SURF_ATM(HPROGRAM,HFILE,HFILETYPE,OZS)
7 !     ###########################################################
8 !!
9 !!    PURPOSE
10 !!    -------
11 !!   This program prepares the physiographic data fields.
12 !!
13 !!    METHOD
14 !!    ------
15 !!   
16 !!    EXTERNAL
17 !!    --------
18 !!
19 !!
20 !!    IMPLICIT ARGUMENTS
21 !!    ------------------
22 !!
23 !!
24 !!    REFERENCE
25 !!    ---------
26 !!
27 !!    AUTHOR
28 !!    ------
29 !!
30 !!    V. Masson                   Meteo-France
31 !!
32 !!    MODIFICATION
33 !!    ------------
34 !!
35 !!    Original     13/10/03
36 !!      A. Lemonsu      05/2009         Ajout de la clef LGARDEN pour TEB
37 !!      J. Escobar      11/2013         Add USE MODI_READ_NAM_PGD_CHEMISTRY
38 !!      M.Moge          02/2015         check with MPPDB
39 !----------------------------------------------------------------------------
40 !
41 !*    0.     DECLARATION
42 !            -----------
43 !
44 USE MODD_SURF_CONF,       ONLY : CPROGNAME
45 USE MODD_PGD_GRID,        ONLY : LLATLONMASK
46 USE MODD_SURF_ATM_n,      ONLY : CNATURE, CSEA, CWATER, CTOWN,     &
47                                  XSEA, XWATER,                     &
48                                  NDIM_NATURE, NDIM_SEA,            &
49                                  NDIM_TOWN,NDIM_WATER,             &
50                                  LECOCLIMAP, LWATER_TO_NATURE,     &
51                                  LTOWN_TO_ROCK, LGARDEN, NDIM_FULL,&
52                                  NSIZE_FULL
53 USE MODD_SURF_ATM_GRID_n, ONLY : CGRID, XGRID_PAR, NGRID_PAR, XLAT, &
54                                  XLON, XMESH_SIZE, XJPDIR   
55 USE MODD_CH_SURF_n,       ONLY : LCH_EMIS, CCH_EMIS
56 !
57 USE MODI_GET_LUOUT
58 USE MODI_READ_PGD_ARRANGE_COVER
59 USE MODI_READ_PGD_COVER_GARDEN
60 USE MODI_INI_DATA_COVER
61 USE MODI_READ_PGD_SCHEMES
62 USE MODI_READ_NAM_WRITE_COVER_TEX
63 USE MODI_WRITE_COVER_TEX_START
64 USE MODI_WRITE_COVER_TEX_COVER
65 USE MODI_LATLON_GRID
66 USE MODI_PUT_PGD_GRID
67 USE MODI_LATLONMASK
68 USE MODI_PGD_GAUSS_INDEX
69 USE MODI_PGD_FRAC
70 USE MODI_PGD_COVER
71 USE MODI_PGD_OROGRAPHY
72 USE MODI_PGD_NATURE
73 USE MODI_PGD_TOWN
74 USE MODI_PGD_INLAND_WATER
75 USE MODI_PGD_SEA
76 USE MODI_PGD_DUMMY
77 USE MODI_PGD_CHEMISTRY
78 USE MODI_PGD_CHEMISTRY_SNAP
79 USE MODI_WRITE_COVER_TEX_END
80 USE MODI_INIT_READ_DATA_COVER
81 !
82 USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
83 USE PARKIND1  ,ONLY : JPRB
84 !
85 USE MODI_READ_NAM_PGD_CHEMISTRY
86 !
87 #ifdef MNH_PARALLEL
88 USE MODE_MPPDB
89 !
90 #endif
91 IMPLICIT NONE
92 !
93 !*    0.1    Declaration of dummy arguments
94 !            ------------------------------
95 !
96  CHARACTER(LEN=6),     INTENT(IN)  :: HPROGRAM ! program calling
97  CHARACTER(LEN=28),    INTENT(IN)  :: HFILE    ! atmospheric file name
98  CHARACTER(LEN=6),     INTENT(IN)  :: HFILETYPE! atmospheric file type
99 LOGICAL,              INTENT(IN)  :: OZS      ! .true. if orography is imposed by atm. model
100 !
101 !*    0.2    Declaration of local variables
102 !            ------------------------------
103 !
104 INTEGER :: ILUOUT ! logical unit of output listing file
105 REAL(KIND=JPRB) :: ZHOOK_HANDLE
106 !------------------------------------------------------------------------------
107 IF (LHOOK) CALL DR_HOOK('PGD_SURF_ATM',0,ZHOOK_HANDLE)
108 CPROGNAME=HPROGRAM
109 !
110  CALL GET_LUOUT(HPROGRAM,ILUOUT)
111 !
112 !*    1.      Set default constant values 
113 !             ---------------------------
114 !
115  CALL READ_PGD_ARRANGE_COVER(HPROGRAM,LWATER_TO_NATURE,LTOWN_TO_ROCK)
116 !
117  CALL READ_PGD_COVER_GARDEN(HPROGRAM,LGARDEN)
118 !
119  CALL INIT_READ_DATA_COVER(HPROGRAM)
120 !
121  CALL INI_DATA_COVER
122 !
123 !*    1.2     surface schemes
124  CALL READ_PGD_SCHEMES(HPROGRAM,CNATURE,CSEA,CTOWN,CWATER)
125 !
126 !*    1.3     prints all parameters in a Latex file
127  CALL READ_NAM_WRITE_COVER_TEX(HPROGRAM)
128 !
129  CALL WRITE_COVER_TEX_START(HPROGRAM)
130  CALL WRITE_COVER_TEX_COVER
131 !-------------------------------------------------------------------------------
132 !
133 !*    2.      Grid
134 !             ----
135 !
136 ALLOCATE(XLAT(NSIZE_FULL))
137 ALLOCATE(XLON(NSIZE_FULL))
138 ALLOCATE(XMESH_SIZE(NSIZE_FULL))
139 ALLOCATE(XJPDIR(NSIZE_FULL))
140  CALL LATLON_GRID(CGRID,NGRID_PAR,NSIZE_FULL,ILUOUT,XGRID_PAR,XLAT,XLON,XMESH_SIZE,XJPDIR)
141 #ifdef MNH_PARALLEL
142 ! CALL MPPDB_CHECK_SURFEX2D(XLAT,"PGD_SURF_ATM_n after LATLON_GRID:XLAT",PRECISION,ILUOUT)
143 ! CALL MPPDB_CHECK_SURFEX2D(XLON,"PGD_SURF_ATM_n after LATLON_GRID:XLON",PRECISION,ILUOUT)
144 ! CALL MPPDB_CHECK_SURFEX2D(XMESH_SIZE,"PGD_SURF_ATM_n after LATLON_GRID:XMESH_SIZE",PRECISION,ILUOUT)
145 #endif
146 !
147 !
148 !*    2.3     Stores the grid in the module MODD_PGD_GRID
149 !
150  CALL PUT_PGD_GRID(CGRID,NSIZE_FULL,NGRID_PAR,XGRID_PAR)
151 !
152 !*    2.4     mask to limit the number of input data to read
153  CALL LATLONMASK      (CGRID,NGRID_PAR,XGRID_PAR,LLATLONMASK)
154 !
155 !*    2.5     gaussien grid mesh index
156 !
157 IF(CGRID=='GAUSS') CALL PGD_GAUSS_INDEX(HPROGRAM,OZS)
158 !
159 !-------------------------------------------------------------------------------
160 !
161 !*    3.      surface cover
162 !             -------------
163 !
164  CALL PGD_FRAC(HPROGRAM,LECOCLIMAP)
165 IF (LECOCLIMAP) CALL PGD_COVER(HPROGRAM)
166 !
167 !-------------------------------------------------------------------------------
168 !
169 !*    4.      Orography
170 !             ---------
171 !
172  CALL PGD_OROGRAPHY(HPROGRAM,XSEA,XWATER,HFILE,HFILETYPE,OZS)
173 !
174 !_______________________________________________________________________________
175 !
176 !*    5.      Additionnal fields for nature scheme
177 !             ------------------------------------
178 !
179 IF (NDIM_NATURE>0) CALL PGD_NATURE(HPROGRAM,LECOCLIMAP)  
180 !_______________________________________________________________________________
181 !
182 !*    6.      Additionnal fields for town scheme
183 !             ----------------------------------
184 !
185 IF (NDIM_TOWN>0) CALL PGD_TOWN(HPROGRAM,LECOCLIMAP,LGARDEN)  
186 !_______________________________________________________________________________
187 !
188 !*    7.      Additionnal fields for inland water scheme
189 !             ------------------------------------------
190 !
191 IF (NDIM_WATER>0) CALL PGD_INLAND_WATER(HPROGRAM)   
192 !_______________________________________________________________________________
193 !
194 !*    8.      Additionnal fields for sea scheme
195 !             ---------------------------------
196 !
197 IF (NDIM_SEA>0) CALL PGD_SEA(HPROGRAM)  
198 !
199 !_______________________________________________________________________________
200 !
201 !*    9.      Dummy fields
202 !             ------------
203 !
204  CALL PGD_DUMMY(HPROGRAM)
205 !_______________________________________________________________________________
206 !
207 !*   10.      Chemical Emission fields
208 !             ------------------------
209 !
210  CALL READ_NAM_PGD_CHEMISTRY(HPROGRAM,CCH_EMIS)
211 IF (CCH_EMIS=='SNAP') THEN
212   CALL PGD_CHEMISTRY_SNAP(HPROGRAM,LCH_EMIS)
213 ELSE IF (CCH_EMIS=='AGGR') THEN
214   CALL PGD_CHEMISTRY(HPROGRAM,LCH_EMIS)
215 ENDIF
216 !_______________________________________________________________________________
217 !
218 !*   11.     Writing in cover latex file
219 !            ---------------------------
220 !
221  CALL WRITE_COVER_TEX_END(HPROGRAM)
222 IF (LHOOK) CALL DR_HOOK('PGD_SURF_ATM',1,ZHOOK_HANDLE)
223 !_______________________________________________________________________________
224 !
225 END SUBROUTINE PGD_SURF_ATM