!=====================================================================
! NGB1: W3lib, Library for decoding and encoding GRIB1 data (NCEP)
!=====================================================================
!
! W3lib Library: Fortran Decoder/Encoder Routines for GRIB Edition 1.
! Version 2.0.2 (2012)
! 2.0.6 (2017)
!
! http://www.nco.ncep.noaa.gov/pmb/codes/GRIB1/
!
!---------------------------------------
!
! ~~~~~~~~~~~~~~~~~~
! Binary Strteam I/O
! ~~~~~~~~~~~~~~~~~~
!
! NG_BAOPEN - open a binary stream file both for READ and WRITE
! NG_BAOPENR - open a binary stream file for READ-ONLY
! NG_BAOPENW - open a binary stream file for WRITE-ONLY
! NG_BAOPENWA - open a binary stream file for WRITE-ONLY with APPEND
!
! NG_BACLOSE - close a binary stream file opened by BAOPEN/BAOPENR/BAOPENW/BAOPENWA
!
! NG_BAREAD - skip some bytes from beginning, and then, read in some bytes
!
! NG_BAWRITE - skip some bytes from beginning, and then, write out some bytes
! NG_WRYTE - write out some bytes at current pointer position
!
! ~~~~~~~~~~~~~~~~~~~~
! Finds a grib message
! ~~~~~~~~~~~~~~~~~~~~
!
! NG_GETGBH - Returns the full PDS and GDS values of the requested field
! NG_GETGBEH without having to unpack the bitmap and grid point data values.
!
! NG_GETGBP - Returns the requested packed GRIB message instead of the unpacked
! NG_GETGBEP bitmap and data values.
!
! NG_GETGBH (LUGB,LUGI, J,JPDS,JGDS, KG,KF,K,KPDS,KGDS, IRET)
! NG_GETGBEH(LUGB,LUGI, J,JPDS,JGDS,JENS,KG,KF,K,KPDS,KGDS,KENS, IRET)
!
! NG_GETGBP (LUGB,LUGI,JG,J,JPDS,JGDS, KG, K,KPDS,KGDS, G,IRET)
! NG_GETGBEP(LUGB,LUGI,JG,J,JPDS,JGDS,JENS,KG, K,KPDS,KGDS,KENS,G,IRET)
!
! JG, G(JG) - packed GRIB message
!
! JENS, KENS - [PDS, 40-45] NCEP PDS extension to describe ensemble model data.
!
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Finds and unpacks a grib message (GRIB1 Decoding Routines)
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!
! NG_GETGB - Unpack GRIB1 messages from file.
!
! NG_GETGBE - Used to search for and decode GRIB1 messages using NCEP PDS
! NG_GETGBEX extensions used to specify ensemble information.
!
! NG_GETGBENS - Obsolescent version of GETGBE
!
! NG_GETGB (LUGB,LUGI,JF,J,JPDS,JGDS, KF,K,KPDS,KGDS, LB,F,IRET)
! NG_GETGBE (LUGB,LUGI,JF,J,JPDS,JGDS,JENS,KF,K,KPDS,KGDS,KENS, LB,F,IRET)
! NG_GETGBENS(LUGB,LUGI,JF,J,JPDS,JGDS,JENS,KF,K,KPDS,KGDS,KENS, LB,F,IRET)
! NG_GETGBEX (LUGB,LUGI,JF,J,JPDS,JGDS,JENS,KF,K,KPDS,KGDS,KENS,KPROB,XPROB,KCLUST,KMEMBR,LB,F,IRET)
!
! JENS, KENS - [PDS, 40-45] NCEP PDS extension to describe ensemble model data.
! KPROB, XPROB - [PDS, 46-55] NCEP PDS extension, the probability ensemble parameters.
! KCLUST,KMEMBR - [PDS, 61-86] NCEP PDS extension, the cluster ensemble parameters.
!
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Packs and writes a grib message (GRIB1 Encoding Routines)
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!
! NG_PUTGB - Pack and write GRIB1 messages to file.
!
! NG_PUTGBN - Allows users to specify a binary scale factor or limit amount of
! space each data point should occupy.
!
! NG_PUTGBE - Used to encode GRIB1 messages with NCEP PDS
! NG_PUTGBEN extensions to specify ensemble information.
! NG_PUTGBEX
! NG_PUTGBEXN
! NG_PUTGBENS - Obsolescent version of PUTGBE
!
! NG_PUTGB (LUGB,KF,KPDS,KGDS, LB,F,IRET)
! NG_PUTGBN (LUGB,KF,KPDS,KGDS, IBS,NBITS, LB,F,IRET)
! NG_PUTGBE (LUGB,KF,KPDS,KGDS,KENS, LB,F,IRET)
! NG_PUTGBENS(LUGB,KF,KPDS,KGDS,KENS, LB,F,IRET)
! NG_PUTGBEN (LUGB,KF,KPDS,KGDS,KENS,IBS,NBITS, LB,F,IRET)
! NG_PUTGBEX (LUGB,KF,KPDS,KGDS,KENS, KPROB,XPROB,KCLUST,KMEMBR, LB,F,IRET)
! NG_PUTGBEXN(LUGB,KF,KPDS,KGDS,KENS, KPROB,XPROB,KCLUST,KMEMBR,IBS,NBITS,LB,F,IRET)
!
! IBS - [BDS, 5-6] The binary scale factor (E).
! NBITS - [BDS, 11] Number of bits into which a datum point is packed.
! KENS - [PDS, 40-45] NCEP PDS extension to describe ensemble model data.
! KPROB, XPROB - [PDS, 46-55] NCEP PDS extension, the probability ensemble parameters.
! KCLUST,KMEMBR - [PDS, 61-86] NCEP PDS extension, the cluster ensemble parameters.
!
! ~~~~~~~~~~~~~~~~
! Working routines
! ~~~~~~~~~~~~~~~~
!
! SUBROUTINE NG_GETGBMH (LUGB, LUGI, J, JPDS, JGDS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KG, KF, K, KPDS, KGDS, IRET)
!
! SUBROUTINE NG_GETGBEMH(LUGB, LUGI, J, JPDS, JGDS, JENS, MBUF, CBUF,&
! NLEN, NNUM, MNUM, KG, KF, K, KPDS, KGDS, KENS, IRET)
!
! SUBROUTINE NG_GETGBMP (LUGB, LUGI, JG, J, JPDS, JGDS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KG, K, KPDS, KGDS, G, IRET)
!
! SUBROUTINE NG_GETGBEMP(LUGB, LUGI, JG, J, JPDS, JGDS, JENS, MBUF, CBUF,&
! NLEN, NNUM, MNUM, KG, K, KPDS, KGDS, KENS, G, IRET)
!
! SUBROUTINE NG_GETGBM (LUGB, LUGI, JF, J, JPDS, JGDS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KF, K, KPDS, KGDS, LB, F, IRET)
!
! SUBROUTINE NG_GETGBEM (LUGB, LUGI, JF, J, JPDS, JGDS, JENS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KF, K, KPDS, KGDS, KENS, LB, F, IRET)
!
! SUBROUTINE NG_GETGBEXM(LUGB, LUGI, JF, J, JPDS, JGDS, JENS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KF, K, KPDS, KGDS, KENS, KPROB, XPROB,&
! KCLUST, KMEMBR, LB, F, IRET)
!
! SUBROUTINE NG_GETGIR (LUGB, MSK1, MSK2, MNUM, MBUF, CBUF, NLEN, NNUM, IRET)
!
! SUBROUTINE NG_GETGI (LUGI, MNUM, MBUF, CBUF, NLEN, NNUM, IRET)
!
! SUBROUTINE NG_GETGB1S (CBUF, NLEN, NNUM, J, JPDS, JGDS, JENS,&
! K, KPDS, KGDS, KENS, LSKIP, LGRIB, IRET)
!
! SUBROUTINE NG_GETGB1R (LUGB, LSKIP, LGRIB, KF, KPDS, KGDS, KENS,&
! LB, F, NBITSS ,IRET)
!
! SUBROUTINE NG_GETGB1RE(LUGB, LSKIP, LGRIB, KF, KPDS, KGDS, KENS,&
! KPROB, XPROB, KCLUST, KMEMBR, LB, F, IRET)
!
! SUBROUTINE NG_SKGB(LUGB, ISEEK, MSEEK, LSKIP, LGRIB)
!
! SUBROUTINE NG_IXGB(LUGB, LSKIP, LGRIB, NLEN, NNUM, MLEN, CBUF)
!
! SUBROUTINE NG_PDSENS(KENS, KPROB, XPROB, KCLUST, KMEMBR, ILAST, MSGA)
!
! SUBROUTINE NG_PDSEUP(KENS, KPROB, XPROB, KCLUST, KMEMBR, ILAST, MSGA)
!
! INTEGER FUNCTION NG_LENGDS(KGDS)
!
! SUBROUTINE NG_W3FI63(MSGA, KPDS, KGDS, KBMS, DATA, KPTR, KRET)
!
! SUBROUTINE NG_W3FI72(ITYPE, FLD, IFLD, IBITL, IPFLAG, ID, PDS, IGFLAG,&
! IGRID, IGDS, ICOMP, IBFLAG, IBMAP, IBLEN, IBDSFL,&
! NPTS, KBUF, ITOT, JERR)
!
! SUBROUTINE NG_R63W72(KPDS, KGDS, IPDS, IGDS)
!
! SUBROUTINE NG_W3FI01(LW)
!
! SUBROUTINE NG_W3FI58(IFIELD, NPTS, NWORK, NPFLD, NBITS, LEN, KMIN)
!
! SUBROUTINE NG_W3FI59(FIELD, NPTS, NBITS, NWORK, NPFLD, ISCALE, LEN, RMIN)
!
! SUBROUTINE NG_W3FI68(ID, PDS)
!
! SUBROUTINE NG_W3FI71(IGRID, IGDS, IERR)
!
! SUBROUTINE NG_W3FI73(IBFLAG, IBMAP, IBLEN, BMS, LENBMS, IER)
!
! SUBROUTINE NG_W3FI74(IGDS, ICOMP, GDS, LENGDS, NPTS, IGERR)
!
! SUBROUTINE NG_W3FI75(IBITL, ITYPE, ITOSS, FLD, IFLD, IBMAP, IBDSFL, NPTS,&
! BDS11, IPFLD, PFLD, LEN, LENBDS, IBERR, PDS, IGDS)
!
! SUBROUTINE NG_W3FI76(PVAL, KEXP, KMANT, KBITS)
!
! SUBROUTINE NG_W3FI82(IFLD, FVAL1, FDIFF1, NPTS, PDS, IGDS)
!
! SUBROUTINE NG_W3FI83(DATA, NPTS, FVAL1, FDIFF1, ISCAL2, ISC10, KPDS, KGDS)
!
! SUBROUTINE NG_W3FS21(IDATE, NMIN)
!
! SUBROUTINE NG_W3FS26(JLDAYN, IYEAR, MONTH, IDAY, IDAYWK, IDAYYR)
!
! INTEGER FUNCTION NG_IW3JDN(IYEAR, MONTH, IDAY)
!
! SUBROUTINE NG_W3DIFDAT(JDAT, IDAT, IT, RINC)
!
! SUBROUTINE NG_W3LOCDAT(IDAT)
!
! SUBROUTINE NG_W3DOXDAT(IDAT, JDOW, JDOY, JDAY)
!
! SUBROUTINE NG_W3MOVDAT(RINC, IDAT, JDAT)
!
! SUBROUTINE NG_W3REDDAT(IT, RINC, DINC)
!
! SUBROUTINE NG_W3UTCDAT(IDAT)
!
!=====================================================================
!
! ~~~~~~~~~~~~~~~~~~
! Binary Strteam I/O
! ~~~~~~~~~~~~~~~~~~
!
! NG_BAOPEN - open a binary stream file both for READ and WRITE
! NG_BAOPENR - open a binary stream file for READ-ONLY
! NG_BAOPENW - open a binary stream file for WRITE-ONLY
! NG_BAOPENWA - open a binary stream file for WRITE-ONLY with APPEND
!
! NG_BACLOSE - close a binary stream file opened by BAOPEN/BAOPENR/BAOPENW/BAOPENWA
!
! NG_BAREAD - skip some bytes from beginning, and then, read in some bytes
!
! NG_BAWRITE - skip some bytes from beginning, and then, write out some bytes
! NG_WRYTE - write out some bytes at current pointer position
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_BAOPEN( LU, CFN, IRET )
!
! INTEGER, INTENT(IN ) :: LU
! CHARACTER(*), INTENT(IN ) :: CFN
! INTEGER, INTENT( OUT) :: IRET
!
! Routine to open a binary stream file both for READ and WRITE. The
! file must exist.
!
! Variables:
! LU - unit to open (C binary stream I/O, ranged 0-99)
!
! CFN - filename to open
!
! IRET - error flag, nonzero value if error occured
!
!---------------------------------------
!
! SUBROUTINE NG_BAOPENR( LU, CFN, IRET )
!
! INTEGER, INTENT(IN ) :: LU
! CHARACTER(*), INTENT(IN ) :: CFN
! INTEGER, INTENT( OUT) :: IRET
!
! Routine to open a binary stream file for READ-ONLY. The file must
! exist.
!
! Variables:
! LU - unit to open (C binary stream I/O, ranged 0-99)
!
! CFN - filename to open
!
! IRET - error flag, nonzero value if error occured
!
!---------------------------------------
!
! SUBROUTINE NG_BAOPENW( LU, CFN, IRET )
!
! INTEGER, INTENT(IN ) :: LU
! CHARACTER(*), INTENT(IN ) :: CFN
! INTEGER, INTENT( OUT) :: IRET
!
! Routine to open a binary stream file for WRITE-ONLY. If a file with
! the same name already exists, its contents are discarded and the
! file is treated as a new empty file.
!
! Variables:
! LU - unit to open (C binary stream I/O, ranged 0-99)
!
! CFN - filename to open
!
! IRET - error flag, nonzero value if error occured
!
!---------------------------------------
!
! SUBROUTINE NG_BAOPENWA( LU, CFN, IRET )
!
! INTEGER, INTENT(IN ) :: LU
! CHARACTER(*), INTENT(IN ) :: CFN
! INTEGER, INTENT( OUT) :: IRET
!
! Routine to open a binary stream file for WRITE-ONLY with APPEND.
! Output operations always write data at the end of the file,
! expanding it. The file is created if it does not exist.
!
! Variables:
! LU - unit to open (C binary stream I/O, ranged 0-99)
!
! CFN - filename to open
!
! IRET - error flag, nonzero value if error occured
!
!---------------------------------------
!
! SUBROUTINE NG_BACLOSE( LU, IRET )
!
! INTEGER, INTENT(IN ) :: LU
! INTEGER, INTENT( OUT) :: IRET
!
! Routine to close a binary stream file opened by
! NG_BAOPEN/NG_BAOPENR/NG_BAOPENW/NG_BAOPENWA routines
!
! Variables:
! LU - unit number
! IRET - error flag, nonzero value if error occured
!
!---------------------------------------
!
! SUBROUTINE NG_BAREAD( LU, IB, NB, KA, A )
!
! INTEGER, INTENT(IN ) :: LU, IB, NB
! CHARACTER(1), INTENT( OUT) :: A(NB)
! INTEGER, INTENT( OUT) :: KA
!
! Routine to skip a given number of bytes from beginning of the file,
! and then, read in a given number of bytes.
!
! Variables:
!
! LU - unit to read
!
! IB - number of bytes to skip from beginning of the file
!
! NB - number of bytes to read
!
! KA - number of bytes actually read
!
! A - data read
!
!---------------------------------------
!
! SUBROUTINE NG_BAWRITE( LU, IB, NB, KA, A )
!
! INTEGER, INTENT(IN ) :: LU, IB, NB
! CHARACTER(1), INTENT(IN ) :: A(NB)
! INTEGER, INTENT( OUT) :: KA
!
! Routine to skip a given number of bytes from beginning of the file,
! and then, write out a given number of bytes.
!
! Variables:
!
! LU - unit to write
!
! IB - number of bytes to skip from beginning of the file
!
! NB - number of bytes to write
!
! KA - number of bytes actually written
!
! A - data to write
!
!---------------------------------------
!
! SUBROUTINE NG_WRYTE( LU, NB, A )
!
! INTEGER, INTENT(IN) :: LU, NB
! CHARACTER(1), INTENT(IN) :: A(NB)
!
! Routine to write out a given number of bytes.
!
! Variables:
!
! LU - unit to write
!
! NB - number of bytes to write
!
! A - data to write
!
!=====================================================================
!
! ~~~~~~~~~~~~~~~~~~~~
! Finds a grib message
! ~~~~~~~~~~~~~~~~~~~~
!
! NG_GETGBH - Returns the full PDS and GDS values of the requested field
! NG_GETGBEH without having to unpack the bitmap and grid point data values.
!
! NG_GETGBP - Returns the requested packed GRIB message instead of the unpacked
! NG_GETGBEP bitmap and data values.
!
! NG_GETGBH (LUGB,LUGI, J,JPDS,JGDS, KG,KF,K,KPDS,KGDS, IRET)
! NG_GETGBEH(LUGB,LUGI, J,JPDS,JGDS,JENS,KG,KF,K,KPDS,KGDS,KENS, IRET)
!
! NG_GETGBP (LUGB,LUGI,JG,J,JPDS,JGDS, KG, K,KPDS,KGDS, G,IRET)
! NG_GETGBEP(LUGB,LUGI,JG,J,JPDS,JGDS,JENS,KG, K,KPDS,KGDS,KENS,G,IRET)
!
! JG, G(JG) - packed GRIB message
!
! JENS, KENS - [PDS, 40-45] NCEP PDS extension to describe ensemble model data.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBH(LUGB, LUGI, J, JPDS, JGDS, KG, KF, K,&
! KPDS, KGDS, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200)
! INTEGER, INTENT( OUT) :: KG, KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: FIND A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! (THE INDEX BUFFER IS SAVED FOR USE BY FUTURE PROSPECTIVE CALLS.)
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN ITS MESSAGE NUMBER IS
! RETURNED ALONG WITH THE UNPACKED PDS AND GDS PARAMETERS. IF THE
! GRIB MESSAGE IS NOT FOUND, THEN THE RETURN CODE WILL BE NONZERO.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! (ONLY USED IF LUGI=0)
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
!
! OUTPUT ARGUMENTS:
! KG INTEGER NUMBER OF BYTES IN THE GRIB MESSAGE
! KF INTEGER NUMBER OF DATA POINTS IN THE MESSAGE
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 99 REQUEST NOT FOUND
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBEH(LUGB, LUGI, J, JPDS, JGDS, JENS, KG, KF, K,&
! KPDS, KGDS, KENS, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200), JENS(200)
! INTEGER, INTENT( OUT) :: KG, KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: FIND A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! (THE INDEX BUFFER IS SAVED FOR USE BY FUTURE PROSPECTIVE CALLS.)
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN ITS MESSAGE NUMBER IS
! RETURNED ALONG WITH THE UNPACKED PDS AND GDS PARAMETERS. IF THE
! GRIB MESSAGE IS NOT FOUND, THEN THE RETURN CODE WILL BE NONZERO.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! (ONLY USED IF LUGI=0)
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(23)=2)
! (=-1 FOR WILDCARD)
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
!
! OUTPUT ARGUMENTS:
! KG INTEGER NUMBER OF BYTES IN THE GRIB MESSAGE
! KF INTEGER NUMBER OF DATA POINTS IN THE MESSAGE
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 99 REQUEST NOT FOUND
!
!---------------------------------------------------------------------
! SUBROUTINE NG_GETGBP(LUGB, LUGI, JG, J, JPDS, JGDS, KG, K,&
! KPDS, KGDS, G, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JG, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200)
! INTEGER, INTENT( OUT) :: KG, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200)
! CHARACTER(1), INTENT( OUT) :: G(JG)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: FIND A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! (THE INDEX BUFFER IS SAVED FOR USE BY FUTURE PROSPECTIVE CALLS.)
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE. ITS MESSAGE NUMBER IS RETURNED ALONG WITH THE UNPACKED
! PDS AND GDS PARAMETERS AND THE PACKED GRIB MESSAGE. IF THE GRIB
! MESSAGE IS NOT FOUND, THEN THE RETURN CODE WILL BE NONZERO.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JG INTEGER MAXIMUM NUMBER OF BYTES IN THE GRIB MESSAGE
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
!
! OUTPUT ARGUMENTS:
! KG INTEGER NUMBER OF BYTES IN THE GRIB MESSAGE
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! G CHARACTER*1 (KG) GRIB MESSAGE
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF BYTES GREATER THAN JG
! 99 REQUEST NOT FOUND
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBEP(LUGB, LUGI, JG, J, JPDS, JGDS, JENS, KG, K,&
! KPDS, KGDS, KENS, G, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JG, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200), JENS(200)
! INTEGER, INTENT( OUT) :: KG, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! CHARACTER(1), INTENT( OUT) :: G(JG)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: FIND A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! (THE INDEX BUFFER IS SAVED FOR USE BY FUTURE PROSPECTIVE CALLS.)
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE. ITS MESSAGE NUMBER IS RETURNED ALONG WITH THE UNPACKED
! PDS AND GDS PARAMETERS AND THE PACKED GRIB MESSAGE. IF THE GRIB
! MESSAGE IS NOT FOUND, THEN THE RETURN CODE WILL BE NONZERO.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JG INTEGER MAXIMUM NUMBER OF BYTES IN THE GRIB MESSAGE
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(23)=2)
! (=-1 FOR WILDCARD)
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
!
! OUTPUT ARGUMENTS:
! KG INTEGER NUMBER OF BYTES IN THE GRIB MESSAGE
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! G CHARACTER*1 (KG) GRIB MESSAGE
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF BYTES GREATER THAN JG
! 99 REQUEST NOT FOUND
!
!=====================================================================
!
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Finds and unpacks a grib message (GRIB1 Decoding Routines)
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!
! NG_GETGB - Unpack GRIB1 messages from file.
!
! NG_GETGBE - Used to search for and decode GRIB1 messages using NCEP PDS
! NG_GETGBEX extensions used to specify ensemble information.
!
! NG_GETGBENS - Obsolescent version of GETGBE
!
! NG_GETGB (LUGB,LUGI,JF,J,JPDS,JGDS, KF,K,KPDS,KGDS, LB,F,IRET)
! NG_GETGBE (LUGB,LUGI,JF,J,JPDS,JGDS,JENS,KF,K,KPDS,KGDS,KENS, LB,F,IRET)
! NG_GETGBENS(LUGB,LUGI,JF,J,JPDS,JGDS,JENS,KF,K,KPDS,KGDS,KENS, LB,F,IRET)
! NG_GETGBEX (LUGB,LUGI,JF,J,JPDS,JGDS,JENS,KF,K,KPDS,KGDS,KENS,KPROB,XPROB,KCLUST,KMEMBR,LB,F,IRET)
!
! JENS, KENS - [PDS, 40-45] NCEP PDS extension to describe ensemble model data.
! KPROB, XPROB - [PDS, 46-55] NCEP PDS extension, the probability ensemble parameters.
! KCLUST,KMEMBR - [PDS, 61-86] NCEP PDS extension, the cluster ensemble parameters.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGB(LUGB, LUGI, JF, J, JPDS, JGDS, KF, K,&
! KPDS, KGDS, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JF, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200)
! INTEGER, INTENT( OUT) :: KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200)
! LOGICAL*1, INTENT( OUT) :: LB(JF) ! 1-Byte LOGICAL
! REAL, INTENT( OUT) :: F(JF)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: FIND AND UNPACK A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! (THE INDEX BUFFER IS SAVED FOR USE BY FUTURE PROSPECTIVE CALLS.)
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE AND UNPACKED. ITS MESSAGE NUMBER IS RETURNED ALONG WITH
! THE UNPACKED PDS AND GDS PARAMETERS, THE UNPACKED BITMAP (IF ANY),
! AND THE UNPACKED DATA. IF THE GRIB MESSAGE IS NOT FOUND, THEN THE
! RETURN CODE WILL BE NONZERO.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JF INTEGER MAXIMUM NUMBER OF DATA POINTS TO UNPACK
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
!
! OUTPUT ARGUMENTS:
! KF INTEGER NUMBER OF DATA POINTS UNPACKED
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
! F REAL (KF) UNPACKED DATA
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF DATA POINTS GREATER THAN JF
! 99 REQUEST NOT FOUND
! OTHER W3FI63 GRIB UNPACKER RETURN CODE
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBE(LUGB, LUGI, JF, J, JPDS, JGDS, JENS, KF, K,&
! KPDS, KGDS, KENS, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JF, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200), JENS(200)
! INTEGER, INTENT( OUT) :: KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! LOGICAL*1, INTENT( OUT) :: LB(JF) ! 1-Byte LOGICAL
! REAL, INTENT( OUT) :: F(JF)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: FIND AND UNPACK A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! (THE INDEX BUFFER IS SAVED FOR USE BY FUTURE PROSPECTIVE CALLS.)
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE AND UNPACKED. ITS MESSAGE NUMBER IS RETURNED ALONG WITH
! THE UNPACKED PDS AND GDS PARAMETERS, THE UNPACKED BITMAP (IF ANY),
! AND THE UNPACKED DATA. IF THE GRIB MESSAGE IS NOT FOUND, THEN THE
! RETURN CODE WILL BE NONZERO.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JF INTEGER MAXIMUM NUMBER OF DATA POINTS TO UNPACK
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(23)=2)
! (=-1 FOR WILDCARD)
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
!
! OUTPUT ARGUMENTS:
! KF INTEGER NUMBER OF DATA POINTS UNPACKED
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
! F REAL (KF) UNPACKED DATA
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF DATA POINTS GREATER THAN JF
! 99 REQUEST NOT FOUND
! OTHER W3FI63 GRIB UNPACKER RETURN CODE
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBENS(LUGB, LUGI, JF, J, JPDS, JGDS, JENS, KF ,K,&
! KPDS, KGDS, KENS, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JF, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200), JENS(200)
! INTEGER, INTENT( OUT) :: KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! LOGICAL*1, INTENT( OUT) :: LB(JF) ! 1-Byte LOGICAL
! REAL, INTENT( OUT) :: F(JF)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: FINDS AND UNPACKS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 94-04-01
!
! ABSTRACT: FIND AND UNPACK A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! (THE INDEX BUFFER IS SAVED FOR USE BY FUTURE PROSPECTIVE CALLS.)
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE AND UNPACKED. ITS MESSAGE NUMBER IS RETURNED ALONG WITH
! THE UNPACKED PDS AND GDS PARAMETERS, THE UNPACKED BITMAP (IF ANY),
! AND THE UNPACKED DATA. IF THE GRIB MESSAGE IS NOT FOUND, THEN THE
! RETURN CODE WILL BE NONZERO.
! THIS OBSOLESCENT VERSION HAS BEEN REPLACED BY GETGBE.
!
! PROGRAM HISTORY LOG:
! 94-04-01 IREDELL
! 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
! AND ALLOWED FOR UNSPECIFIED INDEX FILE
!
! USAGE: CALL NG_GETGBENS(LUGB,LUGI,JF,J,JPDS,JGDS,JENS,
! & KF,K,KPDS,KGDS,KENS,LB,F,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JF INTEGER MAXIMUM NUMBER OF DATA POINTS TO UNPACK
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(23)=2)
! (=-1 FOR WILDCARD)
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
! OUTPUT ARGUMENTS:
! KF INTEGER NUMBER OF DATA POINTS UNPACKED
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
! F REAL (KF) UNPACKED DATA
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF DATA POINTS GREATER THAN JF
! 99 REQUEST NOT FOUND
! OTHER W3FI63 GRIB UNPACKER RETURN CODE
!
! REMARKS: IN ORDER TO UNPACK GRIB FROM A MULTIPROCESSING ENVIRONMENT
! WHERE EACH PROCESSOR IS ATTEMPTING TO READ FROM ITS OWN PAIR OF
! LOGICAL UNITS, ONE MUST DIRECTLY CALL SUBPROGRAM GETGBEM AS BELOW,
! ALLOCATING A PRIVATE COPY OF CBUF, NLEN AND NNUM TO EACH PROCESSOR.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBEX(LUGB, LUGI, JF, J, JPDS, JGDS, JENS, KF, K,&
! KPDS, KGDS, KENS, KPROB, XPROB, KCLUST, KMEMBR,&
! LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JF, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200), JENS(200)
! INTEGER, INTENT( OUT) :: KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! INTEGER, INTENT( OUT) :: KPROB(2)
! REAL, INTENT( OUT) :: XPROB(2)
! INTEGER, INTENT( OUT) :: KCLUST(16), KMEMBR(80)
! LOGICAL*1, INTENT( OUT) :: LB(JF) ! 1-Byte LOGICAL
! REAL, INTENT( OUT) :: F(JF)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: FIND AND UNPACK A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! (THE INDEX BUFFER IS SAVED FOR USE BY FUTURE PROSPECTIVE CALLS.)
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE AND UNPACKED. ITS MESSAGE NUMBER IS RETURNED ALONG WITH
! THE UNPACKED PDS AND GDS PARAMETERS, THE UNPACKED BITMAP (IF ANY),
! AND THE UNPACKED DATA. IF THE GRIB MESSAGE IS NOT FOUND, THEN THE
! RETURN CODE WILL BE NONZERO.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JF INTEGER MAXIMUM NUMBER OF DATA POINTS TO UNPACK
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(23)=2)
! (=-1 FOR WILDCARD)
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
!
! OUTPUT ARGUMENTS:
! KF INTEGER NUMBER OF DATA POINTS UNPACKED
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! KPROB INTEGER (2) PROBABILITY ENSEMBLE PARMS
! XPROB REAL (2) PROBABILITY ENSEMBLE PARMS
! KCLUST INTEGER (16) CLUSTER ENSEMBLE PARMS
! KMEMBR INTEGER (8) CLUSTER ENSEMBLE PARMS
! LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
! F REAL (KF) UNPACKED DATA
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF DATA POINTS GREATER THAN JF
! 99 REQUEST NOT FOUND
! OTHER W3FI63 GRIB UNPACKER RETURN CODE
!
!=====================================================================
!
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Packs and writes a grib message (GRIB1 Encoding Routines)
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!
! NG_PUTGB - Pack and write GRIB1 messages to file.
!
! NG_PUTGBN - Allows users to specify a binary scale factor or limit amount of
! space each data point should occupy.
!
! NG_PUTGBE - Used to encode GRIB1 messages with NCEP PDS
! NG_PUTGBEN extensions to specify ensemble information.
! NG_PUTGBEX
! NG_PUTGBEXN
! NG_PUTGBENS - Obsolescent version of PUTGBE
!
! NG_PUTGB (LUGB,KF,KPDS,KGDS, LB,F,IRET)
! NG_PUTGBN (LUGB,KF,KPDS,KGDS, IBS,NBITS, LB,F,IRET)
! NG_PUTGBE (LUGB,KF,KPDS,KGDS,KENS, LB,F,IRET)
! NG_PUTGBENS(LUGB,KF,KPDS,KGDS,KENS, LB,F,IRET)
! NG_PUTGBEN (LUGB,KF,KPDS,KGDS,KENS,IBS,NBITS, LB,F,IRET)
! NG_PUTGBEX (LUGB,KF,KPDS,KGDS,KENS, KPROB,XPROB,KCLUST,KMEMBR, LB,F,IRET)
! NG_PUTGBEXN(LUGB,KF,KPDS,KGDS,KENS, KPROB,XPROB,KCLUST,KMEMBR,IBS,NBITS,LB,F,IRET)
!
! IBS - [BDS, 5-6] The binary scale factor (E).
! NBITS - [BDS, 11] Number of bits into which a datum point is packed.
! KENS - [PDS, 40-45] NCEP PDS extension to describe ensemble model data.
! KPROB, XPROB - [PDS, 46-55] NCEP PDS extension, the probability ensemble parameters.
! KCLUST,KMEMBR - [PDS, 61-86] NCEP PDS extension, the cluster ensemble parameters.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_PUTGB(LUGB, KF, KPDS, KGDS, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, KF
! INTEGER, INTENT(IN ) :: KPDS(200), KGDS(200)
! LOGICAL*1, INTENT(IN ) :: LB(KF) ! 1-Byte LOGICAL
! REAL, INTENT(IN ) :: F(KF)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: PACK AND WRITE A GRIB MESSAGE.
! THIS SUBPROGRAM IS NEARLY THE INVERSE OF GETGB.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! KF INTEGER NUMBER OF DATA POINTS
! KPDS INTEGER (200) PDS PARAMETERS
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! KGDS INTEGER (200) GDS PARAMETERS
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! LB LOGICAL*1 (KF) BITMAP IF PRESENT
! F REAL (KF) DATA
!
! OUTPUT ARGUMENTS:
! IRET INTEGER RETURN CODE
! 0 ALL OK
! OTHER W3FI72 GRIB PACKER RETURN CODE
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_PUTGBN(LUGB, KF, KPDS, KGDS, IBS, NBITS, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, KF
! INTEGER, INTENT(IN ) :: KPDS(200), KGDS(200)
! INTEGER, INTENT(IN ) :: IBS, NBITS
! LOGICAL*1, INTENT(IN ) :: LB(KF) ! 1-Byte LOGICAL
! REAL, INTENT(IN ) :: F(KF)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: PACK AND WRITE A GRIB MESSAGE.
! THIS SUBPROGRAM IS NEARLY THE INVERSE OF GETGB.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! KF INTEGER NUMBER OF DATA POINTS
! KPDS INTEGER (200) PDS PARAMETERS
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! KGDS INTEGER (200) GDS PARAMETERS
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! IBS INTEGER BINARY SCALE FACTOR (0 TO IGNORE)
! NBITS INTEGER NUMBER OF BITS IN WHICH TO PACK (0 TO IGNORE)
! LB LOGICAL*1 (KF) BITMAP IF PRESENT
! F REAL (KF) DATA
!
! OUTPUT ARGUMENTS:
! IRET INTEGER RETURN CODE
! 0 ALL OK
! OTHER W3FI72 GRIB PACKER RETURN CODE
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_PUTGBE(LUGB, KF, KPDS, KGDS, KENS, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, KF
! INTEGER, INTENT(IN ) :: KPDS(200), KGDS(200), KENS(200)
! LOGICAL*1, INTENT(IN ) :: LB(KF) ! 1-Byte LOGICAL
! REAL, INTENT(IN ) :: F(KF)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: PACK AND WRITE A GRIB MESSAGE.
! THIS SUBPROGRAM IS NEARLY THE INVERSE OF GETGBE.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! KF INTEGER NUMBER OF DATA POINTS
! KPDS INTEGER (200) PDS PARAMETERS
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! KGDS INTEGER (200) GDS PARAMETERS
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! KENS INTEGER (200) ENSEMBLE PDS PARMS
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
! LB LOGICAL*1 (KF) BITMAP IF PRESENT
! F REAL (KF) DATA
!
! OUTPUT ARGUMENTS:
! IRET INTEGER RETURN CODE
! 0 ALL OK
! OTHER W3FI72 GRIB PACKER RETURN CODE
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_PUTGBENS(LUGB, KF, KPDS, KGDS, KENS, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, KF
! INTEGER, INTENT(IN ) :: KPDS(200), KGDS(200), KENS(200)
! LOGICAL*1, INTENT(IN ) :: LB(KF) ! 1-Byte LOGICAL
! REAL, INTENT(IN ) :: F(KF)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: PACKS AND WRITES A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 94-04-01
!
! ABSTRACT: PACK AND WRITE A GRIB MESSAGE.
! THIS SUBPROGRAM IS NEARLY THE INVERSE OF GETGBENS.
! THIS OBSOLESCENT VERSION HAS BEEN REPLACED BY PUTGBE.
!
! PROGRAM HISTORY LOG:
! 94-04-01 IREDELL
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
!
! USAGE: CALL NG_PUTGBENS(LUGB,KF,KPDS,KGDS,KENS,LB,F,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! KF INTEGER NUMBER OF DATA POINTS
! KPDS INTEGER (200) PDS PARAMETERS
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! KGDS INTEGER (200) GDS PARAMETERS
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! KENS INTEGER (200) ENSEMBLE PDS PARMS
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
! LB LOGICAL*1 (KF) BITMAP IF PRESENT
! F REAL (KF) DATA
! OUTPUT ARGUMENTS:
! IRET INTEGER RETURN CODE
! 0 ALL OK
! OTHER W3FI72 GRIB PACKER RETURN CODE
!
! REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_PUTGBEN(LUGB, KF, KPDS, KGDS, KENS, IBS, NBITS,&
! LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, KF
! INTEGER, INTENT(IN ) :: KPDS(200), KGDS(200), KENS(200)
! INTEGER, INTENT(IN ) :: IBS, NBITS
! LOGICAL*1, INTENT(IN ) :: LB(KF) ! 1-Byte LOGICAL
! REAL, INTENT(IN ) :: F(KF)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: PACK AND WRITE A GRIB MESSAGE.
! THIS SUBPROGRAM IS NEARLY THE INVERSE OF GETGBE.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! KF INTEGER NUMBER OF DATA POINTS
! KPDS INTEGER (200) PDS PARAMETERS
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! KGDS INTEGER (200) GDS PARAMETERS
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! KENS INTEGER (200) ENSEMBLE PDS PARMS
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
! IBS INTEGER BINARY SCALE FACTOR (0 TO IGNORE)
! NBITS INTEGER NUMBER OF BITS IN WHICH TO PACK (0 TO IGNORE)
! LB LOGICAL*1 (KF) BITMAP IF PRESENT
! F REAL (KF) DATA
!
! OUTPUT ARGUMENTS:
! IRET INTEGER RETURN CODE
! 0 ALL OK
! OTHER W3FI72 GRIB PACKER RETURN CODE
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_PUTGBEX(LUGB, KF, KPDS, KGDS, KENS, KPROB, XPROB,&
! KCLUST, KMEMBR, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, KF
! INTEGER, INTENT(IN ) :: KPDS(200), KGDS(200), KENS(200)
! INTEGER, INTENT(IN ) :: KPROB(2)
! REAL, INTENT(IN ) :: XPROB(2)
! INTEGER, INTENT(IN ) :: KCLUST(16), KMEMBR(80)
! LOGICAL*1, INTENT(IN ) :: LB(KF) ! 1-Byte LOGICAL
! REAL, INTENT(IN ) :: F(KF)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: PACK AND WRITE A GRIB MESSAGE.
! THIS SUBPROGRAM IS NEARLY THE INVERSE OF GETGBE.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! KF INTEGER NUMBER OF DATA POINTS
! KPDS INTEGER (200) PDS PARAMETERS
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! KGDS INTEGER (200) GDS PARAMETERS
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! KENS INTEGER (200) ENSEMBLE PDS PARMS
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
! KPROB INTEGER (2) PROBABILITY ENSEMBLE PARMS
! XPROB REAL (2) PROBABILITY ENSEMBLE PARMS
! KCLUST INTEGER (16) CLUSTER ENSEMBLE PARMS
! KMEMBR INTEGER (8) CLUSTER ENSEMBLE PARMS
! LB LOGICAL*1 (KF) BITMAP IF PRESENT
! F REAL (KF) DATA
!
! OUTPUT ARGUMENTS:
! IRET INTEGER RETURN CODE
! 0 ALL OK
! OTHER W3FI72 GRIB PACKER RETURN CODE
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_PUTGBEXN(LUGB, KF, KPDS, KGDS, KENS, KPROB, XPROB,&
! KCLUST, KMEMBR, IBS, NBITS, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, KF
! INTEGER, INTENT(IN ) :: KPDS(200), KGDS(200), KENS(200)
! INTEGER, INTENT(IN ) :: KPROB(2)
! REAL, INTENT(IN ) :: XPROB(2)
! INTEGER, INTENT(IN ) :: KCLUST(16), KMEMBR(80)
! INTEGER, INTENT(IN ) :: IBS, NBITS
! LOGICAL*1, INTENT(IN ) :: LB(KF) ! 1-Byte LOGICAL
! REAL, INTENT(IN ) :: F(KF)
! INTEGER, INTENT( OUT) :: IRET
!
! ABSTRACT: PACK AND WRITE A GRIB MESSAGE.
! THIS SUBPROGRAM IS NEARLY THE INVERSE OF GETGBE.
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! KF INTEGER NUMBER OF DATA POINTS
! KPDS INTEGER (200) PDS PARAMETERS
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! KGDS INTEGER (200) GDS PARAMETERS
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! KENS INTEGER (200) ENSEMBLE PDS PARMS
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
! KPROB INTEGER (2) PROBABILITY ENSEMBLE PARMS
! XPROB REAL (2) PROBABILITY ENSEMBLE PARMS
! KCLUST INTEGER (16) CLUSTER ENSEMBLE PARMS
! KMEMBR INTEGER (8) CLUSTER ENSEMBLE PARMS
! IBS INTEGER BINARY SCALE FACTOR (0 TO IGNORE)
! NBITS INTEGER NUMBER OF BITS IN WHICH TO PACK (0 TO IGNORE)
! LB LOGICAL*1 (KF) BITMAP IF PRESENT
! F REAL (KF) DATA
! OUTPUT ARGUMENTS:
! IRET INTEGER RETURN CODE
! 0 ALL OK
! OTHER W3FI72 GRIB PACKER RETURN CODE
!
!=====================================================================
!
! ~~~~~~~~~~~~~~~~
! Working routines
! ~~~~~~~~~~~~~~~~
!
! SUBROUTINE NG_GETGBMH (LUGB, LUGI, J, JPDS, JGDS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KG, KF, K, KPDS, KGDS, IRET)
!
! SUBROUTINE NG_GETGBEMH(LUGB, LUGI, J, JPDS, JGDS, JENS, MBUF, CBUF,&
! NLEN, NNUM, MNUM, KG, KF, K, KPDS, KGDS, KENS, IRET)
!
! SUBROUTINE NG_GETGBMP (LUGB, LUGI, JG, J, JPDS, JGDS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KG, K, KPDS, KGDS, G, IRET)
!
! SUBROUTINE NG_GETGBEMP(LUGB, LUGI, JG, J, JPDS, JGDS, JENS, MBUF, CBUF,&
! NLEN, NNUM, MNUM, KG, K, KPDS, KGDS, KENS, G, IRET)
!
! SUBROUTINE NG_GETGBM (LUGB, LUGI, JF, J, JPDS, JGDS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KF, K, KPDS, KGDS, LB, F, IRET)
!
! SUBROUTINE NG_GETGBEM (LUGB, LUGI, JF, J, JPDS, JGDS, JENS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KF, K, KPDS, KGDS, KENS, LB, F, IRET)
!
! SUBROUTINE NG_GETGBEXM(LUGB, LUGI, JF, J, JPDS, JGDS, JENS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KF, K, KPDS, KGDS, KENS, KPROB, XPROB,&
! KCLUST, KMEMBR, LB, F, IRET)
!
! SUBROUTINE NG_GETGIR (LUGB, MSK1, MSK2, MNUM, MBUF, CBUF, NLEN, NNUM, IRET)
!
! SUBROUTINE NG_GETGI (LUGI, MNUM, MBUF, CBUF, NLEN, NNUM, IRET)
!
! SUBROUTINE NG_GETGB1S (CBUF, NLEN, NNUM, J, JPDS, JGDS, JENS,&
! K, KPDS, KGDS, KENS, LSKIP, LGRIB, IRET)
!
! SUBROUTINE NG_GETGB1R (LUGB, LSKIP, LGRIB, KF, KPDS, KGDS, KENS,&
! LB, F, NBITSS ,IRET)
!
! SUBROUTINE NG_GETGB1RE(LUGB, LSKIP, LGRIB, KF, KPDS, KGDS, KENS,&
! KPROB, XPROB, KCLUST, KMEMBR, LB, F, IRET)
!
! SUBROUTINE NG_SKGB(LUGB, ISEEK, MSEEK, LSKIP, LGRIB)
!
! SUBROUTINE NG_IXGB(LUGB, LSKIP, LGRIB, NLEN, NNUM, MLEN, CBUF)
!
! SUBROUTINE NG_PDSENS(KENS, KPROB, XPROB, KCLUST, KMEMBR, ILAST, MSGA)
!
! SUBROUTINE NG_PDSEUP(KENS, KPROB, XPROB, KCLUST, KMEMBR, ILAST, MSGA)
!
! INTEGER FUNCTION NG_LENGDS(KGDS)
!
! SUBROUTINE NG_W3FI63(MSGA, KPDS, KGDS, KBMS, DATA, KPTR, KRET)
!
! SUBROUTINE NG_W3FI72(ITYPE, FLD, IFLD, IBITL, IPFLAG, ID, PDS, IGFLAG,&
! IGRID, IGDS, ICOMP, IBFLAG, IBMAP, IBLEN, IBDSFL,&
! NPTS, KBUF, ITOT, JERR)
!
! SUBROUTINE NG_R63W72(KPDS, KGDS, IPDS, IGDS)
!
! SUBROUTINE NG_W3FI01(LW)
!
! SUBROUTINE NG_W3FI58(IFIELD, NPTS, NWORK, NPFLD, NBITS, LEN, KMIN)
!
! SUBROUTINE NG_W3FI59(FIELD, NPTS, NBITS, NWORK, NPFLD, ISCALE, LEN, RMIN)
!
! SUBROUTINE NG_W3FI68(ID, PDS)
!
! SUBROUTINE NG_W3FI71(IGRID, IGDS, IERR)
!
! SUBROUTINE NG_W3FI73(IBFLAG, IBMAP, IBLEN, BMS, LENBMS, IER)
!
! SUBROUTINE NG_W3FI74(IGDS, ICOMP, GDS, LENGDS, NPTS, IGERR)
!
! SUBROUTINE NG_W3FI75(IBITL, ITYPE, ITOSS, FLD, IFLD, IBMAP, IBDSFL, NPTS,&
! BDS11, IPFLD, PFLD, LEN, LENBDS, IBERR, PDS, IGDS)
!
! SUBROUTINE NG_W3FI76(PVAL, KEXP, KMANT, KBITS)
!
! SUBROUTINE NG_W3FI82(IFLD, FVAL1, FDIFF1, NPTS, PDS, IGDS)
!
! SUBROUTINE NG_W3FI83(DATA, NPTS, FVAL1, FDIFF1, ISCAL2, ISC10, KPDS, KGDS)
!
! SUBROUTINE NG_W3FS21(IDATE, NMIN)
!
! SUBROUTINE NG_W3FS26(JLDAYN, IYEAR, MONTH, IDAY, IDAYWK, IDAYYR)
!
! INTEGER FUNCTION NG_IW3JDN(IYEAR, MONTH, IDAY)
!
! SUBROUTINE NG_W3DIFDAT(JDAT, IDAT, IT, RINC)
!
! SUBROUTINE NG_W3LOCDAT(IDAT)
!
! SUBROUTINE NG_W3DOXDAT(IDAT, JDOW, JDOY, JDAY)
!
! SUBROUTINE NG_W3MOVDAT(RINC, IDAT, JDAT)
!
! SUBROUTINE NG_W3REDDAT(IT, RINC, DINC)
!
! SUBROUTINE NG_W3UTCDAT(IDAT)
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBMH(LUGB, LUGI, J, JPDS, JGDS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KG, KF, K, KPDS, KGDS, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200)
! INTEGER, INTENT(IN ) :: MBUF
! CHARACTER(1), INTENT( OUT) :: CBUF(MBUF)
! INTEGER, INTENT( OUT) :: NLEN, NNUM, MNUM, KG, KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: FINDS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 94-04-01
!
! ABSTRACT: FIND A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN ITS MESSAGE NUMBER IS
! RETURNED ALONG WITH THE UNPACKED PDS AND GDS PARAMETERS. IF THE
! GRIB MESSAGE IS NOT FOUND, THEN THE RETURN CODE WILL BE NONZERO.
!
! PROGRAM HISTORY LOG:
! 94-04-01 IREDELL
! 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
! AND ALLOWED FOR UNSPECIFIED INDEX FILE
!
! USAGE: CALL NG_GETGBMH(LUGB,LUGI,J,JPDS,JGDS,
! & MBUF,CBUF,NLEN,NNUM,MNUM,
! & KG,KF,K,KPDS,KGDS,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! (ONLY USED IF LUGI=0)
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! MBUF INTEGER LENGTH OF INDEX BUFFER IN BYTES
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! (INITIALIZE BY SETTING J=-1)
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! (INITIALIZE BY SETTING J=-1)
! NNUM INTEGER NUMBER OF INDEX RECORDS
! (INITIALIZE BY SETTING J=-1)
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! (INITIALIZE BY SETTING J=-1)
! OUTPUT ARGUMENTS:
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER NUMBER OF INDEX RECORDS
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! KG INTEGER NUMBER OF BYTES IN THE GRIB MESSAGE
! KF INTEGER NUMBER OF DATA POINTS IN THE MESSAGE
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 99 REQUEST NOT FOUND
!
! REMARKS: SPECIFY AN INDEX FILE IF FEASIBLE TO INCREASE SPEED.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBEMH(LUGB, LUGI, J, JPDS, JGDS, JENS, MBUF, CBUF,&
! NLEN, NNUM, MNUM, KG, KF, K, KPDS, KGDS, KENS, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200), JENS(200)
! INTEGER, INTENT(IN ) :: MBUF
! CHARACTER(1), INTENT( OUT) :: CBUF(MBUF)
! INTEGER, INTENT( OUT) :: NLEN, NNUM, MNUM, KG, KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: FINDS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 94-04-01
!
! ABSTRACT: FIND A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN ITS MESSAGE NUMBER IS
! RETURNED ALONG WITH THE UNPACKED PDS AND GDS PARAMETERS. IF THE
! GRIB MESSAGE IS NOT FOUND, THEN THE RETURN CODE WILL BE NONZERO.
!
! PROGRAM HISTORY LOG:
! 94-04-01 IREDELL
! 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
! AND ALLOWED FOR UNSPECIFIED INDEX FILE
!
! USAGE: CALL NG_GETGBEMH(LUGB,LUGI,J,JPDS,JGDS,JENS,
! & MBUF,CBUF,NLEN,NNUM,MNUM,
! & KG,KF,K,KPDS,KGDS,KENS,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! (ONLY USED IF LUGI=0)
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(23)=2)
! (=-1 FOR WILDCARD)
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
! MBUF INTEGER LENGTH OF INDEX BUFFER IN BYTES
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! (INITIALIZE BY SETTING J=-1)
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! (INITIALIZE BY SETTING J=-1)
! NNUM INTEGER NUMBER OF INDEX RECORDS
! (INITIALIZE BY SETTING J=-1)
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! (INITIALIZE BY SETTING J=-1)
! OUTPUT ARGUMENTS:
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER NUMBER OF INDEX RECORDS
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! KG INTEGER NUMBER OF BYTES IN THE GRIB MESSAGE
! KF INTEGER NUMBER OF DATA POINTS IN THE MESSAGE
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 99 REQUEST NOT FOUND
!
! REMARKS: SPECIFY AN INDEX FILE IF FEASIBLE TO INCREASE SPEED.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBMP(LUGB, LUGI, JG, J, JPDS, JGDS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KG, K, KPDS, KGDS, G, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JG, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200)
! INTEGER, INTENT(IN ) :: MBUF
! CHARACTER(1), INTENT( OUT) :: CBUF(MBUF)
! INTEGER, INTENT( OUT) :: NLEN, NNUM, MNUM, KG, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200)
! CHARACTER(1), INTENT( OUT) :: G(JG)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: FINDS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 94-04-01
!
! ABSTRACT: FIND A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE. ITS MESSAGE NUMBER IS RETURNED ALONG WITH THE UNPACKED
! PDS AND GDS PARAMETERS AND THE PACKED GRIB MESSAGE. IF THE GRIB
! MESSAGE IS NOT FOUND, THEN THE RETURN CODE WILL BE NONZERO.
!
! PROGRAM HISTORY LOG:
! 94-04-01 IREDELL
! 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
! AND ALLOWED FOR UNSPECIFIED INDEX FILE
!
! USAGE: CALL NG_GETGBMP(LUGB,LUGI,JG,J,JPDS,JGDS,
! & MBUF,CBUF,NLEN,NNUM,MNUM,
! & KG,K,KPDS,KGDS,G,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JG INTEGER MAXIMUM NUMBER OF BYTES IN THE GRIB MESSAGE
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! MBUF INTEGER LENGTH OF INDEX BUFFER IN BYTES
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! (INITIALIZE BY SETTING J=-1)
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! (INITIALIZE BY SETTING J=-1)
! NNUM INTEGER NUMBER OF INDEX RECORDS
! (INITIALIZE BY SETTING J=-1)
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! (INITIALIZE BY SETTING J=-1)
! OUTPUT ARGUMENTS:
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER NUMBER OF INDEX RECORDS
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! KG INTEGER NUMBER OF BYTES IN THE GRIB MESSAGE
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! G CHARACTER*1 (KG) GRIB MESSAGE
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF BYTES GREATER THAN JG
! 99 REQUEST NOT FOUND
!
! REMARKS: SPECIFY AN INDEX FILE IF FEASIBLE TO INCREASE SPEED.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBEMP(LUGB, LUGI, JG, J, JPDS, JGDS, JENS, MBUF, CBUF,&
! NLEN, NNUM, MNUM, KG, K, KPDS, KGDS, KENS, G, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JG, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200), JENS(200)
! INTEGER, INTENT(IN ) :: MBUF
! CHARACTER(1), INTENT( OUT) :: CBUF(MBUF)
! INTEGER, INTENT( OUT) :: NLEN, NNUM, MNUM, KG, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! CHARACTER(1), INTENT( OUT) :: G(JG)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: FINDS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 94-04-01
!
! ABSTRACT: FIND A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE. ITS MESSAGE NUMBER IS RETURNED ALONG WITH THE UNPACKED
! PDS AND GDS PARAMETERS AND THE PACKED GRIB MESSAGE. IF THE GRIB
! MESSAGE IS NOT FOUND, THEN THE RETURN CODE WILL BE NONZERO.
!
! PROGRAM HISTORY LOG:
! 94-04-01 IREDELL
! 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
! AND ALLOWED FOR UNSPECIFIED INDEX FILE
!
! USAGE: CALL NG_GETGBEMP(LUGB,LUGI,JG,J,JPDS,JGDS,JENS,
! & MBUF,CBUF,NLEN,NNUM,MNUM,
! & KG,K,KPDS,KGDS,KENS,G,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JG INTEGER MAXIMUM NUMBER OF BYTES IN THE GRIB MESSAGE
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(23)=2)
! (=-1 FOR WILDCARD)
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
! MBUF INTEGER LENGTH OF INDEX BUFFER IN BYTES
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! (INITIALIZE BY SETTING J=-1)
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! (INITIALIZE BY SETTING J=-1)
! NNUM INTEGER NUMBER OF INDEX RECORDS
! (INITIALIZE BY SETTING J=-1)
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! (INITIALIZE BY SETTING J=-1)
! OUTPUT ARGUMENTS:
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER NUMBER OF INDEX RECORDS
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! KG INTEGER NUMBER OF BYTES IN THE GRIB MESSAGE
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! G CHARACTER*1 (KG) GRIB MESSAGE
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF BYTES GREATER THAN JG
! 99 REQUEST NOT FOUND
!
! REMARKS: SPECIFY AN INDEX FILE IF FEASIBLE TO INCREASE SPEED.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBM(LUGB, LUGI, JF, J, JPDS, JGDS, MBUF, CBUF, NLEN,&
! NNUM, MNUM, KF, K, KPDS, KGDS, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JF, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200)
! INTEGER, INTENT(IN ) :: MBUF
! CHARACTER(1), INTENT( OUT) :: CBUF(MBUF)
! INTEGER, INTENT( OUT) :: NLEN, NNUM, MNUM, KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200)
! LOGICAL*1, INTENT( OUT) :: LB(JF) ! 1-Byte LOGICAL
! REAL, INTENT( OUT) :: F(JF)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: FINDS AND UNPACKS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 94-04-01
!
! ABSTRACT: FIND AND UNPACK A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE AND UNPACKED. ITS MESSAGE NUMBER IS RETURNED ALONG WITH
! THE UNPACKED PDS AND GDS PARAMETERS, THE UNPACKED BITMAP (IF ANY),
! AND THE UNPACKED DATA. IF THE GRIB MESSAGE IS NOT FOUND, THEN THE
! RETURN CODE WILL BE NONZERO.
!
! PROGRAM HISTORY LOG:
! 94-04-01 IREDELL
! 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
! AND ALLOWED FOR UNSPECIFIED INDEX FILE
! 04-07-22 CHUANG ADD NBITSS TO THE ARGUMENT LIST OF GETGB1R THAT
! IS CALLED IN THIS SUBROUTINE
! 10-03-02 WANG INCREASE MSK1 TO 256000000 FOR NEMSIO FILES
!
! USAGE: CALL NG_GETGBM(LUGB,LUGI,JF,J,JPDS,JGDS,
! & MBUF,CBUF,NLEN,NNUM,MNUM,
! & KF,K,KPDS,KGDS,LB,F,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JF INTEGER MAXIMUM NUMBER OF DATA POINTS TO UNPACK
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! MBUF INTEGER LENGTH OF INDEX BUFFER IN BYTES
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! (INITIALIZE BY SETTING J=-1)
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! (INITIALIZE BY SETTING J=-1)
! NNUM INTEGER NUMBER OF INDEX RECORDS
! (INITIALIZE BY SETTING J=-1)
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! (INITIALIZE BY SETTING J=-1)
! OUTPUT ARGUMENTS:
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER NUMBER OF INDEX RECORDS
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! KF INTEGER NUMBER OF DATA POINTS UNPACKED
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
! F REAL (KF) UNPACKED DATA
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF DATA POINTS GREATER THAN JF
! 99 REQUEST NOT FOUND
! OTHER W3FI63 GRIB UNPACKER RETURN CODE
!
! REMARKS: SPECIFY AN INDEX FILE IF FEASIBLE TO INCREASE SPEED.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBEM(LUGB, LUGI, JF, J, JPDS, JGDS, JENS, MBUF, CBUF,&
! NLEN, NNUM, MNUM, KF, K, KPDS, KGDS, KENS, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JF, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200), JENS(200)
! INTEGER, INTENT(IN ) :: MBUF
! CHARACTER(1), INTENT( OUT) :: CBUF(MBUF)
! INTEGER, INTENT( OUT) :: NLEN, NNUM, MNUM, KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! LOGICAL*1, INTENT( OUT) :: LB(JF) ! 1-Byte LOGICAL
! REAL, INTENT( OUT) :: F(JF)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: FINDS AND UNPACKS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 94-04-01
!
! ABSTRACT: FIND AND UNPACK A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE AND UNPACKED. ITS MESSAGE NUMBER IS RETURNED ALONG WITH
! THE UNPACKED PDS AND GDS PARAMETERS, THE UNPACKED BITMAP (IF ANY),
! AND THE UNPACKED DATA. IF THE GRIB MESSAGE IS NOT FOUND, THEN THE
! RETURN CODE WILL BE NONZERO.
!
! PROGRAM HISTORY LOG:
! 94-04-01 IREDELL
! 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
! AND ALLOWED FOR UNSPECIFIED INDEX FILE
! 16-10-21 CHIANGTP ADD NBITSS TO THE ARGUMENT LIST OF GETGB1R THAT
! IS CALLED IN THIS SUBROUTINE
!
! USAGE: CALL NG_GETGBEM(LUGB,LUGI,JF,J,JPDS,JGDS,JENS,
! & MBUF,CBUF,NLEN,NNUM,MNUM,
! & KF,K,KPDS,KGDS,KENS,LB,F,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JF INTEGER MAXIMUM NUMBER OF DATA POINTS TO UNPACK
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(23)=2)
! (=-1 FOR WILDCARD)
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
! MBUF INTEGER LENGTH OF INDEX BUFFER IN BYTES
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! (INITIALIZE BY SETTING J=-1)
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! (INITIALIZE BY SETTING J=-1)
! NNUM INTEGER NUMBER OF INDEX RECORDS
! (INITIALIZE BY SETTING J=-1)
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! (INITIALIZE BY SETTING J=-1)
! OUTPUT ARGUMENTS:
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER NUMBER OF INDEX RECORDS
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! KF INTEGER NUMBER OF DATA POINTS UNPACKED
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
! F REAL (KF) UNPACKED DATA
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF DATA POINTS GREATER THAN JF
! 99 REQUEST NOT FOUND
! OTHER W3FI63 GRIB UNPACKER RETURN CODE
!
! REMARKS: SPECIFY AN INDEX FILE IF FEASIBLE TO INCREASE SPEED.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGBEXM(LUGB, LUGI, JF, J, JPDS, JGDS, JENS, MBUF,&
! CBUF, NLEN, NNUM, MNUM, KF, K, KPDS, KGDS,&
! KENS, KPROB, XPROB, KCLUST, KMEMBR, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LUGI, JF, J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200), JENS(200)
! INTEGER, INTENT(IN ) :: MBUF
! CHARACTER(1), INTENT( OUT) :: CBUF(MBUF)
! INTEGER, INTENT( OUT) :: NLEN, NNUM, MNUM, KF, K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! INTEGER, INTENT( OUT) :: KPROB(2), KCLUST(16), KMEMBR(80)
! REAL, INTENT( OUT) :: XPROB(2)
! LOGICAL*1, INTENT( OUT) :: LB(JF) ! 1-Byte LOGICAL
! REAL, INTENT( OUT) :: F(JF)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: FINDS AND UNPACKS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 94-04-01
!
! ABSTRACT: FIND AND UNPACK A GRIB MESSAGE.
! READ A GRIB INDEX FILE (OR OPTIONALLY THE GRIB FILE ITSELF)
! TO GET THE INDEX BUFFER (I.E. TABLE OF CONTENTS) FOR THE GRIB FILE.
! FIND IN THE INDEX BUFFER A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
! IF THE REQUESTED GRIB MESSAGE IS FOUND, THEN IT IS READ FROM THE
! GRIB FILE AND UNPACKED. ITS MESSAGE NUMBER IS RETURNED ALONG WITH
! THE UNPACKED PDS AND GDS PARAMETERS, THE UNPACKED BITMAP (IF ANY),
! AND THE UNPACKED DATA. IF THE GRIB MESSAGE IS NOT FOUND, THEN THE
! RETURN CODE WILL BE NONZERO.
!
! PROGRAM HISTORY LOG:
! 94-04-01 IREDELL
! 95-10-31 IREDELL MODULARIZED PORTIONS OF CODE INTO SUBPROGRAMS
! AND ALLOWED FOR UNSPECIFIED INDEX FILE
! 97-02-11 Y.ZHU INCLUDED PROBABILITY AND CLUSTER ARGUMENTS
!
! USAGE: CALL NG_GETGBEXM(LUGB,LUGI,JF,J,JPDS,JGDS,JENS,
! & MBUF,CBUF,NLEN,NNUM,MNUM,
! & KF,K,KPDS,KGDS,KENS,KPROB,XPROB,KCLUST,KMEMBR,
! & LB,F,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! (=0 TO GET INDEX BUFFER FROM THE GRIB FILE)
! JF INTEGER MAXIMUM NUMBER OF DATA POINTS TO UNPACK
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! (<0 TO READ INDEX BUFFER AND SKIP -1-J MESSAGES)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(23)=2)
! (=-1 FOR WILDCARD)
! (1) - APPLICATION IDENTIFIER
! (2) - ENSEMBLE TYPE
! (3) - ENSEMBLE IDENTIFIER
! (4) - PRODUCT IDENTIFIER
! (5) - SMOOTHING FLAG
! MBUF INTEGER LENGTH OF INDEX BUFFER IN BYTES
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! (INITIALIZE BY SETTING J=-1)
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! (INITIALIZE BY SETTING J=-1)
! NNUM INTEGER NUMBER OF INDEX RECORDS
! (INITIALIZE BY SETTING J=-1)
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! (INITIALIZE BY SETTING J=-1)
! OUTPUT ARGUMENTS:
! CBUF CHARACTER*1 (MBUF) INDEX BUFFER
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER NUMBER OF INDEX RECORDS
! MNUM INTEGER NUMBER OF INDEX RECORDS SKIPPED
! KF INTEGER NUMBER OF DATA POINTS UNPACKED
! K INTEGER MESSAGE NUMBER UNPACKED
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! KPROB INTEGER (2) PROBABILITY ENSEMBLE PARMS
! XPROB REAL (2) PROBABILITY ENSEMBLE PARMS
! KCLUST INTEGER (16) CLUSTER ENSEMBLE PARMS
! KMEMBR INTEGER (8) CLUSTER ENSEMBLE PARMS
! LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
! F REAL (KF) UNPACKED DATA
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 96 ERROR READING INDEX FILE
! 97 ERROR READING GRIB FILE
! 98 NUMBER OF DATA POINTS GREATER THAN JF
! 99 REQUEST NOT FOUND
! OTHER W3FI63 GRIB UNPACKER RETURN CODE
!
! REMARKS: SPECIFY AN INDEX FILE IF FEASIBLE TO INCREASE SPEED.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGIR(LUGB, MSK1, MSK2, MNUM, MBUF, CBUF, NLEN, NNUM, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, MSK1, MSK2, MNUM, MBUF
! CHARACTER(1), INTENT( OUT) :: CBUF(MBUF)
! INTEGER, INTENT( OUT) :: NLEN, NNUM, IRET
!
! SUBPROGRAM: READS A GRIB INDEX FILE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 95-10-31
!
! ABSTRACT: READ A GRIB FILE AND RETURN ITS INDEX CONTENTS.
! THE INDEX BUFFER RETURNED CONTAINS INDEX RECORDS WITH THE INTERNAL FORMAT:
! BYTE 001-004: BYTES TO SKIP IN DATA FILE BEFORE GRIB MESSAGE
! BYTE 005-008: BYTES TO SKIP IN MESSAGE BEFORE PDS
! BYTE 009-012: BYTES TO SKIP IN MESSAGE BEFORE GDS (0 IF NO GDS)
! BYTE 013-016: BYTES TO SKIP IN MESSAGE BEFORE BMS (0 IF NO BMS)
! BYTE 017-020: BYTES TO SKIP IN MESSAGE BEFORE BDS
! BYTE 021-024: BYTES TOTAL IN THE MESSAGE
! BYTE 025-025: GRIB VERSION NUMBER
! BYTE 026-053: PRODUCT DEFINITION SECTION (PDS)
! BYTE 054-095: GRID DEFINITION SECTION (GDS) (OR NULLS)
! BYTE 096-101: FIRST PART OF THE BIT MAP SECTION (BMS) (OR NULLS)
! BYTE 102-112: FIRST PART OF THE BINARY DATA SECTION (BDS)
! BYTE 113-172: (OPTIONAL) BYTES 41-100 OF THE PDS
! BYTE 173-184: (OPTIONAL) BYTES 29-40 OF THE PDS
! BYTE 185-320: (OPTIONAL) BYTES 43-178 OF THE GDS
!
! PROGRAM HISTORY LOG:
! 95-10-31 IREDELL
! 96-10-31 IREDELL AUGMENTED OPTIONAL DEFINITIONS TO BYTE 320
!
! USAGE: CALL NG_GETGIR(LUGB,MSK1,MSK2,MNUM,MBUF,CBUF,NLEN,NNUM,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB FILE
! MSK1 INTEGER NUMBER OF BYTES TO SEARCH FOR FIRST MESSAGE
! MSK2 INTEGER NUMBER OF BYTES TO SEARCH FOR OTHER MESSAGES
! MNUM INTEGER NUMBER OF INDEX RECORDS TO SKIP (USUALLY 0)
! MBUF INTEGER LENGTH OF CBUF IN BYTES
! OUTPUT ARGUMENTS:
! CBUF CHARACTER*1 (MBUF) BUFFER TO RECEIVE INDEX DATA
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER NUMBER OF INDEX RECORDS
! (=0 IF NO GRIB MESSAGES ARE FOUND)
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 1 CBUF TOO SMALL TO HOLD INDEX DATA
!
! REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGI(LUGI, MNUM, MBUF, CBUF, NLEN, NNUM, IRET)
! INTEGER, INTENT(IN ) :: LUGI, MNUM, MBUF
!
! CHARACTER(1), INTENT( OUT) :: CBUF(MBUF)
! INTEGER, INTENT( OUT) :: NLEN, NNUM, IRET
!
! SUBPROGRAM: READS A GRIB INDEX FILE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 95-10-31
!
! ABSTRACT: READ A GRIB INDEX FILE AND RETURN ITS CONTENTS.
! VERSION 1 OF THE INDEX FILE HAS THE FOLLOWING FORMAT:
! 81-BYTE S.LORD HEADER WITH 'GB1IX1' IN COLUMNS 42-47 FOLLOWED BY
! 81-BYTE HEADER WITH NUMBER OF BYTES TO SKIP BEFORE INDEX RECORDS,
! NUMBER OF BYTES IN EACH INDEX RECORD, NUMBER OF INDEX RECORDS,
! AND GRIB FILE BASENAME WRITTEN IN FORMAT ('IX1FORM:',3I10,2X,A40).
! EACH FOLLOWING INDEX RECORD CORRESPONDS TO A GRIB MESSAGE
! AND HAS THE INTERNAL FORMAT:
! BYTE 001-004: BYTES TO SKIP IN DATA FILE BEFORE GRIB MESSAGE
! BYTE 005-008: BYTES TO SKIP IN MESSAGE BEFORE PDS
! BYTE 009-012: BYTES TO SKIP IN MESSAGE BEFORE GDS (0 IF NO GDS)
! BYTE 013-016: BYTES TO SKIP IN MESSAGE BEFORE BMS (0 IF NO BMS)
! BYTE 017-020: BYTES TO SKIP IN MESSAGE BEFORE BDS
! BYTE 021-024: BYTES TOTAL IN THE MESSAGE
! BYTE 025-025: GRIB VERSION NUMBER
! BYTE 026-053: PRODUCT DEFINITION SECTION (PDS)
! BYTE 054-095: GRID DEFINITION SECTION (GDS) (OR NULLS)
! BYTE 096-101: FIRST PART OF THE BIT MAP SECTION (BMS) (OR NULLS)
! BYTE 102-112: FIRST PART OF THE BINARY DATA SECTION (BDS)
! BYTE 113-172: (OPTIONAL) BYTES 41-100 OF THE PDS
! BYTE 173-184: (OPTIONAL) BYTES 29-40 OF THE PDS
! BYTE 185-320: (OPTIONAL) BYTES 43-178 OF THE GDS
!
! PROGRAM HISTORY LOG:
! 95-10-31 IREDELL
! 96-10-31 IREDELL AUGMENTED OPTIONAL DEFINITIONS TO BYTE 320
!
! USAGE: CALL NG_GETGI(LUGI,MNUM,MBUF,CBUF,NLEN,NNUM,IRET)
! INPUT ARGUMENTS:
! LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE
! MNUM INTEGER NUMBER OF INDEX RECORDS TO SKIP (USUALLY 0)
! MBUF INTEGER LENGTH OF CBUF IN BYTES
! OUTPUT ARGUMENTS:
! CBUF CHARACTER*1 (MBUF) BUFFER TO RECEIVE INDEX DATA
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER NUMBER OF INDEX RECORDS
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 1 CBUF TOO SMALL TO HOLD INDEX BUFFER
! 2 ERROR READING INDEX FILE BUFFER
! 3 ERROR READING INDEX FILE HEADER
!
! REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGB1S(CBUF, NLEN, NNUM, J, JPDS, JGDS, JENS, K, KPDS,&
! KGDS, KENS, LSKIP, LGRIB, IRET)
!
! INTEGER, INTENT(IN ) :: NLEN, NNUM
! CHARACTER(1), INTENT(IN ) :: CBUF(NLEN*NNUM)
! INTEGER, INTENT(IN ) :: J
! INTEGER, INTENT(IN ) :: JPDS(200), JGDS(200), JENS(200)
! INTEGER, INTENT( OUT) :: K
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! INTEGER, INTENT( OUT) :: LSKIP, LGRIB, IRET
!
! SUBPROGRAM: FINDS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 95-10-31
!
! ABSTRACT: FIND A GRIB MESSAGE.
! FIND IN THE INDEX FILE A REFERENCE TO THE GRIB MESSAGE REQUESTED.
! THE GRIB MESSAGE REQUEST SPECIFIES THE NUMBER OF MESSAGES TO SKIP
! AND THE UNPACKED PDS AND GDS PARAMETERS. (A REQUESTED PARAMETER
! OF -1 MEANS TO ALLOW ANY VALUE OF THIS PARAMETER TO BE FOUND.)
!
! PROGRAM HISTORY LOG:
! 95-10-31 IREDELL
! 2001-06-05 IREDELL APPLY LINUX PORT BY EBISUZAKI
!
! USAGE: CALL NG_GETGB1S(CBUF,NLEN,NNUM,J,JPDS,JGDS,JENS,
! & K,KPDS,KGDS,KENS,LSKIP,LGRIB,IRET)
! INPUT ARGUMENTS:
! CBUF CHARACTER*1 (NLEN*NNUM) BUFFER CONTAINING INDEX DATA
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER NUMBER OF INDEX RECORDS
! J INTEGER NUMBER OF MESSAGES TO SKIP
! (=0 TO SEARCH FROM BEGINNING)
! JPDS INTEGER (200) PDS PARAMETERS FOR WHICH TO SEARCH
! (=-1 FOR WILDCARD)
! JGDS INTEGER (200) GDS PARAMETERS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(3)=255)
! (=-1 FOR WILDCARD)
! JENS INTEGER (200) ENSEMBLE PDS PARMS FOR WHICH TO SEARCH
! (ONLY SEARCHED IF JPDS(23)=2)
! (=-1 FOR WILDCARD)
! OUTPUT ARGUMENTS:
! K INTEGER MESSAGE NUMBER FOUND
! (CAN BE SAME AS J IN CALLING PROGRAM
! IN ORDER TO FACILITATE MULTIPLE SEARCHES)
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! LSKIP INTEGER NUMBER OF BYTES TO SKIP
! LGRIB INTEGER NUMBER OF BYTES TO READ
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 1 REQUEST NOT FOUND
!
! REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! THIS SUBPROGRAM IS INTENDED FOR PRIVATE USE BY GETGB ROUTINES ONLY.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGB1R(LUGB, LSKIP, LGRIB, KF, KPDS, KGDS, KENS, LB,&
! F, NBITSS ,IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LSKIP, LGRIB
! INTEGER, INTENT( OUT) :: KF
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! LOGICAL*1, INTENT( OUT) :: LB(*) ! 1-Byte LOGICAL
! REAL, INTENT( OUT) :: F(*)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: READS AND UNPACKS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 95-10-31
!
! ABSTRACT: READ AND UNPACK A GRIB MESSAGE.
!
! PROGRAM HISTORY LOG:
! 95-10-31 IREDELL
! 04-07-22 CHUANG ADD PACKING BIT NUMBER NBITSS IN THE ARGUMENT
! LIST BECAUSE ETA GRIB FILES NEED IT TO REPACK GRIB FILE
!
! USAGE: CALL NG_GETGB1R(LUGB,LSKIP,LGRIB,KF,KPDS,KGDS,KENS,LB,F,IRET)
!
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LSKIP INTEGER NUMBER OF BYTES TO SKIP
! LGRIB INTEGER NUMBER OF BYTES TO READ
! OUTPUT ARGUMENTS:
! KF INTEGER NUMBER OF DATA POINTS UNPACKED
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
! F REAL (KF) UNPACKED DATA
! NBITSS INTEGER NUMBER OF PACKING BIT NUMBER
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 97 ERROR READING GRIB FILE
! OTHER W3FI63 GRIB UNPACKER RETURN CODE
!
! REMARKS: THERE IS NO PROTECTION AGAINST UNPACKING TOO MUCH DATA.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
! THIS SUBPROGRAM IS INTENDED FOR PRIVATE USE BY GETGB ROUTINES ONLY.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_GETGB1RE(LUGB, LSKIP, LGRIB, KF, KPDS, KGDS, KENS, KPROB,&
! XPROB, KCLUST, KMEMBR, LB, F, IRET)
!
! INTEGER, INTENT(IN ) :: LUGB, LSKIP, LGRIB
! INTEGER, INTENT( OUT) :: KF
! INTEGER, INTENT( OUT) :: KPDS(200), KGDS(200), KENS(200)
! INTEGER, INTENT( OUT) :: KPROB(2), KCLUST(16), KMEMBR(80)
! REAL, INTENT( OUT) :: XPROB(2)
! LOGICAL*1, INTENT( OUT) :: LB(*) ! 1-Byte LOGICAL
! REAL, INTENT( OUT) :: F(*)
! INTEGER, INTENT( OUT) :: IRET
!
! SUBPROGRAM: READS AND UNPACKS A GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 95-10-31
!
! ABSTRACT: READ AND UNPACK A GRIB MESSAGE.
!
! PROGRAM HISTORY LOG:
! 95-10-31 IREDELL
! 97-02-11 Y.ZHU INCLUDED PROBABILITY AND CLUSTER ARGUMENTS
!
! USAGE: CALL NG_GETGB1RE(LUGB,LSKIP,LGRIB,KF,KPDS,KGDS,KENS,
! & KPROB,XPROB,KCLUST,KMEMBR,LB,F,IRET)
! INPUT ARGUMENTS:
! LUGB INTEGER UNIT OF THE UNBLOCKED GRIB DATA FILE
! LSKIP INTEGER NUMBER OF BYTES TO SKIP
! LGRIB INTEGER NUMBER OF BYTES TO READ
! OUTPUT ARGUMENTS:
! KF INTEGER NUMBER OF DATA POINTS UNPACKED
! KPDS INTEGER (200) UNPACKED PDS PARAMETERS
! KGDS INTEGER (200) UNPACKED GDS PARAMETERS
! KENS INTEGER (200) UNPACKED ENSEMBLE PDS PARMS
! KPROB INTEGER (2) PROBABILITY ENSEMBLE PARMS
! XPROB REAL (2) PROBABILITY ENSEMBLE PARMS
! KCLUST INTEGER (16) CLUSTER ENSEMBLE PARMS
! KMEMBR INTEGER (8) CLUSTER ENSEMBLE PARMS
! LB LOGICAL*1 (KF) UNPACKED BITMAP IF PRESENT
! F REAL (KF) UNPACKED DATA
! IRET INTEGER RETURN CODE
! 0 ALL OK
! 97 ERROR READING GRIB FILE
! OTHER W3FI63 GRIB UNPACKER RETURN CODE
!
! REMARKS: THERE IS NO PROTECTION AGAINST UNPACKING TOO MUCH DATA.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
! DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR.
! THIS SUBPROGRAM IS INTENDED FOR PRIVATE USE BY GETGB ROUTINES ONLY.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_SKGB(LUGB, ISEEK, MSEEK, LSKIP, LGRIB)
!
! INTEGER, INTENT(IN ) :: LUGB, ISEEK, MSEEK
! INTEGER, INTENT( OUT) :: LSKIP, LGRIB
!
! SUBPROGRAM: SEARCH FOR NEXT GRIB MESSAGE
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 93-11-22
!
! ABSTRACT: THIS SUBPROGRAM SEARCHES A FILE FOR THE NEXT GRIB 1 MESSAGE.
! A GRIB 1 MESSAGE IS IDENTIFIED BY ITS INDICATOR SECTION, I.E.
! AN 8-BYTE SEQUENCE WITH 'GRIB' IN BYTES 1-4 AND 1 IN BYTE 8.
! IF FOUND, THE LENGTH OF THE MESSAGE IS DECODED FROM BYTES 5-7.
! THE SEARCH IS DONE OVER A GIVEN SECTION OF THE FILE.
! THE SEARCH IS TERMINATED IF AN EOF OR I/O ERROR IS ENCOUNTERED.
!
! PROGRAM HISTORY LOG:
! 93-11-22 IREDELL
! 95-10-31 IREDELL ADD CALL TO BAREAD
! 97-03-14 IREDELL CHECK FOR '7777'
! 2001-12-05 GILBERT MODIFIED TO ALSO LOOK FOR GRIB2 MESSAGES
!
! USAGE: CALL NG_SKGB(LUGB,ISEEK,MSEEK,LSKIP,LGRIB)
! INPUT ARGUMENTS:
! LUGB INTEGER LOGICAL UNIT OF INPUT GRIB FILE
! ISEEK INTEGER NUMBER OF BYTES TO SKIP BEFORE SEARCH
! MSEEK INTEGER MAXIMUM NUMBER OF BYTES TO SEARCH
! OUTPUT ARGUMENTS:
! LSKIP INTEGER NUMBER OF BYTES TO SKIP BEFORE MESSAGE
! LGRIB INTEGER NUMBER OF BYTES IN MESSAGE (0 IF NOT FOUND)
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_IXGB(LUGB, LSKIP, LGRIB, NLEN, NNUM, MLEN, CBUF)
!
! INTEGER, INTENT(IN ) :: LUGB, LSKIP, LGRIB, NLEN, NNUM
! INTEGER, INTENT( OUT) :: MLEN
! CHARACTER(1), INTENT( OUT) :: CBUF(*)
!
! SUBPROGRAM: MAKE INDEX RECORD
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 95-10-31
!
! ABSTRACT: THIS SUBPROGRAM MAKES ONE INDEX RECORD.
! BYTE 001-004: BYTES TO SKIP IN DATA FILE BEFORE GRIB MESSAGE
! BYTE 005-008: BYTES TO SKIP IN MESSAGE BEFORE PDS
! BYTE 009-012: BYTES TO SKIP IN MESSAGE BEFORE GDS (0 IF NO GDS)
! BYTE 013-016: BYTES TO SKIP IN MESSAGE BEFORE BMS (0 IF NO BMS)
! BYTE 017-020: BYTES TO SKIP IN MESSAGE BEFORE BDS
! BYTE 021-024: BYTES TOTAL IN THE MESSAGE
! BYTE 025-025: GRIB VERSION NUMBER
! BYTE 026-053: PRODUCT DEFINITION SECTION (PDS)
! BYTE 054-095: GRID DEFINITION SECTION (GDS) (OR NULLS)
! BYTE 096-101: FIRST PART OF THE BIT MAP SECTION (BMS) (OR NULLS)
! BYTE 102-112: FIRST PART OF THE BINARY DATA SECTION (BDS)
! BYTE 113-172: (OPTIONAL) BYTES 41-100 OF THE PDS
! BYTE 173-184: (OPTIONAL) BYTES 29-40 OF THE PDS
! BYTE 185-320: (OPTIONAL) BYTES 43-178 OF THE GDS
!
! PROGRAM HISTORY LOG:
! 95-10-31 IREDELL
! 96-10-31 IREDELL AUGMENTED OPTIONAL DEFINITIONS TO BYTE 320
! 2001-06-05 IREDELL APPLY LINUX PORT BY EBISUZAKI
!
! USAGE: CALL NG_IXGB(LUGB, LSKIP, LGRIB, NLEN, NNUM, MLEN, CBUF)
! INPUT ARGUMENTS:
! LUGB INTEGER LOGICAL UNIT OF INPUT GRIB FILE
! LSKIP INTEGER NUMBER OF BYTES TO SKIP BEFORE GRIB MESSAGE
! LGRIB INTEGER NUMBER OF BYTES IN GRIB MESSAGE
! NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES
! NNUM INTEGER INDEX RECORD NUMBER TO MAKE
! OUTPUT ARGUMENTS:
! MLEN INTEGER ACTUAL VALID LENGTH OF INDEX RECORD
! CBUF CHARACTER*1 (MBUF) BUFFER TO RECEIVE INDEX DATA
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_PDSENS(KENS, KPROB, XPROB, KCLUST, KMEMBR, ILAST, MSGA)
!
! INTEGER, INTENT(IN ) :: KENS(5), KPROB(2), KCLUST(16), KMEMBR(80)
! REAL, INTENT(IN ) :: XPROB(2)
! INTEGER, INTENT(IN ) :: ILAST
! CHARACTER(1), INTENT( OUT) :: MSGA(100)
!
! SUBPROGRAM: PACKS GRIB PDS EXTENSION 41- FOR ENSEMBLE
! PRGMMR: RICHARD WOBUS ORG: W/NP20 DATE: 98-09-28
!
! ABSTRACT: PACKS BRIB PDS EXTENSION STARTING ON BYTE 41 FOR ENSEMBLE
! FORECAST PRODUCTS. FOR FORMAT OF PDS EXTENSION, SEE NMC OFFICE NOTE 38
!
! PROGRAM HISTORY LOG:
! 95-03-14 ZOLTAN TOTH AND MARK IREDELL
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
! 98-09-28 WOBUS CORRECTED MEMBER ENTRY, BLANK ALL UNUSED FIELDS
! 2001-06-05 IREDELL APPLY LINUX PORT BY EBISUZAKI
!
! USAGE: CALL NG_PDSENS(KENS,KPROB,XPROB,KCLUST,KMEMBR,ILAST,MSGA)
! INPUT ARGUMENT LIST:
! KENS(5) - BYTES 41-45 (GENERAL SECTION, ALWAYS PRESENT.)
! KPROB(2) - BYTES 46-47 (PROBABILITY SECTION, PRESENT ONLY IF NEEDE
! XPROB(2) - BYTES 48-51&52-55 (PROBABILITY SECTION, IF NEEDED.)
! KCLUST(16)-BYTES 61-76 (CLUSTERING SECTION, IF NEEDED.)
! KMEMBR(80)-BYTES 77-86 (CLUSTER MEMBERSHIP SECTION, IF NEEDED.)
! ILAST - LAST BYTE TO BE PACKED (IF GREATER OR EQUAL TO FIRST BY
! IN ANY OF FOUR SECTIONS ABOVE, WHOLE SECTION IS PACKED.
!
! OUTPUT ARGUMENT LIST: (INCLUDING WORK ARRAYS)
! MSGA - FULL PDS SECTION, INCLUDING NEW ENSEMBLE EXTENSION
!
! REMARKS: USE PDSEUP.F FOR UNPACKING PDS ENSEMBLE EXTENSION.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_PDSEUP(KENS, KPROB, XPROB, KCLUST, KMEMBR, ILAST, MSGA)
!
! INTEGER, INTENT(IN ) :: ILAST
! CHARACTER(1), INTENT(IN ) :: MSGA(100)
! INTEGER, INTENT( OUT) :: KENS(5), KPROB(2), KCLUST(16), KMEMBR(80)
! REAL, INTENT( OUT) :: XPROB(2)
!
! SUBPROGRAM: UNPACKS GRIB PDS EXTENSION 41- FOR ENSEMBLE
! PRGMMR: RICHARD WOBUS ORG: W/NP20 DATE: 98-09-28
!
! ABSTRACT: UNPACKS GRIB PDS EXTENSION STARTING ON BYTE 41 FOR ENSEMBLE
! FORECAST PRODUCTS. FOR FORMAT OF PDS EXTENSION, SEE NMC OFFICE NOTE 38
!
! PROGRAM HISTORY LOG:
! 95-03-14 ZOLTAN TOTH AND MARK IREDELL
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
! 98-09-28 WOBUS CORRECTED MEMBER EXTRACTION
! 2001-06-05 IREDELL APPLY LINUX PORT BY EBISUZAKI
!
! USAGE: CALL NG_PDSENS(KENS,KPROB,XPROB,KCLUST,KMEMBR,ILAST,MSGA)
! INPUT ARGUMENT LIST:
! ILAST - LAST BYTE TO BE UNPACKED (IF GREATER/EQUAL TO FIRST BYT
! IN ANY OF FOUR SECTIONS BELOW, WHOLE SECTION IS PACKED.
! MSGA - FULL PDS SECTION, INCLUDING NEW ENSEMBLE EXTENSION
!
! OUTPUT ARGUMENT LIST: (INCLUDING WORK ARRAYS)
! KENS(5) - BYTES 41-45 (GENERAL SECTION, ALWAYS PRESENT.)
! KPROB(2) - BYTES 46-47 (PROBABILITY SECTION, PRESENT ONLY IF NEEDE
! XPROB(2) - BYTES 48-51&52-55 (PROBABILITY SECTION, IF NEEDED.)
! KCLUST(16)-BYTES 61-76 (CLUSTERING SECTION, IF NEEDED.)
! KMEMBR(80)-BYTES 77-86 (CLUSTER MEMBERSHIP SECTION, IF NEEDED.)
!
! REMARKS: USE PDSENS.F FOR PACKING PDS ENSEMBLE EXTENSION.
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
!---------------------------------------------------------------------
!
! INTEGER FUNCTION NG_LENGDS(KGDS)
!
! INTEGER, INTENT(IN) :: KGDS(200)
!
! SUBPROGRAM: RETURN THE LENGTH OF A GRID
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 96-07-19
!
! ABSTRACT: GIVEN A GRID DESCRIPTION SECTION (IN W3FI63 FORMAT),
! RETURN ITS SIZE IN TERMS OF NUMBER OF DATA POINTS.
!
! PROGRAM HISTORY LOG:
! 96-07-19 IREDELL
!
! USAGE: NG_LENGDS(KGDS)
! INPUT ARGUMENTS:
! KGDS INTEGER (200) GDS PARAMETERS IN W3FI63 FORMAT
! OUTPUT ARGUMENTS:
! NG_LENGDS INTEGER SIZE OF GRID
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI63(MSGA, KPDS, KGDS, KBMS, DATA, KPTR, KRET)
!
! CHARACTER(1), INTENT(IN ) :: MSGA(*)
! LOGICAL*1, INTENT( OUT) :: KBMS(*) ! 1-Byte LOGICAL
! INTEGER, INTENT( OUT) :: KPDS(*)
! INTEGER, INTENT( OUT) :: KGDS(*)
! REAL, INTENT( OUT) :: DATA(*)
! INTEGER, INTENT( OUT) :: KPTR(*)
! INTEGER, INTENT( OUT) :: KRET
!
! SUBPROGRAM: UNPK GRIB FIELD TO GRIB GRID
! PRGMMR: FARLEY ORG: NMC421 DATE:94-11-22
!
! ABSTRACT: UNPACK A GRIB (EDITION 1) FIELD TO THE EXACT GRID
! SPECIFIED IN THE GRIB MESSAGE, ISOLATE THE BIT MAP, AND MAKE
! THE VALUES OF THE PRODUCT DESCRIPTON SECTION (PDS) AND THE
! GRID DESCRIPTION SECTION (GDS) AVAILABLE IN RETURN ARRAYS.
!
! WHEN DECODING IS COMPLETED, DATA AT EACH GRID POINT HAS BEEN
! RETURNED IN THE UNITS SPECIFIED IN THE GRIB MANUAL.
!
! PROGRAM HISTORY LOG:
! 91-09-13 CAVANAUGH
! 91-11-12 CAVANAUGH MODIFIED SIZE OF ECMWF GRIDS 5-8
! 91-12-22 CAVANAUGH CORRECTED PROCESSING OF MERCATOR PROJECTIONS
! IN GRID DEFINITION SECTION (GDS) IN
! ROUTINE FI633
! 92-08-05 CAVANAUGH CORRECTED MAXIMUM GRID SIZE TO ALLOW FOR
! ONE DEGREE BY ONE DEGREE GLOBAL GRIDS
! 92-08-27 CAVANAUGH CORRECTED TYPO ERROR, ADDED CODE TO COMPARE
! TOTAL BYTE SIZE FROM SECTION 0 WITH SUM OF
! SECTION SIZES.
! 92-10-21 CAVANAUGH CORRECTIONS WERE MADE (IN FI634) TO REDUCE
! PROCESSING TIME FOR INTERNATIONAL GRIDS.
! REMOVED A TYPOGRAPHICAL ERROR IN FI635.
! 93-01-07 CAVANAUGH CORRECTIONS WERE MADE (IN FI635) TO
! FACILITATE USE OF THESE ROUTINES ON A PC.
! A TYPOGRAPHICAL ERROR WAS ALSO CORRECTED
! 93-01-13 CAVANAUGH CORRECTIONS WERE MADE (IN FI632) TO
! PROPERLY HANDLE CONDITION WHEN
! TIME RANGE INDICATOR = 10.
! ADDED U.S.GRID 87.
! 93-02-04 CAVANAUGH ADDED U.S.GRIDS 85 AND 86
! 93-02-26 CAVANAUGH ADDED GRIDS 2, 3, 37 THRU 44,AND
! GRIDS 55, 56, 90, 91, 92, AND 93 TO
! LIST OF U.S. GRIDS.
! 93-04-07 CAVANAUGH ADDED GRIDS 67 THRU 77 TO
! LIST OF U.S. GRIDS.
! 93-04-20 CAVANAUGH INCREASED MAX SIZE TO ACCOMODATE
! GAUSSIAN GRIDS.
! 93-05-26 CAVANAUGH CORRECTED GRID RANGE SELECTION IN FI634
! FOR RANGES 67-71 & 75-77
! 93-06-08 CAVANAUGH CORRECTED FI635 TO ACCEPT GRIB MESSAGES
! WITH SECOND ORDER PACKING. ADDED ROUTINE FI636
! TO PROCESS MESSAGES WITH SECOND ORDER PACKING.
! 93-09-22 CAVANAUGH MODIFIED TO EXTRACT SUB-CENTER NUMBER FROM
! PDS BYTE 26
! 93-10-13 CAVANAUGH MODIFIED FI634 TO CORRECT GRID SIZES FOR
! GRIDS 204 AND 208
! 93-10-14 CAVANAUGH INCREASED SIZE OF KGDS TO INCLUDE ENTRIES FOR
! NUMBER OF POINTS IN GRID AND NUMBER OF WORDS
! IN EACH ROW
! 93-12-08 CAVANAUGH CORRECTED TEST FOR EDITION NUMBER INSTEAD
! OF VERSION NUMBER
! 93-12-15 CAVANAUGH MODIFIED SECOND ORDER POINTERS TO FIRST ORDER
! VALUES AND SECOND ORDER VALUES CORRECTLY
! IN ROUTINE FI636
! 94-03-02 CAVANAUGH ADDED CALL TO W3FI83 WITHIN DECODER. USER
! NO LONGER NEEDS TO MAKE CALL TO THIS ROUTINE
! 94-04-22 CAVANAUGH MODIFIED FI635, FI636 TO PROCESS ROW BY ROW
! SECOND ORDER PACKING, ADDED SCALING CORRECTION
! TO FI635, AND CORRECTED TYPOGRAPHICAL ERRORS
! IN COMMENT FIELDS IN FI634
! 94-05-17 CAVANAUGH CORRECTED ERROR IN FI633 TO EXTRACT RESOLUTION
! FOR LAMBERT-CONFORMAL GRIDS. ADDED CLARIFYING
! INFORMATION TO DOCBLOCK ENTRIES
! 94-05-25 CAVANAUGH ADDED CODE TO PROCESS COLUMN BY COLUMN AS WELL
! AS ROW BY ROW ORDERING OF SECOND ORDER DATA
! 94-06-27 CAVANAUGH ADDED PROCESSING FOR GRIDS 45, 94 AND 95.
! INCLUDES CONSTRUCTION OF SECOND ORDER BIT MAPS
! FOR THINNED GRIDS IN FI636.
! 94-07-08 CAVANAUGH COMMENTED OUT PRINT OUTS USED FOR DEBUGGING
! 94-09-08 CAVANAUGH ADDED GRIDS 220, 221, 223 FOR FNOC
! 94-11-10 FARLEY INCREASED MXSIZE FROM 72960 TO 260000
! FOR .5 DEGREE SST ANALYSIS FIELDS
! 94-12-06 R.E.JONES CHANGES IN FI632 FOR PDS GREATER THAN 28
! 95-02-14 R.E.JONES CORRECT IN FI633 FOR NAVY WAFS GRIB
! 95-03-20 M.BALDWIN FI633 MODIFICATION TO GET
! DATA REP TYPES [KGDS(1)] 201 AND 202 TO WORK.
! 95-04-10 E.ROGERS ADDED GRIDS 96 AND 97 FOR ETA MODEL IN FI634.
! 95-04-26 R.E.JONES FI636 CORECTION FOR 2ND ORDER COMPLEX
! UNPACKING. R
! 95-05-19 R.E.JONES ADDED GRID 215, 20 KM AWIPS GRID
! 95-07-06 R.E.JONES ADDED GAUSSIAN T62, T126 GRID 98, 126
! 95-10-19 R.E.JONES ADDED GRID 216, 45 KM ETA AWIPS ALASKA GRID
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
! 96-03-07 R.E.JONES CONTINUE UNPACK WITH KRET ERROR 9 IN FI631.
! 96-08-19 R.E.JONES ADDED MERCATOR GRIDS 8 AND 53, AND GRID 196
! 97-02-12 W BOSTELMAN CORRECTS ECMWF US GRID 2 PROCESSING
! 98-06-17 IREDELL REMOVED ALTERNATE RETURN IN FI637
! 98-08-31 IREDELL ELIMINATED NEED FOR MXSIZE
! 98-09-02 Gilbert Corrected error in map size for U.S. Grid 92
! 98-09-08 BALDWIN ADD DATA REP TYPE [KGDS(1)] 203
! 01-03-08 ROGERS CHANGED ETA GRIDS 90-97, ADDED ETA GRIDS
! 194, 198. ADDED AWIPS GRIDS 241,242,243,
! 245, 246, 247, 248, AND 250
! 01-03-19 VUONG ADDED AWIPS GRIDS 238,239,240, AND 244
! 2001-06-06 GILBERT Changed gbyte/sbyte calls to refer to
! Wesley Ebisuzaki's endian independent
! versions gbytec/sbytec.
! Removed equivalences.
! 01-05-03 ROGERS ADDED GRID 249 (12KM FOR ALASKA)
! 01-10-10 ROGERS REDEFINED GRID 218 FOR 12 KM ETA
! REDEFINED GRID 192 FOR NEW 32-KM ETA GRID
! 02-03-27 VUONG ADDED RSAS GRID 88 AND AWIPS GRIDS 219, 220,
! 223, 224, 225, 226, 227, 228, 229, 230, 231,
! 232, 233, 234, 235, 251, AND 252
! 02-08-06 ROGERS REDEFINED GRIDS 90-93,97,194,245-250 FOR THE
! 8KM HI-RES-WINDOW MODEL AND ADD AWIPS GRID 253
! 2003-06-30 GILBERT SET NEW VALUES IN ARRAY KPTR TO PASS BACK ADDITIONAL
! PACKING INFO.
! KPTR(19) - BINARY SCALE FACTOR
! KPTR(20) - NUM BITS USED TO PACK EACH DATUM
! 2003-06-30 GILBERT ADDED GRIDS 145 and 146 for CMAQ
! and GRID 175 for AWIPS over GUAM.
! 2003-07-08 VUONG ADDED GRIDS 110, 127, 171, 172 AND MODIFIED GRID 170
! 2004-09-02 VUONG ADDED AWIPS GRIDS 147, 148, 173 AND 254
! 2005-01-04 COOKE ADDED AWIPS GRIDS 160 AND 161
! 2005-03-03 VUONG MOVED GRID 170 TO GRID 174 AND ADD GRID 170
! 2005-03-21 VUONG ADDED AWIPS GRID 130
! 2005-10-11 VUONG ADDED AWIPS GRID 163
! 2006-12-12 VUONG ADDED AWIPS GRID 120
! 2007-04-12 VUONG ADDED AWIPS 176 AND DATA REP TYPE KGDS(1) 204
! 2007-06-11 VUONG ADDED NEW GRIDS 11 TO 18 AND 122 TO 125 AND 138
! AND 180 TO 183
! 2007-11-06 VUONG CHANGED GRID 198 FROM ARAKAWA STAGGERED E-GRID TO POLAR
! STEREOGRAPGIC GRID ADDED NEW GRID 10, 99, 150, 151, 197
! 2008-01-17 VUONG ADDED NEW GRID 195 AND CHANGED GRID 196 (ARAKAWA-E TO MERCATOR)
! 2009-05-21 VUONG MODIFIED TO HANDLE GRID 45
! 2010-05-11 VUONG DATA REP TYPE KGDS(1) 205
! 2010-02-18 VUONG ADDED GRID 128, 139 AND 140
! 2010-07-20 GAYNO ADDED ROTATED LAT/LON "A,B,C,D" STAGGERS -> KGDS(1) 205
! 2010-08-05 VUONG ADDED NEW GRID 184, 199, 83 AND
! REDEFINED GRID 90 FOR NEW RTMA CONUS 1.27-KM
! REDEFINED GRID 91 FOR NEW RTMA ALASKA 2.976-KM
! REDEFINED GRID 92 FOR NEW RTMA ALASKA 1.488-KM
! 2010-09-08 ROGERS CHANGED GRID 94 TO ALASKA 6KM STAGGERED B-GRID
! CHANGED GRID 95 TO PUERTO RICO 3KM STAGGERED B-GRID
! CHANGED GRID 96 TO HAWAII 3KM STAGGERED B-GRID
! CHANGED GRID 96 TO HAWAII 3KM STAGGERED B-GRID
! CHANGED GRID 97 TO CONUS 4KM STAGGERED B-GRID
! CHANGED GRID 99 TO NAM 12KM STAGGERED B-GRID
! ADDED GRID 179 (12 KM POLAR STEREOGRAPHIC OVER NORTH AMERICA)
! CHANGED GRID 194 TO 3KM MERCATOR GRID OVER PUERTO RICO
! CORRECTED LATITUDE OF SW CORNER POINT OF GRID 151
! 2011-10-12 VUONG ADDED GRID 129, 187, 188, 189 AND 193
! 2012-04-16 VUONG ADDED NEW GRID 132, 200
! 2017-07-17 VUONG CORRECT GRID 161 NUMBER OF POINT Nj from 102 to 103
! AND MAP SIZE FROM 13974 TO 14111
!
! USAGE: CALL NG_W3FI63(MSGA,KPDS,KGDS,KBMS,DATA,KPTR,KRET)
! INPUT ARGUMENT LIST:
! MSGA - GRIB FIELD - "GRIB" THRU "7777" CHAR*1
! (MESSAGE CAN BE PRECEDED BY JUNK CHARS)
!
! OUTPUT ARGUMENT LIST:
! DATA - ARRAY CONTAINING DATA ELEMENTS
! KPDS - ARRAY CONTAINING PDS ELEMENTS. (EDITION 1)
! (1) - ID OF CENTER
! (2) - GENERATING PROCESS ID NUMBER
! (3) - GRID DEFINITION
! (4) - GDS/BMS FLAG (RIGHT ADJ COPY OF OCTET 8)
! (5) - INDICATOR OF PARAMETER
! (6) - TYPE OF LEVEL
! (7) - HEIGHT/PRESSURE , ETC OF LEVEL
! (8) - YEAR INCLUDING (CENTURY-1)
! (9) - MONTH OF YEAR
! (10) - DAY OF MONTH
! (11) - HOUR OF DAY
! (12) - MINUTE OF HOUR
! (13) - INDICATOR OF FORECAST TIME UNIT
! (14) - TIME RANGE 1
! (15) - TIME RANGE 2
! (16) - TIME RANGE FLAG
! (17) - NUMBER INCLUDED IN AVERAGE
! (18) - VERSION NR OF GRIB SPECIFICATION
! (19) - VERSION NR OF PARAMETER TABLE
! (20) - NR MISSING FROM AVERAGE/ACCUMULATION
! (21) - CENTURY OF REFERENCE TIME OF DATA
! (22) - UNITS DECIMAL SCALE FACTOR
! (23) - SUBCENTER NUMBER
! (24) - PDS BYTE 29, FOR NMC ENSEMBLE PRODUCTS
! 128 IF FORECAST FIELD ERROR
! 64 IF BIAS CORRECTED FCST FIELD
! 32 IF SMOOTHED FIELD
! WARNING: CAN BE COMBINATION OF MORE THAN 1
! (25) - PDS BYTE 30, NOT USED
! (26-35) - RESERVED
! (36-N) - CONSECUTIVE BYTES EXTRACTED FROM PROGRAM
! DEFINITION SECTION (PDS) OF GRIB MESSAGE
! KGDS - ARRAY CONTAINING GDS ELEMENTS.
! (1) - DATA REPRESENTATION TYPE
! (19) - NUMBER OF VERTICAL COORDINATE PARAMETERS
! (20) - OCTET NUMBER OF THE LIST OF VERTICAL COORDINATE
! PARAMETERS
! OR
! OCTET NUMBER OF THE LIST OF NUMBERS OF POINTS
! IN EACH ROW
! OR
! 255 IF NEITHER ARE PRESENT
! (21) - FOR GRIDS WITH PL, NUMBER OF POINTS IN GRID
! (22) - NUMBER OF WORDS IN EACH ROW
! LATITUDE/LONGITUDE GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! GAUSSIAN GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF EXTREME POINT
! (8) - LO(2) LONGITUDE OF EXTREME POINT
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - N - NR OF CIRCLES POLE TO EQUATOR
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - NV - NR OF VERT COORD PARAMETERS
! (13) - PV - OCTET NR OF LIST OF VERT COORD PARAMETERS
! OR
! PL - LOCATION OF THE LIST OF NUMBERS OF POINTS IN
! EACH ROW (IF NO VERT COORD PARAMETERS
! ARE PRESENT
! OR
! 255 IF NEITHER ARE PRESENT
! POLAR STEREOGRAPHIC GRIDS
! (2) - N(I) NR POINTS ALONG LAT CIRCLE
! (3) - N(J) NR POINTS ALONG LON CIRCLE
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV GRID ORIENTATION
! (8) - DX - X DIRECTION INCREMENT
! (9) - DY - Y DIRECTION INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE (RIGHT ADJ COPY OF OCTET 28)
! SPHERICAL HARMONIC COEFFICIENTS
! (2) - J PENTAGONAL RESOLUTION PARAMETER
! (3) - K " " "
! (4) - M " " "
! (5) - REPRESENTATION TYPE
! (6) - COEFFICIENT STORAGE MODE
! MERCATOR GRIDS
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF LAST GRID POINT
! (8) - LO(2) LONGITUDE OF LAST GRID POINT
! (9) - LATIT - LATITUDE OF PROJECTION INTERSECTION
! (10) - RESERVED
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LONGITUDINAL DIR GRID LENGTH
! (13) - LATITUDINAL DIR GRID LENGTH
! LAMBERT CONFORMAL GRIDS
! (2) - NX NR POINTS ALONG X-AXIS
! (3) - NY NR POINTS ALONG Y-AXIS
! (4) - LA1 LAT OF ORIGIN (LOWER LEFT)
! (5) - LO1 LON OF ORIGIN (LOWER LEFT)
! (6) - RESOLUTION (RIGHT ADJ COPY OF OCTET 17)
! (7) - LOV - ORIENTATION OF GRID
! (8) - DX - X-DIR INCREMENT
! (9) - DY - Y-DIR INCREMENT
! (10) - PROJECTION CENTER FLAG
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATIN 1 - FIRST LAT FROM POLE OF SECANT CONE INTER
! (13) - LATIN 2 - SECOND LAT FROM POLE OF SECANT CONE INTER
! E-STAGGERED ARAKAWA ROTATED LAT/LON GRIDS (TYPE 203)
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF ORIGIN
! (5) - LO(1) LONGITUDE OF ORIGIN
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF CENTER
! (8) - LO(2) LONGITUDE OF CENTER
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! CURVILINEAR ORTHIGINAL GRID (TYPE 204)
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - RESERVED SET TO 0
! (5) - RESERVED SET TO 0
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - RESERVED SET TO 0
! (8) - RESERVED SET TO 0
! (9) - RESERVED SET TO 0
! (10) - RESERVED SET TO 0
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! ROTATED LAT/LON A,B,C,D-STAGGERED (TYPE 205)
! (2) - N(I) NR POINTS ON LATITUDE CIRCLE
! (3) - N(J) NR POINTS ON LONGITUDE MERIDIAN
! (4) - LA(1) LATITUDE OF FIRST POINT
! (5) - LO(1) LONGITUDE OF FIRST POINT
! (6) - RESOLUTION FLAG (RIGHT ADJ COPY OF OCTET 17)
! (7) - LA(2) LATITUDE OF CENTER
! (8) - LO(2) LONGITUDE OF CENTER
! (9) - DI LONGITUDINAL DIRECTION OF INCREMENT
! (10) - DJ LATITUDINAL DIRECTION INCREMENT
! (11) - SCANNING MODE FLAG (RIGHT ADJ COPY OF OCTET 28)
! (12) - LATITUDE OF LAST POINT
! (13) - LONGITUDE OF LAST POINT
! KBMS - BITMAP DESCRIBING LOCATION OF OUTPUT ELEMENTS.
! (ALWAYS CONSTRUCTED)
! KPTR - ARRAY CONTAINING STORAGE FOR FOLLOWING PARAMETERS
! (1) - TOTAL LENGTH OF GRIB MESSAGE
! (2) - LENGTH OF INDICATOR (SECTION 0)
! (3) - LENGTH OF PDS (SECTION 1)
! (4) - LENGTH OF GDS (SECTION 2)
! (5) - LENGTH OF BMS (SECTION 3)
! (6) - LENGTH OF BDS (SECTION 4)
! (7) - VALUE OF CURRENT BYTE
! (8) - BIT POINTER
! (9) - GRIB START BIT NR
! (10) - GRIB/GRID ELEMENT COUNT
! (11) - NR UNUSED BITS AT END OF SECTION 3
! (12) - BIT MAP FLAG (COPY OF BMS OCTETS 5,6)
! (13) - NR UNUSED BITS AT END OF SECTION 2
! (14) - BDS FLAGS (RIGHT ADJ COPY OF OCTET 4)
! (15) - NR UNUSED BITS AT END OF SECTION 4
! (16) - RESERVED
! (17) - RESERVED
! (18) - RESERVED
! (19) - BINARY SCALE FACTOR
! (20) - NUM BITS USED TO PACK EACH DATUM
! KRET - FLAG INDICATING QUALITY OF COMPLETION
!
! REMARKS: WHEN DECODING IS COMPLETED, DATA AT EACH GRID POINT HAS BEEN
! RETURNED IN THE UNITS SPECIFIED IN THE GRIB MANUAL.
!
! VALUES FOR RETURN FLAG (KRET)
! KRET = 0 - NORMAL RETURN, NO ERRORS
! = 1 - 'GRIB' NOT FOUND IN FIRST 100 CHARS
! = 2 - '7777' NOT IN CORRECT LOCATION
! = 3 - UNPACKED FIELD IS LARGER THAN 260000
! = 4 - GDS/ GRID NOT ONE OF CURRENTLY ACCEPTED VALUES
! = 5 - GRID NOT CURRENTLY AVAIL FOR CENTER INDICATED
! = 8 - TEMP GDS INDICATED, BUT GDS FLAG IS OFF
! = 9 - GDS INDICATES SIZE MISMATCH WITH STD GRID
! =10 - INCORRECT CENTER INDICATOR
! =11 - BINARY DATA SECTION (BDS) NOT COMPLETELY PROCESSED.
! PROGRAM IS NOT SET TO PROCESS FLAG COMBINATIONS
! SHOWN IN OCTETS 4 AND 14.
! =12 - BINARY DATA SECTION (BDS) NOT COMPLETELY PROCESSED.
! PROGRAM IS NOT SET TO PROCESS FLAG COMBINATIONS
!
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI72(ITYPE, FLD, IFLD, IBITL, IPFLAG, ID, PDS, IGFLAG,&
! IGRID, IGDS, ICOMP, IBFLAG, IBMAP, IBLEN, IBDSFL,&
! NPTS, KBUF, ITOT, JERR)
!
! INTEGER, INTENT(IN ) :: ITYPE
! REAL, INTENT(IN ) :: FLD(*)
! INTEGER, INTENT(IN ) :: IFLD(*)
! INTEGER, INTENT(IN ) :: IBITL
! INTEGER, INTENT(IN ) :: IPFLAG
! INTEGER, INTENT(IN ) :: ID(*)
! CHARACTER(1), INTENT(IN ) :: PDS(*)
! INTEGER, INTENT(IN ) :: IGFLAG
! INTEGER, INTENT(IN ) :: IGRID
! INTEGER, INTENT(IN ) :: IGDS(*)
! INTEGER, INTENT(IN ) :: ICOMP
! INTEGER, INTENT(IN ) :: IBFLAG
! INTEGER, INTENT(IN ) :: IBMAP(*)
! INTEGER, INTENT(IN ) :: IBLEN
! INTEGER, INTENT(IN ) :: IBDSFL(*)
! INTEGER, INTENT( OUT) :: NPTS
! CHARACTER(1), INTENT( OUT) :: KBUF(*)
! INTEGER, INTENT( OUT) :: ITOT
! INTEGER, INTENT( OUT) :: JERR
!
! SUBPROGRAM: MAKE A COMPLETE GRIB MESSAGE
! PRGMMR: FARLEY ORG: NMC421 DATE:94-11-22
!
! ABSTRACT: MAKES A COMPLETE GRIB MESSAGE FROM A USER SUPPLIED
! ARRAY OF FLOATING POINT OR INTEGER DATA. THE USER HAS THE
! OPTION OF SUPPLYING THE PDS OR AN INTEGER ARRAY THAT WILL BE
! USED TO CREATE A PDS (WITH W3FI68). THE USER MUST ALSO
! SUPPLY OTHER NECESSARY INFO; SEE USAGE SECTION BELOW.
!
! PROGRAM HISTORY LOG:
! 91-05-08 R.E.JONES
! 92-07-01 M. FARLEY ADDED GDS AND BMS LOGIC. PLACED EXISTING
! LOGIC FOR BDS IN A ROUTINE.
! 92-10-02 R.E.JONES ADD ERROR EXIT FOR W3FI73
! 93-04-30 R.E.JONES REPLACE DO LOOPS TO MOVE CHARACTER DATA
! WITH XMOVEX, USE XSTORE TO ZERO CHARACTER
! ARRAY. MAKE CHANGE SO FLAT FIELD WILL PACK.
! 93-08-06 CAVANAUGH MODIFIED CALL TO W3FI75
! 93-10-26 CAVANAUGH ADDED CODE TO RESTORE INPUT FIELD TO ORIGINAL
! VALUES IF D-SCALE NOT 0
! 94-01-27 CAVANAUGH ADDED IGDS ARRAY IN CALL TO W3FI75 TO PROVIDE
! INFORMATION FOR BOUSTROPHEDONIC PROCESSING
! 94-03-03 CAVANAUGH INCREASED SIZE OF GDS ARRAY FOR THIN GRIDS
! 94-05-16 FARLEY CLEANED UP DOCUMENTATION
! 94-11-10 FARLEY INCREASED SIZE OF PFLD/IFLD ARRARYS FROM
! 100K TO 260K FOR .5 DEGREE SST ANAL FIELDS
! 94-12-04 R.E.JONES CHANGE DOCUMENT FOR IPFLAG.
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
! 98-05-19 Gilbert Increased array dimensions to handle grids
! of up to 500,000 grid points.
! 95-10-31 IREDELL GENERALIZED WORD SIZE
! 98-12-21 Gilbert Replaced Function ICHAR with mova2i.
! 99-02-01 Gilbert Changed the method of zeroing out array KBUF.
! the old method, using W3FI01 and XSTORE was
! incorrect with 4-byte integers and 8-byte reals.
! 2001-06-07 Gilbert Removed calls to xmovex.
! changed IPFLD from integer to character.
! 10-02-19 GAYNO FIX ALLOCATION OF ARRAY BMS
!
! USAGE: CALL NG_W3FI72(ITYPE,FLD,IFLD,IBITL,
! & IPFLAG,ID,PDS,
! & IGFLAG,IGRID,IGDS,ICOMP,
! & IBFLAG,IBMAP,IBLEN,IBDSFL,
! & IBDSFL,
! & NPTS,KBUF,ITOT,JERR)
!
! INPUT ARGUMENT LIST:
! ITYPE - 0 = FLOATING POINT DATA SUPPLIED IN ARRAY 'FLD'
! 1 = INTEGER DATA SUPPLIED IN ARRAY 'IFLD'
! FLD - REAL ARRAY OF DATA (AT PROPER GRIDPOINTS) TO BE
! CONVERTED TO GRIB FORMAT IF ITYPE=0.
! SEE REMARKS #1 & 2.
! IFLD - INTEGER ARRAY OF DATA (AT PROPER GRIDPOINTS) TO BE
! CONVERTED TO GRIB FORMAT IF ITYPE=1.
! SEE REMARKS #1 & 2.
! IBITL - 0 = COMPUTER COMPUTES LENGTH FOR PACKING DATA FROM
! POWER OF 2 (NUMBER OF BITS) BEST FIT OF DATA
! USING 'VARIABLE' BIT PACKER W3FI58.
! 8, 12, ETC. COMPUTER RESCALES DATA TO FIT INTO THAT
! 'FIXED' NUMBER OF BITS USING W3FI59.
! SEE REMARKS #3.
!
! IPFLAG - 0 = MAKE PDS FROM USER SUPPLIED ARRAY (ID)
! 1 = USER SUPPLYING PDS
! NOTE: IF PDS IS GREATER THAN 30, USE IPLFAG=1.
! THE USER COULD CALL W3FI68 BEFORE HE CALLS
! W3FI72. THIS WOULD MAKE THE FIRST 30 BYTES OF
! THE PDS, USER THEN WOULD MAKE BYTES AFTER 30.
! ID - INTEGER ARRAY OF VALUES THAT W3FI68 WILL USE
! TO MAKE AN EDITION 1 PDS IF IPFLAG=0. (SEE THE
! DOCBLOCK FOR W3FI68 FOR LAYOUT OF ARRAY)
! PDS - CHARACTER ARRAY OF VALUES (VALID PDS SUPPLIED
! BY USER) IF IPFLAG=1. LENGTH MAY EXCEED 28 BYTES
! (CONTENTS OF BYTES BEYOND 28 ARE PASSED
! THROUGH UNCHANGED).
!
! IGFLAG - 0 = MAKE GDS BASED ON 'IGRID' VALUE.
! 1 = MAKE GDS FROM USER SUPPLIED INFO IN 'IGDS'
! AND 'IGRID' VALUE.
! SEE REMARKS #4.
! IGRID - # = GRID IDENTIFICATION (TABLE B)
! 255 = IF USER DEFINED GRID; IGDS MUST BE SUPPLIED
! AND IGFLAG MUST =1.
! IGDS - INTEGER ARRAY CONTAINING USER GDS INFO (SAME
! FORMAT AS SUPPLIED BY W3FI71 - SEE DOCKBLOCK FOR
! LAYOUT) IF IGFLAG=1.
! ICOMP - RESOLUTION AND COMPONENT FLAG FOR BIT 5 OF GDS(17)
! 0 = EARTH ORIENTED WINDS
! 1 = GRID ORIENTED WINDS
!
! IBFLAG - 0 = MAKE BIT MAP FROM USER SUPPLIED DATA
! # = BIT MAP PREDEFINED BY CENTER
! SEE REMARKS #5.
! IBMAP - INTEGER ARRAY CONTAINING BIT MAP
! IBLEN - LENGTH OF BIT MAP WILL BE USED TO VERIFY LENGTH
! OF FIELD (ERROR IF IT DOESN'T MATCH).
!
! IBDSFL - INTEGER ARRAY CONTAINING TABLE 11 FLAG INFO
! BDS OCTET 4:
! (1) 0 = GRID POINT DATA
! 1 = SPHERICAL HARMONIC COEFFICIENTS
! (2) 0 = SIMPLE PACKING
! 1 = SECOND ORDER PACKING
! (3) ... SAME VALUE AS 'ITYPE'
! 0 = ORIGINAL DATA WERE FLOATING POINT VALUES
! 1 = ORIGINAL DATA WERE INTEGER VALUES
! (4) 0 = NO ADDITIONAL FLAGS AT OCTET 14
! 1 = OCTET 14 CONTAINS FLAG BITS 5-12
! (5) 0 = RESERVED - ALWAYS SET TO 0
! BYTE 6 OPTION 1 NOT AVAILABLE (AS OF 5-16-93)
! (6) 0 = SINGLE DATUM AT EACH GRID POINT
! 1 = MATRIX OF VALUES AT EACH GRID POINT
! BYTE 7 OPTION 0 WITH SECOND ORDER PACKING N/A (AS OF 5-16-93)
! (7) 0 = NO SECONDARY BIT MAPS
! 1 = SECONDARY BIT MAPS PRESENT
! (8) 0 = SECOND ORDER VALUES HAVE CONSTANT WIDTH
! 1 = SECOND ORDER VALUES HAVE DIFFERENT WIDTHS
!
! OUTPUT ARGUMENT LIST:
! NPTS - NUMBER OF GRIDPOINTS IN ARRAY FLD OR IFLD
! KBUF - ENTIRE GRIB MESSAGE ('GRIB' TO '7777')
! EQUIVALENCE TO INTEGER ARRAY TO MAKE SURE IT
! IS ON WORD BOUNARY.
! ITOT - TOTAL LENGTH OF GRIB MESSAGE IN BYTES
! JERR - = 0, COMPLETED MAKING GRIB FIELD WITHOUT ERROR
! 1, IPFLAG NOT 0 OR 1
! 2, IGFLAG NOT 0 OR 1
! 3, ERROR CONVERTING IEEE F.P. NUMBER TO IBM370 F.P.
! 4, W3FI71 ERROR/IGRID NOT DEFINED
! 5, W3FK74 ERROR/GRID REPRESENTATION TYPE NOT VALID
! 6, GRID TOO LARGE FOR PACKER DIMENSION ARRAYS
! SEE AUTOMATION DIVISION FOR REVISION!
! 7, LENGTH OF BIT MAP NOT EQUAL TO SIZE OF FLD/IFLD
! 8, W3FI73 ERROR, ALL VALUES IN IBMAP ARE ZERO
!
! REMARKS:
! 1) IF BIT MAP TO BE INCLUDED IN MESSAGE, NULL DATA SHOULD
! BE INCLUDED IN FLD OR IFLD. THIS ROUTINE WILL TAKE CARE
! OF 'DISCARDING' ANY NULL DATA BASED ON THE BIT MAP.
! 2) UNITS MUST BE THOSE IN GRIB DOCUMENTATION: NMC O.N. 388
! OR WMO PUBLICATION 306.
! 3) IN EITHER CASE, INPUT NUMBERS WILL BE MULTIPLIED BY
! '10 TO THE NTH' POWER FOUND IN ID(25) OR PDS(27-28),
! THE D-SCALING FACTOR, PRIOR TO BINARY PACKING.
! 4) ALL NMC PRODUCED GRIB FIELDS WILL HAVE A GRID DEFINITION
! SECTION INCLUDED IN THE GRIB MESSAGE. ID(6) WILL BE
! SET TO '1'.
! - GDS WILL BE BUILT BASED ON GRID NUMBER (IGRID), UNLESS
! IGFLAG=1 (USER SUPPLYING IGDS). USER MUST STILL SUPPLY
! IGRID EVEN IF IGDS PROVIDED.
! 5) IF BIT MAP USED THEN ID(7) OR PDS(8) MUST INDICATE THE
! PRESENCE OF A BIT MAP.
! 6) ARRAY KBUF SHOULD BE EQUIVALENCED TO AN INTEGER VALUE OR
! ARRAY TO MAKE SURE IT IS ON A WORD BOUNDARY.
! 7) SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_R63W72(KPDS, KGDS, IPDS, IGDS)
!
! INTEGER, INTENT(IN ) :: KPDS(200)
! INTEGER, INTENT(IN ) :: KGDS(200)
! INTEGER, INTENT( OUT) :: IPDS(200)
! INTEGER, INTENT( OUT) :: IGDS(200)
!
! SUBPROGRAM: CONVERT W3FI63 PARMS TO W3FI72 PARMS
! PRGMMR: IREDELL ORG: W/NMC23 DATE: 92-10-31
!
! ABSTRACT: DETERMINES THE INTEGER PDS AND GDS PARAMETERS
! FOR THE GRIB1 PACKING ROUTINE W3FI72 GIVEN THE PARAMETERS
! RETURNED FROM THE GRIB1 UNPACKING ROUTINE W3FI63.
!
! PROGRAM HISTORY LOG:
! 91-10-31 MARK IREDELL
! 96-05-03 MARK IREDELL CORRECTED SOME LEVEL TYPES AND
! SOME DATA REPRESENTATION TYPES
! 97-02-14 MARK IREDELL ONLY ALTERED IPDS(26:27) FOR EXTENDED PDS
! 98-06-01 CHRIS CARUSO Y2K FIX FOR YEAR OF CENTURY
! 2005-05-06 DIANE STOKES RECOGNIZE LEVEL 236
!
! USAGE: CALL NG_R63W72(KPDS,KGDS,IPDS,IGDS)
!
! INPUT ARGUMENT LIST:
! KPDS - INTEGER (200) PDS PARAMETERS FROM W3FI63
! KGDS - INTEGER (200) GDS PARAMETERS FROM W3FI63
!
! OUTPUT ARGUMENT LIST:
! IPDS - INTEGER (200) PDS PARAMETERS FOR W3FI72
! IGDS - INTEGER (200) GDS PARAMETERS FOR W3FI72
!
! REMARKS: KGDS AND IGDS EXTEND BEYOND THEIR DIMENSIONS HERE
! IF PL PARAMETERS ARE PRESENT.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI01(LW)
!
! INTEGER, INTENT(OUT) :: LW
!
! SUBPROGRAM: DETERMINES MACHINE WORD LENGTH IN BYTES
! PRGMMR: KEYSER ORG: W/NMC22 DATE: 06-29-92
!
! ABSTRACT: DETERMINES THE NUMBER OF BYTES IN A FULL WORD FOR THE
! PARTICULAR MACHINE (IBM OR CRAY).
!
! PROGRAM HISTORY LOG:
! 92-01-10 R. KISTLER (W/NMC23)
! 92-05-22 D. A. KEYSER -- DOCBLOCKED/COMMENTED
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
! 2001-06-07 Gilbert Uses f90 standard routine bit_size to
! find integer word length
!
! USAGE: CALL NG_W3FI01(LW)
! OUTPUT ARGUMENT LIST: (INCLUDING WORK ARRAYS)
! LW - MACHINE WORD LENGTH IN BYTES
!
! REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
! ATTRIBUTES:
! LANGUAGE: FORTRAN 77
! MACHINE: CRAY, WORKSTATIONS
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI58(IFIELD, NPTS, NWORK, NPFLD, NBITS, LEN, KMIN)
!
! INTEGER, INTENT(IN ) :: IFIELD(*)
! INTEGER, INTENT(IN ) :: NPTS
! INTEGER, INTENT( OUT) :: NWORK(*)
! CHARACTER(1), INTENT( OUT) :: NPFLD(*)
! INTEGER, INTENT( OUT) :: NBITS
! INTEGER, INTENT( OUT) :: LEN
! INTEGER, INTENT( OUT) :: KMIN
!
! SUBPROGRAM: PACK POSITIVE DIFFERENCES IN LEAST BITS
! PRGMMR: ALLARD, R. ORG: NMC411 DATE: JULY 1987
!
! ABSTRACT: CONVERTS AN ARRAY OF INTEGER NUMBERS INTO AN ARRAY OF
! POSITIVE DIFFERENCES (NUMBER(S) - MINIMUM VALUE) AND PACKS THE
! MAGNITUDE OF EACH DIFFERENCE RIGHT-ADJUSTED INTO THE LEAST
! NUMBER OF BITS THAT HOLDS THE LARGEST DIFFERENCE.
!
! PROGRAM HISTORY LOG:
! 87-09-02 ALLARD
! 88-10-02 R.E.JONES CONVERTED TO CDC CYBER 205 FTN200 FORTRAN
! 90-05-17 R.E.JONES CONVERTED TO CRAY CFT77 FORTRAN
! 90-05-18 R.E.JONES CHANGE NAME VBIMPK TO W3LIB NAME W3FI58
! 96-05-14 IREDELL GENERALIZED COMPUTATION OF NBITS
! 98-06-30 EBISUZAKI LINUX PORT
!
! USAGE: CALL NG_W3FI58(IFIELD,NPTS,NWORK,NPFLD,NBITS,LEN,KMIN)
!
! INPUT:
!
! IFIELD - ARRAY OF INTEGER DATA FOR PROCESSING
! NPTS - NUMBER OF DATA VALUES TO PROCESS IN IFIELD (AND NWORK)
! WHERE, NPTS > 0
!
! OUTPUT:
!
! NWORK - WORK ARRAY WITH INTEGER DIFFERENCE
! NPFLD - ARRAY FOR PACKED DATA (character*1)
! (USER IS RESPONSIBLE FOR AN ADEQUATE DIMENSION.)
! NBITS - NUMBER OF BITS USED TO PACK DATA WHERE, 0 < NBITS < 32
! (THE MAXIMUM DIFFERENCE WITHOUT OVERFLOW IS 2**31 -1)
! LEN - NUMBER OF PACKED BYTES IN NPFLD (SET TO 0 IF NO PACKING)
! WHERE, LEN = (NBITS * NPTS + 7) / 8 WITHOUT REMAINDER
! KMIN - MINIMUM VALUE (SUBTRACTED FROM EACH DATUM). IF THIS
! PACKED DATA IS BEING USED FOR GRIB DATA, THE
! PROGRAMER WILL HAVE TO CONVERT THE KMIN VALUE TO AN
! IBM370 32 BIT FLOATING POINT NUMBER.
!
! NOTE: LEN = 0, NBITS = 0, AND NO PACKING PERFORMED IF
!
! (1) KMAX = KMIN (A CONSTANT FIELD)
! (2) NPTS < 1 (SEE INPUT ARGUMENT)
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI59(FIELD, NPTS, NBITS, NWORK, NPFLD, ISCALE, LEN, RMIN)
!
! REAL, INTENT(IN ) :: FIELD(*)
! INTEGER, INTENT(IN ) :: NPTS
! INTEGER, INTENT(IN ) :: NBITS
! INTEGER, INTENT( OUT) :: NWORK(*)
! CHARACTER(1), INTENT( OUT) :: NPFLD(*)
! INTEGER, INTENT( OUT) :: ISCALE
! INTEGER, INTENT( OUT) :: LEN
! INTEGER, INTENT( OUT) :: RMIN
!
! SUBPROGRAM: FORM AND PACK POSITIVE, SCALED DIFFERENCES
! PRGMMR: ALLARD, R. ORG: NMC41 DATE: 84-08-01
!
! ABSTRACT: CONVERTS AN ARRAY OF SINGLE PRECISION REAL NUMBERS INTO
! AN ARRAY OF POSITIVE SCALED DIFFERENCES (NUMBER(S) - MINIMUM VALUE),
! IN INTEGER FORMAT AND PACKS THE ARGUMENT-SPECIFIED NUMBER OF
! SIGNIFICANT BITS FROM EACH DIFFERENCE.
!
! PROGRAM HISTORY LOG:
! 84-08-01 ALLARD ORIGINAL AUTHOR
! 90-05-17 R.E.JONES CONVERT TO CRAY CFT77 FORTRAN
! 90-05-18 R.E.JONES CHANGE NAME PAKMAG TO W3LIB NAME W3FI59
! 93-07-06 R.E.JONES ADD NINT TO DO LOOP 2000 SO NUMBERS ARE
! ROUNDED TO NEAREST INTEGER, NOT TRUNCATED.
! 94-01-05 IREDELL COMPUTATION OF ISCALE FIXED WITH RESPECT TO
! THE 93-07-06 CHANGE.
! 98-06-30 EBISUZAKI LINUX PORT
!
! USAGE: CALL NG_W3FI59(FIELD,NPTS,NBITS,NWORK,NPFLD,ISCALE,LEN,RMIN)
! INPUT ARGUMENT LIST:
! FIELD - ARRAY OF FLOATING POINT DATA FOR PROCESSING (REAL)
! NPTS - NUMBER OF DATA VALUES TO PROCESS IN FIELD (AND NWORK)
! WHERE, NPTS > 0
! NBITS - NUMBER OF SIGNIFICANT BITS OF PROCESSED DATA TO BE PACKED
! WHERE, 0 < NBITS < 32+1
!
! OUTPUT ARGUMENT LIST:
! NWORK - ARRAY FOR INTEGER CONVERSION (INTEGER)
! IF PACKING PERFORMED (SEE NOTE BELOW), THE ARRAY WILL
! CONTAIN THE PRE-PACKED, RIGHT ADJUSTED, SCALED, INTEGER
! DIFFERENCES UPON RETURN TO THE USER.
! (THE USER MAY EQUIVALENCE FIELD AND NWORK. SAME SIZE.)
! NPFLD - ARRAY FOR PACKED DATA (character*1)
! (DIMENSION MUST BE AT LEAST (NBITS * NPTS) / 64 + 1 )
! ISCALE- POWER OF 2 FOR RESTORING DATA, SUCH THAT
! DATUM = (DIFFERENCE * 2**ISCALE) + RMIN
! LEN - NUMBER OF PACKED BYTES IN NPFLD (SET TO 0 IF NO PACKING)
! WHERE, LEN = (NBITS * NPTS + 7) / 8 WITHOUT REMAINDER
! RMIN - MINIMUM VALUE (REFERENCE VALUE SUBTRACTED FROM INPUT DATA)
! THIS IS A CRAY FLOATING POINT NUMBER, IT WILL HAVE TO BE
! CONVERTED TO AN IBM370 32 BIT FLOATING POINT NUMBER AT
! SOME POINT IN YOUR PROGRAM IF YOU ARE PACKING GRIB DATA.
!
! REMARKS: LEN = 0 AND NO PACKING PERFORMED IF
!
! (1) RMAX = RMIN (A CONSTANT FIELD)
! (2) NBITS VALUE OUT OF RANGE (SEE INPUT ARGUMENT)
! (3) NPTS VALUE LESS THAN 1 (SEE INPUT ARGUMENT)
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI68(ID, PDS)
!
! INTEGER, INTENT(IN ) :: ID(*)
! CHARACTER(1), INTENT( OUT) :: PDS(*)
!
! SUBPROGRAM: CONVERT 25 WORD ARRAY TO GRIB PDS
! PRGMMR: R.E.JONES ORG: W/NMC42 DATE: 91-05-14
!
! ABSTRACT: CONVERTS AN ARRAY OF 25, OR 27 INTEGER WORDS INTO A
! GRIB PRODUCT DEFINITION SECTION (PDS) OF 28 BYTES , OR 30 BYTES.
! IF PDS BYTES > 30, THEY ARE SET TO ZERO.
!
! PROGRAM HISTORY LOG:
! 91-05-08 R.E.JONES
! 92-09-25 R.E.JONES CHANGE TO 25 WORDS OF INPUT, LEVEL
! CAN BE IN TWO WORDS. (10,11)
! 93-01-08 R.E.JONES CHANGE FOR TIME RANGE INDICATOR IF 10,
! STORE TIME P1 IN PDS BYTES 19-20.
! 93-01-26 R.E.JONES CORRECTION FOR FIXED HEIGHT ABOVE
! GROUND LEVEL
! 93-03-29 R.E.JONES ADD SAVE STATEMENT
! 93-06-24 CAVANOUGH MODIFIED PROGRAM TO ALLOW FOR GENERATION
! OF PDS GREATER THAN 28 BYTES (THE DESIRED
! PDS SIZE IS IN ID(1).
! 93-09-30 FARLEY CHANGE TO ALLOW FOR SUBCENTER ID; PUT
! ID(24) INTO PDS(26).
! 93-10-12 R.E.JONES CHANGES FOR ON388 REV. OCT 9,1993, NEW
! LEVELS 125, 200, 201.
! 94-02-23 R.E.JONES TAKE OUT SBYTES, REPLACE WITH DO LOOP
! 94-04-14 R.E.JONES CHANGES FOR ON388 REV. MAR 24,1994, NEW
! LEVELS 115,116.
! 94-12-04 R.E.JONES CHANGE TO ADD ID WORDS 26, 27 FOR PDS
! BYTES 29 AND 30.
! 95-09-07 R.E.JONES CHANGE FOR NEW LEVEL 117, 119.
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
! 98-06-30 EBISUZAKI LINUX PORT
! 2001-06-05 GILBERT Changed fortran intrinsic function OR() to
! f90 standard intrinsic IOR().
! 2003-02-25 IREDELL RECOGNIZE LEVEL TYPE 126
! 2005-05-06 D.C.STOKES RECOGNIZE LEVEL TYPES 235, 237, 238
!
! USAGE: CALL NG_W3FI68 (ID, PDS)
! INPUT ARGUMENT LIST:
! ID - 25, 27 WORD INTEGER ARRAY
! OUTPUT ARGUMENT LIST:
! PDS - 28 30, OR GREATER CHARACTER PDS FOR EDITION 1
!
! REMARKS: LAYOUT OF 'ID' ARRAY:
! ID(1) = NUMBER OF BYTES IN PRODUCT DEFINITION SECTION (PDS)
! ID(2) = PARAMETER TABLE VERSION NUMBER
! ID(3) = IDENTIFICATION OF ORIGINATING CENTER
! ID(4) = MODEL IDENTIFICATION (ALLOCATED BY ORIGINATING CENTER)
! ID(5) = GRID IDENTIFICATION
! ID(6) = 0 IF NO GDS SECTION, 1 IF GDS SECTION IS INCLUDED
! ID(7) = 0 IF NO BMS SECTION, 1 IF BMS SECTION IS INCLUDED
! ID(8) = INDICATOR OF PARAMETER AND UNITS (TABLE 2)
! ID(9) = INDICATOR OF TYPE OF LEVEL (TABLE 3)
! ID(10) = VALUE 1 OF LEVEL (0 FOR 1-100,102,103,105,107
! 109,111,113,115,117,119,125,126,160,200,201,
! 235,237,238
! LEVEL IS IN ID WORD 11)
! ID(11) = VALUE 2 OF LEVEL
! ID(12) = YEAR OF CENTURY
! ID(13) = MONTH OF YEAR
! ID(14) = DAY OF MONTH
! ID(15) = HOUR OF DAY
! ID(16) = MINUTE OF HOUR (IN MOST CASES SET TO 0)
! ID(17) = FCST TIME UNIT
! ID(18) = P1 PERIOD OF TIME
! ID(19) = P2 PERIOD OF TIME
! ID(20) = TIME RANGE INDICATOR
! ID(21) = NUMBER INCLUDED IN AVERAGE
! ID(22) = NUMBER MISSING FROM AVERAGES
! ID(23) = CENTURY (20, CHANGE TO 21 ON JAN. 1, 2001)
! ID(24) = SUBCENTER IDENTIFICATION
! ID(25) = SCALING POWER OF 10
! ID(26) = FLAG BYTE, 8 ON/OFF FLAGS
! BIT NUMBER VALUE ID(26) DEFINITION
! 1 0 0 FULL FCST FIELD
! 1 128 FCST ERROR FIELD
! 2 0 0 ORIGINAL FCST FIELD
! 1 64 BIAS CORRECTED FCST FIELD
! 3 0 0 ORIGINAL RESOLUTION RETAINED
! 1 32 SMOOTHED FIELD
! NOTE: ID(26) CAN BE THE SUM OF BITS 1, 2, 3.
! BITS 4-8 NOT USED, SET TO ZERO
! IF ID(1) IS 28, YOU DO NOT NEED ID(26) AND ID(27).
! ID(27) = UNUSED, SET TO 0 SO PDS BYTE 30 IS SET TO ZERO.
!
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI71(IGRID, IGDS, IERR)
!
! INTEGER, INTENT(IN ) :: IGRID
! INTEGER, INTENT( OUT) :: IGDS(*)
! INTEGER, INTENT( OUT) :: IERR
!
! SUBPROGRAM: MAKE ARRAY USED BY GRIB PACKER FOR GDS
! PRGMMR: R.E.JONES ORG: W/NMC42 DATE: 93-03-26
!
! ABSTRACT: W3FI71 MAKES A 18, 37, 55, 64, OR 91 WORD INTEGER ARRAY
! USED BY W3FI72 GRIB PACKER TO MAKE THE GRID DESCRIPTION SECTION
! (GDS) - SECTION 2.
!
! PROGRAM HISTORY LOG:
! 92-02-21 R.E.JONES
! 92-07-01 M. FARLEY ADDED REMARKS FOR 'IGDS' ARRAY ELEMENTS.
! ADDED LAMBERT CONFORMAL GRIDS AND ENLARGED
! IDGS ARRAY FROM 14 TO 18 WORDS.
! 92-10-03 R.E.JONES ADDED CORRECTIONS TO AWIPS GRIB TABLES
! 92-10-16 R.E.JONES ADD GAUSSIAN GRID 126 TO TABLES
! 92-10-18 R.E.JONES CORRECTIONS TO LAMBERT CONFORMAL TABLES
! AND OTHER TABLES
! 92-10-19 R.E.JONES ADD GAUSSIAN GRID 98 TO TABLES
! 93-01-25 R.E.JONES ADD ON84 GRIDS 87, 106, 107 TO TABLES
! 93-03-10 R.E.JONES ADD ON84 GRIDS 1, 55, 56 TO TABLES
! 93-03-26 R.E.JONES ADD GRIB GRIDS 2, 3 TO TABLES
! 93-03-29 R.E.JONES ADD SAVE STATEMENT
! 93-06-15 R.E.JONES ADD GRIB GRIDS 37 TO 44 TO TABLES
! 93-09-29 R.E.JONES GAUSSIAN GRID DOCUMENT NOT CORRECT,
! W3FI74 WILL BE CHANGED TO AGREE WITH
! IT. GAUSSIAN GRID 98 TABLE HAS WRONG
! VALUE.
! 93-10-12 R.E.JONES CHANGES FOR ON388 REV. OCT 8,1993 FOR
! GRID 204, 208.
! 93-10-13 R.E.JONES CORRECTION FOR GRIDS 37-44, BYTES 7-8,
! 24-25 SET TO ALL BITS 1 FOR MISSING.
! 93-11-23 R.E.JONES ADD GRIDS 90-93 FOR ETA MODEL
! ADD GRID 4 FOR 720*361 .5 DEG. GRID
! 94-04-12 R.E.JONES CORRECTION FOR GRID 28
! 94-06-01 R.E.JONES ADD GRID 45, 288*145 1.25 DEG. GRID
! 94-06-22 R.E.JONES ADD GRIDS 94, 95 FOR ETA MODEL
! 95-04-11 R.E.JONES ADD GRIDS 96, 97 FOR ETA MODEL
! 95-05-19 R.E.JONES ADD FROM 20 KM ETA MODEL AWIPS GRID 215
! 95-10-19 R.E.JONES ADD FROM 20 KM ETA MODEL ALASKA GRID 216
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
! 96-05-08 IREDELL CORRECT FIRST LATITUDE FOR GRIDS 27 AND 28
! 96-07-02 R.E.JONES ADD FROM 10 KM ETA MODEL OLYMPIC GRID 218
! 96-07-02 R.E.JONES ADD 196 FOR ETA MODEL
! 96-08-15 R.E.JONES ADD O.N. 84 GRID 8 AND 53 AS GRIB GRID 8
! AND 53
! 96-11-29 R.E.JONES CORRECTION TO TABLES FOR GRID 21-26, 61-64
! 97-01-31 IREDELL CORRECT FIRST LATITUDE FOR GRID 30
! 97-10-20 IREDELL CORRECT LAST LONGITUDE FOR GRID 98
! 98-07-07 Gilbert Add grids 217 and 219 through 235
! 98-09-21 BALDWIN ADD GRIDS 190, 192 FOR ETA MODEL
! 99-01-20 BALDWIN ADD GRIDS 236, 237
! 99-08-18 IREDELL ADD GRID 170
! 01-03-08 ROGERS CHANGED ETA GRIDS 90-97, ADDED ETA GRIDS
! 194, 198. ADDED AWIPS GRIDS 241,242,243,
! 245, 246, 247, 248, AND 250
! 01-03-19 VUONG ADDED AWIPS GRIDS 238,239,240, AND 244
! 01-04-02 VUONG CORRECT LAST LONGITUDE FOR GRID 225
! 01-05-03 ROGERS ADDED GRID 249
! 01-10-10 ROGERS REDEFINED 218 FOR 12-KM ETA
! REDEFINED GRID 192 FOR NEW 32-KM ETA GRID
! 02-03-27 VUONG ADDED RSAS GRID 88 AND AWIPS GRIDS 251 AND 252
! 02-08-06 ROGERS REDEFINED GRIDS 90-93,97,194,245-250 FOR THE
! 8KM HI-RES-WINDOW MODEL AND ADD AWIPS GRID 253
! 2003-06-30 GILBERT ADDED GRIDS 145 and 146 for CMAQ
! and GRID 175 for AWIPS over GUAM.
! 2003-07-08 VUONG CORRECTED LATITUDE FOR GRID 253 AND 170, ADD GRID
! 110, 127, 171 AND 172
! 2004-08-05 VUONG CORRECTED LATITUDE FOR GRID 253
! 2004-09-01 GILBERT Corrected the orientation and projection center flag
! for southern hemisphere grids 28, 172, 220 and 224
! 2004-09-02 VUONG ADDED GRIDS 147, 148, 173 AND 254
! 2005-01-04 COOKE Added grids 160, 161 and corrected longitude of orientation for grid 172
! 2005-03-03 VUONG MOVED GRID 170 TO GRID 174 AND ADD GRID 170
! 2005-03-21 VUONG ADDED GRIDS 130
! 2005-09-12 VUONG ADDED GRIDS 163
! 2006-10-27 VUONG CORRECTED X AND Y-DIRECTION GRID LENGTH FOR GRIDS 252
! 2006-11-16 VUONG CHANGED THE LONGITUDE FROM NEGATIVE TO POSITIVE DEGREE FOR GRIDS 252
! 2006-12-12 VUONG CHANGED DATA REPRESENTATION TYPE (OCTET 6) FROM 0 TO 1 FOR GRID 254
! ADD GRID 120 (CURVILINEAR ORTHOGONAL GRID)
! 2006-12-27 VUONG CORRECTED THE LAT/LON DIRECTION INCREMENT FOR GRID 160
! 2007-03-21 VUONG CORRECTED THE LAT/LON DIRECTION INCREMENT, RESOULUTION,
! SCANNING MODE FOR GRID 235 AND GRID TYPE 204 FOR GRID 120
! 2007-04-24 VUONG CORRECTED THE LAT/LON DIRECTION INCREMENT, RESOULUTION,
! FOR GRIDS (219,173,220,171,233,238,239,244,253) AND ADDED
! GRID 176.
! 2007-06-11 VUONG ADDED NEW GRIDS (11,12,13,14,15,16,18,122,123,124,125,138
! 180, 181, 182, 183) AND CORRECTED THE LAT/LON DIRECTION
! INCREMENT FOR GRID 240.
! 2007-11-06 VUONG CORRECTED THE SCANNING MODE FOR GRIDS (11,12,13,14,15,16,18)
! CHANGED GRID 198 FROM ARAKAWA STAGGERED E-GRID TO POLAR
! STEREOGRAPHIC GRID ADDED NEW GRID 10, 99, 150, 151, 197
! 2008-01-17 VUONG ADDED NEW GRID 195 AND CHANGED GRID 196 (ARAKAWA-E TO MERCATOR)
! 2010-02-15 VUONG MODIFIED TO CORRECT LATITUDE FOR GRID 151 AND ADDED
! 2010-06-01 VUONG MODIFIED TO CORRECT LATITUDE AND LONGITUDE FOR GRID 196
! 2010-08-05 VUONG ADDED NEW GRID 184, 199, 83 AND
! REDEFINED GRID 90 FOR NEW RTMA CONUS 1.27-KM
! REDEFINED GRID 91 FOR NEW RTMA ALASKA 2.976-KM
! REDEFINED GRID 92 FOR NEW RTMA ALASKA 1.488-KM
! 2010-09-08 ROGERS CHANGED GRID 94 TO ALASKA 6KM STAGGERED B-GRID
! CHANGED GRID 95 TO PUERTO RICO 3KM STAGGERED B-GRID
! CHANGED GRID 96 TO HAWAII 3KM STAGGERED B-GRID
! CHANGED GRID 96 TO HAWAII 3KM STAGGERED B-GRID
! CHANGED GRID 97 TO CONUS 4KM STAGGERED B-GRID
! CHANGED GRID 99 TO NAM 12KM STAGGERED B-GRID
! ADDED GRID 179 (12 KM POLAR STEREOGRAPHIC OVER NORTH AMERICA)
! CHANGED GRID 194 TO 3KM MERCATOR GRID OVER PUERTO RICO
! CORRECTED LATITUDE OF SW CORNER POINT OF GRID 151
! 2011-10-12 VUONG ADDED GRID 129, 187, 188, 189 and 193
! 2012-04-16 VUONG ADDED GRID 132, 200
! 2017-07-17 VUONG CORRECT GRID 161 NUMBER OF POINT Nj from 102 to 103
! AND MAP SIZE FROM 13974 TO 14111
!
! USAGE: CALL NG_W3FI71 (IGRID, IGDS, IERR)
! INPUT ARGUMENT LIST:
! IGRID - GRIB GRID NUMBER, OR OFFICE NOTE 84 GRID NUMBER
!
! OUTPUT ARGUMENT LIST:
! IGDS - 18, 37, 55, 64, OR 91 WORD INTEGER ARRAY WITH
! INFORMATION TO MAKE A GRIB GRID DESCRIPTION SECTION.
! IERR - 0 CORRECT EXIT
! 1 GRID TYPE IN IGRID IS NOT IN TABLE
!
! REMARKS:
! 1) OFFICE NOTE GRID TYPE 26 IS 6 IN GRIB, 26 IS AN
! INTERNATIONAL EXCHANGE GRID.
!
! 2) VALUES RETURNED IN 18, 37, 55, 64, OR 91 WORD INTEGER ARRAY
! IGDS VARY DEPENDING ON GRID REPRESENTATION TYPE.
!
! LAT/LON GRID:
! IGDS( 1) = NUMBER OF VERTICAL COORDINATES
! IGDS( 2) = PV, PL OR 255
! IGDS( 3) = DATA REPRESENTATION TYPE (CODE TABLE 6)
! IGDS( 4) = NO. OF POINTS ALONG A LATITUDE
! IGDS( 5) = NO. OF POINTS ALONG A LONGITUDE MERIDIAN
! IGDS( 6) = LATITUDE OF ORIGIN (SOUTH - IVE)
! IGDS( 7) = LONGITUDE OF ORIGIN (WEST -IVE)
! IGDS( 8) = RESOLUTION FLAG (CODE TABLE 7)
! IGDS( 9) = LATITUDE OF EXTREME POINT (SOUTH - IVE)
! IGDS(10) = LONGITUDE OF EXTREME POINT (WEST - IVE)
! IGDS(11) = LATITUDE INCREMENT
! IGDS(12) = LONGITUDE INCREMENT
! IGDS(13) = SCANNING MODE FLAGS (CODE TABLE 8)
! IGDS(14) = ... THROUGH ...
! IGDS(18) = ... NOT USED FOR THIS GRID
! IGDS(19) - IGDS(91) FOR GRIDS 37-44, NUMBER OF POINTS
! IN EACH OF 73 ROWS.
!
! GAUSSIAN GRID:
! IGDS( 1) = ... THROUGH ...
! IGDS(10) = ... SAME AS LAT/LON GRID
! IGDS(11) = NUMBER OF LATITUDE LINES BETWEEN A POLE
! AND THE EQUATOR
! IGDS(12) = LONGITUDE INCREMENT
! IGDS(13) = SCANNING MODE FLAGS (CODE TABLE 8)
! IGDS(14) = ... THROUGH ...
! IGDS(18) = ... NOT USED FOR THIS GRID
!
! SPHERICAL HARMONICS:
! IGDS( 1) = NUMBER OF VERTICAL COORDINATES
! IGDS( 2) = PV, PL OR 255
! IGDS( 3) = DATA REPRESENTATION TYPE (CODE TABLE 6)
! IGDS( 4) = J - PENTAGONAL RESOLUTION PARAMETER
! IGDS( 5) = K - PENTAGONAL RESOLUTION PARAMETER
! IGDS( 6) = M - PENTAGONAL RESOLUTION PARAMETER
! IGDS( 7) = REPRESENTATION TYPE (CODE TABLE 9)
! IGDS( 8) = REPRESENTATION MODE (CODE TABLE 10)
! IGDS( 9) = ... THROUGH ...
! IGDS(18) = ... NOT USED FOR THIS GRID
!
! POLAR STEREOGRAPHIC:
! IGDS( 1) = NUMBER OF VERTICAL COORDINATES
! IGDS( 2) = PV, PL OR 255
! IGDS( 3) = DATA REPRESENTATION TYPE (CODE TABLE 6)
! IGDS( 4) = NO. OF POINTS ALONG X-AXIS
! IGDS( 5) = NO. OF POINTS ALONG Y-AXIS
! IGDS( 6) = LATITUDE OF ORIGIN (SOUTH -IVE)
! IGDS( 7) = LONGITUTE OF ORIGIN (WEST -IVE)
! IGDS( 8) = RESOLUTION FLAG (CODE TABLE 7)
! IGDS( 9) = LONGITUDE OF MERIDIAN PARALLEL TO Y-AXIS
! IGDS(10) = X-DIRECTION GRID LENGTH (INCREMENT)
! IGDS(11) = Y-DIRECTION GRID LENGTH (INCREMENT)
! IGDS(12) = PROJECTION CENTER FLAG (0=NORTH POLE ON PLANE,
! 1=SOUTH POLE ON PLANE,
! IGDS(13) = SCANNING MODE FLAGS (CODE TABLE 8)
! IGDS(14) = ... THROUGH ...
! IGDS(18) = .. NOT USED FOR THIS GRID
!
! MERCATOR:
! IGDS( 1) = ... THROUGH ...
! IGDS(12) = ... SAME AS LAT/LON GRID
! IGDS(13) = LATITUDE AT WHICH PROJECTION CYLINDER
! INTERSECTS EARTH
! IGDS(14) = SCANNING MODE FLAGS
! IGDS(15) = ... THROUGH ...
! IGDS(18) = .. NOT USED FOR THIS GRID
!
! LAMBERT CONFORMAL:
! IGDS( 1) = NUMBER OF VERTICAL COORDINATES
! IGDS( 2) = PV, PL OR 255
! IGDS( 3) = DATA REPRESENTATION TYPE (CODE TABLE 6)
! IGDS( 4) = NO. OF POINTS ALONG X-AXIS
! IGDS( 5) = NO. OF POINTS ALONG Y-AXIS
! IGDS( 6) = LATITUDE OF ORIGIN (SOUTH -IVE)
! IGDS( 7) = LONGITUTE OF ORIGIN (WEST -IVE)
! IGDS( 8) = RESOLUTION FLAG (CODE TABLE 7)
! IGDS( 9) = LONGITUDE OF MERIDIAN PARALLEL TO Y-AXIS
! IGDS(10) = X-DIRECTION GRID LENGTH (INCREMENT)
! IGDS(11) = Y-DIRECTION GRID LENGTH (INCREMENT)
! IGDS(12) = PROJECTION CENTER FLAG (0=NORTH POLE ON PLANE,
! 1=SOUTH POLE ON PLANE,
! IGDS(13) = SCANNING MODE FLAGS (CODE TABLE 8)
! IGDS(14) = NOT USED
! IGDS(15) = FIRST LATITUDE FROM THE POLE AT WHICH THE
! SECANT CONE CUTS THE SPERICAL EARTH
! IGDS(16) = SECOND LATITUDE ...
! IGDS(17) = LATITUDE OF SOUTH POLE (MILLIDEGREES)
! IGDS(18) = LONGITUDE OF SOUTH POLE (MILLIDEGREES)
!
! ARAKAWA SEMI-STAGGERED E-GRID ON ROTATED LAT/LON GRID
! IGDS( 1) = NUMBER OF VERTICAL COORDINATES
! IGDS( 2) = PV, PL OR 255
! IGDS( 3) = DATA REPRESENTATION TYPE (CODE TABLE 6) [201]
! IGDS( 4) = NI - TOTAL NUMBER OF ACTUAL DATA POINTS
! INCLUDED ON GRID
! IGDS( 5) = NJ - DUMMY SECOND DIMENSION; SET=1
! IGDS( 6) = LA1 - LATITUDE OF FIRST GRID POINT
! IGDS( 7) = LO1 - LONGITUDE OF FIRST GRID POINT
! IGDS( 8) = RESOLUTION AND COMPONENT FLAG (CODE TABLE 7)
! IGDS( 9) = LA2 - NUMBER OF MASS POINTS ALONG
! SOUTHERNMOST ROW OF GRID
! IGDS(10) = LO2 - NUMBER OF ROWS IN EACH COLUMN
! IGDS(11) = DI - LONGITUDINAL DIRECTION INCREMENT
! IGDS(12) = DJ - LATITUDINAL DIRECTION INCREMENT
! IGDS(13) = SCANNING MODE FLAGS (CODE TABLE 8)
! IGDS(14) = ... THROUGH ...
! IGDS(18) = ... NOT USED FOR THIS GRID (SET TO ZERO)
!
! ARAKAWA FILLED E-GRID ON ROTATED LAT/LON GRID
! IGDS( 1) = NUMBER OF VERTICAL COORDINATES
! IGDS( 2) = PV, PL OR 255
! IGDS( 3) = DATA REPRESENTATION TYPE (CODE TABLE 6) [202]
! IGDS( 4) = NI - TOTAL NUMBER OF ACTUAL DATA POINTS
! INCLUDED ON GRID
! IGDS( 5) = NJ - DUMMY SECOND DIMENTION; SET=1
! IGDS( 6) = LA1 - LATITUDE LATITUDE OF FIRST GRID POINT
! IGDS( 7) = LO1 - LONGITUDE OF FIRST GRID POINT
! IGDS( 8) = RESOLUTION AND COMPONENT FLAG (CODE TABLE 7)
! IGDS( 9) = LA2 - NUMBER OF (ZONAL) POINTS IN EACH ROW
! IGDS(10) = LO2 - NUMBER OF (MERIDIONAL) POINTS IN EACH
! COLUMN
! IGDS(11) = DI - LONGITUDINAL DIRECTION INCREMENT
! IGDS(12) = DJ - LATITUDINAL DIRECTION INCREMENT
! IGDS(13) = SCANNING MODE FLAGS (CODE TABLE 8)
! IGDS(14) = ... THROUGH ...
! IGDS(18) = ... NOT USED FOR THIS GRID
!
! ARAKAWA STAGGERED E-GRID ON ROTATED LAT/LON GRID
! IGDS( 1) = NUMBER OF VERTICAL COORDINATES
! IGDS( 2) = PV, PL OR 255
! IGDS( 3) = DATA REPRESENTATION TYPE (CODE TABLE 6) [203]
! IGDS( 4) = NI - NUMBER OF DATA POINTS IN EACH ROW
! IGDS( 5) = NJ - NUMBER OF ROWS
! IGDS( 6) = LA1 - LATITUDE OF FIRST GRID POINT
! IGDS( 7) = LO1 - LONGITUDE OF FIRST GRID POINT
! IGDS( 8) = RESOLUTION AND COMPONENT FLAG (CODE TABLE 7)
! IGDS( 9) = LA2 - CENTRAL LATITUDE
! IGDS(10) = LO2 - CENTRAL LONGTITUDE
! IGDS(11) = DI - LONGITUDINAL DIRECTION INCREMENT
! IGDS(12) = DJ - LATITUDINAL DIRECTION INCREMENT
! IGDS(13) = SCANNING MODE FLAGS (CODE TABLE 8)
! IGDS(14) = ... THROUGH ...
! IGDS(18) = ... NOT USED FOR THIS GRID
!
! CURVILINEAR ORTHOGONAL GRID
! IGDS( 1) = NUMBER OF VERTICAL COORDINATES
! IGDS( 2) = PV, PL OR 255
! IGDS( 3) = DATA REPRESENTATION TYPE (CODE TABLE 6) [204]
! IGDS( 4) = NI - NUMBER OF DATA POINTS IN EACH ROW
! IGDS( 5) = NJ - NUMBER OF ROWS
! IGDS( 6) = RESERVED (SET TO 0)
! IGDS( 7) = RESERVED (SET TO 0)
! IGDS( 8) = RESOLUTION AND COMPONENT FLAG (CODE TABLE 7)
! IGDS( 9) = RESERVED (SET TO 0)
! IGDS(10) = RESERVED (SET TO 0)
! IGDS(11) = RESERVED (SET TO 0)
! IGDS(12) = RESERVED (SET TO 0)
! IGDS(13) = SCANNING MODE FLAGS (CODE TABLE 8)
! IGDS(14) = ... THROUGH ...
! IGDS(18) = ... NOT USED FOR THIS GRID
!
! SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI73(IBFLAG, IBMAP, IBLEN, BMS, LENBMS, IER)
!
! INTEGER, INTENT(IN ) :: IBFLAG
! INTEGER, INTENT(IN ) :: IBMAP(*)
! INTEGER, INTENT(IN ) :: IBLEN
! CHARACTER(1), INTENT( OUT) :: BMS(*)
! INTEGER, INTENT( OUT) :: LENBMS
! INTEGER, INTENT( OUT) :: IER
!
! SUBPROGRAM: CONSTRUCT GRIB BIT MAP SECTION (BMS)
! PRGMMR: FARLEY ORG: NMC421 DATE:92-11-16
!
! ABSTRACT: THIS SUBROUTINE CONSTRUCTS A GRIB BIT MAP SECTION.
!
! PROGRAM HISTORY LOG:
! 92-07-01 M. FARLEY ORIGINAL AUTHOR
! 94-02-14 CAVANAUGH RECODED
! 98-06-30 EBISUZAKI LINUX PORT
!
! USAGE: CALL NG_W3FI73 (IBFLAG, IBMAP, IBLEN, BMS, LENBMS, IER)
! INPUT ARGUMENT LIST:
! IBFLAG - 0, IF BIT MAP SUPPLIED BY USER
! - #, NUMBER OF PREDEFINED CENTER BIT MAP
! IBMAP - INTEGER ARRAY CONTAINING USER BIT MAP
! IBLEN - LENGTH OF BIT MAP
!
! OUTPUT ARGUMENT LIST:
! BMS - COMPLETED GRIB BIT MAP SECTION
! LENBMS - LENGTH OF BIT MAP SECTION
! IER - 0 NORMAL EXIT, 8 = IBMAP VALUES ARE ALL ZERO
!
! SUBPROGRAMS CALLED:
! LIBRARY:
! W3LIB - SBYTE
!
! ATTRIBUTES:
! LANGUAGE: IBM370 VS FORTRAN 77, CRAY CFT77 FORTRAN
! MACHINE: HDS, CRAY C916/256, CRAY J916/2048
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI74(IGDS, ICOMP, GDS, LENGDS, NPTS, IGERR)
!
! INTEGER, INTENT(IN ) :: IGDS(*)
! INTEGER, INTENT(IN ) :: ICOMP
! CHARACTER(1), INTENT( OUT) :: GDS(*)
! INTEGER, INTENT( OUT) :: LENGDS
! INTEGER, INTENT( OUT) :: NPTS
! INTEGER, INTENT( OUT) :: IGERR
!
! SUBPROGRAM: CONSTRUCT GRID DEFINITION SECTION (GDS)
! PRGMMR: FARLEY ORG: W/NMC42 DATE: 93-08-24
!
! ABSTRACT: THIS SUBROUTINE CONSTRUCTS A GRIB GRID DEFINITION
! SECTION.
!
! PROGRAM HISTORY LOG:
! 92-07-07 M. FARLEY ORIGINAL AUTHOR
! 92-10-16 R.E.JONES ADD CODE TO LAT/LON SECTION TO DO
! GAUSSIAN GRIDS.
! 93-03-29 R.E.JONES ADD SAVE STATEMENT
! 93-08-24 R.E.JONES CHANGES FOR GRIB GRIDS 37-44
! 93-09-29 R.E.JONES CHANGES FOR GAUSSIAN GRID FOR DOCUMENT
! CHANGE IN W3FI71.
! 94-02-15 R.E.JONES CHANGES FOR ETA MODEL GRIDS 90-93
! 95-04-20 R.E.JONES CHANGE 200 AND 201 TO 201 AND 202
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
! 98-08-20 BALDWIN ADD TYPE 203
! 07-03-20 VUONG ADD TYPE 204
! 10-01-21 GAYNO ADD GRID 205 - ROTATED LAT/LON A,B,C,D STAGGERS
!
!
! USAGE: CALL NG_W3FI74 (IGDS, ICOMP, GDS, LENGDS, NPTS, IGERR)
! INPUT ARGUMENT LIST:
! IGDS - INTEGER ARRAY SUPPLIED BY W3FI71
! ICOMP - TABLE 7- RESOLUTION & COMPONENT FLAG (BIT 5)
! FOR GDS(17) WIND COMPONENTS
!
! OUTPUT ARGUMENT LIST:
! GDS - COMPLETED GRIB GRID DEFINITION SECTION
! LENGDS - LENGTH OF GDS
! NPTS - NUMBER OF POINTS IN GRID
! IGERR - 1, GRID REPRESENTATION TYPE NOT VALID
!
! REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI75(IBITL, ITYPE, ITOSS, FLD, IFLD, IBMAP, IBDSFL, NPTS,&
! BDS11, IPFLD, PFLD, LEN, LENBDS, IBERR, PDS, IGDS)
!
! INTEGER, INTENT(IN ) :: IBITL
! INTEGER, INTENT(IN ) :: ITYPE
! INTEGER, INTENT(IN ) :: ITOSS
! REAL, INTENT(IN ) :: FLD(*)
! INTEGER, INTENT(IN ) :: IFLD(*)
! INTEGER, INTENT(IN ) :: IBMAP(*)
! INTEGER, INTENT(IN ) :: IBDSFL(*)
! INTEGER, INTENT(IN ) :: NPTS
! CHARACTER(1), INTENT( OUT) :: BDS11(11)
! CHARACTER(1), INTENT( OUT) :: IPFLD(*)
! CHARACTER(1), INTENT( OUT) :: PFLD(*)
! INTEGER, INTENT( OUT) :: LEN
! INTEGER, INTENT( OUT) :: LENBDS
! INTEGER, INTENT( OUT) :: IBERR
! CHARACTER(1), INTENT(IN ) :: PDS(*)
! INTEGER, INTENT(IN ) :: IGDS(*)
!
! SUBPROGRAM: GRIB PACK DATA AND FORM BDS OCTETS(1-11)
! PRGMMR: FARLEY ORG: NMC421 DATE:94-11-22
!
! ABSTRACT: THIS ROUTINE PACKS A GRIB FIELD AND FORMS OCTETS(1-11)
! OF THE BINARY DATA SECTION (BDS).
!
! PROGRAM HISTORY LOG:
! 92-07-10 M. FARLEY ORIGINAL AUTHOR
! 92-10-01 R.E.JONES CORRECTION FOR FIELD OF CONSTANT DATA
! 92-10-16 R.E.JONES GET RID OF ARRAYS FP AND INT
! 93-08-06 CAVANAUGH ADDED ROUTINES FI7501, FI7502, FI7503
! TO ALLOW SECOND ORDER PACKING IN PDS.
! 93-07-21 STACKPOLE ASSORTED REPAIRS TO GET 2ND DIFF PACK IN
! 93-10-28 CAVANAUGH COMMENTED OUT NONOPERATIONAL PRINTS AND
! WRITE STATEMENTS
! 93-12-15 CAVANAUGH CORRECTED LOCATION OF START OF FIRST ORDER
! VALUES AND START OF SECOND ORDER VALUES TO
! REFLECT A BYTE LOCATION IN THE BDS INSTEAD
! OF AN OFFSET IN SUBROUTINE FI7501.
! 94-01-27 CAVANAUGH ADDED IGDS AS INPUT ARGUMENT TO THIS ROUTINE
! AND ADDED PDS AND IGDS ARRAYS TO THE CALL TO
! W3FI82 TO PROVIDE INFORMATION NEEDED FOR
! BOUSTROPHEDONIC PROCESSING.
! 94-05-25 CAVANAUGH SUBROUTINE FI7503 HAS BEEN ADDED TO PROVIDE
! FOR ROW BY ROW OR COLUMN BY COLUMN SECOND
! ORDER PACKING. THIS FEATURE CAN BE ACTIVATED
! BY SETTING IBDSFL(7) TO ZERO.
! 94-07-08 CAVANAUGH COMMENTED OUT PRINT STATEMENTS USED FOR DEBUG
! 94-11-22 FARLEY ENLARGED WORK ARRAYS TO HANDLE .5DEGREE GRIDS
! 95-06-01 R.E.JONES CORRECTION FOR NUMBER OF UNUSED BITS AT END
! OF SECTION 4, IN BDS BYTE 4, BITS 5-8.
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
! 2001-06-06 GILBERT CHanged gbyte/sbyte calls to refer to
! Wesley Ebisuzaki's endian independent
! versions gbytec/sbytec.
! Use f90 standard routine bit_size to get
! number of bits in an integer instead of w3fi01.
!
! USAGE: CALL NG_W3FI75 (IBITL,ITYPE,ITOSS,FLD,IFLD,IBMAP,IBDSFL,
! & NPTS,BDS11,IPFLD,PFLD,LEN,LENBDS,IBERR,PDS,IGDS)
! INPUT ARGUMENT LIST:
! IBITL - 0, COMPUTER COMPUTES PACKING LENGTH FROM POWER
! OF 2 THAT BEST FITS THE DATA.
! 8, 12, ETC. COMPUTER RESCALES DATA TO FIT INTO
! SET NUMBER OF BITS.
! ITYPE - 0 = IF INPUT DATA IS FLOATING POINT (FLD)
! 1 = IF INPUT DATA IS INTEGER (IFLD)
! ITOSS - 0 = NO BIT MAP IS INCLUDED (DON'T TOSS DATA)
! 1 = TOSS NULL DATA ACCORDING TO IBMAP
! FLD - REAL ARRAY OF DATA TO BE PACKED IF ITYPE=0
! IFLD - INTEGER ARRAY TO BE PACKED IF ITYPE=1
! IBMAP - BIT MAP SUPPLIED FROM USER
! IBDSFL - INTEGER ARRAY CONTAINING TABLE 11 FLAG INFO
! BDS OCTET 4:
! (1) 0 = GRID POINT DATA
! 1 = SPHERICAL HARMONIC COEFFICIENTS
! (2) 0 = SIMPLE PACKING
! 1 = SECOND ORDER PACKING
! (3) 0 = ORIGINAL DATA WERE FLOATING POINT VALUES
! 1 = ORIGINAL DATA WERE INTEGER VALUES
! (4) 0 = NO ADDITIONAL FLAGS AT OCTET 14
! 1 = OCTET 14 CONTAINS FLAG BITS 5-12
! (5) 0 = RESERVED - ALWAYS SET TO 0
! (6) 0 = SINGLE DATUM AT EACH GRID POINT
! 1 = MATRIX OF VALUES AT EACH GRID POINT
! (7) 0 = NO SECONDARY BIT MAPS
! 1 = SECONDARY BIT MAPS PRESENT
! (8) 0 = SECOND ORDER VALUES HAVE CONSTANT WIDTH
! 1 = SECOND ORDER VALUES HAVE DIFFERENT WIDTHS
! NPTS - NUMBER OF GRIDPOINTS IN ARRAY TO BE PACKED
! PDS - FLAG INDICATING PRESENCE OF GDS SECTION
! IGDS - ARRAY OF GDS INFORMATION
!
! OUTPUT ARGUMENT LIST:
! BDS11 - FIRST 11 OCTETS OF BDS
! IPFLD - CONTAINS BDS FROM BYTE 12 ON
! PFLD - PACKED GRIB FIELD
! LEN - LENGTH OF PFLD
! LENBDS - LENGTH OF BDS
! IBERR - 1, ERROR CONVERTING IEEE F.P. NUMBER TO IBM370 F.P.
!
! REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI76(PVAL, KEXP, KMANT, KBITS)
!
! REAL, INTENT(IN ) :: PVAL
! INTEGER, INTENT( OUT) :: KEXP
! INTEGER, INTENT( OUT) :: KMANT
! INTEGER, INTENT( IN) :: KBITS
!
! SUBPROGRAM: CONVERT TO IBM370 FLOATING POINT
! PRGMMR: REJONES ORG: NMC421 DATE:92-11-16
!
! ABSTRACT: CONVERTS FLOATING POINT NUMBER FROM MACHINE
! REPRESENTATION TO GRIB REPRESENTATION (IBM370 32 BIT F.P.).
!
! PROGRAM HISTORY LOG:
! 85-09-15 JOHN HENNESSY ECMWF
! 92-09-23 JONES R. E. CHANGE NAME, ADD DOC BLOCK
! 93-10-27 JONES,R. E. CHANGE TO AGREE WITH HENNESSY CHANGES
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
! 98-03-10 B. VUONG REMOVE THE CDIR$ INTEGER=64 DIRECTIVE
!
! USAGE: CALL NG_W3FI76 (FVAL, KEXP, KMANT, NBITS)
! INPUT ARGUMENT LIST:
! PVAL - FLOATING POINT NUMBER TO BE CONVERTED
! KBITS - NUMBER OF BITS IN COMPUTER WORD (32 OR 64)
!
! OUTPUT ARGUMENT LIST:
! KEXP - 8 BIT SIGNED EXPONENT
! KMANT - 24 BIT MANTISSA (FRACTION)
!
! REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI82(IFLD, FVAL1, FDIFF1, NPTS, PDS, IGDS)
!
! INTEGER, INTENT(INOUT) :: IFLD(*)
! REAL, INTENT( OUT) :: FVAL1
! REAL, INTENT( OUT) :: FDIFF1
! INTEGER, INTENT(IN ) :: NPTS
! CHARACTER(1), INTENT(IN ) :: PDS(*)
! INTEGER, INTENT(IN ) :: IGDS(*)
!
! SUBPROGRAM: CONVERT TO SECOND DIFF ARRAY
! PRGMMR: CAVANAUGH ORG: NMC421 DATE:93-08-18
!
! ABSTRACT: ACCEPT AN INPUT ARRAY, CONVERT TO ARRAY OF SECOND
! DIFFERENCES. RETURN THE ORIGINAL FIRST VALUE AND THE FIRST
! FIRST-DIFFERENCE AS SEPARATE VALUES. ALIGN DATA IN
! BOUSTREPHEDONIC STYLE, (ALTERNATE ROW REVERSAL).
!
! PROGRAM HISTORY LOG:
! 93-07-14 CAVANAUGH
! 94-01-27 CAVANAUGH ADDED REVERSAL OF EVEN NUMBERED ROWS
! (BOUSTROPHEDONIC PROCESSING)
! 94-03-02 CAVANAUGH CORRECTED IMPROPER ORDERING OF EVEN
! NUMBERED ROWS
! 99-12-06 EBISUZAKI LINUX PORT
!
! USAGE: CALL NG_W3FI82 (IFLD,FVAL1,FDIFF1,NPTS,PDS,IGDS)
! INPUT ARGUMENT LIST:
! IFLD - INTEGER INPUT ARRAY
! NPTS - NUMBER OF POINTS IN ARRAY
! IGDS(5) - NUMBER OF ROWS IN ARRAY
! IGDS(4) - NUMBER OF COLUMNS IN ARRAY
! PDS(8) - FLAG INDICATING PRESENCE OF GDS SECTION
!
! OUTPUT ARGUMENT LIST:
! IFLD - SECOND DIFFERENCED FIELD
! FVAL1 - FLOATING POINT ORIGINAL FIRST VALUE
! FDIFF1 - " " FIRST FIRST-DIFFERENCE
!
! REMARKS: LIST CAVEATS, OTHER HELPFUL HINTS OR INFORMATION
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FI83(DATA, NPTS, FVAL1, FDIFF1, ISCAL2, ISC10, KPDS, KGDS)
!
! REAL, INTENT(INOUT) :: DATA(*)
! INTEGER, INTENT(IN ) :: NPTS
! REAL, INTENT(IN ) :: FVAL1
! REAL, INTENT(IN ) :: FDIFF1
! INTEGER, INTENT(IN ) :: ISCAL2
! INTEGER, INTENT(IN ) :: ISC10
! INTEGER, INTENT(IN ) :: KPDS(*)
! INTEGER, INTENT(IN ) :: KGDS(*)
!
! SUBPROGRAM: RESTORE DELTA PACKED DATA TO ORIGINAL
! PRGMMR: CAVANAUGH ORG: NMC421 DATE:93-08-18
!
! ABSTRACT: RESTORE DELTA PACKED DATA TO ORIGINAL VALUES
! RESTORE FROM BOUSTREPHEDONIC ALIGNMENT
!
! PROGRAM HISTORY LOG:
! 93-07-14 CAVANAUGH
! 93-07-22 STACKPOLE ADDITIONS TO FIX SCALING
! 94-01-27 CAVANAUGH ADDED REVERSAL OF EVEN NUMBERED ROWS
! (BOUSTROPHEDONIC PROCESSING) TO RESTORE
! DATA TO ORIGINAL SEQUENCE.
! 94-03-02 CAVANAUGH CORRECTED REVERSAL OF EVEN NUMBERED ROWS
! 95-10-31 IREDELL REMOVED SAVES AND PRINTS
!
! USAGE: CALL NG_W3FI83(DATA,NPTS,FVAL1,FDIFF1,ISCAL2,ISC10,KPDS,KGDS)
! INPUT ARGUMENT LIST:
! DATA - SECOND ORDER DIFFERENCES
! NPTS - NUMBER OF POINTS IN ARRAY
! FVAL1 - ORIGINAL FIRST ENTRY IN ARRAY
! FDIFF1 - ORIGINAL FIRST FIRST-DIFFERENCE
! ISCAL2 - POWER-OF-TWO EXPONENT FOR UNSCALING
! ISC10 - POWER-OF-TEN EXPONENT FOR UNSCALING
! KPDS - ARRAY OF INFORMATION FOR PDS
! KGDS - ARRAY OF INFORMATION FOR GDS
!
! OUTPUT ARGUMENT LIST:
! DATA - EXPANDED ORIGINAL DATA VALUES
!
! REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FS21(IDATE, NMIN)
!
! INTEGER, INTENT(IN ) :: IDATE(5)
! INTEGER, INTENT( OUT) :: NMIN
!
! SUBPROGRAM: NUMBER OF MINUTES SINCE JAN 1, 1978
! PRGMMR: REJONES ORG: NMC421 DATE: 89-07-17
!
! ABSTRACT: CALCULATES THE NUMBER OF MINUTES SINCE 0000,
! 1 JANUARY 1978.
!
! PROGRAM HISTORY LOG:
! 84-06-21 A. DESMARAIS
! 89-07-14 R.E.JONES CONVERT TO CYBER 205 FORTRAN 200,
! CHANGE LOGIC SO IT WILL WORK IN
! 21 CENTURY.
! 89-11-02 R.E.JONES CONVERT TO CRAY CFT77 FORTRAN
!
! USAGE: CALL NG_W3FS21 (IDATE, NMIN)
! INPUT ARGUMENT LIST:
! IDATE - INTEGER SIZE 5 ARRAY CONTAINING YEAR OF CENTURY,
! MONTH, DAY, HOUR AND MINUTE. IDATE(1) MAY BE
! A TWO DIGIT YEAR OR 4. IF 2 DIGITS AND GE THAN 78
! 1900 IS ADDED TO IT. IF LT 78 THEN 2000 IS ADDED
! TO IT. IF 4 DIGITS THE SUBROUTINE WILL WORK
! CORRECTLY TO THE YEAR 3300 A.D.
!
! OUTPUT ARGUMENT LIST:
! NMIN - INTEGER NUMBER OF MINUTES SINCE 1 JANUARY 1978
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3FS26(JLDAYN, IYEAR, MONTH, IDAY, IDAYWK, IDAYYR)
!
! INTEGER, INTENT(IN ) :: JLDAYN
! INTEGER, INTENT( OUT) :: IYEAR
! INTEGER, INTENT( OUT) :: MONTH
! INTEGER, INTENT( OUT) :: IDAY
! INTEGER, INTENT( OUT) :: IDAYWK
! INTEGER, INTENT( OUT) :: IDAYYR
!
! SUBPROGRAM: YEAR, MONTH, DAY FROM JULIAN DAY NUMBER
! AUTHOR: JONES,R.E. ORG: W342 DATE: 87-03-29
!
! ABSTRACT: COMPUTES YEAR (4 DIGITS), MONTH, DAY, DAY OF WEEK, DAY
! OF YEAR FROM JULIAN DAY NUMBER. THIS SUBROUTINE WILL WORK
! FROM 1583 A.D. TO 3300 A.D.
!
! PROGRAM HISTORY LOG:
! 87-03-29 R.E.JONES
! 89-10-25 R.E.JONES CONVERT TO CRAY CFT77 FORTRAN
!
! USAGE: CALL NG_W3FS26(JLDAYN,IYEAR,MONTH,IDAY,IDAYWK,IDAYYR)
!
! INPUT VARIABLES:
! NAMES INTERFACE DESCRIPTION OF VARIABLES AND TYPES
! ------ --------- -----------------------------------------------
! JLDAYN ARG LIST INTEGER JULIAN DAY NUMBER
!
! OUTPUT VARIABLES:
! NAMES INTERFACE DESCRIPTION OF VARIABLES AND TYPES
! ------ --------- -----------------------------------------------
! IYEAR ARG LIST INTEGER YEAR (4 DIGITS)
! MONTH ARG LIST INTEGER MONTH
! IDAY ARG LIST INTEGER DAY
! IDAYWK ARG LIST INTEGER DAY OF WEEK (1 IS SUNDAY, 7 IS SAT)
! IDAYYR ARG LIST INTEGER DAY OF YEAR (1 TO 366)
!
! REMARKS: A JULIAN DAY NUMBER CAN BE COMPUTED BY USING ONE OF THE
! FOLLOWING STATEMENT FUNCTIONS. A DAY OF WEEK CAN BE COMPUTED
! FROM THE JULIAN DAY NUMBER. A DAY OF YEAR CAN BE COMPUTED FROM
! A JULIAN DAY NUMBER AND YEAR.
!
! IYEAR (4 DIGITS)
!
! JDN(IYEAR,MONTH,IDAY) = IDAY - 32075
! & + 1461 * (IYEAR + 4800 + (MONTH - 14) / 12) / 4
! & + 367 * (MONTH - 2 - (MONTH -14) / 12 * 12) / 12
! & - 3 * ((IYEAR + 4900 + (MONTH - 14) / 12) / 100) / 4
!
! IYR (4 DIGITS) , IDYR(1-366) DAY OF YEAR
!
! JULIAN(IYR,IDYR) = -31739 + 1461 * (IYR + 4799) / 4
! & -3 * ((IYR + 4899) / 100) / 4 + IDYR
!
! DAY OF WEEK FROM JULIAN DAY NUMBER, 1 IS SUNDAY, 7 IS SATURDAY.
!
! JDAYWK(JLDAYN) = MOD((JLDAYN + 1),7) + 1
!
! DAY OF YEAR FROM JULIAN DAY NUMBER AND 4 DIGIT YEAR.
!
! JDAYYR(JLDAYN,IYEAR) = JLDAYN -
! & (-31739+1461*(IYEAR+4799)/4-3*((IYEAR+4899)/100)/4)
!
! THE FIRST FUNCTION WAS IN A LETTER TO THE EDITOR COMMUNICATIONS
! OF THE ACM VOLUME 11 / NUMBER 10 / OCTOBER, 1968. THE 2ND
! FUNCTION WAS DERIVED FROM THE FIRST. THIS SUBROUTINE WAS ALSO
! INCLUDED IN THE SAME LETTER. JULIAN DAY NUMBER 1 IS
! JAN 1,4713 B.C. A JULIAN DAY NUMBER CAN BE USED TO REPLACE A
! DAY OF CENTURY, THIS WILL TAKE CARE OF THE DATE PROBLEM IN
! THE YEAR 2000, OR REDUCE PROGRAM CHANGES TO ONE LINE CHANGE
! OF 1900 TO 2000. JULIAN DAY NUMBERS CAN BE USED FOR FINDING
! RECORD NUMBERS IN AN ARCHIVE OR DAY OF WEEK, OR DAY OF YEAR.
!
!---------------------------------------------------------------------
!
! INTEGER FUNCTION NG_IW3JDN(IYEAR, MONTH, IDAY)
!
! INTEGER, INTENT(IN) :: IYEAR, MONTH, IDAY
!
! SUBPROGRAM: COMPUTE JULIAN DAY NUMBER
! AUTHOR: JONES,R.E. ORG: W342 DATE: 87-03-29
!
! ABSTRACT: COMPUTES JULIAN DAY NUMBER FROM YEAR (4 DIGITS), MONTH,
! AND DAY. IW3JDN IS VALID FOR YEARS 1583 A.D. TO 3300 A.D.
! JULIAN DAY NUMBER CAN BE USED TO COMPUTE DAY OF WEEK, DAY OF
! YEAR, RECORD NUMBERS IN AN ARCHIVE, REPLACE DAY OF CENTURY,
! FIND THE NUMBER OF DAYS BETWEEN TWO DATES.
!
! PROGRAM HISTORY LOG:
! 87-03-29 R.E.JONES
! 89-10-25 R.E.JONES CONVERT TO CRAY CFT77 FORTRAN
!
! USAGE: II = NG_IW3JDN(IYEAR,MONTH,IDAY)
!
! INPUT VARIABLES:
! NAMES INTERFACE DESCRIPTION OF VARIABLES AND TYPES
! ------ --------- -----------------------------------------------
! IYEAR ARG LIST INTEGER YEAR ( 4 DIGITS)
! MONTH ARG LIST INTEGER MONTH OF YEAR (1 - 12)
! IDAY ARG LIST INTEGER DAY OF MONTH (1 - 31)
!
! OUTPUT VARIABLES:
! NAMES INTERFACE DESCRIPTION OF VARIABLES AND TYPES
! ------ --------- -----------------------------------------------
! IW3JDN FUNTION INTEGER JULIAN DAY NUMBER
! JAN. 1,1960 IS JULIAN DAY NUMBER 2436935
! JAN. 1,1987 IS JULIAN DAY NUMBER 2446797
!
! REMARKS: JULIAN PERIOD WAS DEVISED BY JOSEPH SCALIGER IN 1582.
! JULIAN DAY NUMBER #1 STARTED ON JAN. 1,4713 B.C. THREE MAJOR
! CHRONOLOGICAL CYCLES BEGIN ON THE SAME DAY. A 28-YEAR SOLAR
! CYCLE, A 19-YEAR LUNER CYCLE, A 15-YEAR INDICTION CYCLE, USED
! IN ANCIENT ROME TO REGULATE TAXES. IT WILL TAKE 7980 YEARS
! TO COMPLETE THE PERIOD, THE PRODUCT OF 28, 19, AND 15.
! SCALIGER NAMED THE PERIOD, DATE, AND NUMBER AFTER HIS FATHER
! JULIUS (NOT AFTER THE JULIAN CALENDAR). THIS SEEMS TO HAVE
! CAUSED A LOT OF CONFUSION IN TEXT BOOKS. SCALIGER NAME IS
! SPELLED THREE DIFFERENT WAYS. JULIAN DATE AND JULIAN DAY
! NUMBER ARE INTERCHANGED. A JULIAN DATE IS USED BY ASTRONOMERS
! TO COMPUTE ACCURATE TIME, IT HAS A FRACTION. WHEN TRUNCATED TO
! AN INTEGER IT IS CALLED AN JULIAN DAY NUMBER. THIS FUNCTION
! WAS IN A LETTER TO THE EDITOR OF THE COMMUNICATIONS OF THE ACM
! VOLUME 11 / NUMBER 10 / OCTOBER 1968. THE JULIAN DAY NUMBER
! CAN BE CONVERTED TO A YEAR, MONTH, DAY, DAY OF WEEK, DAY OF
! YEAR BY CALLING SUBROUTINE W3FS26.
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3DIFDAT(JDAT, IDAT, IT, RINC)
!
! INTEGER, INTENT(IN ) :: JDAT(8)
! INTEGER, INTENT(IN ) :: IDAT(8)
! INTEGER, INTENT(IN ) :: IT
! REAL, INTENT( OUT) :: RINC(5)
!
! SUBPROGRAM: RETURN A TIME INTERVAL BETWEEN TWO DATES
! AUTHOR: MARK IREDELL ORG: WP23 DATE: 98-01-05
!
! ABSTRACT: THIS SUBPROGRAM RETURNS THE ELAPSED TIME INTERVAL FROM
! AN NCEP ABSOLUTE DATE AND TIME GIVEN IN THE SECOND ARGUMENT UNTIL
! AN NCEP ABSOLUTE DATE AND TIME GIVEN IN THE FIRST ARGUMENT.
! THE OUTPUT TIME INTERVAL IS IN ONE OF SEVEN CANONICAL FORMS
! OF THE NCEP RELATIVE TIME INTERVAL DATA STRUCTURE.
!
! PROGRAM HISTORY LOG:
! 98-01-05 MARK IREDELL
!
! USAGE: CALL NG_W3DIFDAT(JDAT,IDAT,IT,RINC)
!
! INPUT VARIABLES:
! JDAT INTEGER (8) NCEP ABSOLUTE DATE AND TIME
! (YEAR, MONTH, DAY, TIME ZONE,
! HOUR, MINUTE, SECOND, MILLISECOND)
! IDAT INTEGER (8) NCEP ABSOLUTE DATE AND TIME
! (YEAR, MONTH, DAY, TIME ZONE,
! HOUR, MINUTE, SECOND, MILLISECOND)
! IT INTEGER RELATIVE TIME INTERVAL FORMAT TYPE
! (-1 FOR FIRST REDUCED TYPE (HOURS ALWAYS POSITIVE),
! 0 FOR SECOND REDUCED TYPE (HOURS CAN BE NEGATIVE),
! 1 FOR DAYS ONLY, 2 FOR HOURS ONLY, 3 FOR MINUTES ONLY,
! 4 FOR SECONDS ONLY, 5 FOR MILLISECONDS ONLY)
!
! OUTPUT VARIABLES:
! RINC REAL (5) NCEP RELATIVE TIME INTERVAL
! (DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS)
! (TIME INTERVAL IS POSITIVE IF JDAT IS LATER THAN IDAT.)
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3LOCDAT(IDAT)
!
! INTEGER, INTENT(OUT) :: IDAT(8)
!
! SUBPROGRAM: RETURN THE LOCAL DATE AND TIME
! AUTHOR: MARK IREDELL ORG: WP23 DATE: 98-01-05
!
! ABSTRACT: THIS SUBPROGRAM RETURNS THE LOCAL DATE AND TIME
! IN THE NCEP ABSOLUTE DATE AND TIME DATA STRUCTURE.
!
! PROGRAM HISTORY LOG:
! 98-01-05 MARK IREDELL
! 1999-04-28 Gilbert - added a patch to check for the proper
! UTC offset. Needed until the IBM bug
! in date_and_time is fixed. The patch
! can then be removed. See comments in
! the section blocked with "&&&&&&&&&&&".
! 1999-08-12 Gilbert - Changed so that czone variable is saved
! and the system call is only done for
! first invocation of this routine.
!
! USAGE: CALL NG_W3LOCDAT(IDAT)
!
! OUTPUT VARIABLES:
! IDAT INTEGER (8) NCEP ABSOLUTE DATE AND TIME
! (YEAR, MONTH, DAY, TIME ZONE,
! HOUR, MINUTE, SECOND, MILLISECOND)
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3DOXDAT(IDAT, JDOW, JDOY, JDAY)
!
! INTEGER, INTENT(IN ) :: IDAT(8)
! INTEGER, INTENT( OUT) :: JDOW
! INTEGER, INTENT( OUT) :: JDOY
! INTEGER, INTENT( OUT) :: JDAY
!
! SUBPROGRAM: RETURN WEEK DAY, YEAR DAY, AND JULIAN DAY
! AUTHOR: MARK IREDELL ORG: WP23 DATE: 98-01-05
!
! ABSTRACT: THIS SUBPROGRAM RETURNS THE INTEGER DAY OF WEEK, THE DAY
! OF YEAR, AND JULIAN DAY GIVEN AN NCEP ABSOLUTE DATE AND TIME.
!
! PROGRAM HISTORY LOG:
! 98-01-05 MARK IREDELL
!
! USAGE: CALL NG_W3DOXDAT(IDAT,JDOW,JDOY,JDAY)
!
! INPUT VARIABLES:
! IDAT INTEGER (8) NCEP ABSOLUTE DATE AND TIME
! (YEAR, MONTH, DAY, TIME ZONE,
! HOUR, MINUTE, SECOND, MILLISECOND)
!
! OUTPUT VARIABLES:
! JDOW INTEGER DAY OF WEEK (1-7, WHERE 1 IS SUNDAY)
! JDOY INTEGER DAY OF YEAR (1-366, WHERE 1 IS JANUARY 1)
! JDAY INTEGER JULIAN DAY (DAY NUMBER FROM JAN. 1,4713 B.C.)
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3MOVDAT(RINC, IDAT, JDAT)
!
! REAL, INTENT(IN ) :: RINC(5)
! INTEGER, INTENT(IN ) :: IDAT(8)
! INTEGER, INTENT( OUT) :: JDAT(8)
!
! SUBPROGRAM: RETURN A DATE FROM A TIME INTERVAL AND DATE
! AUTHOR: MARK IREDELL ORG: WP23 DATE: 98-01-05
!
! ABSTRACT: THIS SUBPROGRAM RETURNS THE DATE AND TIME THAT IS A GIVEN
! NCEP RELATIVE TIME INTERVAL FROM AN NCEP ABSOLUTE DATE AND TIME.
! THE OUTPUT IS IN THE NCEP ABSOLUTE DATE AND TIME DATA STRUCTURE.
!
! PROGRAM HISTORY LOG:
! 98-01-05 MARK IREDELL
!
! USAGE: CALL NG_W3MOVDAT(RINC,IDAT,JDAT)
!
! INPUT VARIABLES:
! RINC REAL (5) NCEP RELATIVE TIME INTERVAL
! (DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS)
! IDAT INTEGER (8) NCEP ABSOLUTE DATE AND TIME
! (YEAR, MONTH, DAY, TIME ZONE,
! HOUR, MINUTE, SECOND, MILLISECOND)
!
! OUTPUT VARIABLES:
! JDAT INTEGER (8) NCEP ABSOLUTE DATE AND TIME
! (YEAR, MONTH, DAY, TIME ZONE,
! HOUR, MINUTE, SECOND, MILLISECOND)
! (JDAT IS LATER THAN IDAT IF TIME INTERVAL IS POSITIVE.)
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3REDDAT(IT, RINC, DINC)
!
! INTEGER, INTENT(IN ) :: IT
! REAL, INTENT(IN ) :: RINC(5)
! REAL, INTENT( OUT) :: DINC(5)
!
! SUBPROGRAM: REDUCE A TIME INTERVAL TO A CANONICAL FORM
! AUTHOR: MARK IREDELL ORG: WP23 DATE: 98-01-05
!
! ABSTRACT: THIS SUBPROGRAM REDUCES AN NCEP RELATIVE TIME INTERVAL
! INTO ONE OF SEVEN CANONICAL FORMS, DEPENDING ON THE INPUT IT VALUE.
!
! First reduced format type (IT=-1):
! RINC(1) is an arbitrary integer.
! RINC(2) is an integer between 00 and 23, inclusive.
! RINC(3) is an integer between 00 and 59, inclusive.
! RINC(4) is an integer between 00 and 59, inclusive.
! RINC(5) is an integer between 000 and 999, inclusive.
! If RINC(1) is negative, then the time interval is negative.
!
! Second reduced format type (IT=0):
! If the time interval is not negative, then the format is:
! RINC(1) is zero or a positive integer.
! RINC(2) is an integer between 00 and 23, inclusive.
! RINC(3) is an integer between 00 and 59, inclusive.
! RINC(4) is an integer between 00 and 59, inclusive.
! RINC(5) is an integer between 000 and 999, inclusive.
! Otherwise if the time interval is negative, then the format is:
! RINC(1) is zero or a negative integer.
! RINC(2) is an integer between 00 and -23, inclusive.
! RINC(3) is an integer between 00 and -59, inclusive.
! RINC(4) is an integer between 00 and -59, inclusive.
! RINC(5) is an integer between 000 and -999, inclusive.
!
! Days format type (IT=1):
! RINC(1) is arbitrary.
! RINC(2) is zero.
! RINC(3) is zero.
! RINC(4) is zero.
! RINC(5) is zero.
!
! Hours format type (IT=2):
! RINC(1) is zero.
! RINC(2) is arbitrary.
! RINC(3) is zero.
! RINC(4) is zero.
! RINC(5) is zero.
! (This format should not express time intervals longer than 300 years.)
!
! Minutes format type (IT=3):
! RINC(1) is zero.
! RINC(2) is zero.
! RINC(3) is arbitrary.
! RINC(4) is zero.
! RINC(5) is zero.
! (This format should not express time intervals longer than five years.)
!
! Seconds format type (IT=4):
! RINC(1) is zero.
! RINC(2) is zero.
! RINC(3) is zero.
! RINC(4) is arbitrary.
! RINC(5) is zero.
! (This format should not express time intervals longer than one month.)
!
! Milliseconds format type (IT=5):
! RINC(1) is zero.
! RINC(2) is zero.
! RINC(3) is zero.
! RINC(4) is zero.
! RINC(5) is arbitrary.
! (This format should not express time intervals longer than one hour.)
!
! PROGRAM HISTORY LOG:
! 98-01-05 MARK IREDELL
!
! USAGE: CALL NG_W3REDDAT(IT,RINC,DINC)
!
! INPUT VARIABLES:
! IT INTEGER RELATIVE TIME INTERVAL FORMAT TYPE
! (-1 FOR FIRST REDUCED TYPE (HOURS ALWAYS POSITIVE),
! 0 FOR SECOND REDUCED TYPE (HOURS CAN BE NEGATIVE),
! 1 FOR DAYS ONLY, 2 FOR HOURS ONLY, 3 FOR MINUTES ONLY,
! 4 FOR SECONDS ONLY, 5 FOR MILLISECONDS ONLY)
! RINC REAL (5) NCEP RELATIVE TIME INTERVAL
! (DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS)
!
! OUTPUT VARIABLES:
! DINC REAL (5) NCEP RELATIVE TIME INTERVAL
! (DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS)
!
!---------------------------------------------------------------------
!
! SUBROUTINE NG_W3UTCDAT(IDAT)
!
! INTEGER, INTENT(OUT) :: IDAT(8)
!
! SUBPROGRAM: RETURN THE UTC DATE AND TIME
! AUTHOR: MARK IREDELL ORG: WP23 DATE: 98-01-05
!
! ABSTRACT: THIS SUBPROGRAM RETURNS THE UTC (GREENWICH) DATE AND TIME
! IN THE NCEP ABSOLUTE DATE AND TIME DATA STRUCTURE.
!
! PROGRAM HISTORY LOG:
! 98-01-05 MARK IREDELL
! 1999-04-28 Gilbert - added a patch to check for the proper
! UTC offset. Needed until the IBM bug
! in date_and_time is fixed. The patch
! can then be removed. See comments in
! the section blocked with "&&&&&&&&&&&".
! 1999-08-12 Gilbert - Changed so that czone variable is saved
! and the system call is only done for
! first invocation of this routine.
!
! USAGE: CALL NG_W3UTCDAT(IDAT)
!
! OUTPUT VARIABLES:
! IDAT INTEGER (8) NCEP ABSOLUTE DATE AND TIME
! (YEAR, MONTH, DAY, TIME ZONE,
! HOUR, MINUTE, SECOND, MILLISECOND)
!
!=====================================================================