1 subroutine da_setup_firstguess(xbx, grid, config_flags, ens )
3 !---------------------------------------------------------------------------
4 ! Purpose: Allocate and read in components of first guess state.
5 ! Updated for Analysis on Arakawa-C grid
6 ! Author: Syed RH Rizvi, MMM/ESSL/NCAR, Date: 10/22/2008
7 !---------------------------------------------------------------------------
11 type (xbx_type),intent(out) :: xbx ! Header & non-gridded vars.
13 type(domain),intent(inout) :: grid
14 type(grid_config_rec_type), intent(in) :: config_flags
15 logical, intent(in) :: ens
17 integer :: is, ie, js, je, ij, i, j
20 if (trace_use) call da_trace_entry("da_setup_firstguess")
27 ! Calculate sin and cosine values used in da_get_avpoles
30 if (grid%xp%jts == grid%xp%jds) then
32 allocate(cos_xls(grid%xp%its:grid%xp%ite))
33 allocate(sin_xls(grid%xp%its:grid%xp%ite))
34 cos_xls(grid%xp%its:grid%xp%ite) = &
35 cos(deg_to_rad*grid%xlong(grid%xp%its:grid%xp%ite,grid%xp%jts))
36 sin_xls(grid%xp%its:grid%xp%ite) = &
37 sin(deg_to_rad*grid%xlong(grid%xp%its:grid%xp%ite,grid%xp%jts))
40 if (grid%xp%jte == grid%xp%jde) then
41 allocate(cos_xle(grid%xp%its:grid%xp%ite))
42 allocate(sin_xle(grid%xp%its:grid%xp%ite))
43 cos_xle(grid%xp%its:grid%xp%ite) = &
44 cos(deg_to_rad*grid%xlong(grid%xp%its:grid%xp%ite,grid%xp%jte))
45 sin_xle(grid%xp%its:grid%xp%ite) = &
46 sin(deg_to_rad*grid%xlong(grid%xp%its:grid%xp%ite,grid%xp%jte))
50 !---------------------------------------------------------------------------
51 ! [1.0] Setup and read in fields from first guess:
52 !---------------------------------------------------------------------------
54 if ((fg_format==fg_format_wrf_arw_regional) .or. &
55 (fg_format==fg_format_wrf_arw_global ) ) then
56 call da_setup_firstguess_wrf(xbx, grid, config_flags,ens)
57 ! when ens=.true., da_setup_firstguess(_wrf) is called solely for map_info,
58 ! the rest of the code should be skipped
60 if (trace_use) call da_trace_exit("da_setup_firstguess")
63 else if (fg_format == fg_format_wrf_nmm_regional ) then
64 call da_setup_firstguess_wrf_nmm_regional(xbx, grid)
65 else if (fg_format == fg_format_kma_global) then
66 ! First guess is an KMA format file:
67 call da_setup_firstguess_kma(xbx, grid)
70 !---------------------------------------------------------------------------
71 ! Exchange halo region for XB arrays.
72 !---------------------------------------------------------------------------
74 if ((fg_format==fg_format_wrf_arw_regional) .or. &
75 (fg_format==fg_format_wrf_arw_global ) ) then
76 ! Calculate multiplicative constants for PsiChi_TO_UV
78 !$OMP PRIVATE (ij, i, j)
79 do ij = 1, grid%num_tiles
80 do j = grid%j_start(ij), grid%j_end(ij)
82 grid%xb%coefx(i,j) = 0.5 * grid%xb%map_factor(i,j)/grid%xb%ds
83 grid%xb%coefy(i,j) = grid%xb%coefx(i,j)
84 grid%xb%coefz(i,j) = 0.5 / (grid%xb%map_factor(i,j)*grid%xb%ds)
89 else if (fg_format == fg_format_wrf_nmm_regional) then
90 grid%xb%coefx(is:ie,js:je) = 0.5/grid%mu0(is:ie,js:je)
91 grid%xb%coefy(is:ie,js:je) = 0.5/grid%xb%ds
92 else if (fg_format == fg_format_kma_global) then
93 ! Calculate multiplicative constants for PsiChi_TO_UV
94 ddx = earth_radius*1000 * 2.0 * pi / (grid%xb%ide-grid%xb%ids+1)
95 ddy = earth_radius*1000 * pi / (grid%xb%jde-grid%xb%jds)
96 grid%xb% coefx(is:ie,js:je) = 0.5 / (ddx * cos(grid%xlat(is:ie,js:je)*pi/180.))
97 grid%xb% coefy(is:ie,js:je) = 0.5 / ddy
99 write(unit=message(1),fmt='(A,I5)') &
100 "Wrong choice for fg_format = ",fg_format
101 call da_error(__FILE__,__LINE__,message(1:1))
105 if ((fg_format==fg_format_wrf_arw_regional .or. &
106 fg_format==fg_format_wrf_arw_global ) .and. ide == ipe ) then
111 if ((fg_format==fg_format_wrf_arw_regional .or. &
112 fg_format==fg_format_wrf_arw_global ) .and. jde == jpe ) then
118 #include "HALO_INIT.inc"
120 #include "HALO_CHEM_INIT.inc"
125 if ((fg_format==fg_format_wrf_arw_regional .or. &
126 fg_format==fg_format_wrf_arw_global ) .and. ide == ipe ) then
131 if ((fg_format==fg_format_wrf_arw_regional .or. &
132 fg_format==fg_format_wrf_arw_global ) .and. jde == jpe ) then
138 periodic_x = grid%periodic_x
141 ! Set East-West boundary for Xb-array
142 call da_set_boundary_xb(grid)
145 !---------------------------------------------------------------------------
146 ! [2.0] Setup grid-dependent constants used:
147 !---------------------------------------------------------------------------
149 ! [2.1] Set up fast Fourier & Legendre transform constants:
151 if (SIZE(xbx%fft_factors_x) /=num_fft_factors) &
152 call da_setup_runconstants(grid, xbx)
154 if (trace_use) call da_trace_exit("da_setup_firstguess")
156 end subroutine da_setup_firstguess