	program nbase
c
c---_----1----_----2----_----3----_----4----_----5----_----6----_----7--+
c
c     Written by Terry E. Koontz
c                Sandia National Laboratories, SNLA
c                Division 7553, Electromagnetic Analysis Group
c                Albuquerque, NM 87185
c                (505) 846-6036
c
c     Original: Jan. 12, 1988
c     Revised:  Jul. 20, 1989
c
c Description:
c
c     Convert a number between bases 2 thru 62
c
c---_----1----_----2----_----3----_----4----_----5----_----6----_----7--+
c
	character*32 a,b,userp1
	integer*4 c,r1,r2,v,v2
	double precision t
	
10	write(*,1) 
1       format(' Convert the number (0 to quit) ',$)
        read(*,2) a
2	format(a32)
	v=ichar(a(1:1))
	if (v.eq.48) goto 999
	
20	write(5,21)
21      format(' From base ',$)
	read(*,*) r1
	if ((r1.lt.2).or.(r1.gt.62)) then
	  write(*,*) '2 to 62 only'
	  goto 20
	else
	endif
	
30	write(5,31)
31      format(' To base ',$)
	read(*,*) r2
	if ((r2.lt.2).or.(r2.gt.62)) then
	  write(*,*) '2 to 62 only'
	  goto 30
	else
	endif
	
	t=0
	do 100 c=1,len(a)
	  v=ichar(a(c:c))
	  if (v.eq.32) goto 40
	  if ((v.ge.48).and.(v.le. 57)) v2=v-48
	  if ((v.ge.65).and.(v.le. 90)) v2=v-55
	  if ((v.ge.97).and.(v.le.122)) v2=v-61
	  if (v2.ge.r1) then
	    write(*,*) 'Character ',v,' invalid for base ',r1
	    goto 10
	  else
	  endif
	  t=t*r1+v2
100	continue
	
40      b='                    '
	c=20
200	if (t.eq.0) goto 300
	  v2=t-aint(t/r2)*r2
	  t=(t-v2)/r2
	  if (v2.le.9) v=v2+48
	  if ((v2.ge.10).and.(v2.le.35)) v=v2+55
	  if (v2.ge.36) v=v2+61
	  b(c:c)=char(v)
	  c=c-1		
        goto 200
	
300	write(*,*) 'The answer is: ',b(c:20)
	goto 10
	
999	end    
