!+ <A one line description of this subroutine>
!
! Method:
!	Two archives are read and their headers and entries are
!	simply concatenated.
!
! Current Owner of Code: J. M. Edwards
!
! History:
!	Version		Date			Comment
!	1.0		12-04-95		First Version under RCS
!						(J. M. Edwards)
!
! Description of Code:
!   FORTRAN 77  with extensions listed in documentation.
!
!- ---------------------------------------------------------------------
      SUBROUTINE CONCAT_ARCH(IERR, IUNIT_OUT
     &   , IUNIT_1, N_ENTRY_1
     &   , DATE_1, DATABASE_1, LBL_CODE_1
     &   , LINESHAPE_1, CUTOFF_1, CONTINUUM_1, LINE_COUPLE_1
     &   , I_GAS_1, P_1, T_1, AMOUNT_1, PARTIAL_P_1
     &   , FREQ_ENTRY_LOW_1, FREQ_ENTRY_HIGH_1
     &   , N_TRANS_RECORD_1, I1_RECORD_1, N_TRANS_1
     &   , IUNIT_2, N_ENTRY_2
     &   , DATE_2, DATABASE_2, LBL_CODE_2
     &   , LINESHAPE_2, CUTOFF_2, CONTINUUM_2, LINE_COUPLE_2
     &   , I_GAS_2, P_2, T_2, AMOUNT_2, PARTIAL_P_2
     &   , FREQ_ENTRY_LOW_2, FREQ_ENTRY_HIGH_2
     &   , N_TRANS_RECORD_2, I1_RECORD_2, N_TRANS_2
     &   )
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/dimensions_arch.ucf'
      INCLUDE 'incl/arch_record_size.pcf'
      INCLUDE 'incl/error.pcf'
!
!
!     DUMMY ARGUMENTS.
!
      INTEGER	!, INTENT(IN)
     &     IERR
!             ERROR FLAG
     &   , IUNIT_1
!             UNIT NUMBER FOR FIRST ARCHIVE
     &   , IUNIT_2
!             UNIT NUMBER FOR SECOND ARCHIVE
     &   , IUNIT_OUT
!             UNIT NUMBER FOR OUPUT
!
!     PROPERTIES OF FIRST ARCHIVE:
      INTEGER	!, INTENT(IN)
     &     N_ENTRY_1
!             NUMBER OF ENTRIES IN FIRST ARCHIVE
     &   , LINESHAPE_1(NPD_ARCH_ENTRY)
!             LINE SHAPES IN FIRST ARCHIVE
     &   , I_GAS_1(NPD_ARCH_ENTRY)
!             IDENTITIES OF GASES IN 1ST ARCHIVE
     &   , N_TRANS_RECORD_1(NPD_ARCH_ENTRY)
!             NUMBER OF RECORDS
     &   , I1_RECORD_1(NPD_ARCH_ENTRY)
!             POINTERS TO 1ST RECORD OF ENTRY
     &   , N_TRANS_1(NPD_ARCH_ENTRY)
!             NUMBER OF TRANSMISSIONS IN ENTRY
     &   , DATABASE_1(NPD_ARCH_ENTRY)
!             DATABASES IN FIRST ARCHIVE
     &   , LBL_CODE_1(NPD_ARCH_ENTRY)
!             LBL CODES IN FIRST ARCHIVE
      CHARACTER	!, INTENT(IN)
     &     DATE_1(NPD_ARCH_ENTRY)*9
!             DATES IN FIRST ARCHIVE
      LOGICAL	!, INTENT(IN)
     &     LINE_COUPLE_1(NPD_ARCH_ENTRY)
!             LINE COUPLING IN 1ST ARCHIVE
     &   , CONTINUUM_1(NPD_ARCH_ENTRY)
!             CONTINUUM IN 1ST ARCVIVE
      REAL*8	!, INTENT(IN)
     &     CUTOFF_1(NPD_ARCH_ENTRY)
!             LINE CUTOFFS IN FIRST ARCHIVE
     &   , P_1(NPD_ARCH_ENTRY)
!             PRESSURES IN FIRST ARCHIVES
     &   , T_1(NPD_ARCH_ENTRY)
!             TEMPERATURES IN FIRST ARCHIVES
     &   , AMOUNT_1(NPD_ARCH_ENTRY)
!             AMOUNTS IN FIRST ARCHIVE
     &   , PARTIAL_P_1(NPD_ARCH_ENTRY)
!             PARTIAL PRESSURES IN FIRST ARCHIVE
     &   , FREQ_ENTRY_LOW_1(NPD_ARCH_ENTRY)
!             LOW FREQUENCY LIMITS OF ENTRIES
     &   , FREQ_ENTRY_HIGH_1(NPD_ARCH_ENTRY)
!             HIGH FREQUENCY LIMITS OF ENTRIES
!
!     PROPERTIES OF SECOND ARCHIVE.
      INTEGER	!, INTENT(IN)
     &     N_ENTRY_2
!             NUMBER OF ENTRIES IN 2ND ARCHIVE
     &   , LINESHAPE_2(NPD_ARCH_ENTRY)
!             LINE SHAPES IN 2ND ARCHIVE
     &   , I_GAS_2(NPD_ARCH_ENTRY)
!             IDENTITIES OF GASES IN 2ND ARCHIVE
     &   , N_TRANS_RECORD_2(NPD_ARCH_ENTRY)
!             NUMBER OF RECORDS
     &   , I1_RECORD_2(NPD_ARCH_ENTRY)
!             POINTERS TO 1ST RECORD OF ENTRY
     &   , N_TRANS_2(NPD_ARCH_ENTRY)
!             NUMBER OF TRANSMISSIONS IN ENTRY
     &   , DATABASE_2(NPD_ARCH_ENTRY)
!             DATABASES IN SECOND ARCHIVE
     &   , LBL_CODE_2(NPD_ARCH_ENTRY)
!             LBL CODES IN SECOND ARCHIVE
      CHARACTER	!, INTENT(IN)
     &     DATE_2(NPD_ARCH_ENTRY)*9
!             DATES IN SECOND ARCHIVE
      LOGICAL	!, INTENT(IN)
     &     LINE_COUPLE_2(NPD_ARCH_ENTRY)
!             LINE COUPLING IN 2ND ARCHIVE
     &   , CONTINUUM_2(NPD_ARCH_ENTRY)
!             CONTINUUM IN 2ND ARCVIVE
      REAL*8	!, INTENT(IN)
     &     CUTOFF_2(NPD_ARCH_ENTRY)
!             LINE CUTOFFS IN 2ND ARCH
     &   , P_2(NPD_ARCH_ENTRY)
!             PRESSURES IN 2ND ARCHIVES
     &   , T_2(NPD_ARCH_ENTRY)
!             TEMPERATURES IN 2ND ARCHIVES
     &   , AMOUNT_2(NPD_ARCH_ENTRY)
!             AMOUNTS IN 2ND ARCHIVE
     &   , PARTIAL_P_2(NPD_ARCH_ENTRY)
!             PARTIAL PRESSURES IN 2ND ARCHIVE
     &   , FREQ_ENTRY_LOW_2(NPD_ARCH_ENTRY)
!             LOW FREQUENCY LIMITS OF ENTRIES
     &   , FREQ_ENTRY_HIGH_2(NPD_ARCH_ENTRY)
!             HIGH FREQUENCY LIMITS OF ENTRIES
!
!
!     LOCAL VARIABLES
!
      INTEGER
     &     N_PER_ARCH_RECORD
!             NUMBER INTERVALS IN ONE RECORD.
!
!     PROPERTIES OF MERGED ARCHIVE:
      INTEGER
     &     I_VERSION_M
!             VERSION OF EDITED ARCHIVE
     &   , N_ENTRY_M
!             NUMBER OF ENTRIES IN MERGED FILE
     &   , DATABASE_M(NPD_ARCH_ENTRY)
!             DATABASES USED
     &   , LBL_CODE_M(NPD_ARCH_ENTRY)
!             LBL CODES USED
     &   , LINESHAPE_M(NPD_ARCH_ENTRY)
!             LINE SHAPES IN MERGED FILE
     &   , I_GAS_M(NPD_ARCH_ENTRY)
!             IDENTITIES OF GASES IN MERGED FILE
     &   , N_TRANS_RECORD_M(NPD_ARCH_ENTRY)
!             NUMBER OF RECORDS IN MERGED FILE
     &   , I1_RECORD_M(NPD_ARCH_ENTRY)
!             POINTERS TO FIRST RECORD OF ENTRY
     &   , N_TRANS_M(NPD_ARCH_ENTRY)
!             TRANSMISSIONS IN MERGED ARCHIVE
     &   , OFFSET
!             OFFSET OF SECOND BLOCK
     &   , I
!             LOOP VARIABLE
     &   , II
!             LOOP VARIABLE
      CHARACTER
     &     DATE_M(NPD_ARCH_ENTRY)*9
!             DATES OF COMPOSITION OF ARCHIVES
      LOGICAL
     &     LINE_COUPLE_M(NPD_ARCH_ENTRY)
!             LINE COUPLING IN MERGED ARCHIVE
     &   , CONTINUUM_M(NPD_ARCH_ENTRY)
!             CONTINUUM IN MERGED ARCVIVE
      REAL*8
     &     CUTOFF_M(NPD_ARCH_ENTRY)
!             LINE CUTOFFS IN MERGED ARCH
     &   , P_M(NPD_ARCH_ENTRY)
!             PRESSURES IN MERGED ARCHIVES
     &   , T_M(NPD_ARCH_ENTRY)
!             TEMPERATURES IN MERGED ARCHIVES
     &   , AMOUNT_M(NPD_ARCH_ENTRY)
!             AMOUNTS IN MERGED ARCHIVE
     &   , PARTIAL_P_M(NPD_ARCH_ENTRY)
!             PARTIAL PRESSURES IN MERGED ARCHIVE
     &   , FREQ_ENTRY_LOW_M(NPD_ARCH_ENTRY)
!             LOW FREQUENCY LIMITS OF ENTRIES
     &   , FREQ_ENTRY_HIGH_M(NPD_ARCH_ENTRY)
!             HIGH FREQUENCY LIMITS OF ENTRIES
     &   , FREQ_LOW(NPD_FREQ_ENTRY)
!             LOW FREQUENCY LIMIT OF ARCHIVE
     &   , FREQ_HIGH(NPD_FREQ_ENTRY)
!             HIGH FREQUENCY LIMIT OF ARCHIVE
     &   , TRANS(NPD_FREQ_ENTRY)
!             TRANSMISSIONS IN ARCHIVE
!
!     SUBROUTINES CALLED
      EXTERNAL
     &     WRITE_ARCHIVE_HEADER_0
     &   , READ_ARCHIVE_ENTRY_0, WRITE_ARCHIVE_ENTRY_0
!
!     ONLY ARCHIVES OF TYPE 0 CAN BE MERGED.
      DATA I_VERSION_M/0/
!
!
!
      N_PER_ARCH_RECORD=NP_BYTES_PER_RECORD/24
!
!     DETERMINE THE TOTAL LENGTH OF THE MERGED FILE AND CHECK FOR SPACE.
      N_ENTRY_M=N_ENTRY_1+N_ENTRY_2
      IF (N_ENTRY_M.GT.NPD_ARCH_ENTRY) THEN
         WRITE(IU_ERR, '(/A)') '*** ERROR: THE MERGED FILE '
     &      //'WOULD CONTAIN TOO MANY ENTRIES.'
         IERR=I_ERR_FATAL
         RETURN
      ENDIF
!
!     BUILD THE MERGED HEADER BLOCK.
!     CALCULATE THE OFFSET FOR THE ENTRIES OF 
!     THE SECOND ARCHIVE AS WELL.
      OFFSET=4*N_ENTRY_1
      DO I=1, N_ENTRY_1
         DATE_M(I)(1:9)=DATE_1(I)(1:9)
         DATABASE_M(I)=DATABASE_1(I)
         LBL_CODE_M(I)=LBL_CODE_1(I)
         LINESHAPE_M(I)=LINESHAPE_1(I)
         CUTOFF_M(I)=CUTOFF_1(I)
         LINE_COUPLE_M(I)=LINE_COUPLE_1(I)
         CONTINUUM_M(I)=CONTINUUM_1(I)
         I_GAS_M(I)=I_GAS_1(I)
         P_M(I)=P_1(I)
         T_M(I)=T_1(I)
         AMOUNT_M(I)=AMOUNT_1(I)
         PARTIAL_P_M(I)=PARTIAL_P_1(I)
         N_TRANS_RECORD_M(I)=N_TRANS_RECORD_1(I)
         OFFSET=OFFSET+N_TRANS_RECORD_1(I)
         I1_RECORD_M(I)=I1_RECORD_1(I)+4*N_ENTRY_2
         N_TRANS_M(I)=N_TRANS_1(I)
         FREQ_ENTRY_LOW_M(I)=FREQ_ENTRY_LOW_1(I)
         FREQ_ENTRY_HIGH_M(I)=FREQ_ENTRY_HIGH_1(I)
      ENDDO
      DO I=1, N_ENTRY_2
         II=N_ENTRY_1+I
         DATE_M(II)(1:9)=DATE_2(I)(1:9)
         DATABASE_M(II)=DATABASE_2(I)
         LBL_CODE_M(II)=LBL_CODE_2(I)
         LINESHAPE_M(II)=LINESHAPE_2(I)
         CUTOFF_M(II)=CUTOFF_2(I)
         CONTINUUM_M(II)=CONTINUUM_2(I)
         LINE_COUPLE_M(II)=LINE_COUPLE_2(I)
         I_GAS_M(II)=I_GAS_2(I)
         P_M(II)=P_2(I)
         T_M(II)=T_2(I)
         AMOUNT_M(II)=AMOUNT_2(I)
         PARTIAL_P_M(II)=PARTIAL_P_2(I)
         N_TRANS_RECORD_M(II)=N_TRANS_RECORD_2(I)
         I1_RECORD_M(II)=I1_RECORD_2(I)+OFFSET
         N_TRANS_M(II)=N_TRANS_2(I)
         FREQ_ENTRY_LOW_M(II)=FREQ_ENTRY_LOW_2(I)
         FREQ_ENTRY_HIGH_M(II)=FREQ_ENTRY_HIGH_2(I)
      ENDDO
!
      CALL WRITE_ARCHIVE_HEADER_0(IERR, IUNIT_OUT
     &   , N_ENTRY_M
     &   , DATE_M, DATABASE_M, LBL_CODE_M
     &   , LINESHAPE_M, CUTOFF_M, CONTINUUM_M, LINE_COUPLE_M
     &   , I_GAS_M, P_M, T_M, AMOUNT_M, PARTIAL_P_M
     &   , FREQ_ENTRY_LOW_M, FREQ_ENTRY_HIGH_M
     &   , N_TRANS_RECORD_M, I1_RECORD_M, N_TRANS_M
     &   )
!
!
!     EACH BLOCK IN TURN IS NOW READ FROM THE INPUT FILES AND
!     WRITEN OUT: THIS APPROACH MEANS THAT ONLY ONE ARCHIVE IS
!     IN MEMORY AT ANY ONE TIME THUS SAVING SPACE.
      DO I=1, N_ENTRY_1
         CALL READ_ARCHIVE_ENTRY_0(IUNIT_1, N_TRANS_RECORD_1(I)
     &      , I1_RECORD_1(I), N_PER_ARCH_RECORD, N_TRANS_1(I)
     &      , FREQ_LOW, FREQ_HIGH, TRANS)
         CALL WRITE_ARCHIVE_ENTRY_0(IUNIT_OUT, N_TRANS_RECORD_M(I)
     &      , I1_RECORD_M(I), N_PER_ARCH_RECORD, N_TRANS_M(I)
     &      , FREQ_LOW, FREQ_HIGH, TRANS)
      ENDDO
      DO I=1, N_ENTRY_2
         II=I+N_ENTRY_1
         CALL READ_ARCHIVE_ENTRY_0(IUNIT_2, N_TRANS_RECORD_2(I)
     &      , I1_RECORD_2(I), N_PER_ARCH_RECORD, N_TRANS_2(I)
     &      , FREQ_LOW, FREQ_HIGH, TRANS)
         CALL WRITE_ARCHIVE_ENTRY_0(IUNIT_OUT, N_TRANS_RECORD_M(II)
     &      , I1_RECORD_M(II), N_PER_ARCH_RECORD, N_TRANS_M(II)
     &      , FREQ_LOW, FREQ_HIGH, TRANS)
      ENDDO
!
!
!     WRITE THE TOP RECORD AND CLOSE THE FILE.
      WRITE(IUNIT_OUT, REC=1) I_VERSION_M, N_ENTRY_M
      CLOSE(IUNIT_OUT)
!
!
!
      RETURN
      END
