test_binary_io Subroutine

private subroutine test_binary_io(matrix_a, io_unit)

dumps and retrieves a dbcsr matrix, and checks a checksum

Arguments

Type IntentOptional Attributes Name
type(dbcsr_type) :: matrix_a

matrix to be written

integer :: io_unit

unit for status updates


Source Code

   SUBROUTINE test_binary_io(matrix_a, io_unit)
      !! dumps and retrieves a dbcsr matrix, and checks a checksum

      TYPE(dbcsr_type)                                   :: matrix_a
         !! matrix to be written
      INTEGER                                            :: io_unit
         !! unit for status updates

      CHARACTER(LEN=100)                                 :: file_name
      REAL(kind=real_8)                                  :: norm, post, pre
      TYPE(dbcsr_type)                                   :: matrix_a_read

      file_name = "test_dbcsr_binary_io.dat"

      pre = dbcsr_checksum(matrix_a, pos=.TRUE.)

      CALL dbcsr_binary_write(matrix_a, file_name)

      ! needs a new matrix, reading into matrix_a does not work
      CALL dbcsr_binary_read(file_name, distribution=dbcsr_distribution(matrix_a), &
                             matrix_new=matrix_a_read)

      post = dbcsr_checksum(matrix_a_read, pos=.TRUE.)
      CALL dbcsr_add(matrix_a_read, matrix_a, -1.0_dp, 1.0_dp)
      norm = dbcsr_frobenius_norm(matrix_a_read)
      IF (io_unit > 0) THEN
         WRITE (io_unit, *) "checksums", pre, post
         WRITE (io_unit, *) "difference norm", norm
      END IF

      IF (norm /= 0.0_dp) &
         DBCSR_ABORT("bug in binary io")

      CALL dbcsr_release(matrix_a_read)

   END SUBROUTINE test_binary_io