| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(inout), | target | :: | val(:) | ||
| real(kind=dp), | intent(inout), | allocatable | :: | buf(:) |
subroutine move_dp_1d_dataset_buffer(val,buf) ! moves the data from buf to val, eventually truncating/expanding it ! deallocates buf real(dp), allocatable, intent(inout) :: buf(:) real(dp), target, intent(inout) :: val(:) integer :: dimsVal, dimsBuf ! if buf is unallocated, this is not going anywhere if(.not. allocated(buf)) then write(stdout,*) "WARNING: Trying to move data from empty buffer" return endif ! we need to check if the buffer can be copied 1:1 dimsVal = size(val) dimsBuf = size(buf) if(dimsVal .eq. dimsBuf) then val(:) = buf(:) else ! now it depends if val is larger or smaller than buf if(dimsVal < dimsBuf) then ! depending, we either omit the last entries val(1:dimsVal) = buf(1:dimsVal) else ! or copy the last one val(1:dimsBuf) = buf(1:dimsBuf) val(dimsBuf+1:dimsVal) = buf(dimsBuf) endif endif deallocate(buf) end subroutine move_dp_1d_dataset_buffer