      program lod_test
c
c     Sample program for testing the limits of
c     detection code.
c
      parameter (maxobv=2000)
      real x(maxobv)
      real y(maxobv)
      real temp1(maxobv)
      real temp2(maxobv)
      real temp3(maxobv)
      real temp4(maxobv)
      real temp5(maxobv)
      real temp6(maxobv)
      real temp7(maxobv)
      real temp8(maxobv)
      real temp9(maxobv)
      real temp10(maxobv)
      real temp11(maxobv)
      real temp12(maxobv)
      real temp13(maxobv)
      real temp14(maxobv)
      real temp15(maxobv)
      real temp16(maxobv)
      real temp17(maxobv)
      real temp18(maxobv)
      real temp19(maxobv)
      real temp20(maxobv)
      real temp21(maxobv)
      real temp22(maxobv)
c
      integer itemp1(maxobv)
      integer itemp2(maxobv)
      integer itemp3(maxobv)
c
      character*4 idebug
      character*4 ierror
      character*4 ilodcv
      character*4 ilodof
      character*4 ilodst
      character*4 ilodta
      character*4 ilodpc
      character*1 ia
C
C-----COMMON----------------------------------------------------------
C
C-----THIS IS COMMON/INCLUDE FILE DPCOMC.INC-----
C     THIS IS COMMON FOR MACHINE CONSTANTS
C
C               **************************
C               **************************
C               **  DEFINE THE INTEGER  **
C               **  MACHINE CONSTANTS   **
C               **  ARRAY               **
C               **************************
C               **************************
C
      COMMON /IMACH/I1MACH(16)
C
C               ********************************************************
C               ********************************************************
C               **  DEFINE THE REAL (SINGLE PRECISION FLOATING POINT)  *
C               **  MACHINE CONSTANTS                                  *
C               **  ARRAY                                              *
C               ********************************************************
C               ********************************************************
C
      COMMON /RMACH/R1MACH(5)
C
C               ***********************************
C               ***********************************
C               **  DEFINE THE DOUBLE PRECISION  **
C               **  MACHINE CONSTANTS            **
C               **  ARRAY                        **
C               ***********************************
C               ***********************************
C
      DOUBLE PRECISION D1MACH
C
      COMMON /DMACH/D1MACH(5)
C
      call initmc(idebug,ipr)
      cpumin=-r1mach(2)
c
c     Read a test data file in "test_lod.txt".
c
c     The first 3 lines in this file contain header
c     information, so skip over these lines.
c
      iline=0
      ird=10
      open(ird,file='lod_test.txt')
      read(ird,'(a1)',end=9010)ia
      read(ird,'(a1)',end=9010)ia
      read(ird,'(a1)',end=9010)ia
      n=0
      do100i=1,maxobv
        iline=i+1
        read(ird,*,err=9010,end=190)x(i),y(i)
        n=n+1
  100 continue
  190 continue
c
c     Call dplod2
c
      idebug='OFF'
      ierror='NO'
      ipr=6
c
c     Following options determine what LOD output is printed:
c
c        ilodcv = quan => LOD critical value based on quantiles
c                 norm => LOD critical value based on normal ppf
c        ilodof = write output tables to files TABLE1.OUT and TABLE2.OUT
c        ilodst = print summary table
c        ilodta = print lod table
c        ilodpc = print lod critical value
c
      ilodcv='QUAN'
      ilodof='ON'
      ilodst='ON'
      ilodta='ON'
      ilodpc='ON'
c
c        alpha   = Probability of a false alarm
c        beta    = Probability of a false negative
c        gamma   = Confidence limit for the tolerance bound
c        pa      = Coverage for the tolerance bound
c        thrper  = Threshold percentage (should be between 0.8 and
c                  1, although recommended minimum value is 0.9)
c
c                  The threshold is used to identify the lowest level
c                  of the mass value for which the measurements are
c                  above the critical value.  That is, if thrper = 0.9,
c                  identify the smallest mass level where >= 90% of the
c                  measurements are above the critical value.
c
c        cv      = User specified critical value (set to cpumin if
c                  none).  For example, this value might be provided
c                  by the manufacturer of the instrument.
c
      alpha  = 0.1
      beta   = 0.1
      pa     = 0.1
      gamma  = 0.1
      thrper = 0.9
      cv     = cpumin
c
c     On return
c
c         alod   = LOD value
c         alodse = standard error of LOD value
c         cv     = the critical value
c         alodlu = the upper confidence limit on the LOD value
c
      call dplod2(y,x,n,maxobv,ipr,
     1            temp1,temp2,temp3,temp4,temp5,temp6,
     1            temp7,temp8,temp9,temp10,temp11,temp12,
     1            temp13,temp14,temp15,temp16,temp17,temp18,
     1            temp19,temp20,temp21,temp22,
     1            itemp1,itemp2,itemp3,
     1            alpha,beta,gamma,pa,thrper,cvuser,
     1            ilodcv,ilodof,ilodst,ilodta,ilodpc,
     1            alod,alodse,cv,alodlu,
     1            idebug,ierror)
      goto9000
c
c     Error reading data file
c
 9010 continue
      print *,'Error reading data file on line ',iline
      goto9000
c
c     End
c
 9000 continue
      close(ird)
      stop
      end
