!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer,
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer
!version 3 or (at your option) any later version that should be found at:
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software;
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec),
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
!

      SUBROUTINE SELECT 1,2
#if defined (DOC)
*
*
************************************************************************
*
*      PURPOSE: READ CMC BURP FILES FILL UP CMA FILE
*
*
*    ARGUMENTS:
*                 INPUT: NONE
*                OUTPUT: NONE
*
*
*       AUTHOR: P. KOCLAS(CMC TEL. 4665)
*       Revision:
*        .      P. Koclas  *CMC/CMDA February 95
*        .           -data families and files are taken
*        .            from CVCORD CDATFAM comdecks which have been
*        .            initialized by brpcheck routine
*        .      C.Charette *ARMA/AES April 96
*        .           -Modified FNOM and introduced NUMBLKS
*        .      P. Koclas  *CMC/CMDA April 96
*                    -remove exdb exfin
*                    -initialize nbegin nend variables that point to
*                     the limits of each data type in the CMA
*                    -JPFILES parameter now in cvcord COMMON
*        .      P. Koclas  *CMC/CMSV Jan 97
*                    -FIX BUG TO ALLOW SINGLE DATA
*        .      S. Pellerin *ARMA/SMC May 2000
*                    -Logical unit cleanup
*        .      L. Fillion *ARMA/EC - 19 Mar 2008 - Include Shallow-water option via lsw.
*
*     NOTE:
*     BURP FILES ARE ASSUMED TO BE PRESENT IN CURRENT WORKING DIRECTORY
*
************************************************************************
#endif
*
      IMPLICIT NONE
#include "comdim.cdk"
#include "comlun.cdk"
#include "cvcord.cdk"
#include "comdimo.cdk"
#include "comgrd_param.cdk"
#include "comcva.cdk"
      INTEGER IER,INBLKS,INRECS,IBRP1,IBEG
      INTEGER EXDB,EXFIN,FCLOS,FNOM,MRFCLS,MRFOPN,MRFOPC,NUMBLKS
*
      INTEGER NVALS,J
      CHARACTER *2   CLTYP(JPFILES)
      CHARACTER *128 CLVAL(JPFILES)
*
      LOGICAL LLAPPEND
*
      EXTERNAL EXDB,EXFIN,FCLOS,FNOM,MRFCLS,MRFOPN,MRFOPC,NUMBLKS
*
*  ------NOTE----------
* currently supported families of data 'UA' 'AI' 'SF' 'TO' 'GO'
*
************************************************************************
*     READ DATA FROM FILES CONTAINED IN ARRAY CLVAL.
************************************************************************
*
      WRITE(NULOUT,*)' '
      WRITE(NULOUT,*)'================================================='
      WRITE(NULOUT,*)'                SELECT BEGIN                     '
      WRITE(NULOUT,*)'================================================='
      WRITE(NULOUT,*)' '
      IER   =MRFOPC('MSGLVL','FATAL')
*
      NVALS=NFILES
      LLAPPEND=.FALSE.
      NOBTOT=0
       NDATA=0
      DO J =1,NVALS
         NVTYP=J
         CLVAL(J) = CFILNAM(J)
         ibrp1 = 0
         IER   =FNOM(IBRP1,CLVAL(J),'RND+OLD',0)
         IF ( IER .EQ. 0 ) THEN
            INBLKS= -1
            INBLKS=NUMBLKS(IBRP1)
            IF ( INBLKS .GT. 0) THEN
               CLTYP(J)=CFAMTYP(J)
               INRECS=MRFOPN(IBRP1,'READ')
               WRITE(NULOUT,*)  ' '
               WRITE(NULOUT,*)
     +       '========================================================='
               WRITE(NULOUT,*) ' ',INRECS,
     +       ' ',CLTYP(J),' OBSERVATIONS IN BURP FILE ',CLVAL(J)
               WRITE(NULOUT,*)
     +       '========================================================='
               WRITE(NULOUT,*)  ' '
*
               IBEG=NDATA+1
!
               if(grd_typ.eq.'LU'.and.(.not.lobsclip)) then
                 CALL BRPACMA_LA(CLTYP(J),J,LLAPPEND,IBRP1,INRECS)
               else
                 CALL BRPACMA(CLTYP(J),J,LLAPPEND,IBRP1,INRECS)
               endif
               IF ( IBEG .LE. NDATA ) THEN
                  NBEGINTYP(J)=IBEG
                  NENDTYP(J) =NDATA
               ELSE
                  NBEGINTYP(J)=-999
                  NENDTYP(J)  =-999
               ENDIF
            IER=MRFCLS(IBRP1)
            ENDIF
            LLAPPEND = .TRUE.
*
         ENDIF
         IER= FCLOS(IBRP1)
      END DO
*
      write(nulout,*) 'SELECT: NOBTOT = ',NOBTOT
      WRITE(NULOUT,*)' '
      WRITE(NULOUT,*)'================================================='
      WRITE(NULOUT,*)'                SELECT     END                   '
      WRITE(NULOUT,*)'================================================='
      WRITE(NULOUT,*)' '
      IER   =MRFOPC('MSGLVL','FATAL')
      RETURN
      END