!=============================================================================! ! International Comprehensive Ocean-Atmosphere Data Set (ICOADS) 25 Jul 2012 ! ! Filename:level: base36.f Fortran 90 Library ! ! Function: base 36 conversion routines Author: S.Lubker ! !=============================================================================! ! Software documentation for the routines {b36,ib36}: ! ! Functionality: Convert a selected_int_kind(10) integer to a base 36 ! ("alphadecimal") 6-character string and vice versa. For one base 36 ! character, the conversion between decimal and base 36 is as follows: ! ! ib36=b36 ib36=b36 ib36=b36 ib36=b36 ! 0 = 0 10 = A 20 = K 30 = U ! 1 = 1 11 = B 21 = L 31 = V ! 2 = 2 12 = C 22 = M 32 = W ! 3 = 3 13 = D 23 = N 33 = X ! 4 = 4 14 = E 24 = O 34 = Y ! 5 = 5 15 = F 25 = P 35 = Z ! 6 = 6 16 = G 26 = Q ! 7 = 7 17 = H 27 = R ! 8 = 8 18 = I 28 = S ! 9 = 9 19 = J 29 = T ! ! The largest integer that can be represented in six base 36 characters ! (ZZZZZZ) is 2,176,782,335, therefore that upper-limit on ib36 is ! imposed in b36. ! ! Machine/language dependencies: None known, however If there is no ! integer kind available on the computer system that accommodates the ! range +/-10**10, SELECTED_INT_KIND returns -1, which should lead ! to a compiler error. !-----------------------------------------------------------------------3456789 function b36(ib36) ! convert from integer to base 36 character string implicit integer (selected_int_kind(10)) (a-z) character (len=6) b36 character (len=36) :: str='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' if (ib36.gt.2176782335) stop 'function b36' b36=' ' int=1 do j=len(b36),1,-1 b36(j:j)=str(mod(ib36/int,36)+1:) int=int*36 enddo end !-----------------------------------------------------------------------3456789 function ib36(b36) ! convert from base 36 character string to integer implicit integer (selected_int_kind(10)) (a-z) character (len=6) b36 character (len=36) :: str='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ib36=0 int=1 do j=len(b36),1,-1 ib36=ib36+(index(str,b36(j:j))-1)*int int=int*36 enddo end