Skip to content

Commit

Permalink
Merge pull request #199 from lanl/fortran_tools
Browse files Browse the repository at this point in the history
Added bml_get_element_type() and bml_get_element_precision()
  • Loading branch information
nicolasbock committed Mar 30, 2018
2 parents 3089314 + 4261e1a commit 34e4057
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions src/Fortran-interface/bml_introspection_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module bml_introspection_m
public :: bml_get_N
public :: bml_get_M
public :: bml_get_type
public :: bml_get_element_precision
public :: bml_get_precision
public :: bml_get_element_type
public :: bml_get_row_bandwidth
public :: bml_get_bandwidth
public :: bml_get_distribution_mode
Expand Down Expand Up @@ -97,10 +99,15 @@ function bml_get_type(a)

end function bml_get_type

!> Get the precision of a matrix.
!> Get the precision/type index of the elements of a matrix.
!!
!! @param a The matrix.
!! @returns The bml format precision of the matrix.
!! @returns The bml type and precision index for the matrix elements.
!! 0 = not initialized
!! 1 = single real
!! 2 = double real
!! 3 = single complex
!! 4 = double complex
function bml_get_precision(a)

type(bml_matrix_t), intent(in) :: a
Expand All @@ -110,6 +117,61 @@ function bml_get_precision(a)

end function bml_get_precision

!> Get the precision of the elements of a matrix.
!!
!! @param a The matrix.
!! @returns The bml format precision the matrix elements.
function bml_get_element_precision(a)

type(bml_matrix_t), intent(in) :: a
integer :: bml_precision_id
integer :: bml_get_element_precision

bml_precision_id = bml_get_precision_C(a%ptr)

select case(bml_precision_id)
case(0)
stop 'Type/precision elements not initialized'
case(1)
bml_get_element_precision = kind(1.0)
case(2)
bml_get_element_precision = kind(1.0d0)
case default
stop 'Unknown elements type/precision'
end select

end function bml_get_element_precision


!> Get the elements type of a matrix.
!!
!! @param a The matrix.
!! @returns The bml format type of all the elements of the matrix.
function bml_get_element_type(a)

type(bml_matrix_t), intent(in) :: a
integer :: bml_precision_id
character(20) :: bml_get_element_type

bml_precision_id = bml_get_precision_C(a%ptr)

select case(bml_precision_id)
case(0)
stop 'Type/precision elements not initialized'
case(1)
bml_get_element_type = "real"
case(2)
bml_get_element_type = "real"
case(3)
bml_get_element_type = "complex"
case(4)
bml_get_element_type = "complex"
case default
stop 'Unknown elements type/precision'
end select

end function bml_get_element_type

!> Get the distribution mode of a matrix.
!!
!! @param a The matrix.
Expand Down

0 comments on commit 34e4057

Please sign in to comment.