[UP]


Manual Reference Pages  - crc32_hash (3)

NAME

crc32_hash(3f) - [M_hashkeys] CRC (Cyclic Redundancy Check) (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
References
Author
Example

SYNOPSIS

function crc32_hash(a,continue) result (crc)

   class(*),intent(in)          :: anything(:)
   logical,intent(in),optional  :: continue
   integer(int64)               :: crc_out

DESCRIPTION

This ia 32-bit version of the Cyclic Redundancy Check(CRC). This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF_int32, and complements the final CRC.

The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG.

OPTIONS

anything
  input value to generate a CRC check for. May be a scalar or string value of type CHARACTER, int8, int16, int32, int64, real32, real64, real128
continue
  optional parameter. If not present or .F. starts new CRC sum. If .T. continues a CRC starting with last CRC calculated.

RETURNS

crc The calculated CRC sum. It is calculated as a 32-bit value but returned as a 64-bit value, as Fortran does not currently support unsigned integers.

REFERENCES

Algorithms are described in "Computation of CRC" in Wikipedia. Also see

      https://en.wikipedia.org/wiki/Cyclic_redundancy_check

AUTHOR

This was derived from an unattributed example on http://rosettacode.org, but has been modified.

EXAMPLE

Sample program:

   program demo_crc32_hash
   use,intrinsic :: ISO_FORTRAN_ENV, only : int64
   use M_hashkeys, only : crc32_hash
   implicit none
   integer :: i
   integer(int64) :: crc
   character(*), parameter :: s = "The quick brown fox jumps over the lazy dog"
      ! string
      crc=crc32_hash(s)
      print "(Z8)", crc
      print "(i0)", crc
      ! character array
      print "(i0)", crc32_hash([ &
              & ’T’,’h’,’e’,’ ’,&
              & ’q’,’u’,’i’,’c’,’k’,’ ’,&
              & ’b’,’r’,’o’,’w’,’n’,’ ’,&
              & ’f’,’o’,’x’,’ ’])
      print "(i0)", crc32_hash([ &
              & ’j’,’u’,’m’,’p’,’s’,’ ’,&
              & ’o’,’v’,’e’,’r’,’ ’,&
              & ’t’,’h’,’e’,’ ’,&
              & ’l’,’a’,’z’,’y’,’ ’,&
              & ’d’,’o’,’g’],continue=.true.)
      ! numeric array
      print "(i0)", crc32_hash([(i,i=1,100)])
   end program demo_crc32_hash

Expected output:

   414FA339
   1095738169
   2293265890
   1095738169
   1783575711


crc32_hash (3) October 17, 2020
Generated by manServer 1.08 from 10dc979a-7c9f-405c-8b06-1d301567115f using man macros.