[go: up one dir, main page]

Menu

[r34]: / common / char2int.f90  Maximize  Restore  History

Download this file

50 lines (44 with data), 970 Bytes

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
subroutine char2int(string,int)
character(80)::string
integer::int,i,index1,index2
integer::signe
signe=1
!print*,'char2int',string
!chiffre : ((ichar()>=48).and.(ichar()<=57))
!((ichar()<48).or.(ichar()>57))
!do i=1,10
! print*,i,ichar(string(i:i))
!enddo
i=0
if((ichar(string(1:1))<48).or.(ichar(string(1:1))>58)) then
!if(string(1:1)==' ') then
i=1
do while((ichar(string(i:i))<48).or.(ichar(string(i:i))>58))
i=i+1
enddo
index1=i
else
index1=1
endif
if(index(string(1:index1),'-')<=index1) signe= (-1)
i=index1
do while ((ichar(string(i:i))>=48).and.(ichar(string(i:i))<=58))
i=i+1
enddo
index2=i
k=1
!print*,'DEBUG char2int'
!print*,'string',string
!print*,'index1',index1
!print*,'index2',index2
int=0
do i=index2,index1,-1
if (i==index1) goto 100
! print*,k,string(i-1:i-1),ichar(string(i-1:i-1))
int=int+(ichar(string(i-1:i-1))-48)*k
k=k*10
enddo
int=int*signe
100 continue
!print*,'Result',int
end subroutine char2int