Name: PGNUMB
Purpose: convert a number into a plottable character string
Category: GRAPHICS
File: pgplot.src
Author: T.J. Pearson
Use: see description below.
Description:
SUBROUTINE PGNUMB (MM, PP, FORM, STRING, NC)
INTEGER MM, PP, FORM
CHARACTER*(*) STRING
INTEGER NC
This routine converts a number into a decimal character
representation. To avoid problems of floating-point roundoff, the
number must be provided as an integer (MM) multiplied by a power of 10
(10**PP). The output string retains only significant digits of MM,
and will be in either integer format (123), decimal format (0.0123),
or exponential format (1.23x10**5). Standard escape sequences \u, \d
raise the exponent and \x is used for the multiplication sign.
This routine is used by PGBOX to create numeric labels for a plot.
Formatting rules:
(a) Decimal notation (FORM=1):
- Trailing zeros to the right of the decimal sign are
omitted
- The decimal sign is omitted if there are no digits
to the right of it
- When the decimal sign is placed before the first digit
of the number, a zero is placed before the decimal sign
- The decimal sign is a period (.)
- No spaces are placed between digits (ie digits are not
grouped in threes as they should be)
- A leading minus (-) is added if the number is negative
(b) Exponential notation (FORM=2):
- The exponent is adjusted to put just one (non-zero)
digit before the decimal sign
- The mantissa is formatted as in (a), unless its value is
1 in which case it and the multiplication sign are omitted
- If the power of 10 is not zero and the mantissa is not
zero, an exponent of the form \x10\u[-]nnn is appended,
where \x is a multiplication sign (cross), \u is an escape
sequence to raise the exponent, and as many digits nnn
are used as needed
(c) Automatic choice (FORM=0):
Decimal notation is used if the absolute value of the
number is less than 10000 or greater than or equal to
0.01. Otherwise exponential notation is used.
Arguments:
MM (input)
PP (input) : the value to be formatted is MM*10**PP.
FORM (input) : controls how the number is formatted:
FORM = 0 -- use either decimal or exponential
FORM = 1 -- use decimal notation
FORM = 2 -- use exponential notation
STRING (output) : the formatted character string, left justified.
If the length of STRING is insufficient, a single
asterisk is returned, and NC=1.
NC (output) : the number of characters used in STRING:
the string to be printed is STRING(1:NC).
Updates: Oct 16, 1998: JPT automatically extracted from source.