decode_base64_to_int64 Subroutine

public subroutine decode_base64_to_int64(input, values, n)

Decode base64 string to integer array (from 8-byte int64 encoding)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: input
integer, intent(out), allocatable :: values(:)
integer, intent(out) :: n

Source Code

  subroutine decode_base64_to_int64(input, values, n)
    !! Decode base64 string to integer array (from 8-byte int64 encoding)
    use iso_fortran_env, only: int8, int64
    implicit none
    character(*), intent(in) :: input
    integer, allocatable, intent(out) :: values(:)
    integer, intent(out) :: n

    integer(int8), allocatable :: bytes(:)
    integer :: nbytes, i, j
    integer(int64) :: ival64

    call base64_decode_bytes(input, bytes, nbytes)
    n = nbytes / 8
    allocate(values(n))

    do i = 1, n
       ival64 = 0
       do j = 0, 7
          ival64 = ior(ival64, &
               ishft(iand(int(bytes((i-1)*8 + j + 1), int64), &
                    int(255, int64)), j*8))
       end do
       values(i) = int(ival64)
    end do

    deallocate(bytes)

  end subroutine decode_base64_to_int64