11! $Id$
2- ! VERIFY_ and RETURN_ macros for error handling
3-
4- #include " MAPL_Generic.h"
2+ #include " MAPL_ErrLog.h"
53
64! BOP
75
@@ -14,7 +12,8 @@ module GEOS_TopoGetMod
1412! !USES:
1513
1614 use ESMF
17- use MAPL2
15+ use MAPL
16+ use MAPL2, only: MAPL_VarRead, GETFILE
1817
1918 implicit none
2019 private
@@ -36,11 +35,46 @@ module GEOS_TopoGetMod
3635! directional variances associated with Gravity-Wave-Drag scales (10-100 km)
3736! and turbulence scales (0-10 km).
3837
39-
4038! EOP
4139
4240contains
4341
42+ ! ==========================================================================
43+
44+ ! Helper: get a string value from HConfig with a default
45+ subroutine hconfig_get_string (cf , label , value , default , rc )
46+ type (ESMF_HConfig), intent (in ) :: cf
47+ character (len=* ), intent (in ) :: label
48+ character (len=* ), intent (out ) :: value
49+ character (len=* ), intent (in ) :: default
50+ integer , optional , intent (out ) :: rc
51+ integer :: status
52+ logical :: defined
53+ character (len= :), allocatable :: tmp
54+ value = default
55+ defined = ESMF_HConfigIsDefined(cf, keyString= label, _RC)
56+ if (defined) then
57+ tmp = ESMF_HConfigAsString(cf, keyString= label, _RC)
58+ value = tmp
59+ end if
60+ _RETURN(ESMF_SUCCESS)
61+ end subroutine hconfig_get_string
62+
63+ ! Helper: get a real(4) value from HConfig with a default
64+ subroutine hconfig_get_r4 (cf , label , value , default , rc )
65+ type (ESMF_HConfig), intent (in ) :: cf
66+ character (len=* ), intent (in ) :: label
67+ real , intent (out ) :: value
68+ real , intent (in ) :: default
69+ integer , optional , intent (out ) :: rc
70+ integer :: status
71+ logical :: defined
72+ value = default
73+ defined = ESMF_HConfigIsDefined(cf, keyString= label, _RC)
74+ if (defined) value = ESMF_HConfigAsR4 (cf, keyString= label, _RC)
75+ _RETURN(ESMF_SUCCESS)
76+ end subroutine hconfig_get_r4
77+
4478! ==========================================================================
4579
4680! BOP
@@ -56,7 +90,7 @@ subroutine GEOS_TopoGet ( cf, &
5690
5791! !ARGUMENTS
5892
59- type (ESMF_Config) :: cf
93+ type (ESMF_HConfig), intent ( in ) :: cf
6094 type (ESMF_Field), optional , intent (INOUT ) :: MEAN
6195 type (ESMF_Field), optional , intent (INOUT ) :: GWDVAR
6296 type (ESMF_Field), optional , intent (INOUT ) :: GWDVARX
@@ -66,45 +100,6 @@ subroutine GEOS_TopoGet ( cf, &
66100 type (ESMF_Field), optional , intent (INOUT ) :: TRBVAR
67101 integer , optional , intent (OUT ) :: RC
68102
69- ! !DESCRIPTION
70-
71- ! This subroutine creates topographic data associated with an input
72- ! ESMF grid. The available topographic data types are: MEAN, GWDVAR,
73- ! GWDVARX, GWDVARY, GWDVARXY, GWDVARYX, and TRBVAR. The raw data
74- ! for each of these types has been pre-processed and stored at 2.5'x2.5'
75- ! resolution. The resulting gridded data will be binned-averaged on the
76- ! input ESMF grid from the 2.5'x2.5' data.
77- ! The arguments are:
78- !
79- ! \begin{description}
80- ! \item[GRID]
81- ! The ESMF GRID which contains information about
82- ! horizontal grid structure.
83- ! \item[MEAN]
84- ! The mean values of topography with scales >= 100 km.
85- ! \item[GWDVAR]
86- ! The isotropic variance of the GWD topography data,
87- ! (scales 10-100 km).
88- ! \item[GWDVARX]
89- ! The variance of the GWD topography data in the
90- ! East - West direction.
91- ! \item[GWDVARY]
92- ! The variance of the GWD topography data in the
93- ! North - South direction.
94- ! \item[GWDVARXY]
95- ! The variance of the GWD topography data in the
96- ! South_West - North_East direction.
97- ! \item[GWDVARYX]
98- ! The variance of the GWD topography data in the
99- ! North_West - South_East direction.
100- ! \item[TRBVAR]
101- ! The isotropic variance of the Turbulence topography data,
102- ! (scales 1-10 km).
103- ! \item[RC]
104- ! Return code
105- ! \end{description}
106- !
107-
108103! EOP
109104
110105! Locals
@@ -122,119 +117,93 @@ subroutine GEOS_TopoGet ( cf, &
122117 real :: GWDFACYX
123118 real :: TRBFAC
124119
125- type (MAPL_MetaComp) :: MAPLOBJ
126-
127- ! Initialize CONFIG File into MAPL Object
128- ! ---------------------------------------
129- call MAPL_Set (MAPLOBJ, name= ' DUMMY' , cf= cf, rc= STATUS )
130- VERIFY_(STATUS)
131-
132120! Get filenames for Get_Topo utility
133121! ----------------------------------
134- call ESMF_ConfigGetAttribute ( cf, value= filename(1 ), label = ' TOPO_MEAN_FILE:' , &
135- default= ' hmean.2.5x2.5min.data' , rc= status )
136- VERIFY_(STATUS)
137-
138- call ESMF_ConfigGetAttribute ( cf, value= filename(2 ), label = ' TOPO_GWDVAR_FILE:' , &
139- default= ' hgrav_var.2.5x2.5min.data' , rc= status )
140- VERIFY_(STATUS)
141-
142- call ESMF_ConfigGetAttribute ( cf, value= filename(3 ), label = ' TOPO_GWDVARX_FILE:' , &
143- default= ' hgrav_varx.2.5x2.5min.data' , rc= status )
144- VERIFY_(STATUS)
145-
146- call ESMF_ConfigGetAttribute ( cf, value= filename(4 ), label = ' TOPO_GWDVARY_FILE:' , &
147- default= ' hgrav_vary.2.5x2.5min.data' , rc= status )
148- VERIFY_(STATUS)
149-
150- call ESMF_ConfigGetAttribute ( cf, value= filename(5 ), label = ' TOPO_GWDVARXY_FILE:' , &
151- default= ' hgrav_varxy.2.5x2.5min.data' , rc= status )
152- VERIFY_(STATUS)
153-
154- call ESMF_ConfigGetAttribute ( cf, value= filename(6 ), label = ' TOPO_GWDVARYX_FILE:' , &
155- default= ' hgrav_varyx.2.5x2.5min.data' , rc= status )
156- VERIFY_(STATUS)
157-
158- call ESMF_ConfigGetAttribute ( cf, value= filename(7 ), label = ' TOPO_TRBVAR_FILE:' , &
159- default= ' hturb_var.2.5x2.5min.data' , rc= status )
160- VERIFY_(STATUS)
122+ call hconfig_get_string(cf, ' TOPO_MEAN_FILE' , filename(1 ), default= ' hmean.2.5x2.5min.data' , _RC)
123+ call hconfig_get_string(cf, ' TOPO_GWDVAR_FILE' , filename(2 ), default= ' hgrav_var.2.5x2.5min.data' , _RC)
124+ call hconfig_get_string(cf, ' TOPO_GWDVARX_FILE' , filename(3 ), default= ' hgrav_varx.2.5x2.5min.data' , _RC)
125+ call hconfig_get_string(cf, ' TOPO_GWDVARY_FILE' , filename(4 ), default= ' hgrav_vary.2.5x2.5min.data' , _RC)
126+ call hconfig_get_string(cf, ' TOPO_GWDVARXY_FILE' , filename(5 ), default= ' hgrav_varxy.2.5x2.5min.data' , _RC)
127+ call hconfig_get_string(cf, ' TOPO_GWDVARYX_FILE' , filename(6 ), default= ' hgrav_varyx.2.5x2.5min.data' , _RC)
128+ call hconfig_get_string(cf, ' TOPO_TRBVAR_FILE' , filename(7 ), default= ' hturb_var.2.5x2.5min.data' , _RC)
161129
162130 if ( present (MEAN) ) then
163131! -------------------------
164132 UNIT = GETFILE ( filename(1 ),form= " unformatted" )
165133 call MAPL_VarRead (UNIT,MEAN)
166134 CALL FREE_FILE (UNIT)
167135 call ESMF_FieldGet(MEAN, 0 , PTR, rc= status)
136+ _VERIFY(STATUS)
168137 ptr = ptr* MAPL_GRAV
169138 endif
170139
171140 if ( present (GWDVAR) ) then
172141! --------------------------
173- call MAPL_GetResource( MAPLOBJ, GWDFAC, label= " GWDVAR_FACTOR:" , default = 1.0 , RC= STATUS )
174- VERIFY_(STATUS)
142+ call hconfig_get_r4 (cf, ' GWDVAR_FACTOR' , GWDFAC, default= 1.0 , _RC)
175143 UNIT = GETFILE (filename(2 ), form= " unformatted" )
176144 call MAPL_VarRead (UNIT,GWDVAR)
177145 CALL FREE_FILE (UNIT)
178- call ESMF_FieldGet (GWDVAR, 0 , PTR, rc = status)
146+ call ESMF_FieldGet (GWDVAR, 0 , PTR, rc= status)
147+ _VERIFY(STATUS)
179148 ptr = sqrt ( max (gwdfac* ptr,0.0 ) )
180149 endif
181150
182151 if ( present (GWDVARX) ) then
183152! ---------------------------
184- call MAPL_GetResource( MAPLOBJ, GWDFACX, label= " GWDVARX_FACTOR:" , default = 1.0 , RC= STATUS )
185- VERIFY_(STATUS)
153+ call hconfig_get_r4 (cf, ' GWDVARX_FACTOR' , GWDFACX, default= 1.0 , _RC)
186154 UNIT = GETFILE (filename(3 ), form= " unformatted" )
187155 call MAPL_VarRead (UNIT,GWDVARX)
188156 CALL FREE_FILE (UNIT)
189- call ESMF_FieldGet (GWDVARX, 0 , PTR, rc = status)
157+ call ESMF_FieldGet (GWDVARX, 0 , PTR, rc= status)
158+ _VERIFY(STATUS)
190159 ptr = sqrt ( max (gwdfacx* ptr,0.0 ) )
191160 endif
192161
193162 if ( present (GWDVARY) ) then
194163! ---------------------------
195- call MAPL_GetResource( MAPLOBJ, GWDFACY, label= " GWDVARY_FACTOR:" , default = 1.0 , RC= STATUS )
196- VERIFY_(STATUS)
164+ call hconfig_get_r4 (cf, ' GWDVARY_FACTOR' , GWDFACY, default= 1.0 , _RC)
197165 UNIT = GETFILE (filename(4 ), form= " unformatted" )
198166 call MAPL_VarRead (UNIT,GWDVARY)
199167 CALL FREE_FILE (UNIT)
200- call ESMF_FieldGet (GWDVARY, 0 , PTR, rc = status)
168+ call ESMF_FieldGet (GWDVARY, 0 , PTR, rc= status)
169+ _VERIFY(STATUS)
201170 ptr = sqrt ( max (gwdfacy* ptr,0.0 ) )
202171 endif
203172
204173 if ( present (GWDVARXY) ) then
205174! ----------------------------
206- call MAPL_GetResource( MAPLOBJ, GWDFACXY, label= " GWDVARXY_FACTOR:" , default = 1.0 , RC= STATUS )
207- VERIFY_(STATUS)
175+ call hconfig_get_r4 (cf, ' GWDVARXY_FACTOR' , GWDFACXY, default= 1.0 , _RC)
208176 UNIT = GETFILE (filename(5 ), form= " unformatted" )
209177 call MAPL_VarRead (UNIT,GWDVARXY)
210178 CALL FREE_FILE (UNIT)
211- call ESMF_FieldGet (GWDVARXY, 0 , PTR, rc = status)
179+ call ESMF_FieldGet (GWDVARXY, 0 , PTR, rc= status)
180+ _VERIFY(STATUS)
212181 ptr = sqrt ( max (gwdfacxy* ptr,0.0 ) )
213182 endif
214183
215184 if ( present (GWDVARYX) ) then
216185! ----------------------------
217- call MAPL_GetResource( MAPLOBJ, GWDFACYX, label= " GWDVARYX_FACTOR:" , default = 1.0 , RC= STATUS )
218- VERIFY_(STATUS)
186+ call hconfig_get_r4 (cf, ' GWDVARYX_FACTOR' , GWDFACYX, default= 1.0 , _RC)
219187 UNIT = GETFILE (filename(6 ), form= " unformatted" )
220188 call MAPL_VarRead (UNIT,GWDVARYX)
221189 CALL FREE_FILE (UNIT)
222- call ESMF_FieldGet (GWDVARYX, 0 , PTR, rc = status)
190+ call ESMF_FieldGet (GWDVARYX, 0 , PTR, rc= status)
191+ _VERIFY(STATUS)
223192 ptr = sqrt ( max (gwdfacyx* ptr,0.0 ) )
224193 endif
225194
226195 if ( present (TRBVAR) ) then
227196! --------------------------
228- call MAPL_GetResource( MAPLOBJ, TRBFAC, label= " TRBVAR_FACTOR:" , default = 1.0 , RC= STATUS )
229- VERIFY_(STATUS)
197+ call hconfig_get_r4 (cf, ' TRBVAR_FACTOR' , TRBFAC, default= 1.0 , _RC)
230198 UNIT = GETFILE (filename(7 ), form= " unformatted" )
231199 call MAPL_VarRead (UNIT,TRBVAR)
232200 CALL FREE_FILE (UNIT)
233- call ESMF_FieldGet (TRBVAR, 0 , PTR, rc = status)
201+ call ESMF_FieldGet (TRBVAR, 0 , PTR, rc= status)
202+ _VERIFY(STATUS)
234203 ptr = max (trbfac* ptr,0.0 )
235204 endif
236205
237- return
206+ _RETURN(ESMF_SUCCESS)
238207 end subroutine GEOS_TopoGet
239208
240209end module GEOS_TopoGetMod
0 commit comments