-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathINT2CHAR.f90
31 lines (25 loc) · 908 Bytes
/
INT2CHAR.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
SUBROUTINE INT2CHAR(N, SZ, STR)
IMPLICIT NONE
! THIS SUBROUTINE CONVERTS INTEGER (N) TO CHARACTER ARRAY (STR). THE PURPOSE OF THIS
! SUBROUTINE IS TO CONVERT INTEGER DATE, MONTH, AND YEAR TO CHARACTERS. THE ARGUMENTS
! OF SUBROUTINE IS
!
! N = THE NUMERAL THAT IS INTERGER TO BE CONVERTED TO CHARACTERS (IN)
! SZ = LENGTH OF N e.g., 2 for N=10 (IN)
! STR = STRING THAT REPRESENT N (OUT)
!
!
! NARENDRA DAS, 05-26-2010
INTEGER*4, INTENT(IN):: N, SZ
INTEGER, PARAMETER:: I0 = IACHAR('0')
INTEGER NN
CHARACTER,PARAMETER:: CDIGIT(0:9) = (/(ACHAR(NN),NN=I0,I0+9)/)
INTEGER*4 ABS_N, ii, DIGIT
CHARACTER(SZ), INTENT(OUT):: STR
ABS_N = ABS(N)
DO ii = SZ,1,-1
DIGIT = MOD(ABS_N, 10)
ABS_N = (ABS_N - DIGIT)/10
STR(ii:ii) = CDIGIT(DIGIT)
ENDDO
END SUBROUTINE INT2CHAR