[Q-e-commits] espresso/flib int_to_char.f90,1.3,1.4

ccavazzoni at qe-forge.org ccavazzoni at qe-forge.org
Sun May 31 09:26:48 CEST 2009


Update of /cvsroot/q-e/espresso/flib
In directory qeforge.qe-forge.org:/tmp/cvs-serv881

Modified Files:
	int_to_char.f90 
Log Message:
- now manage also negative numbers


Index: int_to_char.f90
===================================================================
RCS file: /cvsroot/q-e/espresso/flib/int_to_char.f90,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- int_to_char.f90	10 May 2009 09:16:57 -0000	1.3
+++ int_to_char.f90	31 May 2009 07:26:46 -0000	1.4
@@ -8,29 +8,44 @@
     INTEGER, INTENT(IN) :: i
     CHARACTER (LEN=6)   :: int_to_char
     CHARACTER :: c
-    INTEGER   :: n, j
-    !   
-    IF( i < 0 ) &
-       CALL errore( ' int_to_char ', ' negative input not allowed ', 1 )
+    INTEGER   :: n, j, nc
+    LOGICAL   :: neg
     !   
-    n = i
+    nc = 6
+    !
+    IF( i < 0 ) then
+       nc  = nc - 1
+       n   = -i
+       neg = .true.
+    ELSE
+       n   = i
+       neg = .false.
+    END IF
+    !
     j = 1
-    DO WHILE( j < 7 ) 
+    DO WHILE( j <= nc ) 
        int_to_char(j:j) = CHAR( MOD( n, 10 ) + ICHAR( '0' ) )
        n = n / 10
        IF( n == 0 ) EXIT
        j = j + 1
     END DO
     !
-    IF( j < 7 ) THEN
+    IF( j <= nc ) THEN
        DO n = 1, j/2
           c = int_to_char( n : n )
           int_to_char( n : n ) = int_to_char( j-n+1 : j-n+1 )
           int_to_char( j-n+1 : j-n+1 ) = c
        END DO
-       IF( j < 6 ) int_to_char(j+1:6) = ' '
+       IF( j < nc ) int_to_char(j+1:nc) = ' '
     ELSE
-       int_to_char(1:6) = '*'
+       int_to_char(:) = '*'
+    END IF
+    !
+    IF( neg ) THEN
+       DO n = nc+1, 2, -1
+          int_to_char(n:n) = int_to_char(n-1:n-1)
+       END DO
+       int_to_char(1:1) = '-'
     END IF
     !
     RETURN



More information about the Q-e-commits mailing list