00001
00002 c
00003 c Copyright (c) 1986,1987,1988,1989,1990,1991,1992,1993,
00004 c by Steve McMillan, Drexel University, Philadelphia, PA.
00005 c
00006 c All rights reserved.
00007 c
00008 c Redistribution and use in source and binary forms are permitted
00009 c provided that the above copyright notice and this paragraph are
00010 c duplicated in all such forms and that any documentation,
00011 c advertising materials, and other materials related to such
00012 c distribution and use acknowledge that the software was developed
00013 c by the author named above.
00014 c
00015 c THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
00016 c IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
00017 c WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00018 c
00019
00020 subroutine numsym(f,ic,outstr,m)
00021
00022 implicit double precision (d)
00023 save
00024 real*8 spacc
00025 real*4 f
00026 integer*4 i,ic,j,m,n
00027 character outstr*80
00028
00029 character*1 dot,neg,blank,digit(0:9)
00030 data dot/'.'/neg/'-'/,blank/' '/
00031 & digit/'0','1','2','3','4','5','6','7','8','9'/
00032 & spacc/1.00000001/
00033
00034 dex(dpf) = 10.**dpf
00035
00036 dpf = dble(f)
00037 n = 0
00038 if (dpf.ne.0.) then
00039 n = log10(abs(dpf)) + 1.001 ! digits to left of decimal.
00040 end if
00041 if (n.le.0) n = 1
00042 m = n + 1 + ic ! total characters plotted.
00043 dpg = abs(dpf) ! for discounting.
00044
00045 if (ic.lt.0) then
00046
00047 do i = 1,m
00048 dph = dex(dfloat(n-i))
00049 j = dpg/dph*spacc ! discounted digit.
00050 outstr(i:i) = digit(j)
00051 dpg = dpg - j*dph ! discount dpg for next digit.
00052 end do
00053
00054 else
00055
00056 do i = 1,n
00057 dph = dex(dfloat(n-i))
00058 j = dpg/dph*spacc ! discounted digit.
00059 outstr(i:i) = digit(j)
00060 dpg = dpg-j*dph ! discount dpg for next digit.
00061 end do
00062
00063 outstr(n+1:n+1) = dot ! insert decimal point.
00064 if (ic.gt.0) then
00065 do i = 1,ic ! add decimal digits.
00066 j = 10*dpg*spacc ! discounted digit.
00067 outstr(n+1+i:n+1+i) = digit(j)
00068 dpg = 10.*dpg-j ! continue discounting dpg.
00069 end do
00070 end if
00071
00072 end if
00073
00074 j = 10*dpg*spacc
00075 if(j.lt.5)go to 501 ! round off last digit(s).
00076
00077 if(ic.gt.0)then
00078 do i = m,n+2,-1 ! start at right edge of string.
00079 if (ichar(outstr(i:i)).le.56) then
00080 outstr(i:i) = char(ichar(outstr(i:i))+1)
00081 go to 501
00082 end if
00083 outstr(i:i) = digit(0)
00084 end do
00085 end if
00086
00087 do i = n,1,-1 ! then adjust left, if necessary.
00088 if (ichar(outstr(i:i)).le.56) then
00089 outstr(i:i) = char(ichar(outstr(i:i))+1)
00090 go to 501
00091 end if
00092 outstr(i:i) = digit(0)
00093 end do
00094 do i = m,1,-1
00095 outstr(i+1:i+1) = outstr(i:i)
00096 end do
00097 outstr(1:1) = digit(1)
00098
00099 c Put "-" up front if necessary.
00100
00101 501 if (f.lt.0.) then
00102 do i = 1,m
00103 if (outstr(i:i).ne.'.'.and.outstr(i:i).ne.'0') go to 506
00104 end do
00105 go to 508
00106 506 do i = m+2,1,-1
00107 outstr(i+1:i+1) = outstr(i:i)
00108 end do
00109 outstr(1:1) = neg
00110 m = m+1
00111 end if
00112 508 continue
00113
00114 end