!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
program zeromin2
!
! This is a Fortran 90 update of the FORTRAN 77 original, from which
! most of the following description is retained.
!
! Description and usage:
!
! ZEROMIN2 is an adaptation of ZEROMIN for driving the reverse-
! communication versions of FMIN and ZEROIN.
!
! Like ZEROMIN, it finds (within a user specified interval) either a root
! of a function of one variable or a minimum of a function of one variable.
! It also provides for displaying the function via Tecplot if requested.
!
! The underlying algorithms are both due to Richard Brent (Stanford Uni-
! versity, c. 1970) and described in Forsythe, Malcolm, and Moler (1977).
! FMINRC is actually a revision of FMIN77, itself a subroutine version by
! Robert Kennelly of the original FMIN.
!
! Note that compilation is expected to use -r8 or equivalent in order to
! perform 64-bit arithmetic.
!
! To utilize the program without changes, the user must supply the one-
! dimensional function of interest in the form of a real function FUNC1D
! with a single input argument that is the independent variable.
!
! A sample FUNC1D routine might be:
!
! real function func1d (x)
! real, intent (in) :: x
! func1d = tan (x) - 1./x ! The search interval is assumed to
! end function func1d ! exclude x = 0.
!
! For more elaborate functions, ZEROMIN2 could be modified to evaluate the
! function in any way necessary. The function form of FUNC1D has been
! retained in the initial version to enable simple testing of FMINRC against
! the original FMIN77.
!
! A second routine may be provided by the user. Appropriately enough,
! this subroutine must be titled USER. It allows the user to perform
! operations that ZEROMIN2 and FUNC1D do not already perform. It should
! have the form
!
! subroutine user (luncrt, lunkbd, lunout, lunplt, first)
!
! For example, if more than one variable is used to compute the
! quantity returned by FUNC1D, then the user must supply a USER
! routine to prompt for or set up values for the other variables.
! USER and FUNC1D must communicate through COMMON variables unless
! ZEROMIN2 is modified to change FUNC1D's argument list.
!
! Note that USER is called within the retry loop over different
! search intervals. This may require distinguishing (within USER)
! its first call from subsequent calls.
!
! Even if no extra computation outside FUNC1D is required, a dummy USER is
! still needed, and one such is supplied as part of the ZEROMIN2 package.
! FUNC1D must be relinked with ZEROMIN2 for each new application.
!
! At the start of a run, the user is prompted for the operation to be
! performed and the number of coordinate points wanted in the plot, which
! may also be suppressed. The search interval and length of the interval
! of uncertainty for the search convergence are also prompted for. If it
! appears that the interval does not contain a zero or a minimum, retries
! are permitted.
!
! Two files may be produced by ZEROMIN2. The first file will have either
! the abscissa value for the root or the abscissa value for the minimum
! and the minimum ordinate value. Also output in the same file are the
! interval boundaries. This file is named zeromin2.out. The second file
! is Tecplotable and is optional. It will include the title and the
! specified number of coordinate points that are calculated by the program
! to display the function. The root or minimum will also be plotted as a
! single symbol. This file name is zeromin2.dat.
!
!
! External references:
!
! Name Description
!
! FUNC1D One-dimensional function for which a minimum or root is sought.
! FMINRC Seeks a local minimum of a 1-D function in a specified interval.
!!!!! QPLDAT ENTRY points QPLFRM, QPLCRV write plot data in QPLOT format.
!!!!! No longer used because QPLOT is history now.
! READER Prompting utility, with ENTRY points READD, READI, etc.
! SELECT Menu utility.
! USER Subroutine provided by the user to do any operations
! not already provided by ZEROMIN2 and FUNC1D. May be
! defaulted if no other input or computations are needed.
! ZERORC Finds a root of a 1-D function within a specified interval.
!
!
! History:
!
! 23 Oct. 1987 PTS Initial implementation of ZEROMIN (along the
! lines of NLSQ).
! 10 Apr. 1992 DAS ZEROMIN2 adapted from ZEROMIN in order to
! test FMINRC and ZERORC.
! 19 Oct. 2023 DAS F90 translation during a slow patch.
!
! Authors: Phillip T. Snyder, Sterling Software/NASA Ames Research Center, CA
! David A. Saunders, AMA, Inc. at NASA ARC.
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!