this routine encodes a single variable of type real32 into base64 format
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=c_float), | intent(in), | target | :: | indata |
data to be encoded |
|
integer, | intent(in) | :: | outfile |
output file unit |
subroutine real32_to_base64_single( indata, outfile ) ! --------------------------------------------------------------------------- !> data to be encoded real(kind=c_float), target, intent(in) :: indata !> output file unit integer, intent(in) :: outfile ! --------------------------------------------------------------------------- integer(kind=c_int) :: baserc integer(kind=c_int) :: insize, outsize, ipindex, min_iplen integer :: ind type(c_ptr) :: base64_out type(c_ptr) :: base64_in type(c_ptr) :: encoder_in character, target :: base64_string(encoderlen), encoder_str(encoderblocklen) ! --------------------------------------------------------------------------- base64_in = c_loc(indata) insize = int(c_sizeof(indata), kind=4) outsize = ceiling(insize/3._rk)*4 base64_out = c_loc(base64_string) encoder_in = c_loc(encoder_str) ipindex = 0 do do ind = 0, 2 baserc = encodeindex( base64_in, encoder_in, insize, ind, ipindex ) ipindex = ipindex + 1 end do min_iplen = min(insize - ipindex + 3, 3) baserc = encodeblock( encoder_in, base64_out, min_iplen, outsize ) write(outfile) base64_string if (ipindex >= insize) exit end do end subroutine real32_to_base64_single