SURFEX v8.1
General documentation of Surfex
sfx_xios_setup.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 SUBROUTINE sfx_xios_setup(YSC, KCOMM, KLUOUT, KYEAR, KMONTH, KDAY, PTIME, PTSTEP, &
6  KDIM1, KDIM2, KEXT1, PCLAT, PCLON, KXINDEX, ODXMASK,&
7  KMASKNAT, KMASKSEA, KMASKWAT, KMASKTOWN)
8 !!
9 !!
10 !! PURPOSE
11 !! --------
12 !!
13 !! Initialize all Surfex context for XIOS (calendar, grids, masks, model time step, ...)
14 !!
15 !!
16 !! IMPLICIT ARGUMENTS :
17 !! --------------------
18 !!
19 !! LXIOS, YXIOS_CONTEXT, TXIOS_CONTEXT
20 !!
21 !!
22 !! EXTERNAL
23 !! --------
24 !!
25 !! XIOS LIBRARY
26 !!
27 !!
28 !! REFERENCE
29 !! ---------
30 !!
31 !! XIOS Reference guide - Yann Meurdesoif - 10/10/2014 -
32 !! svn co -r 515 http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/branchs/xios-1.0 <dir> ; cd <dir>/doc ; ....
33 !!
34 !! AUTHOR
35 !! ------
36 !!
37 !! S.Sénési, CNRM
38 !!
39 !! MODIFICATION
40 !! --------------
41 !!
42 !! Original 08/2015
43 !!
44 !-------------------------------------------------------------------------------
45 !
46 !* 0. DECLARATIONS
47 ! ------------
48 !
49 USE modd_surfex_n, ONLY : surfex_t
50 
51 USE modd_csts, ONLY : xpi
52 USE modd_surfex_mpi, ONLY : nrank, nindex
53 !
58 !
59 #ifdef WXIOS
60 USE xios, ONLY : xios_context_initialize, xios_get_handle, &
61  xios_set_current_context, xios_set_timestep, xios_date, &
62  xios_duration, xios_define_calendar, xios_getvar, &
63  xios_solve_inheritance
64 !
65 USE modi_abor1_sfx
66 USE modi_sfx_xios_set_domain
67 USE modi_set_axis
68 !
69 #endif
70 !
71 USE yomhook , ONLY : lhook, dr_hook
72 USE parkind1 , ONLY : jprb
73 !
74 IMPLICIT NONE
75 !
76 !
77 ! Arguments
78 !
79 type(surfex_t), INTENT(IN) :: ysc
80 !
81 INTEGER, INTENT(INOUT) :: KCOMM ! Communicator
82 INTEGER, INTENT(IN) :: KLUOUT ! Listing logical unit number
83 INTEGER, INTENT(IN) :: KYEAR ! current year (UTC)
84 INTEGER, INTENT(IN) :: KMONTH ! current month (UTC)
85 INTEGER, INTENT(IN) :: KDAY ! current day (UTC)
86 REAL, INTENT(IN) :: PTIME ! current time since midnight (UTC,s)
87 REAL, INTENT(IN) :: PTSTEP ! model time step
88 INTEGER, INTENT(IN) :: KDIM1 ! Geometry param. (see sfx_set_domain)
89 INTEGER, INTENT(IN) :: KDIM2 ! Geometry param. (see sfx_set_domain)
90 INTEGER, INTENT(IN) :: KEXT1 ! Geometry param. (see sfx_set_domain)
91 REAL , INTENT(IN) , DIMENSION(:,:) :: PCLAT ! Lat corners "
92 REAL , INTENT(IN) , DIMENSION(:,:) :: PCLON ! Lon corners "
93 INTEGER, INTENT(IN) , DIMENSION(:) :: KXINDEX ! index of proc cells in global grid
94 LOGICAL, INTENT(IN) , DIMENSION(:) :: ODXMASK ! Cells mask
95 INTEGER, INTENT(IN) , DIMENSION(:) :: KMASKNAT ! Masks for the whole MPI task
96 INTEGER, INTENT(IN) , DIMENSION(:) :: KMASKSEA
97 INTEGER, INTENT(IN) , DIMENSION(:) :: KMASKWAT
98 INTEGER, INTENT(IN) , DIMENSION(:) :: KMASKTOWN
99 
100 !
101 ! Local variables
102 !
103 #ifdef WXIOS
104 TYPE(xios_duration) :: TDTIME ! Time-step 'a la XIOS'
105 INTEGER :: INHOURS,INMINUTES,INSECONDS
106 #endif
107 !
108 INTEGER :: ITMP
109 !
110 REAL(KIND=JPRB) :: ZHOOK_HANDLE
111 !
112 IF (lhook) CALL dr_hook('SFX_XIOS_SETUP',0,zhook_handle)
113 !
114 IF (.NOT. lxios ) THEN
115  CALL dr_hook('SFX_XIOS_SETUP',1,zhook_handle)
116  RETURN
117 ENDIF
118 !
119 #ifndef WXIOS
120 !
121 IF (lxios) THEN
122  CALL abor1_sfx('SFX_XIOS_INIT_CONTEXT : cannot setup : Surfex was compiled without XIOS support')
123 ELSE
124  lxios_def_closed=.true.
125 ENDIF
126 !
127 #else
128 !
129 lxios_def_closed=.false.
130 !
131 ! -----------------------------------------------------------------------------
132 !
133 ! Set Xios context to Surfex's one
134 !
135 ! -----------------------------------------------------------------------------
136 !
137 !$OMP SINGLE
138 !
139 !#ifndef CPLOASIS
140 ! CALL XIOS_INITIALIZE('surfex', return_comm=KCOMM)
141 !#endif
142 
143  CALL xios_context_initialize(yxios_context, kcomm)
144  CALL xios_get_handle(yxios_context, txios_context)
145  CALL xios_set_current_context(txios_context)
146 !
147 
148 ! -----------------------------------------------------------------------------
149 !
150 ! Set date for XIOS
151 !
152 ! -----------------------------------------------------------------------------
153 !
154 inhours = int(ptime/3600)
155 inminutes = int((ptime - inhours*3600)/60)
156 inseconds = int(ptime - inhours*3600 - inminutes*60)
157 !
158 !WRITE(KLUOUT,*) 'initializing xios calendar '
159 
160 ! For XIOS-2.0 :
161  CALL xios_define_calendar("Gregorian", &
162  start_date = xios_date(kyear,kmonth,kday,inhours,inminutes,inseconds), &
163  time_origin = xios_date(kyear,kmonth,kday,inhours,inminutes,inseconds))
164 !
165 ! -----------------------------------------------------------------------------
166 !
167 ! Set duration between 2 calls to write_diag_surf
168 !
169 ! -----------------------------------------------------------------------------
170 !
171 IF (xios_getvar("timesteps_between_samples",itmp)) nbase_xios_freq=itmp
172 !
173 tdtime%SECOND = int(ptstep*nbase_xios_freq)
174  CALL xios_set_timestep(tdtime)
175 !
176 !$OMP END SINGLE
177 !
178 !
179 ! ---------------------------------------------------------------------------------
180 !
181 ! Declare a 'full' domain and one domain per tile
182 !
183 ! ---------------------------------------------------------------------------------
184 !
185  CALL sfx_xios_set_domain(ysc%UG%G%CGRID, "FULL" , kdim1, kdim2, kext1, kxindex, odxmask, &
186  ysc%UG%G%XLON, ysc%UG%G%XLAT, pclon, pclat )
187  CALL sfx_xios_set_domain(ysc%UG%G%CGRID, "SEA" , kdim1, kdim2, kext1, kxindex, odxmask, &
188  ysc%UG%G%XLON, ysc%UG%G%XLAT, pclon, pclat, kmask=kmasksea )
189  CALL sfx_xios_set_domain(ysc%UG%G%CGRID, "NATURE", kdim1, kdim2, kext1, kxindex, odxmask, &
190  ysc%UG%G%XLON, ysc%UG%G%XLAT, pclon, pclat, kmask=kmasknat)
191  CALL sfx_xios_set_domain(ysc%UG%G%CGRID, "WATER" , kdim1, kdim2, kext1, kxindex, odxmask, &
192  ysc%UG%G%XLON, ysc%UG%G%XLAT , pclon, pclat, kmask=kmaskwat )
193  CALL sfx_xios_set_domain(ysc%UG%G%CGRID, "TOWN" , kdim1, kdim2, kext1, kxindex, odxmask, &
194  ysc%UG%G%XLON, ysc%UG%G%XLAT , pclon, pclat, kmask=kmasktown )
195 !
196 ! Declare axes, depending on activated schemes
197 !
198 !IF (YSC%U%NDIM_NATURE>0) THEN
199  CALL set_axis(ypatch_dim_name , ksize=SIZE(ysc%IM%NPE%AL))
200  CALL set_axis(yground_layer_dim_name , ksize=SIZE(ysc%IM%NPE%AL(1)%XTG,2))
201  CALL set_axis(ywground_layer_dim_name, ksize=SIZE(ysc%IM%NPE%AL(1)%XWG,2))
202  CALL set_axis(ywiground_layer_dim_name, ksize=SIZE(ysc%IM%NPE%AL(1)%XWG,2))
203  CALL set_axis(yswband_dim_name, ksize=SIZE(ysc%IM%ID%D%XSWBD,2))
204  ! CALL SET_AXIS(YSNOW_PATCH_DIM_NAME, KSIZE=)
205 !ENDIF
206 !IF (YSC%U%NDIM_SEA>0) THEN
207  ! CALL SET_AXIS(YSEAICE_LAYER_DIM_NAME, KSIZE=)
208 !ENDIF
209 !
210 ! Force XIOS inheritance inorder that fields declarations can
211 ! fully account for user settings
212 !
213 ! CALL XIOS_SOLVE_INHERITANCE()
214 #endif
215 !
216 IF (lhook) CALL dr_hook('SFX_XIOS_SETUP',1,zhook_handle)
217 !
218 END SUBROUTINE sfx_xios_setup
character(len=30) yground_layer_dim_name
Definition: modd_xios.F90:64
logical lxios
Definition: modd_xios.F90:41
character(len=30) ywground_layer_dim_name
Definition: modd_xios.F90:65
subroutine set_axis(HNAME, PVALUE, CDPOSITIVE, KSIZE, CDUNITS, PBOUNDS)
Definition: set_axis.F90:6
subroutine sfx_xios_setup(YSC, KCOMM, KLUOUT, KYEAR, KMONTH, KDAY, PTIME, PTSTEP, KDIM1, KDIM2, KEXT1, PCLAT, PCLON, KXINDEX, ODXMASK, KMASKNAT, KMASKSEA, KMASKWAT, KMASKTOWN)
real, save xpi
Definition: modd_csts.F90:43
character(len=6) yxios_context
Definition: modd_xios.F90:46
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
logical lxios_def_closed
Definition: modd_xios.F90:54
integer, parameter jprb
Definition: parkind1.F90:32
subroutine sfx_xios_set_domain(HGRID, HNAME, KDIM1, KDIM2, KEXT1, KINDEX, ODMASK, PLON, PLAT, PCORNER_LON, PCORNER_LAT, KMASK)
character(len=30) ywiground_layer_dim_name
Definition: modd_xios.F90:66
character(len=30) ypatch_dim_name
Definition: modd_xios.F90:63
character(len=30) yswband_dim_name
Definition: modd_xios.F90:69
logical lhook
Definition: yomhook.F90:15
integer, dimension(:), allocatable nindex
type(xios_context) txios_context
Definition: modd_xios.F90:33
integer nbase_xios_freq
Definition: modd_xios.F90:50