decode_bits Subroutine

private pure subroutine decode_bits(code, bits)

Arguments

TypeIntentOptionalAttributesName
character, intent(in) :: code
integer(kind=I1P), intent(out) :: bits(1:)

Called by

proc~~decode_bits~~CalledByGraph proc~decode_bits decode_bits proc~b64_decode_r4 b64_decode_R4 proc~b64_decode_r4->proc~decode_bits proc~b64_decode_i2 b64_decode_I2 proc~b64_decode_i2->proc~decode_bits proc~b64_decode_i8 b64_decode_I8 proc~b64_decode_i8->proc~decode_bits proc~b64_decode_r8_a b64_decode_R8_a proc~b64_decode_r8_a->proc~decode_bits proc~b64_decode_i4 b64_decode_I4 proc~b64_decode_i4->proc~decode_bits proc~b64_decode_i1 b64_decode_I1 proc~b64_decode_i1->proc~decode_bits proc~b64_decode_string b64_decode_string proc~b64_decode_string->proc~decode_bits proc~b64_decode_r16_a b64_decode_R16_a proc~b64_decode_r16_a->proc~decode_bits proc~b64_decode_r8 b64_decode_R8 proc~b64_decode_r8->proc~decode_bits proc~b64_decode_r4_a b64_decode_R4_a proc~b64_decode_r4_a->proc~decode_bits proc~b64_decode_i8_a b64_decode_I8_a proc~b64_decode_i8_a->proc~decode_bits proc~b64_decode_i4_a b64_decode_I4_a proc~b64_decode_i4_a->proc~decode_bits proc~b64_decode_i2_a b64_decode_I2_a proc~b64_decode_i2_a->proc~decode_bits proc~b64_decode_i1_a b64_decode_I1_a proc~b64_decode_i1_a->proc~decode_bits proc~b64_decode_string_a b64_decode_string_a proc~b64_decode_string_a->proc~decode_bits proc~b64_decode_r16 b64_decode_R16 proc~b64_decode_r16->proc~decode_bits proc~b64_decode_up b64_decode_up proc~b64_decode_up->proc~b64_decode_r4 proc~b64_decode_up->proc~b64_decode_i2 proc~b64_decode_up->proc~b64_decode_i8 proc~b64_decode_up->proc~b64_decode_i4 proc~b64_decode_up->proc~b64_decode_i1 proc~b64_decode_up->proc~b64_decode_string proc~b64_decode_up->proc~b64_decode_r8 proc~b64_decode_up_a b64_decode_up_a proc~b64_decode_up_a->proc~b64_decode_r8_a proc~b64_decode_up_a->proc~b64_decode_r4_a proc~b64_decode_up_a->proc~b64_decode_i8_a proc~b64_decode_up_a->proc~b64_decode_i4_a proc~b64_decode_up_a->proc~b64_decode_i2_a proc~b64_decode_up_a->proc~b64_decode_i1_a proc~b64_decode_up_a->proc~b64_decode_string_a interface~b64_decode b64_decode interface~b64_decode->proc~b64_decode_r4 interface~b64_decode->proc~b64_decode_i2 interface~b64_decode->proc~b64_decode_i8 interface~b64_decode->proc~b64_decode_r8_a interface~b64_decode->proc~b64_decode_i4 interface~b64_decode->proc~b64_decode_i1 interface~b64_decode->proc~b64_decode_string interface~b64_decode->proc~b64_decode_r8 interface~b64_decode->proc~b64_decode_r4_a interface~b64_decode->proc~b64_decode_i8_a interface~b64_decode->proc~b64_decode_i4_a interface~b64_decode->proc~b64_decode_i2_a interface~b64_decode->proc~b64_decode_i1_a interface~b64_decode->proc~b64_decode_string_a program~volatile_doctest~922 volatile_doctest program~volatile_doctest~922->interface~b64_decode program~volatile_doctest~938 volatile_doctest program~volatile_doctest~938->interface~b64_decode program~volatile_doctest~914 volatile_doctest program~volatile_doctest~914->interface~b64_decode program~volatile_doctest~1098 volatile_doctest program~volatile_doctest~1098->interface~b64_decode program~volatile_doctest~1114 volatile_doctest program~volatile_doctest~1114->interface~b64_decode program~volatile_doctest~1102 volatile_doctest program~volatile_doctest~1102->interface~b64_decode program~volatile_doctest~1109 volatile_doctest program~volatile_doctest~1109->interface~b64_decode proc~decode~2 decode proc~decode~2->interface~b64_decode program~volatile_doctest~340 volatile_doctest program~volatile_doctest~340->interface~b64_decode program~volatile_doctest~363 volatile_doctest program~volatile_doctest~363->interface~b64_decode program~volatile_doctest~523 volatile_doctest program~volatile_doctest~523->interface~b64_decode program~volatile_doctest~539 volatile_doctest program~volatile_doctest~539->interface~b64_decode program~volatile_doctest~909 volatile_doctest program~volatile_doctest~909->interface~b64_decode program~volatile_doctest~917 volatile_doctest program~volatile_doctest~917->interface~b64_decode program~volatile_doctest~925 volatile_doctest program~volatile_doctest~925->interface~b64_decode program~volatile_doctest~1093 volatile_doctest program~volatile_doctest~1093->interface~b64_decode program~volatile_doctest~336 volatile_doctest program~volatile_doctest~336->interface~b64_decode program~volatile_doctest~518 volatile_doctest program~volatile_doctest~518->interface~b64_decode program~volatile_doctest~534 volatile_doctest program~volatile_doctest~534->interface~b64_decode program~volatile_doctest~928 volatile_doctest program~volatile_doctest~928->interface~b64_decode program~volatile_doctest~1088 volatile_doctest program~volatile_doctest~1088->interface~b64_decode program~volatile_doctest~1096 volatile_doctest program~volatile_doctest~1096->interface~b64_decode program~volatile_doctest~346 volatile_doctest program~volatile_doctest~346->interface~b64_decode program~volatile_doctest~353 volatile_doctest program~volatile_doctest~353->interface~b64_decode program~volatile_doctest~513 volatile_doctest program~volatile_doctest~513->interface~b64_decode program~volatile_doctest~521 volatile_doctest program~volatile_doctest~521->interface~b64_decode program~volatile_doctest~915 volatile_doctest program~volatile_doctest~915->interface~b64_decode program~volatile_doctest~931 volatile_doctest program~volatile_doctest~931->interface~b64_decode program~volatile_doctest~939 volatile_doctest program~volatile_doctest~939->interface~b64_decode program~volatile_doctest~1091 volatile_doctest program~volatile_doctest~1091->interface~b64_decode program~volatile_doctest~1099 volatile_doctest program~volatile_doctest~1099->interface~b64_decode program~volatile_doctest~1115 volatile_doctest program~volatile_doctest~1115->interface~b64_decode interface~b64_decode_up b64_decode_up interface~b64_decode_up->proc~b64_decode_up_a interface~b64_decode_up->proc~b64_decode_up_a interface~b64_decode_up->interface~b64_decode_up interface~b64_decode_up->interface~b64_decode_up program~volatile_doctest~334 volatile_doctest program~volatile_doctest~334->interface~b64_decode program~volatile_doctest~341 volatile_doctest program~volatile_doctest~341->interface~b64_decode program~volatile_doctest~356 volatile_doctest program~volatile_doctest~356->interface~b64_decode program~volatile_doctest~364 volatile_doctest program~volatile_doctest~364->interface~b64_decode program~volatile_doctest~516 volatile_doctest program~volatile_doctest~516->interface~b64_decode program~volatile_doctest~524 volatile_doctest program~volatile_doctest~524->interface~b64_decode program~volatile_doctest~540 volatile_doctest program~volatile_doctest~540->interface~b64_decode program~volatile_doctest~1086 volatile_doctest program~volatile_doctest~1086->interface~b64_decode program~volatile_doctest~1094 volatile_doctest program~volatile_doctest~1094->interface~b64_decode program~volatile_doctest~511 volatile_doctest program~volatile_doctest~511->interface~b64_decode program~volatile_doctest~344 volatile_doctest program~volatile_doctest~344->interface~b64_decode program~volatile_doctest~519 volatile_doctest program~volatile_doctest~519->interface~b64_decode program~volatile_doctest~527 volatile_doctest program~volatile_doctest~527->interface~b64_decode program~volatile_doctest~921 volatile_doctest program~volatile_doctest~921->interface~b64_decode program~volatile_doctest~937 volatile_doctest program~volatile_doctest~937->interface~b64_decode program~volatile_doctest~1105 volatile_doctest program~volatile_doctest~1105->interface~b64_decode program~volatile_doctest~339 volatile_doctest program~volatile_doctest~339->interface~b64_decode program~volatile_doctest~347 volatile_doctest program~volatile_doctest~347->interface~b64_decode program~volatile_doctest~362 volatile_doctest program~volatile_doctest~362->interface~b64_decode program~volatile_doctest~530 volatile_doctest program~volatile_doctest~530->interface~b64_decode program~volatile_doctest~916 volatile_doctest program~volatile_doctest~916->interface~b64_decode program~volatile_doctest~932 volatile_doctest program~volatile_doctest~932->interface~b64_decode program~volatile_doctest~1092 volatile_doctest program~volatile_doctest~1092->interface~b64_decode program~volatile_doctest~1108 volatile_doctest program~volatile_doctest~1108->interface~b64_decode program~volatile_doctest~1116 volatile_doctest program~volatile_doctest~1116->interface~b64_decode proc~decode decode proc~decode->interface~b64_decode program~volatile_doctest~342 volatile_doctest program~volatile_doctest~342->interface~b64_decode program~volatile_doctest~350 volatile_doctest program~volatile_doctest~350->interface~b64_decode program~volatile_doctest~357 volatile_doctest program~volatile_doctest~357->interface~b64_decode program~volatile_doctest~517 volatile_doctest program~volatile_doctest~517->interface~b64_decode program~volatile_doctest~533 volatile_doctest program~volatile_doctest~533->interface~b64_decode program~volatile_doctest~541 volatile_doctest program~volatile_doctest~541->interface~b64_decode program~volatile_doctest~911 volatile_doctest program~volatile_doctest~911->interface~b64_decode program~volatile_doctest~919 volatile_doctest program~volatile_doctest~919->interface~b64_decode

Contents

Source Code


Source Code

   pure subroutine decode_bits(code, bits)
   !< Decode a base64 string into a sequence of bits stream.
   !<
   !< The base64 string must be parsed with a strike of 4 characters and converted into a 3 bytes stream. Considering the base64 code
   !< `QUJD` the decoding process must do
   !<```
   !< +-b64 char--+-b64 char--+-b64 char--+-b64 char--+
   !< |      Q    |      U    |      J    |      D    |
   !< +-b64 index-+-b64 index-+-b64 index-+-b64 index-+
   !< !      16   |      20   |      9    |      3    |
   !< +-6 bits----+-6 bits----+-6 bits----+-6 bits----+
   !< |0 1 0 0 0 0|0 1 0 1 0 0|0 0 1 0 0 1|0 0 0 0 1 1|
   !< +-----------+---+-------+-------+---+-----------+
   !< |0 1 0 0 0 0 0 1|0 1 0 0 0 0 1 0|0 1 0 0 0 0 1 1|
   !< +-----8 bits----+-----8 bits----+-----8 bits----+
   !<```
   !< @note The bits pattern is returned as a 1-byte element array, the dimension of witch must be computed outside this procedure.
   !<
   !< @warning This procedure is the backend of decoding, thus it must be never called outside the module.
   character(*), intent(in)  :: code      !< Characters code.
   integer(I1P), intent(out) :: bits(1:)  !< Bits decoded.
   integer(I1P)              :: sixb(1:4) !< 6 bits slices (stored into 8 bits integer) of 24 bits input.
   integer(I8P)              :: c         !< Counter.
   integer(I8P)              :: e         !< Counter.
   integer(I8P)              :: Nb        !< Length of bits array.

   Nb=size(bits,dim=1,kind=I8P)
   e = 1_I8P
   do c=1_I8P,len(code),4_I8P ! loop over code characters: 3 bytes (24 bits) scanning
      sixb = 0_I1P
      sixb(1) = index(base64,code(c  :c  )) - 1
      sixb(2) = index(base64,code(c+1:c+1)) - 1
      sixb(3) = index(base64,code(c+2:c+2)) - 1
      sixb(4) = index(base64,code(c+3:c+3)) - 1
         call mvbits(sixb(1),0,6,bits(e  ),2) ; call mvbits(sixb(2),4,2,bits(e  ),0)
      if (e+1<=Nb) then
         call mvbits(sixb(2),0,4,bits(e+1),4) ; call mvbits(sixb(3),2,4,bits(e+1),0)
      endif
      if (e+2<=Nb) then
         call mvbits(sixb(3),0,2,bits(e+2),6) ; call mvbits(sixb(4),0,6,bits(e+2),0)
      endif
      e = e + 3_I8P
   enddo
   endsubroutine decode_bits