SURFEX v8.1
General documentation of Surfex
trip_oasis_prep.F90
Go to the documentation of this file.
1 !#########
2 SUBROUTINE trip_oasis_prep (TPG, &
3  KLISTING,KLON,KLAT)
4 !###############################################
5 !
6 !!**** *TRIP_OASIS_PREP* - Definitions for exchange of coupling fields
7 !!
8 !! PURPOSE
9 !! -------
10 !!
11 !!** METHOD
12 !! ------
13 !!
14 !! EXTERNAL
15 !! --------
16 !!
17 !!
18 !! IMPLICIT ARGUMENTS
19 !! ------------------
20 !!
21 !! REFERENCE
22 !! ---------
23 !!
24 !!
25 !! AUTHOR
26 !! ------
27 !! B. Decharme *Meteo France*
28 !!
29 !! MODIFICATIONS
30 !! -------------
31 !! Original 10/2013
32 !! B. Decharme 10/2016 bug surface/groundwater coupling
33 !-------------------------------------------------------------------------------
34 !
35 !* 0. DECLARATIONS
36 ! ------------
37 !
38 !
39 !
40 USE modd_trip_grid, ONLY : trip_grid_t
41 !
44 !
45 USE modd_trip_par, ONLY : nundef
46 !
48 !
50 !
51 USE modi_abort_trip
52 !
53 USE yomhook ,ONLY : lhook, dr_hook
54 USE parkind1 ,ONLY : jprb
55 !
56 #ifdef CPLOASIS
57 USE mod_oasis
58 #endif
59 !
60 IMPLICIT NONE
61 !
62 !* 0.1 Declarations of arguments
63 ! -------------------------
64 !
65 !
66 TYPE(trip_grid_t), INTENT(INOUT) :: TPG
67 !
68 INTEGER, INTENT(IN) :: KLISTING
69 INTEGER, INTENT(IN) :: KLON
70 INTEGER, INTENT(IN) :: KLAT
71 !
72 !* 0.2 Declarations of local parameter
73 ! -------------------------------
74 !
75 INTEGER, PARAMETER :: INCORNER = 4 ! Number of grid-cell corners
76 INTEGER, PARAMETER :: IG_PARSIZE = 3 ! Size of array decomposition
77 INTEGER, PARAMETER :: IG_NSEGMENTS = 1 ! Number of segments of process decomposition
78 INTEGER, DIMENSION(2), PARAMETER :: IVAR_NODIMS = (/2,1/) ! rank and number of bundles in coupling field
79 !
80  CHARACTER(LEN=4) :: YCPL_LAND = 'tlan'
81  CHARACTER(LEN=4) :: YCPL_GW = 'tgw '
82  CHARACTER(LEN=4) :: YCPL_FLD = 'tfld'
83  CHARACTER(LEN=4) :: YCPL_SEA = 'tsea'
84  CHARACTER(LEN=4) :: YCPL_GRE = 'tgre'
85  CHARACTER(LEN=4) :: YCPL_ANT = 'tant'
86 !
87 !* 0.3 Declarations of local variables
88 ! -------------------------------
89 !
90 REAL :: ZRES
91 REAL, DIMENSION(KLON) :: ZLON1D
92 REAL, DIMENSION(KLAT) :: ZLAT1D
93 REAL, DIMENSION(KLON,KLAT) :: ZLON
94 REAL, DIMENSION(KLON,KLAT) :: ZLAT
95 REAL, DIMENSION(KLON,KLAT) :: ZAREA
96 INTEGER, DIMENSION(KLON,KLAT) :: IMASK
97 !
98 REAL, DIMENSION(KLON,KLAT,INCORNER) :: ZCORNER_LON
99 REAL, DIMENSION(KLON,KLAT,INCORNER) :: ZCORNER_LAT
100 !
101 INTEGER, DIMENSION(IG_PARSIZE) :: IPARAL ! Decomposition for each proc
102 INTEGER, DIMENSION(2,2) :: IVAR_SHAPE ! indexes for the coupling field local dimension
103 !
104 INTEGER :: IPART_ID ! Local partition ID
105 INTEGER :: IERR ! Error info
106 !
107 LOGICAL :: GFOUND ! Return code when searching namelist
108 INTEGER :: INAM ! logical unit of namelist file
109 !
110 INTEGER :: JLON, JLAT, JC, IFLAG
111 !
112 REAL(KIND=JPRB) :: ZHOOK_HANDLE
113 !
114 !-------------------------------------------------------------------------------
115 !
116 IF (lhook) CALL dr_hook('TRIP_OASIS_PREP',0,zhook_handle)
117 !
118 !-------------------------------------------------------------------------------
119 #ifdef CPLOASIS
120 !-------------------------------------------------------------------------------
121 !
122 !* 1. Grid definition :
123 ! -----------------
124 !
125  CALL get_trip_grid(tpg%XTRIP_GRID,pres=zres,plon=zlon1d,plat=zlat1d)
126 !
127 zres = zres / 2.0
128 !
129 ! 4_______3
130 ! | |
131 ! | . |
132 ! | |
133 ! |_______|
134 ! 1 2
135 !
136 DO jlon=1,klon
137  DO jlat=1,klat
138 !
139 ! grid cell center
140 !
141  zlon(jlon,jlat)=zlon1d(jlon)
142  zlat(jlon,jlat)=zlat1d(jlat)
143 !
144 ! grid cell corner (counterclockwise sense)
145 !
146  zcorner_lon(jlon,jlat,1) = zlon1d(jlon) - zres
147  zcorner_lat(jlon,jlat,1) = zlat1d(jlat) - zres
148 !
149  zcorner_lon(jlon,jlat,3) = zlon1d(jlon) + zres
150  zcorner_lat(jlon,jlat,3) = zlat1d(jlat) + zres
151 !
152  ENDDO
153 ENDDO
154 !
155 zcorner_lon(:,:,4) = zcorner_lon(:,:,1)
156 zcorner_lat(:,:,4) = zcorner_lat(:,:,3)
157 !
158 zcorner_lon(:,:,2) = zcorner_lon(:,:,3)
159 zcorner_lat(:,:,2) = zcorner_lat(:,:,1)
160 !
161  CALL oasis_start_grids_writing(iflag)
162 !
163 !
164 !* 1.1 Grid definition for Land surface :
165 ! ----------------------------------
166 !
167 IF(lcpl_land)THEN
168 !
169 ! 0 = not masked ; 1 = masked
170  WHERE(tpg%GMASK(:,:))
171  imask(:,:) = 0
172  ELSEWHERE
173  imask(:,:) = 1
174  ENDWHERE
175 !
176  zarea(:,:) = tpg%XAREA(:,:) * (1.0-imask(:,:))
177 !
178  CALL oasis_write_grid (ycpl_land,klon,klat,zlon(:,:),zlat(:,:))
179  CALL oasis_write_corner(ycpl_land,klon,klat,incorner,zcorner_lon(:,:,:),zcorner_lat(:,:,:))
180  CALL oasis_write_area (ycpl_land,klon,klat,zarea(:,:))
181  CALL oasis_write_mask (ycpl_land,klon,klat,imask(:,:))
182 !
183 ENDIF
184 !
185 ! groundwater surface coupling case
186 !
187 IF(lcpl_gw)THEN
188 !
189 ! 0 = not masked ; 1 = masked
190  WHERE(tpg%GMASK_GW(:,:))
191  imask(:,:) = 0
192  ELSEWHERE
193  imask(:,:) = 1
194  ENDWHERE
195 !
196  zarea(:,:) = tpg%XAREA(:,:) * (1.0-imask(:,:))
197 !
198  CALL oasis_write_grid (ycpl_gw,klon,klat,zlon(:,:),zlat(:,:))
199  CALL oasis_write_corner(ycpl_gw,klon,klat,incorner,zcorner_lon(:,:,:),zcorner_lat(:,:,:))
200  CALL oasis_write_area (ycpl_gw,klon,klat,zarea(:,:))
201  CALL oasis_write_mask (ycpl_gw,klon,klat,imask(:,:))
202 !
203 ENDIF
204 !
205 ! Floodplains surface coupling case
206 !
207 IF(lcpl_flood)THEN
208 !
209 ! 0 = not masked ; 1 = masked
210  WHERE(tpg%GMASK_FLD(:,:))
211  imask(:,:) = 0
212  ELSEWHERE
213  imask(:,:) = 1
214  ENDWHERE
215 !
216  zarea(:,:) = tpg%XAREA(:,:) * (1.0-imask(:,:))
217 !
218  CALL oasis_write_grid (ycpl_fld,klon,klat,zlon(:,:),zlat(:,:))
219  CALL oasis_write_corner(ycpl_fld,klon,klat,incorner,zcorner_lon(:,:,:),zcorner_lat(:,:,:))
220  CALL oasis_write_area (ycpl_fld,klon,klat,zarea(:,:))
221  CALL oasis_write_mask (ycpl_fld,klon,klat,imask(:,:))
222 !
223 ENDIF
224 !
225 !* 1.2 Grid definition for sea :
226 ! -------------------------
227 !
228 IF(lcpl_sea)THEN
229 !
230 ! 0 = not masked ; 1 = masked
231  WHERE(tpg%NGRCN(:,:)==9.OR.tpg%NGRCN(:,:)==12)
232  imask(:,:) = 0
233  ELSEWHERE
234  imask(:,:) = 1
235  ENDWHERE
236 !
237  zarea(:,:) = tpg%XAREA(:,:) * (1.0-imask(:,:))
238 !
239  CALL oasis_write_grid (ycpl_sea,klon,klat,zlon(:,:),zlat(:,:))
240  CALL oasis_write_corner(ycpl_sea,klon,klat,incorner,zcorner_lon(:,:,:),zcorner_lat(:,:,:))
241  CALL oasis_write_area (ycpl_sea,klon,klat,zarea(:,:))
242  CALL oasis_write_mask (ycpl_sea,klon,klat,imask(:,:))
243 !
244 ENDIF
245 !
246 !* 1.3 Grid definition for calving flux :
247 ! ----------------------------------
248 !
249 IF(lcpl_calvsea)THEN
250 !
251 !* Over Greenland
252 !
253 ! 0 = not masked ; 1 = masked
254  WHERE(tpg%GMASK_GRE(:,:))
255  imask(:,:) = 0
256  ELSEWHERE
257  imask(:,:) = 1
258  ENDWHERE
259 !
260  zarea(:,:) = tpg%XAREA(:,:) * (1.0-imask(:,:))
261 !
262  CALL oasis_write_grid (ycpl_gre,klon,klat,zlon(:,:),zlat(:,:))
263  CALL oasis_write_corner(ycpl_gre,klon,klat,incorner,zcorner_lon(:,:,:),zcorner_lat(:,:,:))
264  CALL oasis_write_area (ycpl_gre,klon,klat,zarea(:,:))
265  CALL oasis_write_mask (ycpl_gre,klon,klat,imask(:,:))
266 !
267 !* Over Antarctica
268 !
269 ! 0 = not masked ; 1 = masked
270  WHERE(tpg%GMASK_ANT(:,:))
271  imask(:,:) = 0
272  ELSEWHERE
273  imask(:,:) = 1
274  ENDWHERE
275 !
276  zarea(:,:) = tpg%XAREA(:,:) * (1.0-imask(:,:))
277 !
278  CALL oasis_write_grid (ycpl_ant,klon,klat,zlon(:,:),zlat(:,:))
279  CALL oasis_write_corner(ycpl_ant,klon,klat,incorner,zcorner_lon(:,:,:),zcorner_lat(:,:,:))
280  CALL oasis_write_area (ycpl_ant,klon,klat,zarea(:,:))
281  CALL oasis_write_mask (ycpl_ant,klon,klat,imask(:,:))
282 !
283 ENDIF
284 !
285  CALL oasis_terminate_grids_writing()
286 !
287  CALL oasis_enddef(ierr)
288 !
289 IF(ierr/=oasis_ok)THEN
290  WRITE(klisting,*)'TRIP_OASIS_PREP: OASIS enddef problem, err = ',ierr
291  CALL abort_trip('TRIP_OASIS_PREP: OASIS enddef problem')
292 ENDIF
293 !
294 !-------------------------------------------------------------------------------
295 #endif
296 !-------------------------------------------------------------------------------
297 !
298 IF (lhook) CALL dr_hook('TRIP_OASIS_PREP',1,zhook_handle)
299 !
300 !-------------------------------------------------------------------------------
301 !
302 END SUBROUTINE trip_oasis_prep
integer, save nundef
subroutine get_trip_grid(PTRIP_GRID, PLONMIN, PLONMAX, PLATMIN, PLATMAX, PRES, KLON, KLAT, PLON, PLAT)
integer, parameter jprb
Definition: parkind1.F90:32
subroutine trip_oasis_prep(TPG, KLISTING, KLON, KLAT)
logical lhook
Definition: yomhook.F90:15
subroutine abort_trip(YTEXT)
Definition: abort_trip.F90:3