* PACKAGE GTADD   !" ΟΒ
*********************************************************************
      PROGRAM GTADD
*
#ifdef SYS_IBMS
      INCLUDE    (GTSINC)
      INCLUDE    (GZSIZE)
#else
#include         "gtsinc.F"
#include         "gzsize.F"
#endif
      COMMON     /GMWORK/ MWORK
      REAL       MWORK  ( IJKDIM )
*
      CHARACTER  HHEAD1( NDC )*(NCC)
      REAL       GDATA1( IJKDIM )
      CHARACTER  HHEAD2( NDC )*(NCC)
      REAL       GDATA2( IJKDIM )
      CHARACTER  HFILE( 2 ) *(NFILN)
      DATA       HFILE  / '$GTTMPDIR/gtool.out',
     &                    '$GTTMPDIR/gtool.out' /
      INTEGER    IFILE( 2 ) 
      DATA       IFILE  / 50, 51 /
      DATA       JFILE  / 60 /
*
      REAL       OFS1,  OFS2
      DATA       OFS1,  OFS2  / 0.0, 0.0 /
      REAL       FACT1, FACT2
      DATA       FACT1, FACT2 / 1.0, 1.0 /
      REAL       VAL
      DATA       VAL    / 1.0 /
      REAL       OFS , FACT
      DATA       OFS , FACT   / 0.0, 1.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 /4*' '/
*
      DATA       EDIT, ETTL /'ADD','<gtadd>'/
*
      LOGICAL    GRESET
      DATA       GRESET / .TRUE. /
      LOGICAL    HELP
      DATA       HELP   / .FALSE. /
*
      NAMELIST  /OPTION/ OFS1, OFS2, FACT1, FACT2, 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 ( HHEAD1, IJKDIM )
      CALL GTSIZE ( HHEAD2, IJKDIM )
      CALL GMSIZE ( IJKDIM  )
*
      CALL GURNTF ( HFILE( 1 ), OUT  , '$GTTMPDIR/gtool.in' )
      CALL GURNTF ( HFILE( 2 ), OUT  , '$GTTMPDIR/gtool.in' )
*
      CALL GFROPN ( IFILE( 1 ), HFILE( 1 ) )
      IF ( HFILE( 1 ) .NE. HFILE( 2 ) ) THEN
         CALL GFROPN ( IFILE( 2 ), HFILE( 2 ) )
      ENDIF
      CALL GFOOPN ( JFILE, OUT , APND )
*
      CALL GUNENV( OUT,'.',.FALSE. )
      IL=LENC(OUT)
      WRITE (6,*) 'output='//OUT(1:IL)
*
 1100 CONTINUE
*
         CALL   GFREAD
     O        ( HHEAD1, GDATA1, IEOD1 ,
     I          IFILE( 1 ), 1               )
*
         IEOD2 = 0
         IF ( HFILE( 1 ) .NE. HFILE( 2 ) ) THEN
            CALL   GFREAD
     O        ( HHEAD2, GDATA2, IEOD2 ,
     I          IFILE( 2 ), 1               )
         ELSE
            CALL   GPFSET
     I        ( HHEAD1, GDATA1,
     I          '  '  , '  '  ,
     O          HHEAD2, GDATA2  )
            WRITE (6,*) '** DUPLEX'
         ENDIF
*
         IF ( MAX( IEOD1,IEOD2 ) .EQ. 0 ) THEN
*
           IF ( OFS1 .NE. 0.0 ) THEN
              CALL GMFINC
     I        ( HHEAD1, GDATA1, OFS1 ,
     I          '  '  , '  '           )
           ENDIF
           IF ( FACT1 .NE. 1.0 ) THEN
              CALL GMFFCT
     I        ( HHEAD1, GDATA1, FACT1   ,
     I          '  '  , '  '           )
           ENDIF
*
           IF ( OFS2 .NE. 0.0 ) THEN
              CALL GMFINC
     I        ( HHEAD2, GDATA2, OFS2 ,
     I          '  '  , '  '           )
           ENDIF
           IF ( FACT2 .NE. 1.0 ) THEN
              CALL GMFFCT
     I        ( HHEAD2, GDATA2, FACT2 ,
     I          '  '  , '  '           )
           ENDIF
*
           CALL GMFADD
     I        ( HHEAD1, GDATA1,
     I          HHEAD2, GDATA2,
     I          EDIT  , ETTL   )
*
           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  GFWRIT
     I         ( HHEAD1, GDATA1,
     I           JFILE , 1     , 0       )
*
      GOTO 1100
         ENDIF
*
      STOP
      END
