program gam2m
use gam2_sub
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!                                                                      %
! Copyright (C) 1992 Stanford Center for Reservoir Forecasting.  All   %
! rights reserved.  Distributed with: C.V. Deutsch and A.G. Journel.   %
! ``GSLIB: Geostatistical Software Library and User's Guide,'' Oxford  %
! University Press, New York, 1992.                                    %
!                                                                      %
! The programs in GSLIB are distributed in the hope that they will be  %
! useful, but WITHOUT ANY WARRANTY.  No author or distributor accepts  %
! responsibility to anyone for the consequences of using them or for   %
! whether they serve any particular purpose or work at all, unless he  %
! says so in writing.  Everyone is granted permission to copy, modify  %
! and redistribute the programs in GSLIB, but only under the condition %
! that this notice and the above copyright notice remain intact.       %
!                                                                      %
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!-----------------------------------------------------------------------
!
!               Variogram of Data on a 2-D Regular Grid
!               ***************************************
!
! This is a template driver program for GSLIB's "gam2" subroutine.  The
! input data is ordered rowwise (x cycles fastest, then y) in a GEOEAS
! format file.  The User's Guide contains more details.
!
!
!
! The program is executed with no command line arguments.  The user
! will be prompted for the name of a parameter file.  The parameter
! file is described in the documentation (see the example gam2.par)
! and should contain the following information:
!
!   -  name of the data file (GEOEAS format)
!   -  number of variables, and the column number of each variable.
!   -  minimum acceptable value (used to flag missing values)
!   -  name of an output file (may be overwritten)
!   -  nx and ny - number of nodes in the x and y direction
!   -  xsiz and ysiz - spacing of the grid nodes in the x, y direction
!   -  ndir and nlag - number of directions to consider and the
!        number of lags (same for all directions) to compute.
!   -  the next ndir lines should contain pairs of integer values which
!        are the x and y offsets required to identify the directional
!        vector. Some examples, (0,1) is parallel to y axis, (1,0) is
!        parallel to x axis, and (1,1) is at 45 degrees.
!   -  nvarg - the number of variograms to compute
!   -  the following nvarg lines should have three integer values:
!        a) the variable number for the tail of the variogram pair
!        b) the variable number for the head of the variogram pair
!        c) an integer code of the variogram type to calculate:
!                      1. semivariogram
!                      2. cross-semivariogram
!                      3. covariance
!                      4. correlogram
!                      5. general relative semivariogram
!                      6. pairwise relative semivariogram
!                      7. semivariogram of logarithms
!                      8. rodogram
!                      9. madogram
!                     10. indicator semivariogram
!        d) the cutoff if an indicator semivariogram is requested
!
!
!
! The output file will contain each directional variogram ordered by
! direction and then variogram (the directions cycle fastest then the
! variogram number).  For each variogram there will be a one line
! description and then "nlag" lines with the following:
!
!        a) lag number (increasing from 1 to nlag)
!        b) separation distance
!        c) the "variogram" value
!        d) the number of pairs for the lag
!        e) the mean of the data contributing to the tail
!        f) the mean of the data contributing to the head
!
!
!
! Original: C.V. Deutsch                                 Date: July 1990
!-----------------------------------------------------------------------
!      include  'gam2.inc'
      real      vr(MAXX,MAXY,MAXVAR)
      real*8    gam(MXDLV),hm(MXDLV),tm(MXDLV),hv(MXDLV),tv(MXDLV),&
                np(MXDLV)
      integer   ixd(MAXDIR),iyd(MAXDIR),ivtail(MXVARG),ivhead(MXVARG),&
                ivtype(MXVARG)
      character outfl*40,names(MAXVAR)*12
			call initpar()
!
! Read the Parameter File:
!
      call readparm(nlag,nx,ny,xsiz,ysiz,ndir,ixd,iyd,vr,tmin,tmax, &
                    nvarg,ivtail,ivhead,ivtype,outfl,names)
!
! Call gam2 to compute the required variograms:
!
      call gam2(nlag,nx,ny,ndir,ixd,iyd,vr,tmin,tmax,nvarg,ivtail, &
                ivhead,ivtype,np,gam,hm,tm,hv,tv)
!
! Write Results and stop:
!
      call writeout(nlag,ndir,ixd,iyd,xsiz,ysiz,nvarg,ivtail,ivhead,&
                    ivtype,np,gam,hm,tm,hv,tv,outfl,names)
      stop
      end
 
 
