b64_encode_I4 Subroutine

private pure subroutine b64_encode_I4(n, code)

Arguments

TypeIntentOptionalAttributesName
integer(kind=I4P), intent(in) :: n
character(len=:), intent(out), allocatable:: code

Calls

proc~~b64_encode_i4~3~~CallsGraph proc~b64_encode_i4~3 b64_encode_I4 proc~encode_bits~3 encode_bits proc~b64_encode_i4~3->proc~encode_bits~3

Called by

proc~~b64_encode_i4~3~~CalledByGraph proc~b64_encode_i4~3 b64_encode_I4 proc~b64_encode_up~3 b64_encode_up proc~b64_encode_up~3->proc~b64_encode_i4~3 interface~b64_encode~3 b64_encode interface~b64_encode~3->proc~b64_encode_i4~3

Contents

Source Code


Source Code

   pure subroutine b64_encode_I4(n, code)
   !< Encode scalar number to base64 (I4P).
   !<
   !<```fortran
   !< use befor64
   !< use penf
   !< character(len=:), allocatable :: code64
   !< call b64_encode(n=2023_I4P, code=code64)
   !< print "(A)", code64
   !<```
   !=> 5wcAAA== <<<
   integer(I4P),                  intent(in)  :: n       !< Number to be encoded.
   character(len=:), allocatable, intent(out) :: code    !< Encoded scalar.
   integer(I1P),     allocatable              :: nI1P(:) !< One byte integer array containing n.
   integer(I4P)                               :: padd    !< Number of padding characters ('=').

   allocate(nI1P(1:((BYI4P+2)/3)*3)) ; nI1P = 0_I1P
   code = repeat(' ',((BYI4P+2)/3)*4)
   nI1P = transfer(n,nI1P)
   padd = mod((BYI4P),3_I4P) ; if (padd>0_I4P) padd = 3_I4P - padd
   call encode_bits(bits=nI1P,padd=padd,code=code)
   endsubroutine b64_encode_I4