20 subroutine get_grid_version_1_(grid_file, mod_name, domain, lon, lat, min_lon, max_lon)
21 integer,
parameter :: lkind = fms_get_grid_version_kind_
23 character(len=*),
intent(in) :: grid_file
24 character(len=*),
intent(in) :: mod_name
25 type(domain2d),
intent(in) :: domain
26 real(lkind),
intent(out),
dimension(:,:),
allocatable :: lon, lat
27 real(lkind),
intent(out) :: min_lon, max_lon
29 integer :: i, j, siz(4)
31 real(lkind),
dimension(:,:,:),
allocatable :: lon_vert, lat_vert
32 real(lkind),
dimension(:),
allocatable :: glon, glat
33 logical :: is_new_grid
34 integer :: is, ie, js, je
35 integer :: isg, ieg, jsg, jeg
36 integer :: isc, iec, jsc, jec
37 character(len=3) :: xname, yname
38 integer :: start(2), nread(2)
39 type(FmsNetcdfDomainFile_t) :: fileobj
42 if(.not. open_file(fileobj, grid_file,
'read', domain ))
then
43 call mpp_error(fatal,
'data_override_mod(get_grid_version_1): Error in opening file '//trim(grid_file))
46 call mpp_get_global_domain(domain, isg, ieg, jsg, jeg)
47 call mpp_get_compute_domain(domain, isc, iec, jsc, jec)
49 allocate(lon(isc:iec, jsc:jec))
50 allocate(lat(isc:iec, jsc:jec))
55 if(variable_exists(fileobj,
'x_T'))
then
57 else if(variable_exists(fileobj,
'geolon_t'))
then
60 call mpp_error(fatal,
'data_override: both x_T and geolon_t is not in the grid file '//trim(grid_file) )
64 ndims = get_variable_num_dimensions(fileobj,
'x_T')
65 call get_variable_size(fileobj,
'x_T', siz(1:ndims))
66 nlon = siz(1); nlat = siz(2)
67 call check_grid_sizes(trim(mod_name)//
'_domain ', domain, nlon, nlat)
68 allocate(lon_vert(isc:iec,jsc:jec,4), lat_vert(isc:iec,jsc:jec,4) )
70 call read_data(fileobj,
'x_vert_T', lon_vert)
71 call read_data(fileobj,
'y_vert_T', lat_vert)
74 lon(:,:) = (lon_vert(:,:,1) + lon_vert(:,:,2) + lon_vert(:,:,3) + lon_vert(:,:,4))*0.25_lkind
75 lat(:,:) = (lat_vert(:,:,1) + lat_vert(:,:,2) + lat_vert(:,:,3) + lat_vert(:,:,4))*0.25_lkind
78 ndims = get_variable_num_dimensions(fileobj,
'geolon_vert_t')
79 call get_variable_size(fileobj,
'geolon_vert_t', siz(1:ndims))
80 nlon = siz(1) - 1; nlat = siz(2) - 1;
81 call check_grid_sizes(trim(mod_name)//
'_domain ', domain, nlon, nlat)
83 start(1) = isc; nread(1) = iec-isc+2
84 start(2) = jsc; nread(2) = jec-jsc+2
86 allocate(lon_vert(isc:iec+1,jsc:jec+1,1))
87 allocate(lat_vert(isc:iec+1,jsc:jec+1,1))
89 call read_data(fileobj,
'geolon_vert_t', lon_vert(:,:,1), corner=start, edge_lengths=nread)
90 call read_data(fileobj,
'geolat_vert_t', lat_vert(:,:,1), corner=start, edge_lengths=nread)
94 lon(i,j) = (lon_vert(i,j,1) + lon_vert(i+1,j,1) + &
95 lon_vert(i+1,j+1,1) + lon_vert(i,j+1,1))*0.25_lkind
96 lat(i,j) = (lat_vert(i,j,1) + lat_vert(i+1,j,1) + &
97 lat_vert(i+1,j+1,1) + lat_vert(i,j+1,1))*0.25_lkind
104 if(trim(mod_name) ==
'atm')
then
105 xname =
'xta'; yname =
'yta'
107 xname =
'xtl'; yname =
'ytl'
109 ndims = get_variable_num_dimensions(fileobj, xname)
110 call get_variable_size(fileobj, xname, siz(1:ndims))
111 nlon = siz(1);
allocate(glon(nlon))
112 call read_data(fileobj, xname, glon)
114 ndims = get_variable_num_dimensions(fileobj, xname)
115 call get_variable_size(fileobj, yname, siz(1:ndims))
116 nlat = siz(1);
allocate(glat(nlat))
117 call read_data(fileobj, yname, glat)
118 call check_grid_sizes(trim(mod_name)//
'_domain ', domain, nlon, nlat)
120 is = isc - isg + 1; ie = iec - isg + 1
121 js = jsc - jsg + 1; je = jec - jsg + 1
131 call mpp_error(fatal,
"data_override_mod: mod_name should be 'atm', 'ocn', 'ice' or 'lnd' ")
134 call close_file(fileobj)
137 lon = lon * real(deg_to_rad, lkind)
138 lat = lat* real(deg_to_rad, lkind)
139 min_lon = minval(lon)
140 max_lon = maxval(lon)
141 call mpp_min(min_lon)
142 call mpp_max(max_lon)
143 end subroutine get_grid_version_1_
147 subroutine get_grid_version_2_(fileobj, mod_name, domain, lon, lat, min_lon, max_lon, use_center_grid_points)
148 integer,
parameter :: lkind = fms_get_grid_version_kind_
150 type(FmsNetcdfFile_t),
intent(in) :: fileobj
151 character(len=*),
intent(in) :: mod_name
152 type(domain2d),
intent(in) :: domain
153 real(lkind),
intent(out),
dimension(:,:),
allocatable :: lon, lat
154 real(lkind),
intent(out) :: min_lon, max_lon
155 logical,
optional,
intent(in) :: use_center_grid_points
161 integer :: i, j, siz(2)
162 integer :: nlon, nlat
163 integer :: nlon_super, nlat_super
164 integer :: isc, iec, jsc, jec
165 integer :: isc2, iec2, jsc2, jec2
166 character(len=FMS_PATH_LEN) :: solo_mosaic_file, grid_file
167 real(lkind),
allocatable :: tmpx(:,:), tmpy(:,:)
168 logical :: open_solo_mosaic
169 type(FmsNetcdfFile_t) :: mosaicfileobj, tilefileobj
170 integer :: start(2), nread(2)
171 logical :: use_center_grid_points_local
173 use_center_grid_points_local = .false.
174 if (
present(use_center_grid_points)) use_center_grid_points_local = use_center_grid_points
176 if(trim(mod_name) .NE.
'atm' .AND. trim(mod_name) .NE.
'ocn' .AND. &
177 trim(mod_name) .NE.
'ice' .AND. trim(mod_name) .NE.
'lnd' )
call mpp_error(fatal, &
178 "data_override_mod: mod_name should be 'atm', 'ocn', 'ice' or 'lnd' ")
180 call mpp_get_compute_domain(domain, isc, iec, jsc, jec)
182 allocate(lon(isc:iec, jsc:jec))
183 allocate(lat(isc:iec, jsc:jec))
187 if(variable_exists(fileobj, trim(mod_name)//
'_mosaic_file' ))
then
188 call read_data(fileobj, trim(mod_name)//
'_mosaic_file', solo_mosaic_file)
190 solo_mosaic_file =
'INPUT/'//trim(solo_mosaic_file)
191 if(.not. open_file(mosaicfileobj, solo_mosaic_file,
'read'))
then
192 call mpp_error(fatal,
'data_override_mod(get_grid_version_2): Error in opening solo mosaic file '// &
193 & trim(solo_mosaic_file))
195 open_solo_mosaic=.true.
197 mosaicfileobj = fileobj
198 open_solo_mosaic = .false.
201 call get_mosaic_tile_grid(grid_file, mosaicfileobj, domain)
203 if(.not. open_file(tilefileobj, grid_file,
'read'))
then
204 call mpp_error(fatal,
'data_override_mod(get_grid_version_2): Error in opening tile file '//trim(grid_file))
207 call get_variable_size(tilefileobj,
'area', siz)
208 nlon_super = siz(1); nlat_super = siz(2)
209 if( mod(nlon_super,2) .NE. 0)
call mpp_error(fatal, &
210 'data_override_mod: '//trim(mod_name)//
' supergrid longitude size can not be divided by 2')
211 if( mod(nlat_super,2) .NE. 0)
call mpp_error(fatal, &
212 'data_override_mod: '//trim(mod_name)//
' supergrid latitude size can not be divided by 2')
215 call check_grid_sizes(trim(mod_name)//
'_domain ', domain, nlon, nlat)
216 isc2 = 2*isc-1; iec2 = 2*iec+1
217 jsc2 = 2*jsc-1; jec2 = 2*jec+1
219 start(1) = isc2; nread(1) = iec2-isc2+1
220 start(2) = jsc2; nread(2) = jec2-jsc2+1
222 allocate(tmpx(isc2:iec2, jsc2:jec2), tmpy(isc2:iec2, jsc2:jec2) )
224 call read_data( tilefileobj,
'x', tmpx, corner=start,edge_lengths=nread)
225 call read_data( tilefileobj,
'y', tmpy, corner=start,edge_lengths=nread)
228 if(trim(mod_name) ==
'atm' .OR. trim(mod_name) ==
'lnd' .OR. use_center_grid_points_local)
then
231 lon(i,j) = tmpx(i*2,j*2)
232 lat(i,j) = tmpy(i*2,j*2)
238 lon(i,j) = (tmpx(i*2-1,j*2-1)+tmpx(i*2+1,j*2-1)+tmpx(i*2+1,j*2+1)+tmpx(i*2-1,j*2+1))*0.25_lkind
239 lat(i,j) = (tmpy(i*2-1,j*2-1)+tmpy(i*2+1,j*2-1)+tmpy(i*2+1,j*2+1)+tmpy(i*2-1,j*2+1))*0.25_lkind
245 lon = lon * real(deg_to_rad, lkind)
246 lat = lat * real(deg_to_rad, lkind)
248 deallocate(tmpx, tmpy)
249 min_lon = minval(lon)
250 max_lon = maxval(lon)
251 call mpp_min(min_lon)
252 call mpp_max(max_lon)
254 call close_file(tilefileobj)
255 if(open_solo_mosaic)
call close_file(mosaicfileobj)
256 end subroutine get_grid_version_2_