!=====================================================================
! NGAG: Autograph, A Package of Routines to Draw X/Y Plots
!=====================================================================
!
! A graphics package enabling the user to draw graphs, each with a
! labelled background and each displaying one or more curves.
!
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Set/Get internal parameters
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
!
! NG_AGSETC set the value of a CHARACTER internal parameter
! NG_AGSETI set the value of an INTEGER internal parameter
! NG_AGSETR set the value of a REAL internal parameter
! NG_AGSETF set the value of a REAL internal parameter
! NG_AGSETP set the real values of a group of related parameters.
!
! NG_AGGETC get the value of a CHARACTER internal parameter
! NG_AGGETI get the value of an INTEGER internal parameter
! NG_AGGETR get the value of a REAL internal parameter
! NG_AGGETF get the value of a REAL internal parameter
! NG_AGGETP set the real values of a group of related parameters.
!
! The routines NG_ANOTAT and NG_DISPLA provide access to a limited
! subset of the control parameters and are provided principally for
! historical reasons (obsolete routines)
!
! NG_AGSAVE save the current state of AUTOGRAPH in a file
! NG_AGRSTR restore a saved state of AUTOGRAPH from a file
!
! NG_AGBNCH Converts binary dash patterns to character dash patterns.
! NG_AGDSHN Generate the names of parameters in the group 'DASH/PATTERN.'
!
! NG_AGSET1 set pen numbers (color indices) used for AUTOGRAPH (added by CNCARG)
! NG_AGGET1 get pen numbers (color indices) used for AUTOGRAPH (added by CNCARG)
!
! NG_AGRSET reset all internal parameters to its default (added by CNCARG)
!
! ~~~~~~~~~~~~~~~~~~
! Quick-Way Plotting
! ~~~~~~~~~~~~~~~~~~
!
! NG_EZY    graph a single curve defined by the points
!            (I,Y(I)), for I from 1 to N
!
! NG_EZXY   graph a single curve defined by the points
!            (X(I),Y(I)), for I from 1 to N
!
! NG_EZMY   graph the M curves defined by the points
!            (I,Y(I,J)), for I from 1 to N and J from 1 to M
!
! NG_EZMXY  graph the M curves defined by the points
!            (X(I),Y(I,J)) or (X(I,J),Y(I,J)), for I from 1 to N and J from 1 to M
!
! ~~~~~~~~~~~~~~~~~~~
! Normal-Way Plotting
! ~~~~~~~~~~~~~~~~~~~
!
! NG_AGSTUP to perform "set-up".
!
! NG_AGBACK to draw a background.
!
! NG_AGCURV to draw the desired curves, called one or more times (once per curve).
!
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Five Optional Argument Subprograms
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!
! Three routines, AGCHAX, AGCHCU, and AGCHIL, are provided by the user
! to change intensities, line widths, colors, line styles, etc., for
! selected portions of a graph.  Each is called just before an object
! is to be drawn and again just after it has been drawn, with arguments
! enabling the user to completely identify what the current situation
! is and to make the appropriate calls. AGCHAX handles objects which
! are parts of axes, AGCHCU handles curves, and AGCHIL handles
! informational labels.
!
! The routine AGCHNL is called just after the character form of a numeric
! label has been constructed and just before it is to be drawn. The user
! may supply a version of this routine to transform selected numeric
! labels in any desired fashion and return them to AUTOGRAPH. This feature
! may be used to label an axis with the names of the months, Roman numerals,
! etc.
!
! The subroutine AGUTOL is called to do the mapping from the user system
! to the label system (or vice-versa) along the four axes.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_AGSET1( ipax, ipil, ipcu )
!
! Routine to set pen numbers (color indices) used for AUTOGRAPH X/Y plots.
!
! Variables:
!
! INTEGER, INTENT(IN), OPTIONAL :: ipax(4), ipil, ipcu(3)
!
! ipax are the pen numbers (color indices) to draw "axes"
!      ipax(1) - axis line
!      ipax(2) - major tick
!      ipax(3) - minor tick
!      ipax(4) - numeric label
!
! ipil is the pen number (color index) to draw "informational labels"
!
! ipcu are the pen numbers (color indices) to draw "curves"
!      ipcu(1) - polyline of curv,
!      ipcu(2) - label-text along curve,
!      ipcu(3) - label-marker along curve,
!
! Note: This routine added by CNCARG
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_AGGET1( ipax, ipil, ipcu )
!
! Routine to get pen numbers (color indices) used for AUTOGRAPH X/Y plots.
!
! Variables:
!
! INTEGER, INTENT(OUT), OPTIONAL :: ipax(4), ipil, ipcu(3)
!
! Note: This routine added by CNCARG
!
!---------------------------------------------------------------------
!
! Note: Internal parameter "FRAME" has been nullified by CNCARG
!
! Note: CNCARG adding five "optional dummy subprogram arguments",
!       AGUTOL, AGCHNL, AGCHAX, AGCHIL, and AGCHCU to following
!       AUTOGRAPH routines.
!
!       SUBROUTINE NG_EZY   ( YDRA, NPTS, LABG, &
!                             [AGUTOL, AGCHNL, AGCHAX, AGCHIL, AGCHCU] )
!
!       SUBROUTINE NG_EZXY  ( XDRA, YDRA, NPTS, LABG, &
!                             [AGUTOL, AGCHNL, AGCHAX, AGCHIL, AGCHCU] )
!
!       SUBROUTINE NG_EZMY  ( YDRA, IDXY, MANY, NPTS, LABG, &
!                             [AGUTOL, AGCHNL, AGCHAX, AGCHIL, AGCHCU] )
!
!       SUBROUTINE NG_EZMXY ( XDRA, YDRA, IDXY, MANY, NPTS, LABG, &
!                             [AGUTOL, AGCHNL, AGCHAX, AGCHIL, AGCHCU] )
!
!       SUBROUTINE NG_AGSTUP( XDRA, NVIX, IIVX, NEVX, IIEX, &
!                             YDRA, NVIY, IIVY, NEVY, IIEY, &
!                             [AGUTOL, AGCHNL, AGCHAX, AGCHIL] )
!
!       SUBROUTINE NG_AGBACK( [AGUTOL, AGCHNL, AGCHAX, AGCHIL] )
!
!       SUBROUTINE NG_AGCURV( XVEC, IIEX, YVEC, IIEY, NEXY, KDSH, &
!                             [AGCHCU] )
!
!=====================================================================
! Refer "NCAR menu" for interfacing AUTOGRAPH in detail
!=====================================================================

!=====================================================================
! Simple 2D X-Y curve(s) plotting routines cited from PLTBMP v2.68
! built by Kenneth G. Hamilton, 2008; revised by chiangtp, 2015-06-29
!=====================================================================
!
! SUBROUTINE NG_KGHXY1( ITYPE, VP, X, Y1, N, &
!                       TITLE, XLABEL, YLABEL, PLCI0, &
!                       LINTYP1, ISYM1, PLCI1, &
!                       SC1, SC2)
!
! This routine plots a single curve, of Y1 versus X, linear or
! logarithmic decided by ITYPE, inside given viewport VP.  Both
! arrays are assumed to have N members.
!
! The CHARACTER variables TITLE, XLABEL, and YLABEL are drawn at
! the top, bottom, and left side of the figure, respectively.
! Drawing color is PLCI0.
!
! The points are connected with a line of type LINTYP1.  Note that
! if LINTYP1=0, then no line is drawn so that only symbols will be
! visible.  Drawing color is PLCI1.
!
! Each point is marked by a symbol of type ISYM. If ISYM1=0, then
! no symbols will be drawn, so that a plot with only a line can be
! made.  Drawing color is PLCI1.
!
! Variables :
!
!   ITYPE  : INTEGER, INTENT(IN)
!            The type of linear or logarithmic axis scaling.
!              =1 means Linear X, Linear Y;
!              =2 means Linear X, Log Y;
!              =3 means Log X, Linear Y; and,
!              =4 means Log X, Log Y
!
!   VP     : REAL, INTENT(IN), DIMENSION(4)
!            The viewport, in fractional coordinate, of the plot.
!            Array elements are ordered as (/left, right, bottom, top/)
!
!   X      : REAL, INTENT(IN), DIMENSION(N)
!            The x Coordinates array of a curve to be plotted
!
!   Y1     : REAL, INTENT(IN), DIMENSION(N)
!            The y Coordinates array of a curve to be plotted
!
!   N      : INTEGER,  INTENT(IN)
!            The dimension of X and Y1 arrays
!
!   TITLE  : CHARACTER(*), INTENT(IN)
!            The title of plot
!
!   XLABEL : CHARACTER(*), INTENT(IN)
!            The label of x-axis
!
!   YLABEL : CHARACTER(*), INTENT(IN)
!            The label of y-axis
!
!   PLCI0  : INTEGER, INTENT(IN)
!            The color index to draw frame (x and y axes/ticks/labels)
!
!   LINTYP1: INTEGER, INTENT(IN)
!            A code to indicate the type of line to use in
!            connecting the point.
!
!            If LINTYP1 is positive, only the line is drawn;
!
!            if LINTYP1 is zero, then the points are plotted,
!            but no line is drawn;
!
!            if LINTYP1 is negative, then the points are marked,
!            and a line is drawn corresponding to the value of
!            ABS(LINTYP1).
!
!              ABS(lintyp)
!              = 0 (no line is drawn)
!              = 1 (solid line),
!              = 2 (dotted line),
!              = 3 (short dashed line),
!              = 4 (medium dashed line),
!              = 5 (long dashed line),
!              = 6 (dash-dot-dash-dot line),
!              = 7 (long dash-short dash line)
!              = 8 (long dash-dot-dot line)
!              = 9 (long dash-dot-dot-ot line)
!
!   ISYM1  : INTEGER, INTENT(IN)
!            The code for the symbol to plot at the points, if
!            indeed a point is to be plotted (i.e., lintyp<=0).
!            Symbols are plotted by invoking NG_MARKER routine.
!
!   PLCI1  : INTEGER, INTENT(IN)
!            The color index to draw curve (with symbol)
!
!   SC1    : REAL, INTENT(IN), OPTIONAL
!            The scaling factor of the size of symbol to plot.
!            Default symbol size is 0.01*(VP(2)-VP(1))
!
!   SC2    : REAL, INTENT(IN), OPTIONAL
!            The scaling factor of the size of line segment of curve.
!            Default line segmengt is 0.002 in fractional coordinate
!
!   Notes: If LINTYP1 is positive, then the value of ISYM1 is ignored.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_KGHXY2( ITYPE, VP, X, Y1, Y2, N, &
!                       TITLE, XLABEL, YLABEL, PLCI0, &
!                       LINTYP1, ISYM1, PLCI1, &
!                       LINTYP2, ISYM2, PLCI2, &
!                       SC1, SC2)
!
! This routine will draw a plot with two curves, Y1 versus X,
! and Y2 versus X.  The meaning of the arguments is the same
! as in NG_KGHXY1.
!
! Variables:
!
!   INTEGER,      INTENT(IN) :: ITYPE
!   REAL,         INTENT(IN) :: VP(4)
!   INTEGER,      INTENT(IN) :: N, PLCI0
!   REAL,         INTENT(IN) :: X(N), Y1(N), Y2(N)
!   CHARACTER(*), INTENT(IN) :: TITLE, XLABEL, YLABEL
!   INTEGER,      INTENT(IN) :: LINTYP1, LINTYP2
!   INTEGER,      INTENT(IN) :: ISYM1, ISYM2
!   INTEGER,      INTENT(IN) :: PLCI1, PLCI2
!   REAL,         INTENT(IN), OPTIONAL :: SC1, SC2
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_KGHXY3( ITYPE, VP, X, Y1, Y2, Y3, N, &
!                       TITLE, XLABEL, YLABEL, PLCI0, &
!                       LINTYP1, ISYM1, PLCI1, &
!                       LINTYP2, ISYM2, PLCI2, &
!                       LINTYP3, ISYM3, PLCI3, &
!                       SC1, SC2)
!
! This routine draws three curves: Y1 versus X, Y2 versus X,
! and Y3 versus X.  The meaning of the arguments is the same
! as in NG_KGHXY1 and NG_KGHXY2.
!
! Variables:
!
!   INTEGER,      INTENT(IN) :: ITYPE
!   REAL,         INTENT(IN) :: VP(4)
!   INTEGER,      INTENT(IN) :: N, PLCI0
!   REAL,         INTENT(IN) :: X(N), Y1(N), Y2(N), Y3(N)
!   CHARACTER(*), INTENT(IN) :: TITLE, XLABEL, YLABEL
!   INTEGER,      INTENT(IN) :: LINTYP1, LINTYP2, LINTYP3
!   INTEGER,      INTENT(IN) :: ISYM1, ISYM2, ISYM3
!   INTEGER,      INTENT(IN) :: PLCI1, PLCI2, PLCI3
!   REAL,         INTENT(IN), OPTIONAL :: SC1, SC2
!
!=====================================================================