37#ifdef HAVE_ADIOS2_FORTRAN
44 integer(kind=i8),
dimension(4) :: shape_dims, start_dims, count_dims
45 real(kind=
dp),
private,
allocatable :: data_dp(:,:,:,:)
46 real(kind=
sp),
private,
allocatable :: data_sp(:,:,:,:)
50#ifdef HAVE_ADIOS2_FORTRAN
51 procedure :: define => buffer_4d_define
52 procedure :: inquire => buffer_4d_inquire
53 procedure :: write => buffer_4d_write
54 procedure :: read => buffer_4d_read
61 subroutine buffer_4d_init(this, precision, gdim, glb_nelv, offset_el, nelv, &
64 logical,
intent(in) :: precision
65 integer,
intent(in) :: gdim, glb_nelv, offset_el, nelv, lx, ly, lz
72 if (this%dp_precision)
then
73 if (
allocated(this%data_dp))
then
74 deallocate(this%data_dp)
76 allocate(this%data_dp(nelv, lx, ly, lz))
78 if (
allocated(this%data_sp))
then
79 deallocate(this%data_sp)
81 allocate(this%data_sp(nelv, lx, ly, lz))
84 this%shape_dims = [int(glb_nelv,
i8), int(lx,
i8), int(ly,
i8), int(lz,
i8)]
85 this%start_dims = [int(offset_el,
i8), int(0,
i8), int(0,
i8), int(0,
i8)]
86 this%count_dims = [int(nelv,
i8), int(lx,
i8), int(ly,
i8), int(lz,
i8)]
92 integer,
intent(inout) :: n
93 real(kind=
rp),
intent(inout) :: x(n)
94 integer :: i, j, k, l, nelv, lx, ly, lz, index
96 nelv = this%count_dims(1)
97 lx = this%count_dims(2)
98 ly = this%count_dims(3)
99 lz = this%count_dims(4)
101 if (this%dp_precision)
then
106 index = (l-1) + lx*(k-1) + lx*ly*(j-1) + lx*ly*lz*(i-1) + 1
107 this%data_dp(i,l,k,j) =
real(x(index),
dp)
117 index = (l-1) + lx*(k-1) + lx*ly*(j-1) + lx*ly*lz*(i-1) + 1
118 this%data_sp(i,l,k,j) =
real(x(index),
sp)
127#ifdef HAVE_ADIOS2_FORTRAN
129 subroutine buffer_4d_define(this, variable, io, variable_name, ierr)
131 type(adios2_variable),
intent(inout) :: variable
132 type(adios2_io),
intent(inout) :: io
133 character(len=*),
intent(in) :: variable_name
134 integer,
intent(inout) :: ierr
135 integer :: adios2_type
137 if (this%dp_precision)
then
138 adios2_type = adios2_type_dp
140 adios2_type = adios2_type_real
143 call adios2_inquire_variable(variable, io, trim(variable_name), ierr)
144 if (.not.variable%valid)
then
146 call adios2_define_variable(variable, io, variable_name, adios2_type, &
147 size(this%shape_dims), this%shape_dims, this%start_dims, &
148 this%count_dims, .false., ierr)
150 call adios2_set_selection(variable,
size(this%start_dims), &
151 this%start_dims, this%count_dims, ierr)
154 end subroutine buffer_4d_define
156 subroutine buffer_4d_inquire(this, variable, io, variable_name, ierr)
158 type(adios2_variable),
intent(inout) :: variable
159 type(adios2_io),
intent(inout) :: io
160 character(len=*),
intent(in) :: variable_name
161 integer,
intent(inout) :: ierr
163 call adios2_inquire_variable(variable, io, trim(variable_name), ierr)
164 if (variable%valid)
then
165 call adios2_set_selection(variable,
size(this%start_dims), &
166 this%start_dims, this%count_dims, ierr)
169 end subroutine buffer_4d_inquire
171 subroutine buffer_4d_write(this, engine, variable, ierr)
173 type(adios2_engine),
intent(in) :: engine
174 type(adios2_variable),
intent(in) :: variable
175 integer,
intent(inout) :: ierr
177 if (this%dp_precision)
then
178 call adios2_put(engine, variable, this%data_dp, adios2_mode_sync, ierr)
180 call adios2_put(engine, variable, this%data_sp, adios2_mode_sync, ierr)
183 end subroutine buffer_4d_write
185 subroutine buffer_4d_read(this, engine, variable, ierr)
187 type(adios2_engine),
intent(in) :: engine
188 type(adios2_variable),
intent(in) :: variable
189 integer,
intent(inout) :: ierr
191 if (this%dp_precision)
then
192 call adios2_get(engine, variable, this%data_dp, adios2_mode_sync, ierr)
194 call adios2_get(engine, variable, this%data_sp, adios2_mode_sync, ierr)
197 end subroutine buffer_4d_read
204 integer :: i, j, k, l, nelv, lx, ly, lz, index
206 nelv = this%count_dims(1)
207 lx = this%count_dims(2)
208 ly = this%count_dims(3)
209 lz = this%count_dims(4)
211 if (this%dp_precision)
then
216 index = (l-1) + lx*(k-1) + lx*ly*(j-1) + lx*ly*lz*(i-1) + 1
217 x%x(index) = this%data_dp(i,l,k,j)
227 index = (l-1) + lx*(k-1) + lx*ly*(j-1) + lx*ly*lz*(i-1) + 1
228 x%x(index) = this%data_sp(i,l,k,j)
Generic buffer that is extended with buffers of varying rank.
subroutine buffer_4d_copy(this, x)
subroutine buffer_4d_fill(this, x, n)
subroutine buffer_4d_init(this, precision, gdim, glb_nelv, offset_el, nelv, lx, ly, lz)
Generic buffer that is extended with buffers of varying rank.
subroutine buffer_set_precision(this, precision)
integer, parameter, public i8
integer, parameter, public dp
integer, parameter, public sp
integer, parameter, public rp
Global precision used in computations.