updated top-level README and version_decl for V4.5 (#1847)
[WRF.git] / var / external / bufr / nummtb.c
blob2d9b46e7ce1d9ecd537aafcb4f099fddcadabe7e
1 /*$$$ SUBPROGRAM DOCUMENTATION BLOCK
3 C SUBPROGRAM: NUMMTB
4 C PRGMMR: ATOR ORG: NP12 DATE: 2009-03-23
6 C ABSTRACT: THIS ROUTINE SEARCHES FOR AN ENTRY CORRESPONDING TO IDN
7 C IN THE BUFR MASTER TABLE (EITHER 'B' OR 'D', DEPENDING ON THE VALUE
8 C OF IDN). THE SEARCH USES BINARY SEARCH LOGIC, SO ALL OF THE ENTRIES
9 C IN THE TABLE MUST BE SORTED IN ASCENDING ORDER (BY FXY NUMBER) IN
10 C ORDER FOR THIS ROUTINE TO WORK PROPERLY.
12 C PROGRAM HISTORY LOG:
13 C 2009-03-23 J. ATOR -- ORIGINAL AUTHOR
15 C USAGE: CALL NUMMTB( IDN, TAB, IPT )
16 C INPUT ARGUMENT LIST:
17 C IDN - INTEGER: BIT-WISE REPRESENTATION OF FXY VALUE TO BE
18 C SEARCHED FOR
20 C OUTPUT ARGUMENT LIST:
21 C TAB - CHARACTER: TABLE IN WHICH IDN WAS FOUND ('B' OR 'D')
22 C IPT - INTEGER: INDEX OF ENTRY FOR IDN IN MASTER TABLE TAB
24 C REMARKS:
25 C THIS ROUTINE CALLS: BORT CADN30 CMPIA
26 C THIS ROUTINE IS CALLED BY: STSEQ
27 C Normally not called by any application
28 C programs.
30 C ATTRIBUTES:
31 C LANGUAGE: C
32 C MACHINE: PORTABLE TO ALL PLATFORMS
34 C$$$*/
36 #define COMMON_MSTABS
37 #include "bufrlib.h"
39 void nummtb( f77int *idn, char *tab, f77int *ipt )
41 f77int *pifxyn, *pbs, nmt;
43 char adn[7], errstr[129];
45 if ( *idn >= ifxy( "300000", 6 ) ) {
46 *tab = 'D';
47 pifxyn = &mstabs.idfxyn[0];
48 nmt = mstabs.nmtd;
50 else {
51 *tab = 'B';
52 pifxyn = &mstabs.ibfxyn[0];
53 nmt = mstabs.nmtb;
56 pbs = ( f77int * ) bsearch( idn, pifxyn, ( size_t ) nmt, sizeof( f77int ),
57 ( int (*) ( const void *, const void * ) ) cmpia );
58 if ( pbs == NULL ) {
59 cadn30( idn, adn, sizeof( adn ) );
60 adn[6] = '\0';
61 sprintf( errstr, "BUFRLIB: NUMMTB - COULD NOT FIND DESCRIPTOR "
62 "%s IN MASTER TABLE %c", adn, *tab );
63 bort( errstr, ( f77int ) strlen( errstr ) );
65 *ipt = pbs - pifxyn;
67 return;