C Library Functions  - bytes_to_anything (3)

NAME

bytes_to_anything(3f) - [M_anything] convert bytes(character)len=1):: array(:)) to standard types (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Return
Example
Author
License

SYNOPSIS

subroutine bytes_to_anything(chars,anything)

   character(len=1),allocatable :: chars(:)
   class(*) :: anything

DESCRIPTION

This function uses polymorphism to allow input arguments of different types. It is used to create other procedures that can take many argument types as input options and convert them to a single type to simplify storing arbitrary data, to simplify generating data hashes, ...

OPTIONS

CHARS The input value is an array of bytes (character(len=1)).

RETURN

ANYTHING
  May be of KIND INTEGER(kind=int8), INTEGER(kind=int16), INTEGER(kind=int32), INTEGER(kind=int64), REAL(kind=real32, REAL(kind=real64), REAL(kind=real128), complex, or CHARACTER(len=*)

EXAMPLE

Sample program

     program demo_bytes_to_anything
     use M_anything,      only : bytes_to_anything
     use M_anything,      only : anything_to_bytes
     implicit none
     character(len=1),allocatable :: chars(:)
     integer :: ints(10)
     integer :: i
        chars=anything_to_bytes([(i*i,i=1,size(ints))])
        write(*,’(/,4(1x,z2.2))’)chars
        call bytes_to_anything(chars,ints)
        write(*,’(*(g0,1x))’)ints
     end program demo_bytes_to_anything

Results: >
> 01 00 00 00
> 04 00 00 00
> 09 00 00 00
> 10 00 00 00
> 19 00 00 00
> 24 00 00 00
> 31 00 00 00
> 40 00 00 00
> 51 00 00 00
> 64 00 00 00
> 1 4 9 16 25 36 49 64 81 100

AUTHOR

John S. Urban

LICENSE

    MIT


Nemo Release 3.1 bytes_to_anything (3) July 22, 2023
Generated by manServer 1.08 from e96eab00-746d-47da-bf74-8fa566791fa3 using man macros.