NAG Library Routine Document
G01AJF
1 Purpose
G01AJF prints a histogram on a character printing device, allowing you control over size, positioning, and the range of data values included.
2 Specification
SUBROUTINE G01AJF ( 
X, N, NSTEPX, NSTEPY, ITYPE, ISPACE, XMIN, XMAX, XSTEP, N1, MULTY, IFAIL) 
INTEGER 
N, NSTEPX, NSTEPY, ITYPE, ISPACE, N1, MULTY, IFAIL 
REAL (KIND=nag_wp) 
X(N), XMIN, XMAX, XSTEP 

3 Description
A histogram is printed using vertical bars consisting of * characters. The output is directed to the current advisory message unit (see the
Users' Note for your implementation). It may be redirected by a call to
X04ABF before calling G01AJF.
The following options are available:
(a) 
inclusion of all data values, or only of those lying within a specified range; 
(b) 
specification of the size of the histogram in the vertical and horizontal directions, and of positioning in the horizontal direction; 
(c) 
calculation of frequencies or cumulative frequencies in the histogram. 
The maximum and minimum data values used, the (integral) number of observations represented by each * in the histogram, and the step size per character position in the horizontal direction, are returned.
The histogram is headed FREQUENCY or CUM.FREQ. depending on the option selected. Each line is annotated with the minimum frequency which a bar reaching that line represents. The data maximum and minimum are printed under the histogram, unless either exceeds $9999.99$ in modulus, in which case they are not printed (although they are still returned).
4 References
None.
5 Parameters
 1: X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the data values.
 2: N – INTEGERInput
On entry: the number of data values.
Constraint:
${\mathbf{N}}\ge 1$.
 3: NSTEPX – INTEGERInput/Output
On entry: the number of character positions to be used in the horizontal direction, i.e., the number of categories in the histogram.
On exit: if
${\mathbf{NSTEPX}}<10$ on entry,
NSTEPX is reset to
$10$.
If
${\mathbf{NSTEPX}}>99$ on entry,
NSTEPX is reset to
$99$.
Otherwise,
NSTEPX is unchanged on exit.
 4: NSTEPY – INTEGERInput/Output
On entry: the number of character positions to be used in the vertical direction, i.e., the maximum height of a histogram bar.
On exit: if
${\mathbf{NSTEPY}}<10$ on entry,
NSTEPY is reset to
$10$.
If
${\mathbf{NSTEPY}}>99$ on entry,
NSTEPY is reset to
$99$.
Otherwise,
NSTEPY is unchanged on exit.
 5: ITYPE – INTEGERInput
On entry: indicates whether a histogram of frequencies or cumulative frequencies is required.
${\mathbf{ITYPE}}=0$ for frequencies.
${\mathbf{ITYPE}}\ne 0$ for cumulative frequencies.
The second option effectively displays the distribution function of the data rather than the density function.
 6: ISPACE – INTEGERInput/Output
On entry: indicates how many spaces are to be inserted at the beginning of each output line.
If ${\mathbf{ISPACE}}<0$ on input, ${\mathbf{ISPACE}}=0$ is used
If ${\mathbf{ISPACE}}+{\mathbf{NSTEPX}}+14>120$, then ${\mathbf{ISPACE}}=0$ is used.
The second condition imposes an effective line length limit of $120$ characters.
On exit: unchanged unless
${\mathbf{ISPACE}}<0$ or
${\mathbf{ISPACE}}+{\mathbf{NSTEPX}}+14>120$, in which case
ISPACE is set to
$0$.
 7: XMIN – REAL (KIND=nag_wp)Input/Output
 8: XMAX – REAL (KIND=nag_wp)Input/Output
On entry: if
${\mathbf{XMIN}}<{\mathbf{XMAX}}$, only those values in
X such that
${\mathbf{XMIN}}\le {\mathbf{X}}\left(\mathit{i}\right)\le {\mathbf{XMAX}}$, for
$\mathit{i}=1,2,\dots ,n$, are included in the histogram.
If ${\mathbf{XMIN}}\ge {\mathbf{XMAX}}$, all the data are included.
On exit: if
${\mathbf{XMIN}}<{\mathbf{XMAX}}$ on entry, then
XMIN and
XMAX are unchanged.
If
${\mathbf{XMIN}}\ge {\mathbf{XMAX}}$ then
XMIN and
XMAX contain the minimum and maximum data values respectively.
 9: XSTEP – REAL (KIND=nag_wp)Output
On exit: the width of each class interval.
 10: N1 – INTEGEROutput
On exit: the total number of observations actually included in the histogram.
 11: MULTY – INTEGEROutput
On exit: the number of observations represented by each * in the histogram.
 12: IFAIL – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
$0$.
When the value $\mathbf{1}\text{ or}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$

On entry,  ${\mathbf{N}}<1$. 
7 Accuracy
Accuracy is limited by the number of plotting positions available.
The time taken by G01AJF increases with
N,
NSTEPX and
NSTEPY.
A total of $\left({\mathbf{NSTEPX}}+{\mathbf{ISPACE}}+14\right)$ character positions are used in the horizontal direction, not including the carriage control character. It is important that this total does not exceed the maximum line length available on the output device.
A total of
$\left({\mathbf{NSTEPY}}+3\right)$ output lines are normally generated, one less if
XMIN and/or
XMAX is too large in modulus to be printed.
9 Example
A sample of
$50$ random numbers form the data, which correspond to a Normal distribution with mean and standard deviation both equal to
$5.0$. A histogram of the entire sample is drawn first, followed by a cumulative histogram of all data values lying between
$10.0$ and
$5.0$. The first histogram is indented
$10$ character positions. Note the use of
X04ABF to direct the output to unit number
$6$.
9.1 Program Text
Program Text (g01ajfe.f90)
9.2 Program Data
Program Data (g01ajfe.d)
9.3 Program Results
Program Results (g01ajfe.r)