C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MGENVCN     CREATE GENERIC VCN FOR RAOB/NPN/MAP
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 00-03-31
C
C ABSTRACT: TRANSLATE USER'S VARIABLE CODE NUMBER INTO THE GENERIC
C   VARIABLE CODE NUMBER FOR THE DESIRED SOUNDING/PROFILE TYPE.
C
C PROGRAM HISTORY LOG:
C   00-03-31  M. BARTH    ORIGINAL VERSION
C   01-07-10  M. BARTH    - CHANGED NPN VCN'S AND ADDED AWIPS ONES
C                         - CHANGES FOR NPN P, RAOB Q & TV
C   02-04-30  M. BARTH    ADDED MAP DATASET
C   03-07-01  M. BARTH    - ADDED AH VARIABLES TO RAOB DATASET
C                         - ADDED RDMTR DATASET
C   03-09-25  M. BARTH    ADDED SATWND DATASET
C   04-06-16  M. BARTH    ADDED ACARSP DATASET
C   04-09-30  L. BENJAMIN ADDED SATSND DATASET
C                         - ADDED PROFILE VARIABLE CHECK
C   04-12-22  M. BARTH    ADDED DEWPOINT UNCERTAINTY (VCN 48) TO
C                         LIST OF ACARSP PROFILES.
C   05-04-28  M. BARTH    MADE ROOM FOR MORE ACARSP PROFILES VARIABLES.
C   05-06-03  L. BENJAMIN ADDED WVMR TO MULTI-LEVELS DATA IN RDMTR
C   05-09-30  L. BENJAMIN ADDED WVMR TO MULTI-LEVELS DATA IN RAOB
C   05-10-25  L. BENJAMIN ADDED SATRAD DATASET
C                         - ADDED PROFILE VARIABLE CHECK
C   05-11-18  L. BENJAMIN ADDED SNOW DATASET
C                         - COMMENT ONLY, NO SPECIAL HANDELING
C   06-09-20  L. BENJAMIN EXPANDED MAP VARIABLES RANGES FOR MODE
C                         PROCESSING.
C
C USAGE:    CALL MGENVCN (ORIG_VCN,CD,CDBTYPE,VCN,SPT)
C
C   INPUT ARGUMENT LIST:
C     ORIG_VCN - I       USER'S VARIABLE CODE NUMBER
C     CD       - I       CURRENT DATA TYPE
C     CDBTYPE  - I       CURRENT DATABASE TYPE
C
C   OUTPUT ARGUMENT LIST:
C     VCN      - I       GENERIC VARIABLE CODE NUMBER
C     SPT      - I       SOUNDING/PROFILE TYPE:
C
C                        ALL DATA TYPES:
C
C                         0    INTEGRATED RAOB/MAP SOUNDING, OR
C                              NO SPECIAL HANDLING (E.G., RETURN ALL)
C
C                        UPPER-AIR:
C
C                        +N    RAOB LEVEL TYPE N (MAN INCLUDES SFC ALSO)
C
C                        -1    INTEGRATED NPN PROFILE
C                        -2    NPN LOW MODE
C                        -3    NPN HIGH MODE
C
C                        -10   INTEGRATED MAP PROFILE
C                        -10+N MAP MODE N (N=1,3 WIND, N=4 RASS)
C                        -15   MAP WIND MODE PARAMETERS (ALL BEAMS
C                              WILL BE RETURNED)
C
C                        -20   RDMTR/ACARSP PROFILE (NO SPECIAL HANDLING
C                              IS REQUIRED, BUT *DUMP.F NEEDS TO
C                              TELL THE DIFFERENCE BETWEEN A PROFILE
C                              AND A SINGLE-DIMENSIONED VARIABLE.)
C
C                        SATWND:
C
C                        1     IR   (INFRARED)
C                        2     VIS  (VISIBLE)
C                        3     WV   (WATER VAPOR)
C                        5     S11  (GOES SOUNDER CHANNEL 11)
C                        7     S10  (GOES SOUNDER CHANNEL 10)
C
C                        SATSND:
C
C                        -20   SATSMR_VN_P,SATST_VN_P (LEVELS)
C                        0     REST
C
C                        SATRAD:
C
C                        -20   SATRCN_VN_P SATRBT_VN_P (CHANNELS)
C                        0     REST
C
C REMARKS:
C   THE TRANSLATIONS ARE HARD-WIRED IN THIS ROUTINE, SO ANY CHANGES IN
C   THE CODE NUMBERS IN THE INPUT TABLES NEED TO BE MADE HERE AS WELL.
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE MGENVCN(ORIG_VCN,CD,CDBTYPE,VCN,SPT)

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

C     ------------------------------------------------------------------
C     ARGUMENTS
C     ------------------------------------------------------------------
      INTEGER ORIG_VCN,CD,CDBTYPE,VCN,SPT

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------

C     *****************************************************************
C     ******************* BEGIN OF MGENVCN ****************************
C     *****************************************************************

      VCN = ORIG_VCN
      SPT = 0

      IF(CD.EQ.RAOB_DS_P)THEN

         IF((ORIG_VCN.GE.21.AND.ORIG_VCN.LE.33).OR.ORIG_VCN.EQ.54)THEN

            VCN = ORIG_VCN - 20
            SPT = MAN_RAOB_P

         ELSE IF((ORIG_VCN.GE.45.AND.ORIG_VCN.LE.53).OR.ORIG_VCN.EQ.74)
     1           THEN

            VCN = ORIG_VCN - 40
            SPT = SIGT_RAOB_P

         ELSE IF((ORIG_VCN.GE.61.AND.ORIG_VCN.LE.64).OR.
     1           ORIG_VCN.EQ.71.OR.ORIG_VCN.EQ.72)THEN

            VCN = ORIG_VCN - 60
            SPT = SIGW_RAOB_P

         ELSE IF((ORIG_VCN.GE.81.AND.ORIG_VCN.LE.84).OR.
     1           ORIG_VCN.EQ.91.OR.ORIG_VCN.EQ.92)THEN

            VCN = ORIG_VCN - 80
            SPT = MXWND_RAOB_P

         ELSE IF(ORIG_VCN.GE.101.AND.ORIG_VCN.LE.113.OR.ORIG_VCN.EQ.134)
     1           THEN
            VCN = ORIG_VCN - 100
            SPT = TROP_RAOB_P

         ENDIF

      ELSE IF(CD.EQ.NPN_DS_P)THEN

         IF(ORIG_VCN.GE.1.AND.ORIG_VCN.LE.23)THEN

            SPT = -1

         ELSE IF(ORIG_VCN.GE.31.AND.ORIG_VCN.LE.52)THEN

            VCN = ORIG_VCN - 30
            SPT = -2

         ELSE IF(ORIG_VCN.GE.61.AND.ORIG_VCN.LE.82)THEN

            VCN = ORIG_VCN - 60
            SPT = -3

         ENDIF

C     ------------------------------------------------------------------
C     NOTE THAT THE USER SPECIFIES VCN'S 14-18 BUT THE API HAS THOSE
C     INTERNALLY SET TO STATION ID INFO THAT SPANS DATATYPES.  THEREFORE
C     WE TRANSLATE 14-16 TO 94-96, AND 17-18 TO EITHER 97-98 (FSL
C     DATABASE) OR 99-100 (AWIPS DATABASE) INSIDE THE API.  (YES, IT'S
C     *VERY* UGLY, BUT EASIER THAN GOING BACK TO THE DRAWING BOARD AND
C     HOPEFULLY THERE WON'T BE TOO MANY DECISIONS AS BAD AS THIS ONE...)
C     ------------------------------------------------------------------
         IF(SPT.NE.0.AND.VCN.GE.14.AND.VCN.LE.18)THEN
            IF(VCN.LE.16)THEN
               VCN = VCN + 80
            ELSE IF(CDBTYPE.EQ.FSL_DB_P)THEN
               VCN = VCN + 80
            ELSE IF(CDBTYPE.EQ.AWIPS_DB_P)THEN
               VCN = VCN + 82
            ENDIF
         ENDIF

      ELSE IF(CD.EQ.MAP_DS_P)THEN

         IF(ORIG_VCN.GE.1.AND.ORIG_VCN.LE.28)THEN

            SPT = -10

         ELSE IF((ORIG_VCN.GE.31.AND.ORIG_VCN.LE.57) .OR.
     1           (ORIG_VCN.GE.231.AND.ORIG_VCN.LE.234))THEN

            VCN = ORIG_VCN - 30
            SPT = -11

         ELSE IF((ORIG_VCN.GE.61.AND.ORIG_VCN.LE.87) .OR.
     1           (ORIG_VCN.GE.261.AND.ORIG_VCN.LE.264))THEN

            VCN = ORIG_VCN - 60
            SPT = -12

         ELSE IF((ORIG_VCN.GE.91.AND.ORIG_VCN.LE.117) .OR.
     1           (ORIG_VCN.GE.291.AND.ORIG_VCN.LE.294))THEN

            VCN = ORIG_VCN - 90
            SPT = -13

         ELSE IF(ORIG_VCN.GE.126.AND.ORIG_VCN.LE.132)THEN

            VCN = ORIG_VCN - 120
            SPT = -14

         ELSE IF((ORIG_VCN.GE.118.AND.ORIG_VCN.LE.122) .OR.
     1           (ORIG_VCN.GE.221.AND.ORIG_VCN.LE.224))THEN
            
            SPT = -10

         ELSE IF((ORIG_VCN.GE.MAPWMODE_MIN_VN_P.AND.
     1           ORIG_VCN.LE.MAPWMODE_MAX_VN_P).OR.
     2           (ORIG_VCN.GE.MAPDG1_1_VN_P.AND.
     1           ORIG_VCN.LE.MAPDG1_3_VN_P))THEN

            SPT = -15

         ENDIF

C     ------------------------------------------------------------------
C     AS WITH THE NPN DATASET, THE USER SPECIFIES VCN'S 14-18 BUT THE 
C     API HAS THOSE INTERNALLY SET TO STATION ID INFO THAT SPANS 
C     DATATYPES.  THEREFORE WE TRANSLATE 14-18 TO 94-98 (NO AWIPS
C     COMPLICATION).  THE UGLINESS GROWS...
C     ------------------------------------------------------------------
         IF(VCN.GE.14.AND.VCN.LE.18)VCN = VCN + 80

      ELSE IF(CD.EQ.RDMTR_DS_P)THEN

C     ------------------------------------------------------------------
C     ALL WE NEED TO DO IS LET OUR CALLER KNOW THE PROFILE TYPE:
C     -20 FOR A PROFILE, 0 (ALREADY SET ABOVE) FOR SINGLE-DIMENSIONED
C     DATA.
C     ------------------------------------------------------------------
         IF(ORIG_VCN.LE.19.OR.ORIG_VCN.EQ.34)SPT = -20

      ELSE IF(CD.EQ.ACARSP_DS_P)THEN

C     ------------------------------------------------------------------
C     SAME AS RDMTR:  -20 FOR A PROFILE, 0 FOR SINGLE-DIMENSIONED DATA.
C     ------------------------------------------------------------------
         IF((ORIG_VCN.LE.24.AND.ORIG_VCN.NE.17.AND.ORIG_VCN.NE.18.AND.
     1       ORIG_VCN.NE.14.AND.ORIG_VCN.NE.15).OR.ORIG_VCN.EQ.47.OR.
     2       (ORIG_VCN.GE.34.AND.ORIG_VCN.LE.38).OR.ORIG_VCN.EQ.30.OR.
     3       (ORIG_VCN.GE.48.AND.ORIG_VCN.LE.67))SPT = -20     

      ELSE IF(CD.EQ.SATW_DS_P)THEN

C     ------------------------------------------------------------------
C     FOR SATWND DATA, TRANSLATE INDIVIDUAL WIND PRODUCT TYPES (E.G. IR)
C     TO THE GENERIC VARIABLE CODE NUMBERS.  THE SPT INDICATES THE
C     PRODUCT TYPE.
C     ------------------------------------------------------------------
         IF(ORIG_VCN.GE.21.AND.ORIG_VCN.LE.40)THEN

            VCN = ORIG_VCN - 20
            SPT = 1

         ELSE IF(ORIG_VCN.GE.41.AND.ORIG_VCN.LE.60)THEN

            VCN = ORIG_VCN - 40
            SPT = 2

         ELSE IF(ORIG_VCN.GE.61.AND.ORIG_VCN.LE.80)THEN

            VCN = ORIG_VCN - 60
            SPT = 3

         ELSE IF(ORIG_VCN.GE.81.AND.ORIG_VCN.LE.100)THEN

            VCN = ORIG_VCN - 80
            SPT = 7

         ELSE IF(ORIG_VCN.GE.101.AND.ORIG_VCN.LE.120)THEN

            VCN = ORIG_VCN - 100
            SPT = 5

         ENDIF

      ELSE IF(CD.EQ.SATS_DS_P)THEN
C     ------------------------------------------------------------------
C     SET PROFILE VARAIBLES
C     ------------------------------------------------------------------
         IF(ORIG_VCN.EQ.SATSMR_VN_P.OR.ORIG_VCN.EQ.SATST_VN_P.OR.
     1        ORIG_VCN.EQ.SATSP_VN_P.OR.ORIG_VCN.EQ.SATSRH_VN_P.OR.
     2        ORIG_VCN.EQ.SATSDPD_VN_P.OR.ORIG_VCN.EQ.SATSQ_VN_P.OR.
     3        ORIG_VCN.EQ.SATSAH_VN_P.OR.VCN.EQ.SATSTD_VN_P.OR.
     4        VCN.EQ.SATSTV_VN_P.OR.VCN.EQ.SATSHT_VN_P)THEN


            SPT = -20
         ELSE
            SPT = 0
         ENDIF
      ELSE IF(CD.EQ.SATR_DS_P)THEN
C     ------------------------------------------------------------------
C     SET PROFILE VARAIBLES
C     ------------------------------------------------------------------
         IF(ORIG_VCN.EQ.SATRCN_VN_P.OR.ORIG_VCN.EQ.SATRBT_VN_P)THEN
            SPT = -20
         ELSE
            SPT = 0
         ENDIF
      ENDIF

      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**---------------------------------------------------------------------
