[comp.lang.fortran] Plotting Algorithm needed

rsc503@csc.anu.oz (08/07/90)

Hi, 
I realise that this is a fairly mundane request, but I was hoping that 
somebody could give me, or tell me where to find, an algorithm for determining
appropriate axis divisions for plots.  The min and max values could range over
zero to many orders of magnitude and be +ve or -ve, so I need a good general
routine.  I want "sensible" max and mins, and "sensible" divisions.  I think
that the answer would have something to do with taking logs of the range, etc.
You may e-mail to the address below if you like.

Thanking you in anticipation,
			Ian Jamie
--------------------------------------------------------------------------------
jamie@rsc0.anu.oz.au           |"We have sailed many weeks, we have sailed many
Ian Jamie                      |      days
Research School of Chemistry   | (Seven days to the week I allow),
Australian National University | But a Snark, on which we lovingly gaze,
Canberra, ACT, Australia       | We have never beheld till now!"  Lewis Carroll
--------------------------------------------------------------------------------

maine@elxsi.dfrf.nasa.gov (Richard Maine) (08/08/90)

Ian Jamie asked about plot scaling routines.  I tried email, figuring
the reply didn't really merit a post.  But my mailer can't find his
system (probably has to do with it being in Austrailia), so suppose
I`ll break down and post it.

Here's my plot scaling routine.  Nothing fancy, but it works fine for
me.  Do with it what you like; it is not copyrighted.

      subroutine scale3(xmin,xmax,axlen,expand,amn,asc,ticdst)
      
c Richard Maine.  9 Feb 86.
c determine reasonable plotting scales.
      
c******************** common.
c I normally have something like the following in an 'include' here.
c Expanded by hand in this copy.
c Also commented out for ANSI conformance.
c      implicit none
      
c******************** interface.
c xmin,xmax(input): data min and max values which must fit on scale.
c axlen(input): axis length in cm or other scaled units.
c   Reasonable results are not guaranteed if axlen .lt. 2.
c expand(input): can tic interval be expanded?
c amn(output): minimum value on scaled axis.
c asc(output): axis scale in units/cm.  A scale of -999. indicates
c   xmin ge xmax
c ticdst(output): interval between tics in cm.
c   Will always be 2 if expand is false.
      
      double precision xmin,xmax,axlen,amn,asc,ticdst
      logical expand
      
c******************** externals.
      intrinsic log10,nint,anint
      
c******************** local.
      integer nfacs
      parameter (nfacs=5)
      integer i,nTics
      double precision facs(nfacs),evencm,upercm,expon
      save facs
      data facs/1.,2.,5.,10.,20./
      
c--------------------------- executable code --------------------------

      ticdst = 2.
      if (xmax.le.xmin) then
         amn = xmin
         asc = -999.
      else
         evencm = 2.
         if (xmin.lt.0. .and. xmax.gt.0. .and. axlen.lt.4.) evencm=1.
         upercm = (xmax-xmin)/axlen
         expon = 10.**nint(log10(upercm)-.5)
         do 100 i = 1 , nfacs
            asc = facs(i)*expon
            amn = asc*evencm*anint(xmin/(asc*evencm)-.499)
            if (amn+axlen*asc .ge. xmax) go to 200
 100     continue
 200     continue
         if (expand) then
            nTics = (xmax-amn)/(ticdst*asc) + .99999
            ticdst = axlen/nTics
            asc = asc*2./ticdst
         endif
      endif
      return
      end


--

Richard Maine
maine@elxsi.dfrf.nasa.gov [130.134.64.6]