* PACKAGE GTAVR     !"  系列平均
*******************************************************************
      PROGRAM GTAVR
*
#ifdef SYS_IBMS
      INCLUDE    (GTSINC)
      INCLUDE    (GZSIZE)
#else
#include         "gtsinc.F"
#include         "gzsize.F"
#endif
*
      CHARACTER  HHEAD ( NDC )*(NCC)
      REAL       GDATA ( IJKDIM )
      CHARACTER  HHEAD1( NDC )*(NCC)
      REAL       GDATA1( IJKDIM )
      CHARACTER  HHEADW( NDC )*(NCC)
      REAL       GDATAW( IJKDIM )
*
      CHARACTER  HFILE( 1 ) *(NFILN)
      DATA       HFILE / '$GTTMPDIR/gtool.out' /
      DATA       IFILE / 50 /
      DATA       JFILE / 60 /
*
      LOGICAL    WEIGHT
      DATA       WEIGHT / .FALSE. /
      INTEGER    STR, END, STEP
      DATA       STR, END, STEP / 1, 9999999, 1 /
      INTEGER    OSTEP
      DATA       OSTEP  / 0 /
      CHARACTER  OUT    *(NFILN)
      DATA       OUT    / '$GTTMPDIR/gtool.out' /
      LOGICAL    APND
      DATA       APND   / .FALSE. /
      CHARACTER  ITEM   *(NCC)
      CHARACTER  UNIT   *(NCC)
      CHARACTER  TITLE  *(NCC*2)
      CHARACTER  DSET   *(NCC)
      CHARACTER  EDIT   *(NCC)
      CHARACTER  ETTL   *(NCC)
      DATA       ITEM, UNIT, TITLE, DSET, EDIT, ETTL /6*' '/
      LOGICAL    GRESET
      DATA       GRESET / .FALSE. /
      LOGICAL    HELP
      DATA       HELP   / .FALSE. /
*
      NAMELIST  /OPTION/ WEIGHT, STR, END, STEP, OSTEP, OUT, APND,
     &                   ITEM, UNIT, TITLE, DSET, EDIT, ETTL, GRESET,
     &                   HELP, HFILE
*
      CALL OPTARG ( 91, 'OPTION', 'HFILE', NOPT, NFILE )
      READ (91,OPTION,IOSTAT=IOS)
      CLOSE(91)
      IF ( IOS.NE.0 .OR. HELP ) THEN
 
         WRITE(6,OPTION)
         STOP
      ENDIF
*
      CALL GTOPEN
      CALL GTSIZE ( HHEAD , IJKDIM )
      CALL GTSIZE ( HHEAD1, IJKDIM )
      CALL GTSIZE ( HHEADW, IJKDIM )
*
      CALL GURNTF ( HFILE( 1 ), OUT  , '$GTTMPDIR/gtool.in' )
*
      CALL GFROPN ( IFILE, HFILE( 1 ) )
*
      CALL GUNENV( OUT,'.',.FALSE. )
      IL=LENC(OUT)
      WRITE (6,*) 'output='//OUT(1:IL)
*
      CALL GPTAVR ( HHEAD1 )
*
      II = 0
      III = 0
 1100 CONTINUE
         CALL   GFREAD
     O        ( HHEAD , GDATA , IEOD  ,
     I          IFILE , 1               )
*
         IF ( IEOD.EQ.0 ) THEN
            II = II + 1
*
            IF ( ( II.GE.STR ).AND.( II.LE.END ).AND.
     &           ( MOD( II-STR,STEP ).EQ.0 )          ) THEN         
*
               III = III + 1
               IF ( .NOT. WEIGHT ) THEN
                  CALL GHPSET( HHEAD, 'TDUR', 1  )
               ENDIF
               CALL GPTAVG
     I         ( HHEAD , GDATA ,
     I           EDIT  , ETTL  ,
     M           HHEADW, GDATAW,
     O           HHEAD1, GDATA1 )
*
               IF ( OSTEP .GT. 0 ) THEN
                  IF ( III .EQ. OSTEP ) THEN
                     GOTO 2100
                  ENDIF
               ENDIF
*
            ENDIF
*
            IF ( II .LT. END ) THEN
               GOTO 1100
            ENDIF
         ENDIF
*
 2100    CONTINUE 
*
         IF ( III .GT. 0 ) THEN
            CALL GPTAVO
     M         ( HHEADW, GDATAW ,
     M           HHEAD1, GDATA1  )
*
            IF ( ITEM .NE. ' ' ) THEN
               CALL GHCSET( HHEAD1, 'ITEM', ITEM )
            ENDIF
            IF ( UNIT .NE. ' ' ) THEN
               CALL GHCSET( HHEAD1, 'UNIT', UNIT )
            ENDIF
            IF ( TITLE .NE. ' ' ) THEN
               CALL GHCSTS( HHEAD1, 'TITL', TITLE )
            ENDIF
            IF ( DSET .NE. ' ' ) THEN
               CALL GHCSET( HHEAD1, 'DSET', DSET )
            ENDIF
*
            IF ( GRESET ) THEN
               CALL GHRSGP( HHEAD1  )
            ENDIF
*
            CALL  GFOOPN ( JFILE,  OUT , APND )
*
            CALL  GFWRIT
     I               ( HHEAD1, GDATA1,
     I                 JFILE , 1     , 0       )
*
            CALL GPTAVR ( HHEAD1 )
            III = 0
*
         ENDIF
         IF ( (IEOD .EQ. 0) .AND. (II .LT. END) ) THEN
            GOTO 1100
         ENDIF
*
      STOP
      END
