*"表題 1つの軸を描き座標設定 GTOOL3(GGAXSZ)
*
*"履歴 90/08/18 沼口  敦
*"     95/06/05 竹広真一 for dcl-5.0
*"     95/11/08 竹広真一 異なる複数軸ファイルに対応
*"     97/12/01 竹広真一 SET -> STX
*
*********************************************************************
*"         << 1つの軸を描き座標設定 >>
*********************************************************************
      SUBROUTINE GGAXSZ
     I         ( HHEAD , AXISZ , HPOS  )
*
      CHARACTER  HHEAD ( * )*(*)         !" ヘッダー
      REAL       AXISZ ( * )             !" 格子位置
      CHARACTER  HPOS *(*)               !" セットする軸 ('X' or 'Y')
*
#ifdef SYS_IBMS
      INCLUDE    (GZSIZE)                !" NCC, NDC, NED
#else
#include         "gzsize.F"              !" NCC, NDC, NED
#endif
      CHARACTER  HTITL*(NCC)      
      CHARACTER  HTITLZ( 2 )*(NCC)
      CHARACTER  HSIDE *2, HSIDEL *2
      REAL       AZMINZ( 2 )
      REAL       AZMAXZ( 2 )
      LOGICAL    OSETZ ( 2 )
      SAVE       AZMINZ, AZMAXZ, OSETZ, HTITLZ
*
*"         < 1. すでに設定されていれば何もしない >
*
      IF      ( HPOS(1:1) .EQ. 'X' ) THEN
         IIZ = 1
      ELSE IF ( HPOS(1:1) .EQ. 'Y' ) THEN
         IIZ = 2
      ELSE
         CALL MSGDMP('E','GGAXSZ','INVALID AXIS SPECIFIER.' )
      ENDIF
*
      IF  ( OSETZ( IIZ ) ) THEN
         CALL GHCGET ( HHEAD, 'TITL1', HTITL ) !" 設定されている軸と
         CALL CLADJ( HTITL )                   !" 同じかどうか check
         IF( HTITL .NE. HTITLZ(IIZ) )THEN
            CALL MSGDMP('W','GGAXSZ','TITLE OF AXIS IS DIFFERENT' )
         ENDIF
                                             RETURN
      ELSE
            OSETZ( IIZ ) = .TRUE.
      ENDIF
*
*"         < 2. 文字の大きさ等 >
*
      CALL GGPGET ( 'SAXSL'  , SAXSL )
      CALL GGPGET ( 'SAXST'  , SAXST )
      CALL UZPSTX ( 'RSIZEL1', SAXSL )
      CALL UZPSTX ( 'RSIZEC1', SAXST )
*
*"         < 3. ウィンドウ範囲 >
*
      CALL GHPGET ( HHEAD, 'ASTR1', IZSTR )
      CALL GHPGET ( HHEAD, 'AEND1', IZEND )
      CALL GHCGET ( HHEAD, 'TITL1', HTITL )
      HTITLZ(IIZ) = HTITL
      CALL CLADJ( HTITLZ(IIZ) )
*
      CALL GHPGET ( HHEAD , 'MISS' , VMISZ )
      CALL GLPGET ( 'RUNDEF', RUNDEF )
*
      CALL GHPGET ( HHEAD , 'DMIN' , DMINZ )
      CALL GHPGET ( HHEAD , 'DMAX' , DMAXZ )
      CALL GHPGET ( HHEAD , 'DIVS' , DIVSZ )
      CALL GHPGET ( HHEAD , 'DIVL' , DIVLZ )
      IF ( DMINZ .EQ. VMISZ ) DMINZ = RUNDEF
      IF ( DMAXZ .EQ. VMISZ ) DMAXZ = RUNDEF
      IF ( DIVSZ .EQ. VMISZ ) DIVSZ = RUNDEF
      IF ( DIVLZ .EQ. VMISZ ) DIVLZ = RUNDEF
*
*"         < 4. 範囲のセット >
*
      CALL GUSMIS( HHEAD )
*
      IF ( HPOS(1:1) .EQ. 'X' ) THEN
         CALL USSPNT( IZEND-IZSTR+1, AXISZ, RUNDEF)
         CALL USRGET('XDTMIN', DMINQ)
         CALL USRGET('XDTMAX', DMAXQ)
      ELSE
         CALL USSPNT( IZEND-IZSTR+1, RUNDEF, AXISZ )
         CALL USRGET('YDTMIN', DMINQ)
         CALL USRGET('YDTMAX', DMAXQ)
      ENDIF
*
      CALL GHPGET ( HHEAD, 'STYP', ISTYP )
*
      IF ( DIVLZ .NE. RUNDEF ) THEN
         IF      ( DMINZ .NE. RUNDEF .AND.
     &             DMAXZ .NE. RUNDEF       ) THEN
            IF ( DMAXZ-DMINZ .LT. DIVLZ ) THEN
               DIVLZ = DMAXZ-DMINZ
            ENDIF
         ELSE IF ( DMINZ .NE. RUNDEF ) THEN
            IF ( DMAXQ .LT. DMINZ+DIVLZ ) THEN
               DMAXZ = DMINZ + DIVLZ
            ENDIF
         ELSE IF ( DMAXZ .NE. RUNDEF ) THEN
            IF ( DMINQ .GT. DMAXZ-DIVLZ ) THEN
               DMINZ = DMAXZ - DIVLZ
            ENDIF            
         ELSE
            DMINZ =  IGUS( DMINQ/DIVLZ )*DIVLZ
            DMAXZ = -IGUS(-DMAXQ/DIVLZ )*DIVLZ
         ENDIF
      ENDIF

      IF ( HPOS(1:1) .EQ. 'X' ) THEN
         IF ( ISTYP .GT. 0 ) THEN
            CALL USPSTX( 'LXINV', .FALSE. )
         ELSE
            CALL USPSTX( 'LXINV', .TRUE. )
         ENDIF
         CALL SGPSTX( 'UXMIN', DMINZ  )
         CALL SGPSTX( 'UXMAX', DMAXZ  )
         CALL USPSTX( 'DXT' , DIVSZ )
         CALL USPSTX( 'DXL' , DIVLZ )
      ELSE
         IF ( ISTYP .GT. 0 ) THEN
            CALL USPSTX( 'LYINV', .FALSE. )
         ELSE
            CALL USPSTX( 'LYINV', .TRUE. )
         ENDIF
         CALL SGPSTX( 'UYMIN', DMINZ  )
         CALL SGPSTX( 'UYMAX', DMAXZ  )
         CALL USPSTX( 'DYT' , DIVSZ )
         CALL USPSTX( 'DYL' , DIVLZ )
      ENDIF
*
*"         < 5. 座標設定 >
*
      IF ( ABS( ISTYP ) .LE. 2 ) THEN
         CALL SGPGET( 'ITR',ITR )
         IF ( HPOS(1:1) .EQ. 'X' ) THEN
            ITR = MOD(ITR-1,2)+1 + ( ABS( ISTYP )-1 )*2 
         ELSE
            ITR = ((ITR-1)/2) * 2 + ABS( ISTYP ) 
         ENDIF
         CALL SGPSTX( 'ITR',ITR )
      ELSE
         CALL MSGDMP('E','GGAXSZ','INVALID ISTYP.' )
      ENDIF
*
      CALL USPFIT
      CALL GRSTRF
*
*"         < 6. 座標軸を描く >
*
      IF ( HPOS(1:1) .EQ. 'X' ) THEN
         CALL GGAXLZ ( 'X' )

         CALL GGPGET ( 'INNER', INNER )
         CALL UZPSTX ( 'INNER', INNER )
         CALL GGCGET ( 'CXSIDE', HSIDE )
         NCS = LENZ(HSIDE)
         DO 6100 N=1, NCS
            CALL USXAXS(HSIDE(N:N))
 6100    CONTINUE

         CALL GGCGET ( 'CXSIDEL', HSIDEL )
         IF ( INDEX(HSIDEL,HSIDE(1:1)) .GE. 1 ) THEN
            IF (LENZ(HTITL).NE.0) CALL UXSTTL(HSIDE(1:1), HTITL, 0.)
         ENDIF

         CALL UZPSTX ( 'INNER', -INNER )
         CALL GGCGET ( 'CXSIDET', HSIDE )
         NCS = LENZ(HSIDE)
         DO 6110 N=1, NCS
            CALL UXPTMK(HSIDE(N:N),1,AXISZ,IZEND-IZSTR+1 )
 6110    CONTINUE
         CALL UZPSTX ( 'INNER', INNER )
*
      ELSE
         CALL GGAXLZ ( 'Y' )

         CALL GGPGET ( 'INNER', INNER )
         CALL UZPSTX ( 'INNER', INNER )
         CALL GGCGET ( 'CYSIDE', HSIDE )
         NCS = LENZ(HSIDE)
         DO 6200 N=1, NCS
            CALL USYAXS(HSIDE(N:N))
 6200    CONTINUE

         CALL GGCGET ( 'CYSIDEL', HSIDEL )
         IF ( INDEX(HSIDEL,HSIDE(1:1)) .GE. 1 ) THEN
            IF (LENZ(HTITL).NE.0) CALL UYSTTL(HSIDE(1:1), HTITL, 0.)
         ENDIF
*
         CALL UZPSTX ( 'INNER', -INNER )
         CALL GGCGET ( 'CYSIDET', HSIDE )
         NCS = LENZ(HSIDE)
         DO 6210 N=1, NCS
            CALL UYPTMK(HSIDE(N:N),1,AXISZ,IZEND-IZSTR+1 )
 6210    CONTINUE
         CALL UZPSTX ( 'INNER', INNER )
       ENDIF
*
      RETURN
*=====================================================================
*"         << 軸の座標範囲の設定 >>
*=====================================================================
      ENTRY      GGRANG
     I         ( HHEAD , AXISZ , HPOS  )
*
      CALL GHPGET ( HHEAD, 'ASTR1', IZSTR )
      CALL GHPGET ( HHEAD, 'AEND1', IZEND )
      CALL GLPGET ( 'RUNDEF', RUNDEF )
*
      CALL GUSMIS ( HHEAD )
*
      IF ( HPOS(1:1) .EQ. 'X' ) THEN
         CALL USSPNT( IZEND-IZSTR+1, AXISZ, RUNDEF)
      ELSE
         CALL USSPNT( IZEND-IZSTR+1, RUNDEF, AXISZ)
      ENDIF
*
      RETURN
*=====================================================================
*"         << X or Y 軸のリセット >>
*=====================================================================
      ENTRY      GGAXRR( HPOS )
*
      CALL GTPGET ( 'MISS', VMISD )
*
      IF      ( HPOS(1:1) .EQ. 'X' ) THEN
         IIZ = 1
         CALL SGPSTX( 'UXMIN', 0.  )
         CALL SGPSTX( 'UXMAX', 1.  )
      ELSE IF ( HPOS(1:1) .EQ. 'Y' ) THEN
         IIZ = 2
         CALL SGPSTX( 'UYMIN', 0.  )
         CALL SGPSTX( 'UYMAX', 1.  )
      ENDIF
*
      AZMINZ( IIZ ) = VMISD
      AZMAXZ( IIZ ) = VMISD
      OSETZ ( IIZ ) = .FALSE.
*
      RETURN
      END
*=====================================================================
*"         << 軸描画のリセット >>
*=====================================================================
      SUBROUTINE GGAXRS
*
      CALL GGAXRR( 'X' )
      CALL GGAXRR( 'Y' )
*
      RETURN
      END
*=====================================================================
*"         << 軸ラベルの描画フラグ >>
*=====================================================================
      SUBROUTINE GGAXLZ ( HPOS )
*
      CHARACTER  HPOS   * 1
      CHARACTER  HSIDEL * 2
*
      IF ( HPOS .EQ. 'X' ) THEN
         CALL GGCGET ( 'CXSIDEL', HSIDEL )
         IF ( INDEX( HSIDEL, 'B' ) .GE. 1 ) THEN
            CALL UZPSTX('LABELXB',.TRUE.)
         ELSE
            CALL UZPSTX('LABELXB',.FALSE.)            
         ENDIF
         IF ( INDEX( HSIDEL, 'T' ) .GE. 1 ) THEN
            CALL UZPSTX('LABELXT',.TRUE.)
         ELSE
            CALL UZPSTX('LABELXT',.FALSE.)            
         ENDIF
         IF ( INDEX( HSIDEL, 'U' ) .GE. 1 ) THEN
            CALL UZPSTX('LABELXU',.TRUE.)
         ELSE
            CALL UZPSTX('LABELXU',.FALSE.)            
         ENDIF
*
      ELSE IF ( HPOS .EQ. 'Y' ) THEN
         CALL GGCGET ( 'CYSIDEL', HSIDEL )
         IF ( INDEX( HSIDEL, 'L' ) .GE. 1 ) THEN
            CALL UZPSTX('LABELYL',.TRUE.)
         ELSE
            CALL UZPSTX('LABELYL',.FALSE.)            
         ENDIF
         IF ( INDEX( HSIDEL, 'R' ) .GE. 1 ) THEN
            CALL UZPSTX('LABELYR',.TRUE.)
         ELSE
            CALL UZPSTX('LABELYR',.FALSE.)            
         ENDIF
         IF ( INDEX( HSIDEL, 'U' ) .GE. 1 ) THEN
            CALL UZPSTX('LABELYU',.TRUE.)
         ELSE
            CALL UZPSTX('LABELYU',.FALSE.)            
         ENDIF
      ELSE
         CALL MSGDMP('E','GGAXLZ','INVALID AXIS SPECIFIER.' )
      ENDIF
*
      RETURN
      END
