*"表題 トーン段彩 GTOOL3(GGSTON)
*
*"履歴 92/07/08 沼口  敦
*"     95/05/26 竹広真一 for dcl-5.0
*"     96/06/21 竹広真一 bug fixes 
*
*
*********************************************************************
*"         << トーン段彩 >>
*********************************************************************
      SUBROUTINE GGSTON
     I         ( HHEAD , GDATA  )
*
      CHARACTER  HHEAD ( * )*(*)         !" ヘッダー
      REAL       GDATA ( * )             !" データ
*
*"         < 1. サイズ >
*
      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. トーンレベル >
*
      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 )    !" データ最小値
         GMAX = RMAX( GDATA, IXDIM*IYDIM, 1 )    !" データ最大値
         IF (GMIN.EQ.GMAX) RETURN                !" 一定 -> トーンレベル設定せず
*
         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                  !" 目盛間隔(小)未設定時
            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                                     !" 目盛間隔(小)設定時
            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   !" トーンレベル数
            IF ( NUMTON .GT. NL ) THEN               !" NL までトーンレベルを設定
               RANGE = DIVS * NL             !" トーン描画範囲幅 
*                                            !" fixed by S.Takehiro(96/06/21)
               ZMIN  = ZMIN 
     &                + CONFAC*( ZMAX-ZMIN - RANGE ) !" CONFAC=0 : 大きい側を省略
               ZMAX  = ZMIN + RANGE                  !" CONFAC=1 : 小さい側を省略
            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
