1 !----------------------------------------------------------------------
2 ! Subroutine: model_fv3_coord
4 !----------------------------------------------------------------------
5 subroutine model_fv3_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,itile,il0
16 integer :: ncid,nlon_id,nlat_id,ntile_id,nlev_id,lon_id,lat_id,a_id,b_id
18 real(
kind_real),allocatable :: lon(:,:,:),lat(:,:,:),
a(:),b(:)
19 character(len=1024),parameter :: subr =
'model_fv3_coord'
21 ! Open file and get dimensions
22 call mpl%ncerr(subr,nf90_open(trim(nam%datadir)
23 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'fxdim',nlon_id))
24 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'fydim',nlat_id))
25 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'ntile',ntile_id))
26 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nlon_id,len=model%nlon))
27 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nlat_id,len=model%nlat))
28 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,ntile_id,len=model%ntile))
29 model%nmg = model%nlon*model%nlat*model%ntile
30 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'xaxis_1',nlev_id))
31 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nlev_id,len=model%nlev))
32 model%nlev = model%nlev-1
36 allocate(lon(model%nlon,model%nlat,model%ntile))
37 allocate(lat(model%nlon,model%nlat,model%ntile))
38 allocate(
a(model%nlev+1))
39 allocate(b(model%nlev+1))
41 ! Read data and close file
42 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'flons',lon_id))
43 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'flats',lat_id))
44 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'ak',a_id))
45 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'bk',b_id))
46 call mpl%ncerr(subr,nf90_get_var(ncid,lon_id,lon))
47 call mpl%ncerr(subr,nf90_get_var(ncid,lat_id,lat))
48 call mpl%ncerr(subr,nf90_get_var(ncid,a_id,
a,(/1,1/),(/model%nlev+1,1/)))
49 call mpl%ncerr(subr,nf90_get_var(ncid,b_id,b,(/1,1/),(/model%nlev+1,1/)))
50 call mpl%ncerr(subr,nf90_close(ncid))
54 do itile=1,model%ntile
58 model%mg_to_tile(img) = itile
59 model%mg_to_lon(img) = ilon
60 model%mg_to_lat(img) = ilat
61 model%lon(img) = lon(ilon,ilat,itile)
62 model%lat(img) = lat(ilon,ilat,itile)
63 call
lonlatmod(model%lon(img),model%lat(img))
73 sigmaup =
a(nam%levs(il0)+1)/
ps+b(nam%levs(il0)+1)
74 sigmadn =
a(nam%levs(il0))/
ps+b(nam%levs(il0))
75 sigma = 0.5*(sigmaup+sigmadn)
80 model%vunit(:,il0) = log(sigma*
ps)
81 if (model%nl0>nam%nl) model%vunit(:,model%nl0) = log(
ps)
83 model%vunit(:,il0) = sigma
93 end subroutine model_fv3_coord
95 !----------------------------------------------------------------------
96 ! Subroutine: model_fv3_read
98 !----------------------------------------------------------------------
99 subroutine model_fv3_read(model,mpl,nam,filename,fld)
104 class(model_type),intent(inout) :: model !< Model
105 type(mpl_type),intent(inout) :: mpl !< MPI data
106 type(nam_type),intent(in) :: nam !< Namelist
107 character(len=*),intent(in) :: filename !< File name
108 real(
kind_real),intent(out) :: fld(model%nmga,model%nl0,nam%nv) !< Field
111 integer :: iv,il0,imgt,img,ilon,ilat
112 integer :: ncid,fld_id,dimids(4),zlen
113 real(
kind_real) :: fld_mgt(model%nmgt,model%nl0)
114 real(
kind_real),allocatable :: fld_tmp(:,:,:)
115 character(len=1) :: ctile
116 character(len=1024),parameter :: subr =
'model_fv3_read'
118 if (model%ioproc(model%mytile)==mpl%myproc) then
120 allocate(fld_tmp(model%nlon,model%nlat,model%nl0))
123 write(ctile,
'(i1.1)') model%mytile
124 call mpl%ncerr(subr,nf90_open(trim(nam%datadir)
128 if (model%ioproc(model%mytile)==mpl%myproc) then
130 call mpl%ncerr(subr,nf90_inq_varid(ncid,nam%variables(iv),fld_id))
133 call mpl%ncerr(subr,nf90_inquire_variable(ncid,fld_id,dimids=dimids))
134 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,dimids(3),len=zlen))
139 fld_tmp = mpl%msv%valr
140 if (trim(nam%lev2d)==
'first') then
141 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(:,:,1),(/1,1,1,1/),(/model%nlon,model%nlat,1,1/)))
142 elseif (trim(nam%lev2d)==
'last') then
143 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(:,:,model%nl0),(/1,1,1,1/),(/model%nlon,model%nlat,1,1/)))
148 call mpl%ncerr(subr,nf90_get_var(ncid,fld_id,fld_tmp(:,:,il0),(/1,1,nam%levs(il0),1/),(/model%nlon,model%nlat,1,1/)))
154 img = model%mgt_to_mg(imgt)
155 ilon = model%mg_to_lon(img)
156 ilat = model%mg_to_lat(img)
157 fld_mgt(imgt,:) = fld_tmp(ilon,ilat,:)
160 call mpl%glb_to_loc(model%nl0,model%nmga,model%nmgt,model%mga_to_mgt,fld_mgt,fld(:,:,iv), &
161 & model%ioproc(model%mytile),model%tilepool(:,model%mytile))
164 if (model%ioproc(model%mytile)==mpl%myproc) then
166 call mpl%ncerr(subr,nf90_close(ncid))
172 end subroutine model_fv3_read