program converterexample !ccccc This really simple program just shows you an example !ccccc of how to call the chartoint subroutine. BH 01/22/04 integer thevalue call chartoint(5,5555,thevalue,'a number',8) write(*,*) write(*,*) 'You entered the value ', thevalue stop end !ccccc End program and start subroutines subroutine chartoint(minval,maxval,returnval,whatisit,l) !ccccc This subroutine asks the user to Enter the 'whatisit' !ccccc from minval to maxval. It then converts this to an !ccccc integer and returns it as returnval. Both minval and !ccccc must be non-negative. 'whatisit' is a character string !ccccc of up to length 30, and l is its length. character*30 whatisit integer minval, maxval, returnval, l character*8 temp integer okcheck,digit okcheck=0 do 1500 while (okcheck.eq.0) okcheck=1 write(*,*) write(*,*) 'Enter ',whatisit(1:l) write(*,*) ' from ',minval,' to ',maxval write(*,*) read(*,*) temp returnval=0 do 1505 j=1,len_trim(temp) digit=iachar(temp(j:j)) if ((digit.lt.48).or.(digit.gt.57)) then if (okcheck.eq.1) then write(*,*) write(*,*) 'That was not a positive integer!' write(*,*) okcheck=0 endif endif returnval=returnval+(digit-48)*10**(len_trim(temp)-j) 1505 continue if ((returnval.lt.minval).or.(returnval.gt.maxval)) then if (okcheck.eq.1) then write(*,*) write(*,*) 'That value was not in the correct range!' write(*,*) okcheck=0 endif endif 1500 continue return end