!+ Program to edit an archive of line-by-line data.
!
! Method:
!	The headers of the archive are read and the output archive
!	is opened. Detailed editing is deferred to a subroutine.
!
! 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.
!
!- ---------------------------------------------------------------------
      PROGRAM EDIT_ARCHIVE
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/def_arch_io.icf'
      INCLUDE 'incl/dimensions_arch.ucf'
      INCLUDE 'incl/arch_record_size.pcf'
      INCLUDE 'incl/error.pcf'
!
!
!     DECLARATION OF VARIABLES.
!
      INTEGER
     &     IERR
!             ERROR FLAG
!
      INTEGER
     &     I_VERSION
!             VERSION OF INITIAL ARCHIVE
     &   , N_ENTRY
!             NUMBER OF ENTRIES IN INITIAL ARCHIVE
     &   , LINESHAPE(NPD_ARCH_ENTRY)
!             LINE SHAPES IN INITIAL ARCHIVE
     &   , I_GAS(NPD_ARCH_ENTRY)
!             IDENTITIES OF GASES IN INITIAL ARCHIVE
     &   , N_TRANS_RECORD(NPD_ARCH_ENTRY)
!             NUMBER OF RECORDS IN ENTRIES IN INITIAL ARCHIVE
     &   , I1_RECORD(NPD_ARCH_ENTRY)
!             POINTERS TO FIRST RECORD OF EACH ENTRY IN INITIAL ARCHIVE
     &   , N_TRANS(NPD_ARCH_ENTRY)
!             NUMBER OF TRANSMISSIONS IN EACH ENTRY
     &   , DATABASE(NPD_ARCH_ENTRY)
!             DATABASES IN INITIAL ARCHIVE
     &   , LBL_CODE(NPD_ARCH_ENTRY)
!             LBL CODES IN INITIAL ARCHIVE
!
      CHARACTER
     &     DATE(NPD_ARCH_ENTRY)*9
!             DATES OF COMPOSITION OF ENTRIES
!
      LOGICAL
     &     LINE_COUPLE(NPD_ARCH_ENTRY)
!             LINE COUPLING IN INITIAL ARCHIVE
     &   , CONTINUUM(NPD_ARCH_ENTRY)
!             CONTINUUM IN INITIAL ARCHIVE
!
      REAL*8
     &     CUTOFF(NPD_ARCH_ENTRY)
!             LINE CUTOFFS IN INITIAL ARCHIVE
     &   , P(NPD_ARCH_ENTRY)
!             PRESSURES IN INITIAL ARCHIVE
     &   , T(NPD_ARCH_ENTRY)
!             TEMPERATURES IN INITIAL ARCHIVE
     &   , AMOUNT(NPD_ARCH_ENTRY)
!             AMOUNTS IN INITIAL ARCHIVE
     &   , PARTIAL_P(NPD_ARCH_ENTRY)
!             PARTIAL PRESSURES IN INITIAL ARCHIVE
     &   , FREQ_ENTRY_LOW(NPD_ARCH_ENTRY)
!             LOW FREQUENCY LIMITS OF ENTRIES
     &   , FREQ_ENTRY_HIGH(NPD_ARCH_ENTRY)
!             HIGH FREQUENCY LIMITS OF ENTRIES
!
      INTEGER
     &     N_PER_ARCH_RECORD
!             NUMBER OF GROUPS OF DATA IN ONE RECORD
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     OPEN_ARCHIVE_IN, OPEN_ARCHIVE_OUT
     &   , READ_ARCHIVE_HEADER_0, CONSTRUCT_EDITED_ARCHIVE
!
!
      DATA
     &     IERR/I_NORMAL/
!
!
!
!
!     OPEN AND READ IN THE HEADERS FOR THE ORIGINAL ARCHIVE.
      CALL OPEN_ARCHIVE_IN(IERR, IU_ARCHIVE_IN, NP_BYTES_PER_RECORD
     &   , 'ENTER THE NAME OF THE ARCHIVE TO EDIT.'
     &   , I_VERSION, N_ENTRY)
      IF (IERR.NE.I_NORMAL) STOP
!
      IF (I_VERSION.EQ.0) THEN
         CALL READ_ARCHIVE_HEADER_0(IERR, IU_ARCHIVE_IN
     &      , N_ENTRY
     &      , DATE, DATABASE, LBL_CODE
     &      , LINESHAPE, CUTOFF, CONTINUUM, LINE_COUPLE
     &      , I_GAS, P, T, AMOUNT, PARTIAL_P
     &      , FREQ_ENTRY_LOW, FREQ_ENTRY_HIGH
     &      , N_TRANS_RECORD, I1_RECORD, N_TRANS
     &      )
         N_PER_ARCH_RECORD=NP_BYTES_PER_RECORD/24
      ELSE IF (I_VERSION.EQ.1) THEN
         WRITE(IU_ERR, '(/A)')
     &      '*** ERROR: ARCHIVES OF VERSION 1 CANNOT BE EDITED.'
         IERR=I_ERR_FATAL
         STOP
      ENDIF
      IF (IERR.NE.I_NORMAL) STOP
!
!     OPEN THE OUTPUT ARCHIVE TO BE FORMED.
      CALL OPEN_ARCHIVE_OUT(IERR, IU_ARCHIVE_OUT, NP_BYTES_PER_RECORD
     &   , 'ENTER THE NAME OF THE EDITED ARCHIVE TO FORM')
      IF (IERR.NE.I_NORMAL) STOP
!
      CALL CONSTRUCT_EDITED_ARCHIVE(IERR, N_PER_ARCH_RECORD
     &   , IU_ARCHIVE_IN, I_VERSION, N_ENTRY
     &   , DATE, DATABASE, LBL_CODE
     &   , LINESHAPE, CUTOFF, CONTINUUM, LINE_COUPLE
     &   , I_GAS, P, T, AMOUNT, PARTIAL_P
     &   , FREQ_ENTRY_LOW, FREQ_ENTRY_HIGH
     &   , N_TRANS_RECORD, I1_RECORD, N_TRANS
     &   , IU_ARCHIVE_OUT
     &   )
!
      CLOSE(IU_ARCHIVE_OUT)
!
!
!
      STOP
      END
