@@ -119,6 +119,7 @@ subroutine domain_read_2d(fileobj, variable_name, vdata, unlim_dim_level, &
119119 integer :: xgsize !< Size of global x io domain
120120 integer :: ygbegin !< Starting y index of global io domain
121121 integer :: ygsize !< Size of global y io domain
122+ integer :: dim_order(2) !< Order of the dimensions
122123 type(domain2d), pointer :: io_domain !< pointer to the io_domain
123124
124125 !< The global data is only allocated by the io root PEs
@@ -164,14 +165,6 @@ subroutine domain_read_2d(fileobj, variable_name, vdata, unlim_dim_level, &
164165 return
165166 endif
166167
167- if (xdim_index .ne. 1 .or. ydim_index .ne. 2) then
168- ! This is a KLUDGE
169- ! mpp_scatter assumes that the variable is (x,y), if that is not the case it remaps the data
170- ! to a 4D array and calls domain_read_4d which does not use mpp_scatter yet
171- vdata_dummy(1:size(vdata,1),1:size(vdata,2), 1:1, 1:1) => vdata(:,:)
172- call domain_read_4d(fileobj, variable_name, vdata_dummy, unlim_dim_level)
173- return
174- endif
175168 io_domain => mpp_get_io_domain(fileobj%domain)
176169 c(:) = 1
177170 e(:) = shape(vdata)
@@ -240,29 +233,32 @@ subroutine domain_read_2d(fileobj, variable_name, vdata, unlim_dim_level, &
240233 e(xdim_index) = xc_size
241234 e(ydim_index) = yc_size
242235
236+ dim_order(xdim_index) = 1
237+ dim_order(ydim_index) = 2
238+
243239 select type(vdata)
244240 type is (integer(kind=i4_kind))
245241 call allocate_array(buf_i4_kind_pe, e)
246242 call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, fileobj%pelist, &
247- buf_i4_kind_pe, buf_i4_kind, fileobj%is_root)
243+ buf_i4_kind_pe, buf_i4_kind, dim_order, fileobj%is_root)
248244 call put_array_section(buf_i4_kind_pe, vdata, c, e)
249245 deallocate(buf_i4_kind_pe)
250246 type is (integer(kind=i8_kind))
251247 call allocate_array(buf_i8_kind_pe, e)
252248 call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, fileobj%pelist, &
253- buf_i8_kind_pe, buf_i8_kind, fileobj%is_root)
249+ buf_i8_kind_pe, buf_i8_kind, dim_order, fileobj%is_root)
254250 call put_array_section(buf_i8_kind_pe, vdata, c, e)
255251 deallocate(buf_i8_kind_pe)
256252 type is (real(kind=r4_kind))
257253 call allocate_array(buf_r4_kind_pe, e)
258254 call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, fileobj%pelist, &
259- buf_r4_kind_pe, buf_r4_kind, fileobj%is_root)
255+ buf_r4_kind_pe, buf_r4_kind, dim_order, fileobj%is_root)
260256 call put_array_section(buf_r4_kind_pe, vdata, c, e)
261257 deallocate(buf_r4_kind_pe)
262258 type is (real(kind=r8_kind))
263259 call allocate_array(buf_r8_kind_pe, e)
264260 call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, fileobj%pelist, &
265- buf_r8_kind_pe, buf_r8_kind, fileobj%is_root)
261+ buf_r8_kind_pe, buf_r8_kind, dim_order, fileobj%is_root)
266262 call put_array_section(buf_r8_kind_pe, vdata, c, e)
267263 deallocate(buf_r8_kind_pe)
268264 class default
@@ -304,6 +300,7 @@ subroutine domain_read_3d(fileobj, variable_name, vdata, unlim_dim_level, &
304300
305301 integer :: xdim_index !< The index of the variable that is the x dimension
306302 integer :: ydim_index !< The index of the variable that is the y dimension
303+ integer :: zdim_index !< The index of the variable that is the z dimension
307304 integer :: xpos !< The position of the x axis
308305 integer :: ypos !< The position of the y axis
309306 integer :: i !< For do loops
@@ -320,6 +317,7 @@ subroutine domain_read_3d(fileobj, variable_name, vdata, unlim_dim_level, &
320317 integer :: xgsize !< Size of global x io domain
321318 integer :: ygbegin !< Starting y index of global io domain
322319 integer :: ygsize !< Size of global y io domain
320+ integer :: dim_order(3) !< Order of the dimensions
323321 type(domain2d), pointer :: io_domain !< pointer to the io_domain
324322
325323 !< The global data is only allocated by the io root PEs
@@ -365,14 +363,6 @@ subroutine domain_read_3d(fileobj, variable_name, vdata, unlim_dim_level, &
365363 return
366364 endif
367365
368- if (xdim_index .ne. 1 .or. ydim_index .ne. 2) then
369- ! This is a KLUDGE
370- ! mpp_scatter assumes that the variable is (x,y), if that is not the case it remaps the data
371- ! to a 4D array and calls domain_read_4d which does not use mpp_scatter yet
372- vdata_dummy(1:size(vdata,1),1:size(vdata,2), 1:size(vdata,3), 1:1) => vdata(:,:,:)
373- call domain_read_4d(fileobj, variable_name, vdata_dummy, unlim_dim_level)
374- return
375- endif
376366 io_domain => mpp_get_io_domain(fileobj%domain)
377367 c(:) = 1
378368 if (present(corner)) c = corner
@@ -444,29 +434,36 @@ subroutine domain_read_3d(fileobj, variable_name, vdata, unlim_dim_level, &
444434 e(xdim_index) = xc_size
445435 e(ydim_index) = yc_size
446436
437+ ! Calculate the index of the z dimension
438+ zdim_index = 6 - xdim_index - ydim_index
439+
440+ dim_order(xdim_index) = 1
441+ dim_order(ydim_index) = 2
442+ dim_order(zdim_index) = 3
443+
447444 select type(vdata)
448445 type is (integer(kind=i4_kind))
449446 call allocate_array(buf_i4_kind_pe, e)
450- call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, e(3), fileobj%pelist , &
451- buf_i4_kind_pe, buf_i4_kind, fileobj%is_root)
447+ call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, e(zdim_index) , &
448+ fileobj%pelist, buf_i4_kind_pe, buf_i4_kind, dim_order , fileobj%is_root)
452449 call put_array_section(buf_i4_kind_pe, vdata, c, e)
453450 deallocate(buf_i4_kind_pe)
454451 type is (integer(kind=i8_kind))
455452 call allocate_array(buf_i8_kind_pe, e)
456- call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, e(3), fileobj%pelist , &
457- buf_i8_kind_pe, buf_i8_kind, fileobj%is_root)
453+ call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, e(zdim_index) , &
454+ fileobj%pelist, buf_i8_kind_pe, buf_i8_kind, dim_order , fileobj%is_root)
458455 call put_array_section(buf_i8_kind_pe, vdata, c, e)
459456 deallocate(buf_i8_kind_pe)
460457 type is (real(kind=r4_kind))
461458 call allocate_array(buf_r4_kind_pe, e)
462- call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, e(3), fileobj%pelist , &
463- buf_r4_kind_pe, buf_r4_kind, fileobj%is_root)
459+ call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, e(zdim_index) , &
460+ fileobj%pelist, buf_r4_kind_pe, buf_r4_kind, dim_order , fileobj%is_root)
464461 call put_array_section(buf_r4_kind_pe, vdata, c, e)
465462 deallocate(buf_r4_kind_pe)
466463 type is (real(kind=r8_kind))
467464 call allocate_array(buf_r8_kind_pe, e)
468- call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, e(3), fileobj%pelist , &
469- buf_r8_kind_pe, buf_r8_kind, fileobj%is_root)
465+ call mpp_scatter(isc-xgbegin+1, isc+xc_size-xgbegin, jsc-ygbegin+1, jsc+yc_size-ygbegin, e(zdim_index) , &
466+ fileobj%pelist, buf_r8_kind_pe, buf_r8_kind, dim_order , fileobj%is_root)
470467 call put_array_section(buf_r8_kind_pe, vdata, c, e)
471468 deallocate(buf_r8_kind_pe)
472469 class default
0 commit comments