1 !----------------------------------------------------------------------
2 ! Subroutine: model_qg_coord
4 !----------------------------------------------------------------------
5 subroutine model_qg_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
16 integer :: ncid,nx_id,ny_id,nz_id,lon_id,lat_id,z_id,area_id,lmask_id
17 real(
kind_real),allocatable :: lon(:,:),lat(:,:),z(:),area(:,:),lmask(:,:,:)
18 character(len=1024),parameter :: subr =
'model_qg_coord'
20 ! Open file and get dimensions
22 call mpl%ncerr(subr,nf90_open(trim(nam%datadir)
23 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'nx',nx_id))
24 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'ny',ny_id))
25 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nx_id,len=model%nlon))
26 model%nlon = model%nlon+1
27 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,ny_id,len=model%nlat))
28 model%nmg = model%nlon*model%nlat
29 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'nz',nz_id))
30 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nz_id,len=model%nlev))
34 allocate(lon(model%nlon,model%nlat))
35 allocate(lat(model%nlon,model%nlat))
36 allocate(z(model%nlev))
37 allocate(area(model%nlon,model%nlat))
38 allocate(lmask(model%nlon,model%nlat,model%nlev))
40 ! Read data and close file
41 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'lon',lon_id))
42 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'lat',lat_id))
43 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'z',z_id))
44 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'area',area_id))
45 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'lmask',lmask_id))
46 call mpl%ncerr(subr,nf90_get_var(ncid,lon_id,lon(1:model%nlon-1,:)))
47 call mpl%ncerr(subr,nf90_get_var(ncid,lat_id,lat(1:model%nlon-1,:)))
48 call mpl%ncerr(subr,nf90_get_var(ncid,z_id,z))
49 call mpl%ncerr(subr,nf90_get_var(ncid,area_id,area(1:model%nlon-1,:)))
50 call mpl%ncerr(subr,nf90_get_var(ncid,lmask_id,lmask(1:model%nlon-1,:,:)))
51 call mpl%ncerr(subr,nf90_close(ncid))
53 ! Add redundant longitude for tests
54 lon(model%nlon,:) = lon(1,:)
55 lat(model%nlon,:) = lat(1,:)
56 area(model%nlon,:) = area(1,:)
57 lmask(model%nlon,:,:) = lmask(1,:,:)
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 model%area(img) = area(ilon,ilat)/
req**2
75 model%mask(img,il0) = (lmask(ilon,ilat,nam%levs(il0))>0.5)
82 model%vunit(1:model%nmg,il0) = z(nam%levs(il0))
92 end subroutine model_qg_coord
94 !----------------------------------------------------------------------
95 ! Subroutine: model_qg_read
97 !----------------------------------------------------------------------
98 subroutine model_qg_read(model,mpl,nam,filename,fld)
103 class(model_type),intent(inout) :: model !< Model
104 type(mpl_type),intent(inout) :: mpl !< MPI data
105 type(nam_type),intent(in) :: nam !< Namelist
106 character(len=*),intent(in) :: filename !< File name
107 real(
kind_real),intent(out) :: fld(model%nmga,model%nl0,nam%nv) !< Field
110 integer :: iv,il0,img,ilon,ilat,ndims
111 integer :: ncid,fld_id
112 real(
kind_real) :: fld_mg(model%nmg,model%nl0)
113 real(
kind_real),allocatable :: fld_tmp(:,:,:)
114 character(len=1024),parameter :: subr =
'model_qg_read'
118 allocate(fld_tmp(model%nlon,model%nlat,model%nl0))
121 call mpl%ncerr(subr,nf90_open(trim(nam%datadir)
127 call mpl%ncerr(subr,nf90_inq_varid(ncid,nam%variables(iv),fld_id))
130 call mpl%ncerr(subr,nf90_inquire_variable(ncid,fld_id,ndims=ndims))
136 fld_tmp = mpl%msv%valr
137 if (trim(nam%lev2d)==
'first') then
138 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(1:model%nlon-1,:,1),(/1,1/), &
139 & (/model%nlon-1,model%nlat/)))
140 fld_tmp(model%nlon,:,1) = fld_tmp(1,:,1)
141 elseif (trim(nam%lev2d)==
'last') then
142 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(1:model%nlon-1,:,model%nl0),(/1,1/), &
143 & (/model%nlon-1,model%nlat/)))
144 fld_tmp(model%nlon,:,model%nl0) = fld_tmp(1,:,model%nl0)
149 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(1:model%nlon-1,:,il0),(/1,1,nam%levs(il0)/), &
150 & (/model%nlon-1,model%nlat,1/)))
151 fld_tmp(model%nlon,:,il0) = fld_tmp(1,:,il0)
154 call mpl%abort(subr,
'wrong number of dimensions for variable '
160 ilon = model%mg_to_lon(img)
161 ilat = model%mg_to_lat(img)
162 fld_mg(img,il0) = fld_tmp(ilon,ilat,il0)
166 call mpl%glb_to_loc(model%nl0,model%nmga,model%nmg,model%mga_to_mg,fld_mg,fld(:,:,iv))
171 call mpl%ncerr(subr,nf90_close(ncid))
177 end subroutine model_qg_read