FV3 Bundle
fv_arrays_nlm.F90
Go to the documentation of this file.
1 !***********************************************************************
2 !* GNU General Public License *
3 !* This file is a part of fvGFS. *
4 !* *
5 !* fvGFS is free software; you can redistribute it and/or modify it *
6 !* and are expected to follow the terms of the GNU General Public *
7 !* License as published by the Free Software Foundation; either *
8 !* version 2 of the License, or (at your option) any later version. *
9 !* *
10 !* fvGFS is distributed in the hope that it will be useful, but *
11 !* WITHOUT ANY WARRANTY; without even the implied warranty of *
12 !* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 !* General Public License for more details. *
14 !* *
15 !* For the full text of the GNU General Public License, *
16 !* write to: Free Software Foundation, Inc., *
17 !* 675 Mass Ave, Cambridge, MA 02139, USA. *
18 !* or see: http://www.gnu.org/licenses/gpl.html *
19 !***********************************************************************
21 #include <fms_platform.h>
22  use mpp_domains_mod, only: domain2d
23  use fms_io_mod, only: restart_file_type
24  use time_manager_mod, only: time_type
27  use mpp_mod, only: mpp_broadcast
28  use platform_mod, only: r8_kind
29  use, intrinsic :: iso_fortran_env, only: real64, real32
30  public
31 
32  integer, public, parameter :: r_grid = r8_kind
33  integer, parameter :: real4 = real32
34  integer, parameter :: real8 = real64
35 #ifdef SINGLE_FV
36  integer, parameter :: fvprc = real4 ! Full Build Precision for the model
37 #else
38  integer, parameter :: fvprc = real8 ! Full Build Precision for the model
39 #endif
40 
41  !Several 'auxiliary' structures are introduced here. These are for
42  ! the internal use by certain modules, and although fv_atmos_type
43  ! contains one of each of these structures all memory management
44  ! is performed by the module in question.
45 
46 
47  integer, parameter:: max_step = 1000
48 !--- MAY NEED TO TEST THIS
49 #ifdef OVERLOAD_R4
50  real, parameter:: real_big = 1.e8 ! big enough to cause blowup if used
51 #else
52  real, parameter:: real_big = 1.e30 ! big enough to cause blowup if used
53 #endif
55 
56 
57  integer ::id_ps, id_slp, id_ua, id_va, id_pt, id_omga, id_vort, &
58  id_tm, id_pv, id_zsurf, id_oro, id_sgh, id_divg, id_w, &
59  id_ke, id_te, id_zs, id_ze, id_mq, id_vorts, id_us, id_vs, &
60  id_tq, id_rh, id_c15, id_c25, id_c35, id_c45, &
61  id_f15, id_f25, id_f35, id_f45, id_ctp, &
62  id_ppt, id_ts, id_tb, id_ctt, id_pmask, id_pmaskv2, &
63  id_delp, id_delz, id_zratio, id_ws, id_iw, id_lw, &
64  id_pfhy, id_pfnh, &
65  id_qn, id_qn200, id_qn500, id_qn850, id_qp, id_mdt, id_qdt, id_aam, id_amdt, &
66  id_acly, id_acl, id_acl2, id_dbz, id_maxdbz, id_basedbz, id_dbz4km
67 
68 ! Selected p-level fields from 3D variables:
69  integer :: id_vort200, id_vort500, id_w500, id_w700
70  integer :: id_vort850, id_w850, id_x850, id_srh, id_srh25, id_srh01, &
71  id_uh03, id_uh25, id_theta_e, &
72  id_w200, id_s200, id_sl12, id_sl13, id_w5km, id_rain5km, id_w2500m
73 ! NGGPS 31-level diag
74  integer, allocatable :: id_u(:), id_v(:), id_t(:), id_h(:), id_q(:), id_omg(:)
75 
76  integer:: id_u_plev, id_v_plev, id_t_plev, id_h_plev, id_q_plev, id_omg_plev
77 ! IPCC diag
78  integer :: id_rh10, id_rh50, id_rh100, id_rh200, id_rh250, id_rh300, &
79  id_rh500, id_rh700, id_rh850, id_rh925, id_rh1000
80 
81  integer :: id_rh1000_cmip, id_rh925_cmip, id_rh850_cmip, id_rh700_cmip, id_rh500_cmip, &
82  id_rh300_cmip, id_rh250_cmip, id_rh100_cmip, id_rh50_cmip, id_rh10_cmip
83 
84  integer :: id_hght
85  integer :: id_u100m, id_v100m, id_w100m
86 
87  ! For initial conditions:
88  integer ic_ps, ic_ua, ic_va, ic_ppt
89  integer ic_sphum
90  integer, allocatable :: id_tracer(:)
91 ! ESM requested diagnostics - dry mass/volume mixing ratios
92  integer, allocatable :: id_tracer_dmmr(:)
93  integer, allocatable :: id_tracer_dvmr(:)
94  real, allocatable :: w_mr(:)
95 
96  real, allocatable :: phalf(:)
97  real, allocatable :: zsurf(:,:)
98  real, allocatable :: zxg(:,:)
99  real, allocatable :: pt1(:)
100 
101 
102  logical :: initialized = .false.
103  real sphum, liq_wat, ice_wat ! GFDL physics
104  real rainwat, snowwat, graupel
105 
106  real :: efx(max_step), efx_sum, efx_nest(max_step), efx_sum_nest, mtq(max_step), mtq_sum
107  integer :: steps
108 
109  end type fv_diag_type
110 
111 
112  !fv_grid_type is made up of grid-dependent information from fv_grid_tools and fv_grid_utils.
113  ! It should not contain any user options (that goes in a different structure) nor data which
114  ! is altered outside of those two modules.
116  real(kind=R_GRID), allocatable, dimension(:,:,:) :: grid_64, agrid_64
117  real(kind=R_GRID), allocatable, dimension(:,:) :: area_64, area_c_64
118  real(kind=R_GRID), allocatable, dimension(:,:) :: sina_64, cosa_64
119  real(kind=R_GRID), allocatable, dimension(:,:) :: dx_64, dy_64
120  real(kind=R_GRID), allocatable, dimension(:,:) :: dxc_64, dyc_64
121  real(kind=R_GRID), allocatable, dimension(:,:) :: dxa_64, dya_64
122 
123  real, allocatable, dimension(:,:,:) :: grid, agrid
124  real, allocatable, dimension(:,:) :: area, area_c
125  real, allocatable, dimension(:,:) :: rarea, rarea_c
126 
127  real, allocatable, dimension(:,:) :: sina, cosa
128  real, allocatable, dimension(:,:,:) :: e1,e2
129  real, allocatable, dimension(:,:) :: dx, dy
130  real, allocatable, dimension(:,:) :: dxc, dyc
131  real, allocatable, dimension(:,:) :: dxa, dya
132  real, allocatable, dimension(:,:) :: rdx, rdy
133  real, allocatable, dimension(:,:) :: rdxc, rdyc
134  real, allocatable, dimension(:,:) :: rdxa, rdya
135 
136  ! Scalars:
137  real(kind=R_GRID), allocatable :: edge_s(:)
138  real(kind=R_GRID), allocatable :: edge_n(:)
139  real(kind=R_GRID), allocatable :: edge_w(:)
140  real(kind=R_GRID), allocatable :: edge_e(:)
141  ! Vector:
142  real(kind=R_GRID), allocatable :: edge_vect_s(:)
143  real(kind=R_GRID), allocatable :: edge_vect_n(:)
144  real(kind=R_GRID), allocatable :: edge_vect_w(:)
145  real(kind=R_GRID), allocatable :: edge_vect_e(:)
146  ! scalar:
147  real(kind=R_GRID), allocatable :: ex_s(:)
148  real(kind=R_GRID), allocatable :: ex_n(:)
149  real(kind=R_GRID), allocatable :: ex_w(:)
150  real(kind=R_GRID), allocatable :: ex_e(:)
151 
152  real, allocatable :: l2c_u(:,:), l2c_v(:,:)
153  ! divergence Damping:
154  real, allocatable :: divg_u(:,:), divg_v(:,:) !
155  ! del6 diffusion:
156  real, allocatable :: del6_u(:,:), del6_v(:,:) !
157  ! Cubed_2_latlon:
158  real, allocatable :: a11(:,:)
159  real, allocatable :: a12(:,:)
160  real, allocatable :: a21(:,:)
161  real, allocatable :: a22(:,:)
162  ! latlon_2_cubed:
163  real, allocatable :: z11(:,:)
164  real, allocatable :: z12(:,:)
165  real, allocatable :: z21(:,:)
166  real, allocatable :: z22(:,:)
167 
168 ! real, allocatable :: w00(:,:)
169 
170  real, allocatable :: cosa_u(:,:)
171  real, allocatable :: cosa_v(:,:)
172  real, allocatable :: cosa_s(:,:)
173  real, allocatable :: sina_u(:,:)
174  real, allocatable :: sina_v(:,:)
175  real, allocatable :: rsin_u(:,:)
176  real, allocatable :: rsin_v(:,:)
177  real, allocatable :: rsina(:,:)
178  real, allocatable :: rsin2(:,:)
179  real(kind=R_GRID), allocatable :: ee1(:,:,:)
180  real(kind=R_GRID), allocatable :: ee2(:,:,:)
181  real(kind=R_GRID), allocatable :: ec1(:,:,:)
182  real(kind=R_GRID), allocatable :: ec2(:,:,:)
183  real(kind=R_GRID), allocatable :: ew(:,:,:,:)
184  real(kind=R_GRID), allocatable :: es(:,:,:,:)
185 
186 
187  !- 3D Super grid to contain all geometrical factors --
188  ! the 3rd dimension is 9
189  real, allocatable :: sin_sg(:,:,:)
190  real, allocatable :: cos_sg(:,:,:)
191  !--------------------------------------------------
192 
193  ! Unit Normal vectors at cell edges:
194  real(kind=R_GRID), allocatable :: en1(:,:,:)
195  real(kind=R_GRID), allocatable :: en2(:,:,:)
196 
197  ! Extended Cubed cross-edge winds
198  real, allocatable :: eww(:,:)
199  real, allocatable :: ess(:,:)
200 
201  ! Unit vectors for lat-lon grid
202  real(kind=R_GRID), allocatable :: vlon(:,:,:), vlat(:,:,:)
203  real, allocatable :: fc(:,:), f0(:,:)
204 
205  integer, dimension(:,:,:), allocatable :: iinta, jinta, iintb, jintb
206 
207  !Scalar data
208 
209  integer :: npx_g, npy_g, ntiles_g ! global domain
210 
211  real(kind=R_GRID) :: global_area
212  logical :: g_sum_initialized = .false. !Not currently used but can be useful
213  logical:: sw_corner, se_corner, ne_corner, nw_corner
214 
215  real(kind=R_GRID) :: da_min, da_max, da_min_c, da_max_c
216 
217  real :: acapn, acaps
218  real :: globalarea ! total Global Area
219 
220  logical :: latlon = .false.
221  logical :: cubed_sphere = .false.
222  logical :: have_south_pole = .false.
223  logical :: have_north_pole = .false.
224  logical :: stretched_grid = .false.
225 
226  logical :: square_domain = .false.
227 
228 
229  !! Convenience pointers
230 
231  integer, pointer :: grid_type
232  logical, pointer :: nested
233 
234  end type fv_grid_type
235 
237 
238  !! FOR EACH VARIABLE IN FV_FLAGS:
239  !! 1. Must be defined here:
240  !! 2. Must be broadcast in fv_atmos_data
241  !! 3. If a namelist entry, a pointer must
242  !! be defined and associated in fv_control
243  !! 4. Must NOT appear in fv_current_grid_mod.
244  !! (this module will soon be removed)
245  !! 5. Must be referenced through Atm%flagstruct,
246  !! not Atm%, unless a convenience
247  !! pointer is defined
248 
249 !-----------------------------------------------------------------------
250 ! Grid descriptor file setup
251 !-----------------------------------------------------------------------
252  character(len=80) :: grid_name = 'Gnomonic'
253  character(len=120):: grid_file = 'Inline'
254  integer :: grid_type = 0 ! -1: read from file; 0: ED Gnomonic
255 ! ! 0: the "true" equal-distance Gnomonic grid
256 ! ! 1: the traditional equal-distance Gnomonic grid
257 ! ! 2: the equal-angular Gnomonic grid
258 ! ! 3: the lat-lon grid -- to be implemented
259 ! ! 4: double periodic boundary condition on Cartesian grid
260 ! ! 5: channel flow on Cartesian grid
261 ! -> moved to grid_tools
262 
263 ! Momentum (or KE) options:
264  integer :: hord_mt = 9 ! the best option for Gnomonic grids
265  integer :: kord_mt = 8 ! vertical mapping option for (u,v)
266  integer :: kord_wz = 8 ! vertical mapping option for w
267 
268 ! Vorticity & w transport options:
269  integer :: hord_vt = 9 ! 10 not recommended (noisy case-5)
270 
271 ! Heat & air mass (delp) transport options:
272  integer :: hord_tm = 9 ! virtual potential temperature
273  integer :: hord_dp = 9 ! delp (positive definite)
274  integer :: kord_tm = 8 !
275 
276 ! Tracer transport options:
277  integer :: hord_tr = 12 !11: PPM mono constraint (Lin 2004); fast
278  !12: Huynh 2nd constraint (Lin 2004) +
279  ! positive definite (Lin & Rood 1996); slower
280  !>12: positive definite only (Lin & Rood 1996); fastest
281  integer :: kord_tr = 8 !
282  real :: scale_z = 0. ! diff_z = scale_z**2 * 0.25
283  real :: w_max = 75. ! max w (m/s) threshold for hydostatiic adjustment
284  real :: z_min = 0.05 ! min ratio of dz_nonhydrostatic/dz_hydrostatic
285 
286  integer :: nord=1 ! 0: del-2, 1: del-4, 2: del-6, 3: del-8 divergence damping
287  ! Alternative setting for high-res: nord=1; d4_bg = 0.075
288  integer :: nord_tr=0 ! 0: del-2, 1: del-4, 2: del-6
289  real :: dddmp = 0.0 ! coefficient for del-2 divergence damping (0.2)
290  ! for C90 or lower: 0.2
291  real :: d2_bg = 0.0 ! coefficient for background del-2 divergence damping
292  real :: d4_bg = 0.16 ! coefficient for background del-4(6) divergence damping
293  ! for stability, d4_bg must be <=0.16 if nord=3
294  real :: vtdm4 = 0.0 ! coefficient for del-4 vorticity damping
295  real :: trdm2 = 0.0 ! coefficient for del-2 tracer damping
296  real :: d2_bg_k1 = 4. ! factor for d2_bg (k=1)
297  real :: d2_bg_k2 = 2. ! factor for d2_bg (k=2)
298  real :: d2_divg_max_k1 = 0.15 ! d2_divg max value (k=1)
299  real :: d2_divg_max_k2 = 0.08 ! d2_divg max value (k=2)
300  real :: damp_k_k1 = 0.2 ! damp_k value (k=1)
301  real :: damp_k_k2 = 0.12 ! damp_k value (k=2)
302 
303 ! Additional (after the fact) terrain filter (to further smooth the terrain after cold start)
304  integer :: n_zs_filter=0 ! number of application of the terrain filter
305  integer :: nord_zs_filter=4 ! use del-2 (2) OR del-4 (4)
306  logical :: full_zs_filter=.false.! perform full filtering of topography (in external_ic only )
307 
308  logical :: consv_am = .false. ! Apply Angular Momentum Correction (to zonal wind component)
309  logical :: do_sat_adj= .false. !
310  logical :: do_f3d = .false. !
311  logical :: no_dycore = .false. ! skip the dycore
312  logical :: convert_ke = .false.
313  logical :: do_vort_damp = .false.
314  logical :: use_old_omega = .true.
315 ! PG off centering:
316  real :: beta = 0.0 ! 0.5 is "neutral" but it may not be stable
317 #ifdef SW_DYNAMICS
318  integer :: n_zfilter = 0 ! Number of layers at the top of the atmosphere for dz filter
319  integer :: n_sponge = 0 ! Number of sponge layers at the top of the atmosphere
320  real :: d_ext = 0.
321  integer :: nwat = 0 ! Number of water species
322  logical :: warm_start = .false.
323  logical :: inline_q = .true.
324  logical :: adiabatic = .true. ! Run without physics (full or idealized).
325 #else
326  integer :: n_zfilter = 0 ! Number of layers at the top of the atmosphere for dz filter
327  integer :: n_sponge = 1 ! Number of sponge layers at the top of the atmosphere
328  real :: d_ext = 0.02 ! External model damping (was 0.02)
329  integer :: nwat = 3 ! Number of water species
330  logical :: warm_start = .true.
331  ! Set to .F. if cold_start is desired (including terrain generation)
332  logical :: inline_q = .false.
333  logical :: adiabatic = .false. ! Run without physics (full or idealized).
334 #endif
335 !-----------------------------------------------------------
336 ! Grid shifting, rotation, and the Schmidt transformation:
337 !-----------------------------------------------------------
338  real :: shift_fac = 18. ! shift west by 180/shift_fac = 10 degrees
339 ! Defaults for Schmidt transformation:
340  logical :: do_schmidt = .false.
341  real(kind=R_GRID) :: stretch_fac = 1. ! No stretching
342  real(kind=R_GRID) :: target_lat = -90. ! -90: no grid rotation
343  real(kind=R_GRID) :: target_lon = 0. !
344 
345 !-----------------------------------------------------------------------------------------------
346 ! Example #1a: US regional climate simulation, center located over Oklahoma city: (262.4, 35.4)
347 ! stretching factor: 2.5
348 ! Example #1b: US Hurricane model, center over Miami: (279.7, 25.8)
349 ! stretching factor: 3-5
350 ! Example #2a: South-East Asia Regional Climate H*** (SERACH), Central Taiwan: (121.0, 23.5)
351 ! Example #2b: Typhoon Model: (124.0, 22.0)
352 ! stretching factor: 5-10
353 !-----------------------------------------------------------------------------------------------
354 
355  logical :: reset_eta = .false.
356  real :: p_fac = 0.05
357  real :: a_imp = 0.75 ! Off center parameter for the implicit solver [0.5,1.0]
358  integer :: n_split = 0 ! Number of time splits for the lagrangian dynamics
359  ! Default = 0 (automatic computation of best value)
360  integer :: m_split = 0 ! Number of time splits for Riemann solver
361  integer :: k_split = 1 ! Number of time splits for Remapping
362 
363  logical :: use_logp = .false.
364 
365 ! For doubly periodic domain with sim_phys
366 ! 5km 150 20 (7.5 s) 2
367 !
368 ! Estimates for Gnomonic grids:
369  !===================================================
370  ! dx (km) dt (sc) n_split m_split
371  !===================================================
372  ! C1000: ~10 150 16 3
373  ! C2000: ~5 90 18 (5 s) 2
374  !===================================================
375 ! The nonhydrostatic algorithm is described in Lin 2006, QJ, (submitted)
376 ! C2000 should easily scale to at least 6 * 100 * 100 = 60,000 CPUs
377 ! For a 1024 system: try 6 x 13 * 13 = 1014 CPUs
378 
379  integer :: q_split = 0 ! Number of time splits for tracer transport
380 
381  integer :: print_freq = 0 ! Print max/min of selected fields
382  ! 0: off
383  ! positive n: every n hours
384  ! negative n: every time step
385 
386 !------------------------------------------
387 ! Model Domain parameters
388 !------------------------------------------
389  integer :: npx ! Number of Grid Points in X- dir
390  integer :: npy ! Number of Grid Points in Y- dir
391  integer :: npz ! Number of Vertical Levels
392  integer :: npz_rst = 0 ! Original Vertical Levels (in the restart)
393  ! 0: no change (default)
394  integer :: ncnst = 0 ! Number of advected consituents
395  integer :: pnats = 0 ! Number of non-advected consituents
396  integer :: dnats = 0 ! Number of non-advected consituents (as seen by dynamics)
397  integer :: ntiles = 1 ! Number or tiles that make up the Grid
398  integer :: ndims = 2 ! Lat-Lon Dims for Grid in Radians
399  integer :: nf_omega = 1 ! Filter omega "nf_omega" times
400  integer :: fv_sg_adj = -1 ! Perform grid-scale dry adjustment if > 0
401  ! Relaxzation time scale (sec) if positive
402  integer :: na_init = 0 ! Perform adiabatic initialization
403  real :: p_ref = 1.e5
404  real :: dry_mass = 98290.
405  integer :: nt_prog = 0
406  integer :: nt_phys = 0
407  real :: tau_h2o = 0. ! Time scale (days) for ch4_chem
408 
409  real :: delt_max = 1. ! limiter for dissipative heating rate
410  ! large value (~1) essentially imposes no limit
411  real :: d_con = 0.
412  real :: ke_bg = 0. ! background KE production (m^2/s^3) over a small step
413  ! Use this to conserve total energy if consv_te=0
414  real :: consv_te = 0.
415  real :: tau = 0. ! Time scale (days) for Rayleigh friction
416  real :: rf_cutoff = 30.e2 ! cutoff pressure level for RF
417  logical :: filter_phys = .false.
418  logical :: dwind_2d = .false.
419  logical :: breed_vortex_inline = .false.
420  logical :: range_warn = .false.
421  logical :: fill = .false.
422  logical :: fill_dp = .false.
423  logical :: fill_wz = .false.
424  logical :: check_negative = .false.
425  logical :: non_ortho = .true.
426  logical :: moist_phys = .true. ! Run with moist physics
427  logical :: do_held_suarez = .false.
428  logical :: do_reed_physics = .false.
429  logical :: reed_cond_only = .false.
430  logical :: reproduce_sum = .true. ! Make global sum for consv_te reproduce
431  logical :: adjust_dry_mass = .false.
432  logical :: fv_debug = .false.
433  logical :: srf_init = .false.
434  logical :: mountain = .true.
435  integer :: remap_option = 0
436  logical :: z_tracer = .false. ! transport tracers layer by layer with independent
437  ! time split; use this if tracer number is huge and/or
438  ! high resolution (nsplt > 1)
439 
440  logical :: old_divg_damp = .false. ! parameter to revert damping parameters back to values
441  ! defined in a previous revision
442  ! old_values:
443  ! d2_bg_k1 = 6. d2_bg_k2 = 4.
444  ! d2_divg_max_k1 = 0.02 d2_divg_max_k2 = 0.01
445  ! damp_k_k1 = 0. damp_k_k2 = 0.
446  ! current_values:
447  ! d2_bg_k1 = 4. d2_bg_k2 = 2.
448  ! d2_divg_max_k1 = 0.15 d2_divg_max_k2 = 0.08
449  ! damp_k_k1 = 0.2 damp_k_k2 = 0.12
450 
451  logical :: fv_land = .false. ! To cold starting the model with USGS terrain
452 !--------------------------------------------------------------------------------------
453 ! The following options are useful for NWP experiments using datasets on the lat-lon grid
454 !--------------------------------------------------------------------------------------
455  logical :: nudge = .false. ! Perform nudging
456  logical :: nudge_ic = .false. ! Perform nudging on IC
457  logical :: ncep_ic = .false. ! use NCEP ICs
458  logical :: nggps_ic = .false. ! use NGGPS ICs
459  logical :: ecmwf_ic = .false. ! use ECMWF ICs
460  logical :: gfs_phil = .false. ! if .T., compute geopotential inside of GFS physics
461  logical :: agrid_vel_rst = .false. ! if .T., include ua/va (agrid winds) in the restarts
462  logical :: use_new_ncep = .false. ! use the NCEP ICs created after 2014/10/22, if want to read CWAT
463  logical :: use_ncep_phy = .false. ! if .T., separate CWAT by weights of liq_wat and liq_ice in FV_IC
464  logical :: fv_diag_ic = .false. ! reconstruct IC from fv_diagnostics on lat-lon grid
465  logical :: external_ic = .false. ! use ICs from external sources; e.g. lat-lon FV core
466  ! or NCEP re-analysis; both vertical remapping & horizontal
467  ! (lat-lon to cubed sphere) interpolation will be done
468 ! Default restart files from the "Memphis" latlon FV core:
469  character(len=128) :: res_latlon_dynamics = 'INPUT/fv_rst.res.nc'
470  character(len=128) :: res_latlon_tracers = 'INPUT/atmos_tracers.res.nc'
471 ! The user also needs to copy the "cold start" cubed sphere restart files (fv_core.res.tile1-6)
472 ! to the INPUT dir during runtime
473 !------------------------------------------------
474 ! Parameters related to non-hydrostatic dynamics:
475 !------------------------------------------------
476  logical :: hydrostatic = .true.
477  logical :: phys_hydrostatic = .true. ! heating/cooling term from the physics is hydrostatic
478  logical :: use_hydro_pressure = .false. ! GFS control
479  logical :: do_uni_zfull = .false. ! compute zfull as a simply average of two zhalf
480  logical :: hybrid_z = .false. ! use hybrid_z for remapping
481  logical :: make_nh = .false. ! Initialize (w, delz) from hydro restart file
482  logical :: make_hybrid_z = .false. ! transform hydrostatic eta-coord IC into non-hydrostatic hybrid_z
483  logical :: nudge_qv = .false. ! Nudge the water vapor (during na_init) above 30 mb towards HALOE climatology
484  real :: add_noise = -1. !Amplitude of random noise added upon model startup; <=0 means no noise added
485 
486  integer :: a2b_ord = 4 ! order for interpolation from A to B Grid (corners)
487  integer :: c2l_ord = 4 ! order for interpolation from D to lat-lon A winds for phys & output
488 
489  real(kind=R_GRID) :: dx_const = 1000. ! spatial resolution for double periodic boundary configuration [m]
490  real(kind=R_GRID) :: dy_const = 1000.
491  real(kind=R_GRID) :: deglat=15.
492  !The following deglat_*, deglon_* options are not used.
493  real(kind=R_GRID) :: deglon_start = -30., deglon_stop = 30., & ! boundaries of latlon patch
494  deglat_start = -30., deglat_stop = 30.
495 
496  !Convenience pointers
497  integer, pointer :: grid_number
498 
499  !f1p
500  logical :: adj_mass_vmr = .false. !TER: This is to reproduce answers for verona patch. This default can be changed
501  ! to .true. in the next city release if desired
502 
503  !integer, pointer :: test_case
504  !real, pointer :: alpha
505 
506  end type fv_flags_type
507 
509 
510  !!! CLEANUP: could we have pointers to np[xyz], nest_domain, and the index/weight arrays?
511 
512  real, allocatable, dimension(:,:,:) :: west_t1, east_t1, south_t1, north_t1
513  real, allocatable, dimension(:,:,:) :: west_t0, east_t0, south_t0, north_t0
514 
515  integer :: istag, jstag
516 
517  logical :: allocated = .false.
518  logical :: initialized = .false.
519 
520  end type fv_nest_bc_type_3d
521 
523 
524  real, allocatable, dimension(:,:,:,:) :: west_t1, east_t1, south_t1, north_t1
525  real, allocatable, dimension(:,:,:,:) :: west_t0, east_t0, south_t0, north_t0
526 
527  integer :: istag, jstag
528 
529  logical :: allocated = .false.
530  logical :: initialized = .false.
531 
532  end type fv_nest_bc_type_4d
533 
535 
536 !nested grid flags:
537 
538  integer :: refinement = 3 !Refinement wrt parent
539 
540  integer :: parent_tile = 1 !Tile (of cubed sphere) in which nested grid lies
541  logical :: nested = .false.
542  integer :: nestbctype = 1
543  integer :: nsponge = 0
544  integer :: nestupdate = 0
545  logical :: twowaynest = .false.
546  integer :: ioffset, joffset !Position of nest within parent grid
547 
548  integer :: nest_timestep = 0 !Counter for nested-grid timesteps
549  integer :: tracer_nest_timestep = 0 !Counter for nested-grid timesteps
550  real :: s_weight = 1.e-6 !sponge weight
551  logical :: first_step = .true.
552  integer :: refinement_of_global = 1
553  integer :: npx_global
554  integer :: upoff = 1 ! currently the same for all variables
555  integer :: isu = -999, ieu = -1000, jsu = -999, jeu = -1000 ! limits of update regions on coarse grid
556 
557  type(nest_domain_type) :: nest_domain !Structure holding link from this grid to its parent
558  type(nest_domain_type), allocatable :: nest_domain_all(:)
559 
560  !Interpolation arrays for grid nesting
561  integer, allocatable, dimension(:,:,:) :: ind_h, ind_u, ind_v, ind_b
562  real, allocatable, dimension(:,:,:) :: wt_h, wt_u, wt_v, wt_b
563  integer, allocatable, dimension(:,:,:) :: ind_update_h
564 
565  !These arrays are not allocated by allocate_fv_atmos_type; but instead
566  !allocated for all grids, regardless of whether the grid is
567  !on a PE of a concurrent run.
568  logical, allocatable, dimension(:) :: child_grids
569 
570  logical :: parent_proc, child_proc
571  logical :: parent_of_twoway = .false.
572 
573  !These are for time-extrapolated BCs
574  type(fv_nest_bc_type_3d) :: delp_bc, u_bc, v_bc, uc_bc, vc_bc, divg_bc
575  type(fv_nest_bc_type_3d), allocatable, dimension(:) :: q_bc
576 #ifndef SW_DYNAMICS
577  type(fv_nest_bc_type_3d) :: pt_bc, w_bc, delz_bc
578 #ifdef USE_COND
579  type(fv_nest_bc_type_3d) :: q_con_bc
580 #ifdef MOIST_CAPPA
581  type(fv_nest_bc_type_3d) :: cappa_bc
582 #endif
583 #endif
584 #endif
585 
586  !These are for tracer flux BCs
587  logical :: do_flux_bcs, do_2way_flux_bcs !For a parent grid; determine whether there is a need to send BCs
588  type(restart_file_type) :: bcfile_ne, bcfile_sw
589 
590  end type fv_nest_type
591 
593  module procedure allocate_fv_nest_bc_type_3d
594  module procedure allocate_fv_nest_bc_type_3d_atm
595  end interface
596 
598  module procedure deallocate_fv_nest_bc_type_3d
599  end interface
600 
602 
603  integer :: is, ie, js, je
604  integer :: isd, ied, jsd, jed
605  integer :: isc, iec, jsc, jec
606 
607  integer :: ng
608 
609  end type fv_grid_bounds_type
610 
612 
613  logical :: allocated = .false.
614  logical :: dummy = .false. ! same as grids_on_this_pe(n)
615  integer :: grid_number = 1
616 
617  !Timestep-related variables.
618 
619  type(time_type) :: time_init, time, run_length, time_end, time_step_atmos
620 
621 #ifdef GFS_PHYS
622  !--- used for GFS PHYSICS only
623  real, dimension(2048) :: fdiag = 0.
624 #endif
625 
626  logical :: grid_active = .true. !Always active for now
627 
628  !This is kept here instead of in neststruct% simply for convenience
629  type(fv_atmos_type), pointer :: parent_grid _null
630 
631 !-----------------------------------------------------------------------
632 ! Five prognostic state variables for the f-v dynamics
633 !-----------------------------------------------------------------------
634 ! dyn_state:
635 ! D-grid prognostatic variables: u, v, and delp (and other scalars)
636 !
637 ! o--------u(i,j+1)----------o
638 ! | | |
639 ! | | |
640 ! v(i,j)------scalar(i,j)----v(i+1,j)
641 ! | | |
642 ! | | |
643 ! o--------u(i,j)------------o
644 !
645 ! The C grid component is "diagnostic" in that it is predicted every time step
646 ! from the D grid variables.
647  real, _allocatable :: u(:,:,:) _null ! D grid zonal wind (m/s)
648  real, _allocatable :: v(:,:,:) _null ! D grid meridional wind (m/s)
649  real, _allocatable :: pt(:,:,:) _null ! temperature (K)
650  real, _allocatable :: delp(:,:,:) _null ! pressure thickness (pascal)
651  real, _allocatable :: q(:,:,:,:) _null ! specific humidity and prognostic constituents
652  real, _allocatable :: qdiag(:,:,:,:) _null ! diagnostic tracers
653 
654 !----------------------
655 ! non-hydrostatic state:
656 !----------------------------------------------------------------------
657  real, _allocatable :: w(:,:,:) _null ! cell center vertical wind (m/s)
658  real, _allocatable :: delz(:,:,:) _null ! layer thickness (meters)
659  real, _allocatable :: ze0(:,:,:) _null ! height at layer edges for remapping
660  real, _allocatable :: q_con(:,:,:) _null ! total condensates
661 
662 !-----------------------------------------------------------------------
663 ! Auxilliary pressure arrays:
664 ! The 5 vars below can be re-computed from delp and ptop.
665 !-----------------------------------------------------------------------
666 ! dyn_aux:
667  real, _allocatable :: ps (:,:) _null ! Surface pressure (pascal)
668  real, _allocatable :: pe (:,:,: ) _null ! edge pressure (pascal)
669  real, _allocatable :: pk (:,:,:) _null ! pe**cappa
670  real, _allocatable :: peln(:,:,:) _null ! ln(pe)
671  real, _allocatable :: pkz (:,:,:) _null ! finite-volume mean pk
672 
673 ! For phys coupling:
674  real, _allocatable :: u_srf(:,:) _null ! Surface u-wind
675  real, _allocatable :: v_srf(:,:) _null ! Surface v-wind
676  real, _allocatable :: sgh(:,:) _null ! Terrain standard deviation
677  real, _allocatable :: oro(:,:) _null ! land fraction (1: all land; 0: all water)
678  real, _allocatable :: ts(:,:) _null ! skin temperature (sst) from NCEP/GFS (K) -- tile
679 
680 !-----------------------------------------------------------------------
681 ! Others:
682 !-----------------------------------------------------------------------
683  real, _allocatable :: phis(:,:) _null ! Surface geopotential (g*Z_surf)
684  real, _allocatable :: omga(:,:,:) _null ! Vertical pressure velocity (pa/s)
685  real, _allocatable :: ua(:,:,:) _null ! (ua, va) are mostly used as the A grid winds
686  real, _allocatable :: va(:,:,:) _null
687  real, _allocatable :: uc(:,:,:) _null ! (uc, vc) are mostly used as the C grid winds
688  real, _allocatable :: vc(:,:,:) _null
689 
690  real, _allocatable :: ak(:) _null
691  real, _allocatable :: bk(:) _null
692 
693  integer :: ks
694 
695 ! Accumulated Mass flux arrays
696  real, _allocatable :: mfx(:,:,:) _null
697  real, _allocatable :: mfy(:,:,:) _null
698 ! Accumulated Courant number arrays
699  real, _allocatable :: cx(:,:,:) _null
700  real, _allocatable :: cy(:,:,:) _null
701 
702  type(fv_flags_type) :: flagstruct
703 
704  !! Convenience pointers
705  integer, pointer :: npx, npy, npz, ncnst, ng
706 
707  integer, allocatable, dimension(:) :: pelist
708 
710 
711  type(domain2d) :: domain
712 #if defined(SPMD)
713 
714  type(domain2d) :: domain_for_coupler ! domain used in coupled model with halo = 1.
715 
716  integer :: num_contact, npes_per_tile, tile, npes_this_grid
717  integer :: layout(2), io_layout(2) = (/ 1,1 /)
718 
719 #endif
720  !These do not actually belong to the grid, but to the process
721  !integer :: masterproc
722  !integer :: gid
723 
724 !!!!!!!!!!!!!!!!
725 ! From fv_grid_tools
726 !!!!!!!!!!!!!!!!
727 
728 
729  real :: ptop
730 
731  type(fv_grid_type) :: gridstruct
732 
733 
734 !!!!!!!!!!!!!!!!
735 !fv_diagnostics!
736 !!!!!!!!!!!!!!!!
737 
738  type(fv_diag_type) :: idiag
739 
740 !!!!!!!!!!!!!!
741 ! From fv_io !
742 !!!!!!!!!!!!!!
743  type(restart_file_type) :: fv_restart, sst_restart, fv_tile_restart, &
744  rsf_restart, mg_restart, lnd_restart, tra_restart
745 
746  type(fv_nest_type) :: neststruct
747 
748  !Hold on to coarse-grid global grid, so we don't have to waste processor time getting it again when starting to do grid nesting
749  real(kind=R_GRID), allocatable, dimension(:,:,:,:) :: grid_global
750 
751  integer :: atmos_axes(4)
752 
753 
754  end type fv_atmos_type
755 
756 contains
757 
758  subroutine allocate_fv_atmos_type(Atm, isd_in, ied_in, jsd_in, jed_in, is_in, ie_in, js_in, je_in, &
759  npx_in, npy_in, npz_in, ndims_in, ncnst_in, nq_in, ng_in, dummy, alloc_2d, ngrids_in)
761  !WARNING: Before calling this routine, be sure to have set up the
762  ! proper domain parameters from the namelists (as is done in
763  ! fv_control_nlm.F90)
764 
765  implicit none
766  type(fv_atmos_type), intent(INOUT), target :: Atm
767  integer, intent(IN) :: isd_in, ied_in, jsd_in, jed_in, is_in, ie_in, js_in, je_in
768  integer, intent(IN) :: npx_in, npy_in, npz_in, ndims_in, ncnst_in, nq_in, ng_in
769  logical, intent(IN) :: dummy, alloc_2d
770  integer, intent(IN) :: ngrids_in
771  integer:: isd, ied, jsd, jed, is, ie, js, je
772  integer:: npx, npy, npz, ndims, ncnst, nq, ng
773 
774  !For 2D utility arrays
775  integer:: isd_2d, ied_2d, jsd_2d, jed_2d, is_2d, ie_2d, js_2d, je_2d
776  integer:: npx_2d, npy_2d, npz_2d, ndims_2d, ncnst_2d, nq_2d, ng_2d
777 
778  integer :: i,j,k, ns, n
779 
780  if (atm%allocated) return
781 
782  if (dummy) then
783  isd = 0
784  ied= -1
785  jsd= 0
786  jed= -1
787  is= 0
788  ie= -1
789  js= 0
790  je= -1
791  npx= 1
792  npy= 1
793  npz= 1
794  ndims= 1
795  ncnst= 1
796  nq= 1
797  ng = 1
798  else
799  isd = isd_in
800  ied= ied_in
801  jsd= jsd_in
802  jed= jed_in
803  is= is_in
804  ie= ie_in
805  js= js_in
806  je= je_in
807  npx= npx_in
808  npy= npy_in
809  npz= npz_in
810  ndims= ndims_in
811  ncnst= ncnst_in
812  nq= nq_in
813  ng = ng_in
814  endif
815 
816  if ((.not. dummy) .or. alloc_2d) then
817  isd_2d = isd_in
818  ied_2d= ied_in
819  jsd_2d= jsd_in
820  jed_2d= jed_in
821  is_2d= is_in
822  ie_2d= ie_in
823  js_2d= js_in
824  je_2d= je_in
825  npx_2d= npx_in
826  npy_2d= npy_in
827  npz_2d= npz_in
828  ndims_2d= ndims_in
829  ncnst_2d= ncnst_in
830  nq_2d= nq_in
831  ng_2d = ng_in
832  else
833  isd_2d = 0
834  ied_2d= -1
835  jsd_2d= 0
836  jed_2d= -1
837  is_2d= 0
838  ie_2d= -1
839  js_2d= 0
840  je_2d= -1
841  npx_2d= 1
842  npy_2d= 1
843  npz_2d= 0 !for ak, bk
844  ndims_2d= 1
845  ncnst_2d= 1
846  nq_2d= 1
847  ng_2d = 1
848  endif
849 
850 !This should be set up in fv_mp_nlm_mod
851 !!$ Atm%bd%isd = isd_in
852 !!$ Atm%bd%ied = ied_in
853 !!$ Atm%bd%jsd = jsd_in
854 !!$ Atm%bd%jed = jed_in
855 !!$
856 !!$ Atm%bd%is = is_in
857 !!$ Atm%bd%ie = ie_in
858 !!$ Atm%bd%js = js_in
859 !!$ Atm%bd%je = je_in
860 !!$
861 !!$ Atm%bd%isc = Atm%bd%is
862 !!$ Atm%bd%iec = Atm%bd%ie
863 !!$ Atm%bd%jsc = Atm%bd%js
864 !!$ Atm%bd%jec = Atm%bd%je
865 
866  atm%bd%ng = ng
867 
868  !Convenience pointers
869  atm%npx => atm%flagstruct%npx
870  atm%npy => atm%flagstruct%npy
871  atm%npz => atm%flagstruct%npz
872  atm%ncnst => atm%flagstruct%ncnst
873 
874  atm%ng => atm%bd%ng
875 
876 !!$ Atm%npx = npx_in
877 !!$ Atm%npy = npy_in
878 !!$ Atm%npz = npz_in
879  atm%flagstruct%ndims = ndims_in
880 
881  allocate ( atm%u(isd:ied ,jsd:jed+1,npz) )
882  allocate ( atm%v(isd:ied+1,jsd:jed ,npz) )
883 
884  allocate ( atm%pt(isd:ied ,jsd:jed ,npz) )
885  allocate ( atm%delp(isd:ied ,jsd:jed ,npz) )
886  allocate ( atm%q(isd:ied ,jsd:jed ,npz, nq) )
887  allocate (atm%qdiag(isd:ied ,jsd:jed ,npz, nq+1:ncnst) )
888 
889  ! Allocate Auxilliary pressure arrays
890  allocate ( atm%ps(isd:ied ,jsd:jed) )
891  allocate ( atm%pe(is-1:ie+1, npz+1,js-1:je+1) )
892  allocate ( atm%pk(is:ie ,js:je , npz+1) )
893  allocate ( atm%peln(is:ie,npz+1,js:je) )
894  allocate ( atm%pkz(is:ie,js:je,npz) )
895 
896  allocate ( atm%u_srf(is:ie,js:je) )
897  allocate ( atm%v_srf(is:ie,js:je) )
898 
899  if ( atm%flagstruct%fv_land ) then
900  allocate ( atm%sgh(is:ie,js:je) )
901  allocate ( atm%oro(is:ie,js:je) )
902  else
903  allocate ( atm%oro(1,1) )
904  endif
905 
906  ! Allocate others
907  allocate ( atm%ts(is:ie,js:je) )
908  allocate ( atm%phis(isd:ied ,jsd:jed ) )
909  allocate ( atm%omga(isd:ied ,jsd:jed ,npz) ); atm%omga=0.
910  allocate ( atm%ua(isd:ied ,jsd:jed ,npz) )
911  allocate ( atm%va(isd:ied ,jsd:jed ,npz) )
912  allocate ( atm%uc(isd:ied+1,jsd:jed ,npz) )
913  allocate ( atm%vc(isd:ied ,jsd:jed+1,npz) )
914  ! For tracer transport:
915  allocate ( atm%mfx(is:ie+1, js:je, npz) )
916  allocate ( atm%mfy(is:ie , js:je+1,npz) )
917  allocate ( atm%cx(is:ie+1, jsd:jed, npz) )
918  allocate ( atm%cy(isd:ied ,js:je+1, npz) )
919 
920  allocate ( atm%ak(npz_2d+1) )
921  allocate ( atm%bk(npz_2d+1) )
922 
923  !--------------------------
924  ! Non-hydrostatic dynamics:
925  !--------------------------
926  if ( atm%flagstruct%hydrostatic ) then
927  !Note length-one initialization if hydrostatic = .true.
928  allocate ( atm%w(isd:isd, jsd:jsd ,1) )
929  allocate ( atm%delz(isd:isd, jsd:jsd ,1) )
930  allocate ( atm%ze0(is:is, js:js ,1) )
931  else
932  allocate ( atm%w(isd:ied, jsd:jed ,npz ) )
933  allocate ( atm%delz(isd:ied, jsd:jed ,npz) )
934  if( atm%flagstruct%hybrid_z ) then
935  allocate ( atm%ze0(is:ie, js:je ,npz+1) )
936  else
937  allocate ( atm%ze0(is:is, js:js ,1) )
938  endif
939  ! allocate ( mono(isd:ied, jsd:jed, npz))
940  endif
941 
942 #ifdef USE_COND
943  allocate ( atm%q_con(isd:ied,jsd:jed,1:npz) )
944 #else
945  allocate ( atm%q_con(isd:isd,jsd:jsd,1) )
946 #endif
947 
948 #ifndef NO_TOUCH_MEM
949 ! Notes by SJL
950 ! Place the memory in the optimal shared mem space
951 ! This will help the scaling with OpenMP
952 !$OMP parallel do default(none) shared(isd,ied,jsd,jed,npz,Atm,nq,ncnst)
953  do k=1, npz
954  do j=jsd, jed
955  do i=isd, ied
956  atm%ua(i,j,k) = real_big
957  atm%va(i,j,k) = real_big
958  atm%pt(i,j,k) = real_big
959  atm%delp(i,j,k) = real_big
960  enddo
961  enddo
962  do j=jsd, jed+1
963  do i=isd, ied
964  atm%u(i,j,k) = real_big
965  atm%vc(i,j,k) = real_big
966  enddo
967  enddo
968  do j=jsd, jed
969  do i=isd, ied+1
970  atm%v(i,j,k) = real_big
971  atm%uc(i,j,k) = real_big
972  enddo
973  enddo
974  if ( .not. atm%flagstruct%hydrostatic ) then
975  do j=jsd, jed
976  do i=isd, ied
977  atm%w(i,j,k) = real_big
978  atm%delz(i,j,k) = real_big
979  enddo
980  enddo
981  endif
982  do n=1,nq
983  do j=jsd, jed
984  do i=isd, ied
985  atm%q(i,j,k,n) = real_big
986  enddo
987  enddo
988  enddo
989  do n=nq+1,ncnst
990  do j=jsd, jed
991  do i=isd, ied
992  atm%qdiag(i,j,k,n) = real_big
993  enddo
994  enddo
995  enddo
996  enddo
997 #endif
998 
999  allocate ( atm%gridstruct% area(isd_2d:ied_2d ,jsd_2d:jed_2d ) ) ! Cell Centered
1000  allocate ( atm%gridstruct% area_64(isd_2d:ied_2d ,jsd_2d:jed_2d ) ) ! Cell Centered
1001  allocate ( atm%gridstruct%rarea(isd_2d:ied_2d ,jsd_2d:jed_2d ) ) ! Cell Centered
1002 
1003  allocate ( atm%gridstruct% area_c(isd_2d:ied_2d+1,jsd_2d:jed_2d+1) ) ! Cell Corners
1004  allocate ( atm%gridstruct% area_c_64(isd_2d:ied_2d+1,jsd_2d:jed_2d+1) )! Cell Corners
1005  allocate ( atm%gridstruct%rarea_c(isd_2d:ied_2d+1,jsd_2d:jed_2d+1) ) ! Cell Corners
1006 
1007  atm%gridstruct% area = 0.0
1008  atm%gridstruct% area_64 = 0.0
1009  atm%gridstruct%rarea = 0.0
1010 
1011  atm%gridstruct% area_c = 0.0
1012  atm%gridstruct% area_c_64 = 0.0
1013  atm%gridstruct%rarea_c = 0.0
1014 
1015  allocate ( atm%gridstruct% dx(isd_2d:ied_2d ,jsd_2d:jed_2d+1) )
1016  allocate ( atm%gridstruct% dx_64(isd_2d:ied_2d ,jsd_2d:jed_2d+1) )
1017  allocate ( atm%gridstruct%rdx(isd_2d:ied_2d ,jsd_2d:jed_2d+1) )
1018  allocate ( atm%gridstruct% dy(isd_2d:ied_2d+1,jsd_2d:jed_2d ) )
1019  allocate ( atm%gridstruct% dy_64(isd_2d:ied_2d+1,jsd_2d:jed_2d ) )
1020  allocate ( atm%gridstruct%rdy(isd_2d:ied_2d+1,jsd_2d:jed_2d ) )
1021 
1022  allocate ( atm%gridstruct% dxc(isd_2d:ied_2d+1,jsd_2d:jed_2d ) )
1023  allocate ( atm%gridstruct% dxc_64(isd_2d:ied_2d+1,jsd_2d:jed_2d ) )
1024  allocate ( atm%gridstruct%rdxc(isd_2d:ied_2d+1,jsd_2d:jed_2d ) )
1025  allocate ( atm%gridstruct% dyc(isd_2d:ied_2d ,jsd_2d:jed_2d+1) )
1026  allocate ( atm%gridstruct% dyc_64(isd_2d:ied_2d ,jsd_2d:jed_2d+1) )
1027  allocate ( atm%gridstruct%rdyc(isd_2d:ied_2d ,jsd_2d:jed_2d+1) )
1028 
1029  allocate ( atm%gridstruct% dxa(isd_2d:ied_2d ,jsd_2d:jed_2d ) )
1030  allocate ( atm%gridstruct% dxa_64(isd_2d:ied_2d ,jsd_2d:jed_2d ) )
1031  allocate ( atm%gridstruct%rdxa(isd_2d:ied_2d ,jsd_2d:jed_2d ) )
1032  allocate ( atm%gridstruct% dya(isd_2d:ied_2d ,jsd_2d:jed_2d ) )
1033  allocate ( atm%gridstruct% dya_64(isd_2d:ied_2d ,jsd_2d:jed_2d ) )
1034  allocate ( atm%gridstruct%rdya(isd_2d:ied_2d ,jsd_2d:jed_2d ) )
1035 
1036  allocate ( atm%gridstruct%grid (isd_2d:ied_2d+1,jsd_2d:jed_2d+1,1:ndims_2d) )
1037  allocate ( atm%gridstruct%grid_64 (isd_2d:ied_2d+1,jsd_2d:jed_2d+1,1:ndims_2d) )
1038  allocate ( atm%gridstruct%agrid(isd_2d:ied_2d ,jsd_2d:jed_2d ,1:ndims_2d) )
1039  allocate ( atm%gridstruct%agrid_64(isd_2d:ied_2d ,jsd_2d:jed_2d ,1:ndims_2d) )
1040  allocate ( atm%gridstruct% sina(isd_2d:ied_2d+1,jsd_2d:jed_2d+1) ) ! SIN(angle of intersection)
1041  allocate ( atm%gridstruct% sina_64(isd_2d:ied_2d+1,jsd_2d:jed_2d+1) ) ! SIN(angle of intersection)
1042  allocate ( atm%gridstruct%rsina(is_2d:ie_2d+1,js_2d:je_2d+1) ) ! Why is the size different?
1043  allocate ( atm%gridstruct% cosa(isd_2d:ied_2d+1,jsd_2d:jed_2d+1) ) ! COS(angle of intersection)
1044  allocate ( atm%gridstruct% cosa_64(isd_2d:ied_2d+1,jsd_2d:jed_2d+1) ) ! COS(angle of intersection)
1045 
1046  allocate ( atm%gridstruct% e1(3,isd_2d:ied_2d+1,jsd_2d:jed_2d+1) )
1047  allocate ( atm%gridstruct% e2(3,isd_2d:ied_2d+1,jsd_2d:jed_2d+1) )
1048 
1049  allocate (atm%gridstruct%iinta(4, isd_2d:ied_2d ,jsd_2d:jed_2d), &
1050  atm%gridstruct%jinta(4, isd_2d:ied_2d ,jsd_2d:jed_2d), &
1051  atm%gridstruct%iintb(4, is_2d:ie_2d+1 ,js_2d:je_2d+1), &
1052  atm%gridstruct%jintb(4, is_2d:ie_2d+1 ,js_2d:je_2d+1) )
1053 
1054  allocate ( atm%gridstruct%edge_s(npx_2d) )
1055  allocate ( atm%gridstruct%edge_n(npx_2d) )
1056  allocate ( atm%gridstruct%edge_w(npy_2d) )
1057  allocate ( atm%gridstruct%edge_e(npy_2d) )
1058 
1059  allocate ( atm%gridstruct%edge_vect_s(isd_2d:ied_2d) )
1060  allocate ( atm%gridstruct%edge_vect_n(isd_2d:ied_2d) )
1061  allocate ( atm%gridstruct%edge_vect_w(jsd_2d:jed_2d) )
1062  allocate ( atm%gridstruct%edge_vect_e(jsd_2d:jed_2d) )
1063 
1064  allocate ( atm%gridstruct%ex_s(npx_2d) )
1065  allocate ( atm%gridstruct%ex_n(npx_2d) )
1066  allocate ( atm%gridstruct%ex_w(npy_2d) )
1067  allocate ( atm%gridstruct%ex_e(npy_2d) )
1068 
1069 
1070  allocate ( atm%gridstruct%l2c_u(is_2d:ie_2d, js_2d:je_2d+1) )
1071  allocate ( atm%gridstruct%l2c_v(is_2d:ie_2d+1,js_2d:je_2d) )
1072 
1073  ! For diveregnce damping:
1074  allocate ( atm%gridstruct%divg_u(isd_2d:ied_2d, jsd_2d:jed_2d+1) )
1075  allocate ( atm%gridstruct%divg_v(isd_2d:ied_2d+1,jsd_2d:jed_2d) )
1076  ! For del6 diffusion:
1077  allocate ( atm%gridstruct%del6_u(isd_2d:ied_2d, jsd_2d:jed_2d+1) )
1078  allocate ( atm%gridstruct%del6_v(isd_2d:ied_2d+1,jsd_2d:jed_2d) )
1079 
1080  allocate ( atm%gridstruct%z11(is_2d-1:ie_2d+1,js_2d-1:je_2d+1) )
1081  allocate ( atm%gridstruct%z12(is_2d-1:ie_2d+1,js_2d-1:je_2d+1) )
1082  allocate ( atm%gridstruct%z21(is_2d-1:ie_2d+1,js_2d-1:je_2d+1) )
1083  allocate ( atm%gridstruct%z22(is_2d-1:ie_2d+1,js_2d-1:je_2d+1) )
1084 
1085 ! if (.not.Atm%flagstruct%hydrostatic) &
1086 ! allocate ( Atm%gridstruct%w00(is_2d-1:ie_2d+1,js_2d-1:je_2d+1) )
1087 
1088  allocate ( atm%gridstruct%a11(is_2d-1:ie_2d+1,js_2d-1:je_2d+1) )
1089  allocate ( atm%gridstruct%a12(is_2d-1:ie_2d+1,js_2d-1:je_2d+1) )
1090  allocate ( atm%gridstruct%a21(is_2d-1:ie_2d+1,js_2d-1:je_2d+1) )
1091  allocate ( atm%gridstruct%a22(is_2d-1:ie_2d+1,js_2d-1:je_2d+1) )
1092  allocate ( atm%gridstruct%vlon(is_2d-2:ie_2d+2,js_2d-2:je_2d+2,3) )
1093  allocate ( atm%gridstruct%vlat(is_2d-2:ie_2d+2,js_2d-2:je_2d+2,3) )
1094  ! Coriolis parameters:
1095  allocate ( atm%gridstruct%f0(isd_2d:ied_2d ,jsd_2d:jed_2d ) )
1096  allocate ( atm%gridstruct%fC(isd_2d:ied_2d+1,jsd_2d:jed_2d+1) )
1097 
1098  ! Corner unit vectors:
1099  allocate( atm%gridstruct%ee1(3,isd_2d:ied_2d+1,jsd_2d:jed_2d+1) )
1100  allocate( atm%gridstruct%ee2(3,isd_2d:ied_2d+1,jsd_2d:jed_2d+1) )
1101 
1102  ! Center unit vectors:
1103  allocate( atm%gridstruct%ec1(3,isd_2d:ied_2d,jsd_2d:jed_2d) )
1104  allocate( atm%gridstruct%ec2(3,isd_2d:ied_2d,jsd_2d:jed_2d) )
1105 
1106  ! Edge unit vectors:
1107  allocate( atm%gridstruct%ew(3,isd_2d:ied_2d+1,jsd_2d:jed_2d, 2) )
1108  allocate( atm%gridstruct%es(3,isd_2d:ied_2d ,jsd_2d:jed_2d+1,2) )
1109 
1110  ! Edge unit "Normal" vectors: (for omega computation)
1111  allocate( atm%gridstruct%en1(3,is_2d:ie_2d, js_2d:je_2d+1) ) ! E-W edges
1112  allocate( atm%gridstruct%en2(3,is_2d:ie_2d+1,js_2d:je_2d ) ) ! N-S egdes
1113 
1114  allocate ( atm%gridstruct%cosa_u(isd_2d:ied_2d+1,jsd_2d:jed_2d) )
1115  allocate ( atm%gridstruct%sina_u(isd_2d:ied_2d+1,jsd_2d:jed_2d) )
1116  allocate ( atm%gridstruct%rsin_u(isd_2d:ied_2d+1,jsd_2d:jed_2d) )
1117 
1118  allocate ( atm%gridstruct%cosa_v(isd_2d:ied_2d,jsd_2d:jed_2d+1) )
1119  allocate ( atm%gridstruct%sina_v(isd_2d:ied_2d,jsd_2d:jed_2d+1) )
1120  allocate ( atm%gridstruct%rsin_v(isd_2d:ied_2d,jsd_2d:jed_2d+1) )
1121 
1122  allocate ( atm%gridstruct%cosa_s(isd_2d:ied_2d,jsd_2d:jed_2d) ) ! cell center
1123 
1124  allocate ( atm%gridstruct%rsin2(isd_2d:ied_2d,jsd_2d:jed_2d) ) ! cell center
1125 
1126 
1127  ! Super (composite) grid:
1128 
1129  ! 9---4---8
1130  ! | |
1131  ! 1 5 3
1132  ! | |
1133  ! 6---2---7
1134 
1135  allocate ( atm%gridstruct%cos_sg(isd_2d:ied_2d,jsd_2d:jed_2d,9) )
1136  allocate ( atm%gridstruct%sin_sg(isd_2d:ied_2d,jsd_2d:jed_2d,9) )
1137 
1138  allocate( atm%gridstruct%eww(3,4) )
1139  allocate( atm%gridstruct%ess(3,4) )
1140 
1141  if (atm%neststruct%nested) then
1142 
1143  allocate(atm%neststruct%ind_h(isd:ied,jsd:jed,4))
1144  allocate(atm%neststruct%ind_u(isd:ied,jsd:jed+1,4))
1145  allocate(atm%neststruct%ind_v(isd:ied+1,jsd:jed,4))
1146 
1147  allocate(atm%neststruct%wt_h(isd:ied, jsd:jed, 4))
1148  allocate(atm%neststruct%wt_u(isd:ied, jsd:jed+1,4))
1149  allocate(atm%neststruct%wt_v(isd:ied+1, jsd:jed, 4))
1150  allocate(atm%neststruct%ind_b(isd:ied+1,jsd:jed+1,4))
1151  allocate(atm%neststruct%wt_b(isd:ied+1, jsd:jed+1,4))
1152 
1153  ns = atm%neststruct%nsponge
1154 
1155  call allocate_fv_nest_bc_type(atm%neststruct%delp_BC,atm,ns,0,0,dummy)
1156  call allocate_fv_nest_bc_type(atm%neststruct%u_BC,atm,ns,0,1,dummy)
1157  call allocate_fv_nest_bc_type(atm%neststruct%v_BC,atm,ns,1,0,dummy)
1158  call allocate_fv_nest_bc_type(atm%neststruct%uc_BC,atm,ns,1,0,dummy)
1159  call allocate_fv_nest_bc_type(atm%neststruct%vc_BC,atm,ns,0,1,dummy)
1160  call allocate_fv_nest_bc_type(atm%neststruct%divg_BC,atm,ns,1,1,dummy)
1161 
1162  if (ncnst > 0) then
1163  allocate(atm%neststruct%q_BC(ncnst))
1164  do n=1,ncnst
1165  call allocate_fv_nest_bc_type(atm%neststruct%q_BC(n),atm,ns,0,0,dummy)
1166  enddo
1167  endif
1168 
1169 #ifndef SW_DYNAMICS
1170 
1171  call allocate_fv_nest_bc_type(atm%neststruct%pt_BC,atm,ns,0,0,dummy)
1172 #ifdef USE_COND
1173  call allocate_fv_nest_bc_type(atm%neststruct%q_con_BC,atm,ns,0,0,dummy)
1174 #ifdef MOIST_CAPPA
1175  call allocate_fv_nest_bc_type(atm%neststruct%cappa_BC,atm,ns,0,0,dummy)
1176 #endif
1177 #endif
1178  if (.not.atm%flagstruct%hydrostatic) then
1179  call allocate_fv_nest_bc_type(atm%neststruct%w_BC,atm,ns,0,0,dummy)
1180  call allocate_fv_nest_bc_type(atm%neststruct%delz_BC,atm,ns,0,0,dummy)
1181  endif
1182 
1183 #endif
1184 
1185  if (atm%neststruct%twowaynest) allocate(&
1186  atm%neststruct%ind_update_h( &
1187  atm%parent_grid%bd%isd:atm%parent_grid%bd%ied+1, &
1188  atm%parent_grid%bd%jsd:atm%parent_grid%bd%jed+1,2))
1189 
1190  end if
1191 
1192  !--- Do the memory allocation only for nested model
1193  if( ngrids_in > 1 ) then
1194  if (atm%flagstruct%grid_type < 4) then
1195  if (atm%neststruct%nested) then
1196  allocate(atm%grid_global(1-ng_2d:npx_2d +ng_2d,1-ng_2d:npy_2d +ng_2d,2,1))
1197  else
1198  allocate(atm%grid_global(1-ng_2d:npx_2d +ng_2d,1-ng_2d:npy_2d +ng_2d,2,1:6))
1199  endif
1200  end if
1201  endif
1202 
1203  atm%allocated = .true.
1204  if (dummy) atm%dummy = .true.
1205 
1206  end subroutine allocate_fv_atmos_type
1207 
1208  subroutine deallocate_fv_atmos_type(Atm)
1210  implicit none
1211  type(fv_atmos_type), intent(INOUT) :: Atm
1212 
1213  integer :: n
1214 
1215  if (.not.atm%allocated) return
1216 
1217  deallocate ( atm%u )
1218  deallocate ( atm%v )
1219  deallocate ( atm%pt )
1220  deallocate ( atm%delp )
1221  deallocate ( atm%q )
1222  deallocate ( atm%qdiag )
1223  deallocate ( atm%ps )
1224  deallocate ( atm%pe )
1225  deallocate ( atm%pk )
1226  deallocate ( atm%peln )
1227  deallocate ( atm%pkz )
1228  deallocate ( atm%phis )
1229  deallocate ( atm%omga )
1230  deallocate ( atm%ua )
1231  deallocate ( atm%va )
1232  deallocate ( atm%uc )
1233  deallocate ( atm%vc )
1234  deallocate ( atm%mfx )
1235  deallocate ( atm%mfy )
1236  deallocate ( atm%cx )
1237  deallocate ( atm%cy )
1238  deallocate ( atm%ak )
1239  deallocate ( atm%bk )
1240 
1241  deallocate ( atm%u_srf )
1242  deallocate ( atm%v_srf )
1243  if( atm%flagstruct%fv_land ) deallocate ( atm%sgh )
1244  deallocate ( atm%oro )
1245 
1246  deallocate ( atm%w )
1247  deallocate ( atm%delz )
1248  deallocate ( atm%ze0 )
1249  deallocate ( atm%q_con )
1250 
1251  deallocate ( atm%gridstruct% area ) ! Cell Centered
1252  deallocate ( atm%gridstruct%rarea ) ! Cell Centered
1253 
1254  deallocate ( atm%gridstruct% area_c ) ! Cell Corners
1255  deallocate ( atm%gridstruct%rarea_c ) ! Cell Corners
1256 
1257  deallocate ( atm%gridstruct% dx )
1258  deallocate ( atm%gridstruct%rdx )
1259  deallocate ( atm%gridstruct% dy )
1260  deallocate ( atm%gridstruct%rdy )
1261 
1262  deallocate ( atm%gridstruct% dxc )
1263  deallocate ( atm%gridstruct%rdxc )
1264  deallocate ( atm%gridstruct% dyc )
1265  deallocate ( atm%gridstruct%rdyc )
1266 
1267  deallocate ( atm%gridstruct% dxa )
1268  deallocate ( atm%gridstruct%rdxa )
1269  deallocate ( atm%gridstruct% dya )
1270  deallocate ( atm%gridstruct%rdya )
1271 
1272  deallocate ( atm%gridstruct%grid )
1273  deallocate ( atm%gridstruct%agrid )
1274  deallocate ( atm%gridstruct%sina ) ! SIN(angle of intersection)
1275  deallocate ( atm%gridstruct%cosa ) ! COS(angle of intersection)
1276 
1277  deallocate ( atm%gridstruct% e1 )
1278  deallocate ( atm%gridstruct% e2 )
1279 
1280 
1281 
1282 
1283  deallocate (atm%gridstruct%iinta, &
1284  atm%gridstruct%jinta, &
1285  atm%gridstruct%iintb, &
1286  atm%gridstruct%jintb )
1287 
1288  deallocate ( atm%gridstruct%edge_s )
1289  deallocate ( atm%gridstruct%edge_n )
1290  deallocate ( atm%gridstruct%edge_w )
1291  deallocate ( atm%gridstruct%edge_e )
1292 
1293  deallocate ( atm%gridstruct%edge_vect_s )
1294  deallocate ( atm%gridstruct%edge_vect_n )
1295  deallocate ( atm%gridstruct%edge_vect_w )
1296  deallocate ( atm%gridstruct%edge_vect_e )
1297 
1298  deallocate ( atm%gridstruct%ex_s )
1299  deallocate ( atm%gridstruct%ex_n )
1300  deallocate ( atm%gridstruct%ex_w )
1301  deallocate ( atm%gridstruct%ex_e )
1302 
1303 
1304  deallocate ( atm%gridstruct%l2c_u )
1305  deallocate ( atm%gridstruct%l2c_v )
1306  ! For diveregnce damping:
1307  deallocate ( atm%gridstruct%divg_u )
1308  deallocate ( atm%gridstruct%divg_v )
1309  ! For del6 diffusion:
1310 
1311  deallocate ( atm%gridstruct%z11 )
1312  deallocate ( atm%gridstruct%z12 )
1313  deallocate ( atm%gridstruct%z21 )
1314  deallocate ( atm%gridstruct%z22 )
1315 
1316  deallocate ( atm%gridstruct%a11 )
1317  deallocate ( atm%gridstruct%a12 )
1318  deallocate ( atm%gridstruct%a21 )
1319  deallocate ( atm%gridstruct%a22 )
1320  deallocate ( atm%gridstruct%vlon )
1321  deallocate ( atm%gridstruct%vlat )
1322  ! Coriolis parameters:
1323  deallocate ( atm%gridstruct%f0 )
1324  deallocate ( atm%gridstruct%fC )
1325 
1326  ! Corner unit vectors:
1327  deallocate( atm%gridstruct%ee1 )
1328  deallocate( atm%gridstruct%ee2 )
1329 
1330  ! Center unit vectors:
1331  deallocate( atm%gridstruct%ec1 )
1332  deallocate( atm%gridstruct%ec2 )
1333 
1334  ! Edge unit vectors:
1335  deallocate( atm%gridstruct%ew )
1336  deallocate( atm%gridstruct%es )
1337 
1338  ! Edge unit "Normal" vectors: (for omega computation)
1339  deallocate( atm%gridstruct%en1 ) ! E-W edges
1340  deallocate( atm%gridstruct%en2 ) ! N-S egdes
1341 
1342  deallocate ( atm%gridstruct%cosa_u )
1343  deallocate ( atm%gridstruct%sina_u )
1344  deallocate ( atm%gridstruct%rsin_u )
1345 
1346  deallocate ( atm%gridstruct%cosa_v )
1347  deallocate ( atm%gridstruct%sina_v )
1348  deallocate ( atm%gridstruct%rsin_v )
1349 
1350  deallocate ( atm%gridstruct%cosa_s ) ! cell center
1351 
1352  deallocate ( atm%gridstruct%rsin2 ) ! cell center
1353 
1354 
1355  ! Super (composite) grid:
1356 
1357  ! 9---4---8
1358  ! | |
1359  ! 1 5 3
1360  ! | |
1361  ! 6---2---7
1362 
1363  deallocate ( atm%gridstruct%cos_sg )
1364  deallocate ( atm%gridstruct%sin_sg )
1365 
1366  deallocate( atm%gridstruct%eww )
1367  deallocate( atm%gridstruct%ess )
1368 
1369  if (atm%neststruct%nested) then
1370  deallocate(atm%neststruct%ind_h)
1371  deallocate(atm%neststruct%ind_u)
1372  deallocate(atm%neststruct%ind_v)
1373 
1374  deallocate(atm%neststruct%wt_h)
1375  deallocate(atm%neststruct%wt_u)
1376  deallocate(atm%neststruct%wt_v)
1377 
1378  deallocate(atm%neststruct%ind_b)
1379  deallocate(atm%neststruct%wt_b)
1380 
1381  call deallocate_fv_nest_bc_type(atm%neststruct%delp_BC)
1382  call deallocate_fv_nest_bc_type(atm%neststruct%u_BC)
1383  call deallocate_fv_nest_bc_type(atm%neststruct%v_BC)
1384  call deallocate_fv_nest_bc_type(atm%neststruct%uc_BC)
1385  call deallocate_fv_nest_bc_type(atm%neststruct%vc_BC)
1386  call deallocate_fv_nest_bc_type(atm%neststruct%divg_BC)
1387 
1388  if (allocated(atm%neststruct%q_BC)) then
1389  do n=1,size(atm%neststruct%q_BC)
1390  call deallocate_fv_nest_bc_type(atm%neststruct%q_BC(n))
1391  enddo
1392  endif
1393 
1394 #ifndef SW_DYNAMICS
1395  call deallocate_fv_nest_bc_type(atm%neststruct%pt_BC)
1396 #ifdef USE_COND
1397  call deallocate_fv_nest_bc_type(atm%neststruct%q_con_BC)
1398 #ifdef MOIST_CAPPA
1399  call deallocate_fv_nest_bc_type(atm%neststruct%cappa_BC)
1400 #endif
1401 #endif
1402  if (.not.atm%flagstruct%hydrostatic) then
1403  call deallocate_fv_nest_bc_type(atm%neststruct%w_BC)
1404  call deallocate_fv_nest_bc_type(atm%neststruct%delz_BC)
1405  endif
1406 #endif
1407 
1408 
1409  if (atm%neststruct%twowaynest) deallocate(atm%neststruct%ind_update_h)
1410 
1411  end if
1412 
1413  if (atm%flagstruct%grid_type < 4) then
1414  if(allocated(atm%grid_global)) deallocate(atm%grid_global)
1415  end if
1416 
1417  atm%allocated = .false.
1418 
1419  end subroutine deallocate_fv_atmos_type
1420 
1421 
1422 subroutine allocate_fv_nest_bc_type_3d_atm(BC,Atm,ns,istag,jstag,dummy)
1424  type(fv_nest_BC_type_3D), intent(INOUT) :: BC
1425  type(fv_atmos_type), intent(IN) :: Atm
1426  integer, intent(IN) :: ns, istag, jstag
1427  logical, intent(IN) :: dummy
1428 
1429  integer :: is, ie, js, je, isd, ied, jsd, jed, npx, npy, npz, ng
1430 
1431  if (bc%allocated) return
1432 
1433  is = atm%bd%is
1434  ie = atm%bd%ie
1435  js = atm%bd%js
1436  je = atm%bd%je
1437 
1438  isd = atm%bd%isd
1439  ied = atm%bd%ied
1440  jsd = atm%bd%jsd
1441  jed = atm%bd%jed
1442 
1443  npx = atm%npx
1444  npy = atm%npy
1445  npz = atm%npz
1446 
1447  ng = atm%ng
1448 
1449  call allocate_fv_nest_bc_type_3d(bc,is,ie,js,je,isd,ied,jsd,jed,npx,npy,npz,ng,ns,istag,jstag,dummy)
1450 
1451 
1452 end subroutine allocate_fv_nest_bc_type_3d_atm
1453 
1454 subroutine allocate_fv_nest_bc_type_3d(BC,is,ie,js,je,isd,ied,jsd,jed,npx,npy,npz,ng,ns,istag,jstag,dummy)
1456  type(fv_nest_BC_type_3D), intent(INOUT) :: BC
1457  integer, intent(IN) :: ns, istag, jstag
1458  logical, intent(IN) :: dummy
1459 
1460  integer, intent(IN) :: is, ie, js, je, isd, ied, jsd, jed, npx, npy, npz, ng
1461 
1462  if (bc%allocated) return
1463 
1464 
1465  if (ie == npx-1 .and. .not. dummy) then
1466  allocate(bc%east_t1(ie+1-ns+istag:ied+istag,jsd:jed+jstag,npz))
1467  allocate(bc%east_t0(ie+1-ns+istag:ied+istag,jsd:jed+jstag,npz))
1468  do k=1,npz
1469  do j=jsd,jed+jstag
1470  do i=ie+1-ns+istag,ied+istag
1471  bc%east_t1(i,j,k) = 0.
1472  bc%east_t0(i,j,k) = 0.
1473  enddo
1474  enddo
1475  enddo
1476  else
1477  allocate(bc%east_t1(1,1,npz))
1478  allocate(bc%east_t0(1,1,npz))
1479  end if
1480 
1481  if (js == 1 .and. .not. dummy) then
1482  allocate(bc%south_t1(isd:ied+istag,jsd:js-1+ns,npz))
1483  allocate(bc%south_t0(isd:ied+istag,jsd:js-1+ns,npz))
1484  do k=1,npz
1485  do j=jsd,js-1+ns
1486  do i=isd,ied+istag
1487  bc%south_t1(i,j,k) = 0.
1488  bc%south_t0(i,j,k) = 0.
1489  enddo
1490  enddo
1491  enddo
1492  else
1493  allocate(bc%south_t1(1,1,npz))
1494  allocate(bc%south_t0(1,1,npz))
1495  end if
1496 
1497  if (is == 1 .and. .not. dummy) then
1498  allocate(bc%west_t1(isd:is-1+ns,jsd:jed+jstag,npz))
1499  allocate(bc%west_t0(isd:is-1+ns,jsd:jed+jstag,npz))
1500  do k=1,npz
1501  do j=jsd,jed+jstag
1502  do i=isd,is-1+ns
1503  bc%west_t1(i,j,k) = 0.
1504  bc%west_t0(i,j,k) = 0.
1505  enddo
1506  enddo
1507  enddo
1508  else
1509  allocate(bc%west_t1(1,1,npz))
1510  allocate(bc%west_t0(1,1,npz))
1511  end if
1512 
1513  if (je == npy-1 .and. .not. dummy) then
1514  allocate(bc%north_t1(isd:ied+istag,je+1-ns+jstag:jed+jstag,npz))
1515  allocate(bc%north_t0(isd:ied+istag,je+1-ns+jstag:jed+jstag,npz))
1516  do k=1,npz
1517  do j=je+1-ns+jstag,jed+jstag
1518  do i=isd,ied+istag
1519  bc%north_t1(i,j,k) = 0.
1520  bc%north_t0(i,j,k) = 0.
1521  enddo
1522  enddo
1523  enddo
1524  else
1525  allocate(bc%north_t1(1,1,npz))
1526  allocate(bc%north_t0(1,1,npz))
1527  end if
1528 
1529  bc%allocated = .true.
1530 
1531 end subroutine allocate_fv_nest_bc_type_3d
1532 
1533 subroutine deallocate_fv_nest_bc_type_3d(BC)
1535  type(fv_nest_BC_type_3d) :: BC
1536 
1537  if (.not. bc%allocated) return
1538 
1539  deallocate(bc%north_t1)
1540  deallocate(bc%south_t1)
1541  deallocate(bc%west_t1)
1542  deallocate(bc%east_t1)
1543 
1544  if (allocated(bc%north_t0)) then
1545  deallocate(bc%north_t0)
1546  deallocate(bc%south_t0)
1547  deallocate(bc%west_t0)
1548  deallocate(bc%east_t0)
1549  endif
1550 
1551  bc%allocated = .false.
1552 
1553 end subroutine deallocate_fv_nest_bc_type_3d
1554 
1555 
1556 end module fv_arrays_nlm_mod
subroutine allocate_fv_nest_bc_type_3d(BC, is, ie, js, je, isd, ied, jsd, jed, npx, npy, npz, ng, ns, istag, jstag, dummy)
integer, parameter real8
subroutine allocate_fv_atmos_type(Atm, isd_in, ied_in, jsd_in, jed_in, is_in, ie_in, js_in, je_in, npx_in, npy_in, npz_in, ndims_in, ncnst_in, nq_in, ng_in, dummy, alloc_2d, ngrids_in)
subroutine deallocate_fv_nest_bc_type_3d(BC)
subroutine allocate_fv_nest_bc_type_3d_atm(BC, Atm, ns, istag, jstag, dummy)
integer, parameter real4
Definition: mpp.F90:39
integer, parameter max_step
integer, parameter, public r_grid
real, parameter real_big
integer, parameter r8_kind
Definition: platform.F90:24
subroutine deallocate_fv_atmos_type(Atm)
integer, parameter fvprc
Derived type containing the data.