*"$@I=Bj(J $@%H!<%sCJ:L(J GTOOL3(GGSTON)
*
*"$@MzNr(J 92/07/08 $@>B8}(J  $@FX(J
*"     95/05/26 $@C]9-??0l(J for dcl-5.0
*"     96/06/21 $@C]9-??0l(J bug fixes 
*
*
*********************************************************************
*"         << $@%H!<%sCJ:L(J >>
*********************************************************************
      SUBROUTINE GGSTON
     I         ( HHEAD , GDATA  )
*
      CHARACTER  HHEAD ( * )*(*)         !" $@%X%C%@!<(J
      REAL       GDATA ( * )             !" $@%G!<%?(J
*
*"         < 1. $@%5%$%:(J >
*
      CALL GUSMIS ( HHEAD )
*
      CALL GHPGET ( HHEAD, 'ASTR1', IXSTR )
      CALL GHPGET ( HHEAD, 'AEND1', IXEND )
      CALL GHPGET ( HHEAD, 'ASTR2', IYSTR )
      CALL GHPGET ( HHEAD, 'AEND2', IYEND )
      IXDIM = IXEND-IXSTR+1
      IYDIM = IYEND-IYSTR+1
*
*"         < 2. $@%H!<%s%l%Y%k(J >
*
      CALL GHPGET ( HHEAD, 'MISS' , VMISS )
      CALL GHPGET ( HHEAD, 'DMIN' , DMIN  )
      CALL GHPGET ( HHEAD, 'DMAX' , DMAX  )
      CALL GHPGET ( HHEAD, 'DIVS' , DIVS  )
*
      CALL GGPGET ( 'TONESET', ITNSET )
      IF ( ITNSET .LE. 0 ) THEN
         CALL UEITLV
      ENDIF
*
      CALL GGPGET ( 'NTONE',    NL    )
      CALL GGPGET ( 'TONEPAT',  IPAT1 ) 
      CALL GGPGET ( 'TONEINC',  IPINC ) 
*
      CALL GGPGET( 'CONRFCT', CONFAC )
      IF      ( (DMIN.EQ.VMISS) .AND. (DMAX.NE.VMISS) ) THEN
         CONFAC = 1.
      ELSE IF ( (DMIN.NE.VMISS) .AND. (DMAX.EQ.VMISS) ) THEN
         CONFAC = 0.
      ENDIF
*
      IF ( ITNSET .NE. 1 ) THEN
*
         GMIN = RMIN( GDATA, IXDIM*IYDIM, 1 )    !" $@%G!<%?:G>.CM(J
         GMAX = RMAX( GDATA, IXDIM*IYDIM, 1 )    !" $@%G!<%?:GBgCM(J
         IF (GMIN.EQ.GMAX) RETURN                !" $@0lDj(J -> $@%H!<%s%l%Y%k@_Dj$;$:(J
*
         IF       ( DMIN .EQ. VMISS  .AND. DMAX .EQ. VMISS ) THEN
            DMIN = GMIN
            DMAX = GMAX
         ELSE IF  ( DMIN .EQ. VMISS  .AND. DMAX .NE. VMISS ) THEN
            DMIN = GMIN
         ELSE IF  ( DMIN .NE. VMISS  .AND. DMAX .EQ. VMISS ) THEN
            DMAX = GMAX
         ENDIF
*
         IF  (DIVS .EQ. VMISS) THEN                  !" $@L\@94V3V(J($@>.(J)$@L$@_Dj;~(J
            DIVS = RGNGE((DMAX-DMIN)/NL)
            ZMIN = IRLE(DMIN/DIVS)*DIVS      !" fixed by S.Takehiro(96/06/21)
            ZMAX = IRGE(DMAX/DIVS)*DIVS      !" fixed by S.Takehiro(96/06/21)
         ELSE                                     !" $@L\@94V3V(J($@>.(J)$@@_Dj;~(J
            ZMIN = IRLE(DMIN/DIVS)*DIVS      !" fixed by S.Takehiro(96/06/21)
            ZMAX = IRGE(DMAX/DIVS)*DIVS      !" fixed by S.Takehiro(96/06/21)
*     
            NUMTON = NINT( (ZMAX-ZMIN)/DIVS  ) + 1   !" $@%H!<%s%l%Y%k?t(J
            IF ( NUMTON .GT. NL ) THEN               !" NL $@$^$G%H!<%s%l%Y%k$r@_Dj(J
               RANGE = DIVS * NL             !" $@%H!<%sIA2hHO0OI}(J 
*                                            !" fixed by S.Takehiro(96/06/21)
               ZMIN  = ZMIN 
     &                + CONFAC*( ZMAX-ZMIN - RANGE ) !" CONFAC=0 : $@Bg$-$$B&$r>JN,(J
               ZMAX  = ZMIN + RANGE                  !" CONFAC=1 : $@>.$5$$B&$r>JN,(J
            ELSE
               NL = NUMTON 
            ENDIF
         ENDIF
*
         DO 3100 I = 1, NL
            CALL UESTLV ( ZMIN+(I-1)*DIVS, ZMIN+I*DIVS, 
     &                    IPAT1+IPINC*(I-1) )
 3100    CONTINUE
*
         CALL GGPSET( 'TONESET', 2 )
*
      ENDIF
*
      RETURN
      END
