21 subroutine get_grid_version_1_(grid_file, mod_name, domain, lon, lat, min_lon, max_lon)
22 integer,
parameter :: lkind = fms_get_grid_version_kind_
24 character(len=*),
intent(in) :: grid_file
25 character(len=*),
intent(in) :: mod_name
26 type(domain2d),
intent(in) :: domain
27 real(lkind),
intent(out),
dimension(:,:),
allocatable :: lon, lat
28 real(lkind),
intent(out) :: min_lon, max_lon
30 integer :: i, j, siz(4)
32 real(lkind),
dimension(:,:,:),
allocatable :: lon_vert, lat_vert
33 real(lkind),
dimension(:),
allocatable :: glon, glat
34 logical :: is_new_grid
35 integer :: is, ie, js, je
36 integer :: isg, ieg, jsg, jeg
37 integer :: isc, iec, jsc, jec
38 character(len=3) :: xname, yname
39 integer :: start(2), nread(2)
40 type(FmsNetcdfDomainFile_t) :: fileobj
43 if(.not. open_file(fileobj, grid_file,
'read', domain ))
then
44 call mpp_error(fatal,
'data_override_mod(get_grid_version_1): Error in opening file '//trim(grid_file))
47 call mpp_get_global_domain(domain, isg, ieg, jsg, jeg)
48 call mpp_get_compute_domain(domain, isc, iec, jsc, jec)
50 allocate(lon(isc:iec, jsc:jec))
51 allocate(lat(isc:iec, jsc:jec))
56 if(variable_exists(fileobj,
'x_T'))
then
58 else if(variable_exists(fileobj,
'geolon_t'))
then
61 call mpp_error(fatal,
'data_override: both x_T and geolon_t is not in the grid file '//trim(grid_file) )
65 ndims = get_variable_num_dimensions(fileobj,
'x_T')
66 call get_variable_size(fileobj,
'x_T', siz(1:ndims))
67 nlon = siz(1); nlat = siz(2)
68 call check_grid_sizes(trim(mod_name)//
'_domain ', domain, nlon, nlat)
69 allocate(lon_vert(isc:iec,jsc:jec,4), lat_vert(isc:iec,jsc:jec,4) )
71 call read_data(fileobj,
'x_vert_T', lon_vert)
72 call read_data(fileobj,
'y_vert_T', lat_vert)
75 lon(:,:) = (lon_vert(:,:,1) + lon_vert(:,:,2) + lon_vert(:,:,3) + lon_vert(:,:,4))*0.25_lkind
76 lat(:,:) = (lat_vert(:,:,1) + lat_vert(:,:,2) + lat_vert(:,:,3) + lat_vert(:,:,4))*0.25_lkind
79 ndims = get_variable_num_dimensions(fileobj,
'geolon_vert_t')
80 call get_variable_size(fileobj,
'geolon_vert_t', siz(1:ndims))
81 nlon = siz(1) - 1; nlat = siz(2) - 1;
82 call check_grid_sizes(trim(mod_name)//
'_domain ', domain, nlon, nlat)
84 start(1) = isc; nread(1) = iec-isc+2
85 start(2) = jsc; nread(2) = jec-jsc+2
87 allocate(lon_vert(isc:iec+1,jsc:jec+1,1))
88 allocate(lat_vert(isc:iec+1,jsc:jec+1,1))
90 call read_data(fileobj,
'geolon_vert_t', lon_vert(:,:,1), corner=start, edge_lengths=nread)
91 call read_data(fileobj,
'geolat_vert_t', lat_vert(:,:,1), corner=start, edge_lengths=nread)
95 lon(i,j) = (lon_vert(i,j,1) + lon_vert(i+1,j,1) + &
96 lon_vert(i+1,j+1,1) + lon_vert(i,j+1,1))*0.25_lkind
97 lat(i,j) = (lat_vert(i,j,1) + lat_vert(i+1,j,1) + &
98 lat_vert(i+1,j+1,1) + lat_vert(i,j+1,1))*0.25_lkind
105 if(trim(mod_name) ==
'atm')
then
106 xname =
'xta'; yname =
'yta'
108 xname =
'xtl'; yname =
'ytl'
110 ndims = get_variable_num_dimensions(fileobj, xname)
111 call get_variable_size(fileobj, xname, siz(1:ndims))
112 nlon = siz(1);
allocate(glon(nlon))
113 call read_data(fileobj, xname, glon)
115 ndims = get_variable_num_dimensions(fileobj, xname)
116 call get_variable_size(fileobj, yname, siz(1:ndims))
117 nlat = siz(1);
allocate(glat(nlat))
118 call read_data(fileobj, yname, glat)
119 call check_grid_sizes(trim(mod_name)//
'_domain ', domain, nlon, nlat)
121 is = isc - isg + 1; ie = iec - isg + 1
122 js = jsc - jsg + 1; je = jec - jsg + 1
132 call mpp_error(fatal,
"data_override_mod: mod_name should be 'atm', 'ocn', 'ice' or 'lnd' ")
135 call close_file(fileobj)
138 lon = lon * real(deg_to_rad, lkind)
139 lat = lat* real(deg_to_rad, lkind)
140 min_lon = minval(lon)
141 max_lon = maxval(lon)
142 call mpp_min(min_lon)
143 call mpp_max(max_lon)
144 end subroutine get_grid_version_1_
148 subroutine get_grid_version_2_(fileobj, mod_name, domain, lon, lat, min_lon, max_lon, use_center_grid_points)
149 integer,
parameter :: lkind = fms_get_grid_version_kind_
151 type(FmsNetcdfFile_t),
intent(in) :: fileobj
152 character(len=*),
intent(in) :: mod_name
153 type(domain2d),
intent(in) :: domain
154 real(lkind),
intent(out),
dimension(:,:),
allocatable :: lon, lat
155 real(lkind),
intent(out) :: min_lon, max_lon
156 logical,
optional,
intent(in) :: use_center_grid_points
162 integer :: i, j, siz(2)
163 integer :: nlon, nlat
164 integer :: nlon_super, nlat_super
165 integer :: isc, iec, jsc, jec
166 integer :: isc2, iec2, jsc2, jec2
167 character(len=FMS_PATH_LEN) :: solo_mosaic_file, grid_file
168 real(lkind),
allocatable :: tmpx(:,:), tmpy(:,:)
169 logical :: open_solo_mosaic
170 type(FmsNetcdfFile_t) :: mosaicfileobj, tilefileobj
171 integer :: start(2), nread(2)
172 logical :: use_center_grid_points_local
174 use_center_grid_points_local = .false.
175 if (
present(use_center_grid_points)) use_center_grid_points_local = use_center_grid_points
177 if(trim(mod_name) .NE.
'atm' .AND. trim(mod_name) .NE.
'ocn' .AND. &
178 trim(mod_name) .NE.
'ice' .AND. trim(mod_name) .NE.
'lnd' )
call mpp_error(fatal, &
179 "data_override_mod: mod_name should be 'atm', 'ocn', 'ice' or 'lnd' ")
181 call mpp_get_compute_domain(domain, isc, iec, jsc, jec)
183 allocate(lon(isc:iec, jsc:jec))
184 allocate(lat(isc:iec, jsc:jec))
188 if(variable_exists(fileobj, trim(mod_name)//
'_mosaic_file' ))
then
189 call read_data(fileobj, trim(mod_name)//
'_mosaic_file', solo_mosaic_file)
191 solo_mosaic_file =
'INPUT/'//trim(solo_mosaic_file)
192 if(.not. open_file(mosaicfileobj, solo_mosaic_file,
'read'))
then
193 call mpp_error(fatal,
'data_override_mod(get_grid_version_2): Error in opening solo mosaic file '// &
194 & trim(solo_mosaic_file))
196 open_solo_mosaic=.true.
198 mosaicfileobj = fileobj
199 open_solo_mosaic = .false.
202 call get_mosaic_tile_grid(grid_file, mosaicfileobj, domain)
204 if(.not. open_file(tilefileobj, grid_file,
'read'))
then
205 call mpp_error(fatal,
'data_override_mod(get_grid_version_2): Error in opening tile file '//trim(grid_file))
208 call get_variable_size(tilefileobj,
'area', siz)
209 nlon_super = siz(1); nlat_super = siz(2)
210 if( mod(nlon_super,2) .NE. 0)
call mpp_error(fatal, &
211 'data_override_mod: '//trim(mod_name)//
' supergrid longitude size can not be divided by 2')
212 if( mod(nlat_super,2) .NE. 0)
call mpp_error(fatal, &
213 'data_override_mod: '//trim(mod_name)//
' supergrid latitude size can not be divided by 2')
216 call check_grid_sizes(trim(mod_name)//
'_domain ', domain, nlon, nlat)
217 isc2 = 2*isc-1; iec2 = 2*iec+1
218 jsc2 = 2*jsc-1; jec2 = 2*jec+1
220 start(1) = isc2; nread(1) = iec2-isc2+1
221 start(2) = jsc2; nread(2) = jec2-jsc2+1
223 allocate(tmpx(isc2:iec2, jsc2:jec2), tmpy(isc2:iec2, jsc2:jec2) )
225 call read_data( tilefileobj,
'x', tmpx, corner=start,edge_lengths=nread)
226 call read_data( tilefileobj,
'y', tmpy, corner=start,edge_lengths=nread)
229 if(trim(mod_name) ==
'atm' .OR. trim(mod_name) ==
'lnd' .OR. use_center_grid_points_local)
then
232 lon(i,j) = tmpx(i*2,j*2)
233 lat(i,j) = tmpy(i*2,j*2)
239 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
240 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
246 lon = lon * real(deg_to_rad, lkind)
247 lat = lat * real(deg_to_rad, lkind)
249 deallocate(tmpx, tmpy)
250 min_lon = minval(lon)
251 max_lon = maxval(lon)
252 call mpp_min(min_lon)
253 call mpp_max(max_lon)
255 call close_file(tilefileobj)
256 if(open_solo_mosaic)
call close_file(mosaicfileobj)
257 end subroutine get_grid_version_2_