1 !----------------------------------------------------------------------
2 ! Subroutine: model_gfs_coord
4 !----------------------------------------------------------------------
5 subroutine model_gfs_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
16 integer :: ncid,nlon_id,nlat_id,nlev_id,lon_id,lat_id,a_id,b_id
17 real(
kind_real),allocatable :: lon(:),lat(:),
a(:),b(:)
18 character(len=1024),parameter :: subr =
'model_gfs_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,
'longitude',nlon_id))
24 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'latitude',nlat_id))
25 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nlon_id,len=model%nlon))
26 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nlat_id,len=model%nlat))
27 model%nmg = model%nlon*model%nlat
28 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'level',nlev_id))
29 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nlev_id,len=model%nlev))
33 allocate(lon(model%nlon))
34 allocate(lat(model%nlat))
35 allocate(
a(model%nlev+1))
36 allocate(b(model%nlev+1))
38 ! Read data and close file
39 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'longitude',lon_id))
40 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'latitude',lat_id))
41 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'ak',a_id))
42 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'bk',b_id))
43 call mpl%ncerr(subr,nf90_get_var(ncid,lon_id,lon))
44 call mpl%ncerr(subr,nf90_get_var(ncid,lat_id,lat))
45 call mpl%ncerr(subr,nf90_get_var(ncid,a_id,
a))
46 call mpl%ncerr(subr,nf90_get_var(ncid,b_id,b))
47 call mpl%ncerr(subr,nf90_close(ncid))
58 model%mg_to_tile(img) = 1
59 model%mg_to_lon(img) = ilon
60 model%mg_to_lat(img) = ilat
61 model%lon(img) = lon(ilon)
62 model%lat(img) = lat(ilat)
71 model%vunit(img,1:nam%nl) = log(0.5*(
a(nam%levs(1:nam%nl))+
a(nam%levs(1:nam%nl)+1)) &
72 & +0.5*(b(nam%levs(1:nam%nl))+b(nam%levs(1:nam%nl)+1))*
ps)
73 if (model%nl0>nam%nl) model%vunit(img,model%nl0) = log(
ps)
75 model%vunit(img,:) = real(nam%levs(1:model%nl0),
kind_real)
85 end subroutine model_gfs_coord
87 !----------------------------------------------------------------------
88 ! Subroutine: model_gfs_read
90 !----------------------------------------------------------------------
91 subroutine model_gfs_read(model,mpl,nam,filename,fld)
96 class(model_type),intent(inout) :: model !< Model
97 type(mpl_type),intent(inout) :: mpl !< MPI data
98 type(nam_type),intent(in) :: nam !< Namelist
99 character(len=*),intent(in) :: filename !< File name
100 real(
kind_real),intent(out) :: fld(model%nmga,model%nl0,nam%nv) !< Field
103 integer :: iv,il0,img,ilon,ilat,ndims
104 integer :: ncid,fld_id
105 real(
kind_real) :: fld_mg(model%nmg,model%nl0)
106 real(
kind_real),allocatable :: fld_tmp(:,:,:)
107 character(len=1024),parameter :: subr =
'model_gfs_read'
111 allocate(fld_tmp(model%nlon,model%nlat,model%nl0))
114 call mpl%ncerr(subr,nf90_open(trim(nam%datadir)
120 call mpl%ncerr(subr,nf90_inq_varid(ncid,nam%variables(iv),fld_id))
127 fld_tmp = mpl%msv%valr
128 if (trim(nam%lev2d)==
'first') then
129 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(:,:,1),(/1,1/),(/model%nlon,model%nlat/)))
130 elseif (trim(nam%lev2d)==
'last') then
131 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(:,:,model%nl0),(/1,1/),(/model%nlon,model%nlat/)))
136 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(:,:,il0),(/1,1,nam%levs(il0)/),(/model%nlon,model%nlat,1/)))
139 call mpl%abort(subr,
'wrong number of dimensions for variable '
145 ilon = model%mg_to_lon(img)
146 ilat = model%mg_to_lat(img)
147 fld_mg(img,il0) = fld_tmp(ilon,ilat,il0)
151 call mpl%glb_to_loc(model%nl0,model%nmga,model%nmg,model%mga_to_mg,fld_mg,fld(:,:,iv))
156 call mpl%ncerr(subr,nf90_close(ncid))
162 end subroutine model_gfs_read