C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MSETSFCPVDR SET SFC PROVIDER TO ENABLED OR DISABLED
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 99-10-12
C
C ABSTRACT: ENABLE OR DISABLE ONE MADIS DATA PROVIDER.
C
C PROGRAM HISTORY LOG:
C   99-10-12  M. BARTH    ORIGINAL VERSION
C   01-06-27  M. BARTH    CHANGED NSUB & SUBNAME TO NPVD & PVDNAME
C   01-06-29  M. BARTH    - CHANGED "BUOY" TO "MARITIME"
C                         - REMOVED PSOS AND GSOS DATASETS
C   01-07-06  M. BARTH    ADDED SAO_DSET_AVAIL LOGIC
C   01-07-24  M. BARTH    - RENAMED FROM MSETPVDR & SPLIT DATA 
C                           STRUCTURES INTO SFC & HYDRO
C                         - CHANGED METAR SUBCATEGORIES TO
C                           ASOS, AUTO-MTR, OTHER-MTR & ADDED
C                           ALL-MTR CATEGORY
C   03-05-27  M. BARTH    - CHANGES RESULTING FROM REMOVING UPDATES
C                           TO THE SUBSRCIN FILE:  WHEN A PROVIDER ISN'T
C                           FOUND, DON'T RETURN AN ERROR.  INSTEAD, KEEP
C                           A LIST OF PROVIDERS THAT AREN'T FOUND FOR 
C                           USE LATER ON WHEN THEY ARE FOUND IN THE 
C                           INPUT DATA.
C                         - REMOVED 'AUTO-MTR' PROVIDER.
C   04-03-22  M. BARTH    ADDED 'COOP' PROVIDER.
C   06-09-16  L. BENJAMIN ADDED 'UrbaNet' PROVIDER.
C   08-06-23  M. BARTH    ADDED HIGH FREQUENCY METAR PROVIDERS:
C                         ALL-HFMTR, ASOS-HFM, OTHER-HFM
C   09-07-23  L. BENJAMIN ADDED NEPP, HCN, AND CRN AS A SFC DATASETS.
C
C USAGE:    CALL MSETSFCPVDR (PROVDR,FLAG,STATUS)
C
C   INPUT ARGUMENT LIST:
C     PROVDR   - C       PROVIDER NAME (.LE. 10 CHARACTERS)
C     FLAG     - L       .TRUE. - ENABLE, .FALSE. - DISABLE
C
C   OUTPUT ARGUMENT LIST:
C     STATUS   - I       0 - SUCCESS, OR ERROR CODE
C
C SUBPROGRAMS CALLED:
C     UNIQUE:    MERROR
C
C REMARKS:
C   - IN ADDITION TO THE PROVIDER NAMES THE CALLER CAN USE 'ALL-SFC', 
C     'ALL-MESO', OR 'ALL-MTR', OR 'ALL-HFMTR'.
C   - THE MADISCOM PROVIDER ARRAYS (NPVD, PVDNAME, ETC.) HAVE SFC
C     PROVIDERS IN ROW 1, HYDRO PROVIDERS IN ROW 2.
C   - THE LOGIC INVOLVED WITH THE LIST OF PROVIDERS KEPT FOR FUTURE 
C     USE WHEN THEY'RE LOCATED IN THE INPUT DATA DOES RELY ON THE
C     FACT THAT THE NON-MESONET PROVIDERS ARE ALREADY IN THE LIST
C     FROM DAY ONE.  THIS IS RELEVANT IN THAT WE DON'T KEEP TRACK
C     OF 'ALL-MTR' STATUS, OR DISTINGUISH 'ALL-SFC' FROM 'ALL-MESO'.
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE MSETSFCPVDR(PROVDR,FLAG,STATUS)

C     ------------------------------------------------------------------
C     INCLUDES AND COMMONS
C     ------------------------------------------------------------------
      INCLUDE 'IMPLICIT'
      INCLUDE 'MADISCON'
      INCLUDE 'MADISCOM'

C     ------------------------------------------------------------------
C     ARGUMENTS
C     ------------------------------------------------------------------
      CHARACTER*(*) PROVDR
      INTEGER STATUS
      LOGICAL FLAG

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      CHARACTER*10 PROVDR_L
      INTEGER N,I

      N = LEN(PROVDR)
      PROVDR_L = PROVDR(1:N)
      DO 1 I = 10, N+1, -1
         PROVDR_L(I:I) = ' '
 1    CONTINUE

      IF(SFC_INIT.NE.INIT_P)THEN
         STATUS = SELSUB_NOTINIT_P
         CALL MERROR('MSETSFCPVDR: SELECTED SUBSYSTEM NOT '//
     1                'INITIALIZED - SFC')
         GO TO 900
      ENDIF

      STATUS = SUCCESS_P

C     ------------------------------------------------------------------
C     IF 'ALL-SFC' OR 'ALL-MESO', WE'LL USE FLAG FOR ALL PROVIDERS 
C     ALREADY IDENTIFIED, AND USE IT FOR ANY NEW PROVIDERS THAT HAVE 
C     ALREADY BEEN SPECIFIED VIA AN EARLIER CALL TO THIS ROUTINE, BUT 
C     THAT HAVEN'T YET SHOWN UP AND GOTTEN ENABLED/DISABLED.
C     ------------------------------------------------------------------
      IF(PROVDR_L.EQ.'ALL-SFC   ')THEN

         DO 2 I = 1, MAX_SFCDSET_P
            SFCDSET_ENBL(I) = FLAG
 2       CONTINUE
         DO 3 I = 1, NPVD(1)
            PROVDR_ENBL(I,1) = FLAG
 3       CONTINUE

         ALL_ENBL(1) = FLAG

         DO I = 1, NNEWPVD(1)
            NEW_ENBL(I,1) = FLAG
         ENDDO

      ELSE IF(PROVDR_L.EQ.'ALL-MESO  ')THEN

         SFCDSET_ENBL(MESONET_DS_P) = FLAG
         DO 4 I = 7, NPVD(1)
            PROVDR_ENBL(I,1) = FLAG
 4       CONTINUE

         ALL_ENBL(1) = FLAG

         DO I = 1, NNEWPVD(1)
            NEW_ENBL(I,1) = FLAG
         ENDDO

      ELSE IF(PROVDR_L.EQ.'ALL-MTR   ')THEN

         SFCDSET_ENBL(METAR_DS_P) = FLAG
         PROVDR_ENBL(1,1) = FLAG
         PROVDR_ENBL(3,1) = FLAG

      ELSE IF(PROVDR_L.EQ.'ALL-HFMTR ')THEN

         SFCDSET_ENBL(HFMETAR_DS_P) = FLAG
         PROVDR_ENBL(6,1) = FLAG
         PROVDR_ENBL(32,1) = FLAG

      ELSE

C     ------------------------------------------------------------------
C     MAKE SURE THE DATASET ENABLE FLAGS ARE SET PROPERLY TO HANDLE
C     THE PROVIDERS (SOME DATASETS CONTAIN MORE THAN ONE PROVIDER,
C     SOME PROVIDERS SPAN MORE THAN ONE DATASET).  NOTE THAT WE DO
C     THIS OUTSIDE OF THE FIND THE PROVIDER LOOP BECAUSE WE DON'T KNOW
C     THAT WE'LL KNOW ALL THE PROVIDER NAMES AT THIS POINT.
C     ------------------------------------------------------------------
         IF(PROVDR_L.EQ.'MARITIME  ')THEN

            SFCDSET_ENBL(MARITIME_DS_P) = FLAG

         ELSE IF((PROVDR_L.EQ.'ASOS      '.OR.
     1            PROVDR_L.EQ.'OTHER-MTR ').AND.FLAG)THEN

            SFCDSET_ENBL(METAR_DS_P) = .TRUE.

         ELSE IF((PROVDR_L.EQ.'ASOS-HFM  '.OR.
     1            PROVDR_L.EQ.'OTHER-HFM ').AND.FLAG)THEN

            SFCDSET_ENBL(HFMETAR_DS_P) = .TRUE.

         ELSE IF(PROVDR_L.EQ.'SAO       ')THEN
            
            SFCDSET_ENBL(SAO_DS_P) = .TRUE.

         ELSE IF(PROVDR_L.EQ.'COOP      ')THEN
            
            SFCDSET_ENBL(COOP_DS_P) = .TRUE.

         ELSE IF(PROVDR_L.EQ.'UrbaNet   ')THEN
            
            SFCDSET_ENBL(URBANET_DS_P) = .TRUE.

         ELSE IF(PROVDR_L.EQ.'NEPP      ')THEN
            
            SFCDSET_ENBL(NEPP_DS_P) = .TRUE.

         ELSE IF(PROVDR_L.EQ.'HCN       ')THEN
            
            SFCDSET_ENBL(HCN_DS_P) = .TRUE.

         ELSE IF(PROVDR_L.EQ.'CRN       ')THEN
            
            SFCDSET_ENBL(CRN_DS_P) = .TRUE.

         ELSE IF(FLAG)THEN

            SFCDSET_ENBL(MESONET_DS_P) = .TRUE.

         ENDIF

         DO 5 I = 1, NPVD(1)

            IF(PVDNAME(I,1).EQ.PROVDR_L)THEN

               PROVDR_ENBL(I,1) = FLAG
               GO TO 100

            ENDIF

 5       CONTINUE

C     ------------------------------------------------------------------
C     IF WE HAVEN'T HIT MAX_SUBSRC_P IN THE NEW PROVIDER LIST, ADD
C     AN ENTRY FOR THIS AS-YET-UNKNOWN PROVIDER.
C     ------------------------------------------------------------------
         IF(NNEWPVD(1).NE.MAX_SUBSRC_P)THEN
               
            NNEWPVD(1) = NNEWPVD(1) + 1
            NEWPVDNAME(NNEWPVD(1),1) = PROVDR_L
            NEW_ENBL(NNEWPVD(1),1) = FLAG

         ENDIF

      ENDIF

 100  IF(STATUS.EQ.SUCCESS_P)THEN

C     ------------------------------------------------------------------
C     REGARDLESS OF WHAT THE USER HAS ASKED FOR, IF THE 
C     SAO/COOP/URBANET/HFMETAR DATASET ISN'T AVAILABLE IN THE CURRENT 
C     DATABASE, DISABLE IT.
C     ------------------------------------------------------------------
         IF(.NOT.SAO_DSET_AVAIL)SFCDSET_ENBL(SAO_DS_P) = .FALSE.
         IF(.NOT.COOP_DSET_AVAIL)SFCDSET_ENBL(COOP_DS_P) = .FALSE.
         IF(.NOT.URBANET_DSET_AVAIL)SFCDSET_ENBL(URBANET_DS_P) = .FALSE.
         IF(.NOT.HFMETAR_DSET_AVAIL)SFCDSET_ENBL(HFMETAR_DS_P) = .FALSE.
         IF(.NOT.NEPP_DSET_AVAIL)SFCDSET_ENBL(NEPP_DS_P) = .FALSE.
         IF(.NOT.HCN_DSET_AVAIL)SFCDSET_ENBL(HCN_DS_P) = .FALSE.
         IF(.NOT.CRN_DSET_AVAIL)SFCDSET_ENBL(CRN_DS_P) = .FALSE.

C     ------------------------------------------------------------------
C     CLEAR THE LAST TIME READ FIELD SO NEW STATIONS WILL HAVE TO BE
C     LOADED.  ALSO, MAKE SURE THERE'S SOMETHING STILL ENABLED FOR
C     THE METAR & MESONET FILES.  IF NOT, DISABLE THE DATASET.
C     ------------------------------------------------------------------
         LAST_SFC_ATIME = '         '

         IF(.NOT.PROVDR_ENBL(1,1).AND.
     1      .NOT.PROVDR_ENBL(3,1))SFCDSET_ENBL(METAR_DS_P) = .FALSE.

         IF(.NOT.PROVDR_ENBL(6,1).AND.
     1      .NOT.PROVDR_ENBL(32,1))SFCDSET_ENBL(HFMETAR_DS_P) = .FALSE.

         DO 10 I = 6, MAX_SUBSRC_P
            IF(PROVDR_ENBL(I,1))GO TO 900
 10      CONTINUE

         IF(.NOT.ALL_ENBL(1))SFCDSET_ENBL(MESONET_DS_P) = .FALSE.

      ENDIF

 900  RETURN
      END
C**---------------------------------------------------------------------
C**REQUIRED STANDARD FSL DISCLAIMER (NOVEMBER 2000)
C**---------------------------------------------------------------------
C**  OPEN SOURCE LICENSE/DISCLAIMER,  FORECAST SYSTEMS LABORATORY
C**  NOAA/OAR/FSL, 325 BROADWAY BOULDER, CO 80305
C**
C**  THIS SOFTWARE IS DISTRIBUTED UNDER THE OPEN SOURCE DEFINITION, 
C**  WHICH MAY BE FOUND AT http://www.opensource.org/osd.html.
C**
C**  IN PARTICULAR, REDISTRIBUTION AND USE IN SOURCE AND BINARY FORMS,
C**  WITH OR WITHOUT MODIFICATION, ARE PERMITTED PROVIDED THAT THE 
C**  FOLLOWING CONDITIONS ARE MET:
C**
C**  - REDISTRIBUTIONS OF SOURCE CODE MUST RETAIN THIS NOTICE, THIS LIST
C**    OF CONDITIONS AND THE FOLLOWING DISCLAIMER.
C**
C**  - REDISTRIBUTIONS IN BINARY FORM MUST PROVIDE ACCESS TO THIS 
C**    NOTICE, THIS LIST OF CONDITIONS AND THE FOLLOWING DISCLAIMER, AND
C**    THE UNDERLYING SOURCE CODE.
C**
C**  - ALL MODIFICATIONS TO THIS SOFTWARE MUST BE CLEARLY DOCUMENTED, 
C**    AND ARE SOLELY THE RESPONSIBILITY OF THE AGENT MAKING THE 
C**    MODIFICATIONS.
C**
C**  - IF SIGNIFICANT MODIFICATIONS OR ENHANCEMENTS ARE MADE TO THIS
C**    SOFTWARE, THE FSL SOFTWARE POLICY MANAGER 
C**    (softwaremgr.fsl@noaa.gov) BE NOTIFIED.
C**
C**  THIS SOFTWARE AND ITS DOCUMENTATION ARE IN THE PUBLIC DOMAIN AND 
C**  ARE FURNISHED "AS IS."  THE AUTHORS, THE UNITED STATES GOVERNMENT,
C**  ITS INSTRUMENTALITIES, OFFICERS, EMPLOYEES, AND AGENTS MAKE NO 
C**  WARRANTY, EXPRESS OR IMPLIED, AS TO THE USEFULNESS OF THE SOFTWARE
C**  AND DOCUMENTATION FOR ANY PURPOSE.  THEY ASSUME NO RESPONSIBILITY 
C**  (1) FOR THE USE OF THE SOFTWARE AND DOCUMENTATION; OR (2) TO 
C**  PROVIDE TECHNICAL SUPPORT TO USERS.
C**---------------------------------------------------------------------
