1 !----------------------------------------------------------------------
2 ! Subroutine: model_aro_coord
3 !> Load AROME coordinates
4 !----------------------------------------------------------------------
5 subroutine model_aro_coord(model,mpl,nam)
10 class(model_type),intent(inout) :: model !< Model
11 type(mpl_type),intent(inout) :: mpl !< MPI data
12 type(nam_type),intent(in) :: nam !< Namelist
15 integer :: img,ilon,ilat,il0,il0_bot,il0_top,ie,its
16 integer :: ncid,nlon_id,nlat_id,nlev_id,pp_id,lon_id,lat_id,cmask_id,a_id,b_id,fld_id,mask_id
17 integer,allocatable :: mask_counter(:)
19 real(
kind_real),allocatable :: lon(:,:),lat(:,:),cmask(:,:),
a(:),b(:),fld_loc(:,:),fld(:,:)
20 character(len=3) :: ilchar
21 character(len=1024) :: filename
22 character(len=1024),parameter :: subr =
'model_aro_coord'
24 ! Open file and get dimensions
26 call mpl%ncerr(subr,nf90_open(trim(nam%datadir)
27 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'X',nlon_id))
28 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'Y',nlat_id))
29 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nlon_id,len=model%nlon))
30 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nlat_id,len=model%nlat))
31 model%nmg = model%nlon*model%nlat
32 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'Z',nlev_id))
33 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nlev_id,len=model%nlev))
37 allocate(lon(model%nlon,model%nlat))
38 allocate(lat(model%nlon,model%nlat))
39 allocate(cmask(model%nlon,model%nlat))
40 allocate(
a(model%nlev+1))
41 allocate(b(model%nlev+1))
43 ! Read data and close file
44 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'longitude',lon_id))
45 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'latitude',lat_id))
46 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'cmask',cmask_id))
47 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'hybrid_coef_A',a_id))
48 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'hybrid_coef_B',b_id))
49 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'Projection_parameters',pp_id))
50 call mpl%ncerr(subr,nf90_get_var(ncid,lon_id,lon))
51 call mpl%ncerr(subr,nf90_get_var(ncid,lat_id,lat))
52 call mpl%ncerr(subr,nf90_get_var(ncid,cmask_id,cmask))
53 call mpl%ncerr(subr,nf90_get_var(ncid,a_id,
a))
54 call mpl%ncerr(subr,nf90_get_var(ncid,b_id,b))
55 call mpl%ncerr(subr,nf90_get_att(ncid,pp_id,
'x_resolution',dx))
56 call mpl%ncerr(subr,nf90_get_att(ncid,pp_id,
'y_resolution',dy))
57 call mpl%ncerr(subr,nf90_close(ncid))
68 model%mg_to_tile(img) = 1
69 model%mg_to_lon(img) = ilon
70 model%mg_to_lat(img) = ilat
71 model%lon(img) = lon(ilon,ilat)
72 model%lat(img) = lat(ilon,ilat)
73 select case (trim(
zone))
75 model%mask(img,:) = (cmask(ilon,ilat)>0.75)
77 model%mask(img,:) = (cmask(ilon,ilat)>0.25)
79 model%mask(img,:) = .true.
81 call mpl%abort(subr,
'wrong AROME zone')
85 model%area = dx*dy/
req**2
88 select case (trim(nam%mask_type))
90 ! Based on an external file
93 allocate(fld_loc(model%nlon,model%nlat))
96 call mpl%ncerr(subr,nf90_open(trim(nam%datadir)
101 write(ilchar,
'(i3.3)') nam%levs(il0)
102 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'S'
105 call mpl%ncerr(subr,nf90_get_var(ncid,mask_id,fld_loc))
112 model%mask(img,il0) = (fld_loc(ilon,ilat)>nam%mask_th(1))
118 call mpl%ncerr(subr,nf90_close(ncid))
122 case (
"lwc_fog",
"lwc_clear",
"lwc_stratus")
123 ! Based on the ensemble-mean LWC
126 allocate(fld_loc(model%nlon,model%nlat))
127 allocate(fld(model%nmg,model%nl0))
128 allocate(mask_counter(model%nmga))
132 select case (trim(nam%mask_type))
147 write(filename,
'(a,i6.6)')
'ens1_',ie
150 call mpl%ncerr(subr,nf90_open(trim(nam%datadir)
155 write(ilchar,
'(i3.3)') nam%levs(il0)
156 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'S'
159 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_loc))
166 fld(img,il0) = real(fld_loc(ilon,ilat),
kind_real)
172 call mpl%ncerr(subr,nf90_close(ncid))
175 select case (trim(nam%mask_type))
178 if (all(fld(img,il0_top:il0_bot)>nam%mask_th)) mask_counter(img) = mask_counter(img)+1
182 if (all(fld(img,il0_top:il0_bot)<nam%mask_th)) mask_counter(img) = mask_counter(img)+1
186 if (count(fld(img,il0_top:il0_bot)>nam%mask_th)>3) mask_counter(img) = mask_counter(img)+1
193 if (real(mask_counter(img),
kind_real)<0.9*real(nam%ens1_ne,
kind_real)) model%mask(img,:) = .false.
199 if (nam%logpres) then
200 model%vunit(img,1:nam%nl) = log(0.5*(
a(nam%levs(1:nam%nl))+
a(nam%levs(1:nam%nl)+1)) &
201 & +0.5*(b(nam%levs(1:nam%nl))+b(nam%levs(1:nam%nl)+1))*
ps)
202 if (model%nl0>nam%nl) model%vunit(img,model%nl0) = log(
ps)
204 model%vunit(img,:) = real(nam%levs(1:model%nl0),
kind_real)
215 end subroutine model_aro_coord
217 !----------------------------------------------------------------------
218 ! Subroutine: model_aro_read
220 !----------------------------------------------------------------------
221 subroutine model_aro_read(model,mpl,nam,filename,fld)
226 class(model_type),intent(inout) :: model !< Model
227 type(mpl_type),intent(inout) :: mpl !< MPI data
228 type(nam_type),intent(in) :: nam !< Namelist
229 character(len=*),intent(in) :: filename !< File name
230 real(
kind_real),intent(out) :: fld(model%nmga,model%nl0,nam%nv) !< Field
233 integer :: iv,il0,img,ilon,ilat,info,iv_q,iv_lwc
234 integer :: ncid,fld_id
235 real(
kind_real) :: fld_mg(model%nmg,model%nl0)
236 real(
kind_real),allocatable :: fld_tmp(:,:,:)
237 character(len=3) :: ilchar
238 character(len=1024),parameter :: subr =
'model_aro_read'
242 allocate(fld_tmp(model%nlon,model%nlat,model%nl0))
245 call mpl%ncerr(subr,nf90_open(trim(nam%datadir)
252 write(ilchar,
'(i3.3)') nam%levs(il0)
253 info = nf90_inq_varid(ncid,
'S'
256 if (info==nf90_noerr) then
258 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(:,:,il0)))
260 ! Check if the variable exists as 2D data
261 call mpl%ncerr(subr,nf90_inq_varid(ncid,nam%variables(iv),fld_id))
264 if (((trim(nam%lev2d)==
'first').and.(il0==1)).or.((trim(nam%lev2d)==
'last').and.(il0==model%nl0))) then
265 fld_tmp = mpl%msv%valr
266 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(:,:,il0)))
274 ilon = model%mg_to_lon(img)
275 ilat = model%mg_to_lat(img)
276 fld_mg(img,il0) = fld_tmp(ilon,ilat,il0)
280 call mpl%glb_to_loc(model%nl0,model%nmga,model%nmg,model%mga_to_mg,fld_mg,fld(:,:,iv))
285 call mpl%ncerr(subr,nf90_close(ncid))
293 iv_lwc = mpl%msv%vali
295 if (trim(nam%variables(iv))==
'HUMI_SPECIFI') iv_q = iv
296 if (trim(nam%variables(iv))==
'CLOUD_WATER') iv_lwc = iv
298 select case (trim(nam%variable_change))
300 if (mpl%msv%isnot(iv_q)) then
301 fld(:,:,iv_q) = log(max(fld(:,:,iv_q),
qmin))
303 call mpl%abort(subr,
'specific humidity not found')
306 if ((mpl%msv%isnot(iv_q)).and.(mpl%msv%isnot(iv_lwc))) then
307 fld(:,:,iv_q) = log(max(fld(:,:,iv_q)+fld(:,:,iv_lwc),
qmin))
308 fld(:,:,iv_lwc) = mpl%msv%valr
310 call mpl%abort(subr,
'specific humidity, or LWC not found')
314 end subroutine model_aro_read