NCEPLIBS-bufr 11.7.1
srchtbf.c
Go to the documentation of this file.
1
4#include "bufrlib.h"
5#include "cfe.h"
6
74void srchtbf( f77int *ifxyi, f77int *ivali, f77int *ifxyd, f77int *mxfxyd, f77int *ivald,
75 char *meaning, f77int *mxmng, f77int *lnmng, f77int *iret )
76{
77 struct code_flag_entry key, *pkey, *pcfe, *pbs;
78
79 int ipt, ii, slmng;
80
81 *iret = -1;
82
83 /*
84 ** Initialize some values for searching the internal table.
85 */
86
87 key.iffxyn = *ifxyi;
88 key.ifval = *ivali;
89 key.iffxynd = ifxyd[0];
90 key.ifvald = *ivald;
91
92 pkey = &key;
93 pcfe = &cfe[0];
94
95 /*
96 ** Search for a matching entry.
97 */
98 pbs = ( struct code_flag_entry * ) bsearch( pkey, pcfe, ( size_t ) nmtf,
99 sizeof( struct code_flag_entry ),
100 ( int (*) ( const void *, const void * ) ) cmpstia1 );
101 if ( pbs != NULL ) {
102 /*
103 ** A matching entry was found, so set the appropriate output
104 ** values and return.
105 */
106 ipt = pbs - pcfe;
107 slmng = strlen( cfe[ipt].ifmeaning );
108 *lnmng = ( *mxmng > slmng ? slmng : *mxmng );
109 strncpy( meaning, &cfe[ipt].ifmeaning[0], *lnmng );
110 *iret = 0;
111 return;
112 }
113
114 /*
115 ** Was a particular dependency specified in the input?
116 */
117 if ( key.iffxynd != -1 ) {
118 /*
119 ** YES, so there's nothing else to do.
120 */
121 return;
122 }
123
124 /*
125 ** NO, so check whether the given Table B descriptor and value have any
126 ** dependencies, and if so then return a list of those dependencies.
127 */
128 pbs = ( struct code_flag_entry * ) bsearch( pkey, pcfe, ( size_t ) nmtf,
129 sizeof( struct code_flag_entry ),
130 ( int (*) ( const void *, const void * ) ) cmpstia2 );
131 if ( pbs == NULL ) {
132 /*
133 ** There are no dependencies.
134 */
135 return;
136 }
137
138 /*
139 ** Store the dependency that was returned by the secondary search.
140 ** However, there may be others within the internal table, so we'll
141 ** also need to check for those.
142 */
143 ipt = pbs - pcfe;
144 *iret = 0;
145 ifxyd[(*iret)++] = cfe[ipt].iffxynd;
146
147 /*
148 ** Since the internal table is sorted, check immediately before and
149 ** after the returned dependency for any additional table entries which
150 ** correspond to the same Table B descriptor and value, but for which the
151 ** dependency is different. If any such additional dependencies are
152 ** found, return those as well.
153 */
154 ii = ipt - 1;
155 while ( ( ii >= 0 ) &&
156 ( *iret < *mxfxyd ) &&
157 ( cfe[ii].iffxyn == key.iffxyn ) &&
158 ( cfe[ii].ifval == key.ifval ) ) {
159 if ( cfe[ii].iffxynd < ifxyd[(*iret)-1] )
160 ifxyd[(*iret)++] = cfe[ii].iffxynd;
161 ii--;
162 }
163 ii = ipt + 1;
164 while ( ( ii < nmtf ) &&
165 ( *iret < *mxfxyd ) &&
166 ( cfe[ii].iffxyn == key.iffxyn ) &&
167 ( cfe[ii].ifval == key.ifval ) ) {
168 if ( ( cfe[ii].iffxynd > ifxyd[(*iret)-1] ) &&
169 ( cfe[ii].iffxynd > cfe[ipt].iffxynd ) )
170 ifxyd[(*iret)++] = cfe[ii].iffxynd;
171 ii++;
172 }
173
174 return;
175}
Define signatures to enable a number of BUFRLIB subprograms to be called directly from C application ...
Define signatures and declare variables for internal storage of master Code/Flag table entries.
char ifmeaning[MAX_MEANING_LEN+1]
Meaning corresponding to ifval.
Definition: cfe.h:53
f77int iffxynd
Bit-wise representation of FXY number upon which this entry is dependent, if any.
Definition: cfe.h:54
f77int nmtf
Number of stored master Code/Flag table entries in cfe, up to a maximum of MXMTBF.
f77int ifval
Code figure or bit number.
Definition: cfe.h:52
int cmpstia1(const void *, const void *)
This function defines a comparison between two entries within the internal memory structure for stora...
Definition: cmpstia1.c:34
f77int ifvald
Code figure or bit number upon which this entry is dependent, if any.
Definition: cfe.h:55
int cmpstia2(const void *, const void *)
This function defines a comparison between two entries within the internal memory structure for stora...
Definition: cmpstia2.c:34
f77int iffxyn
Bit-wise representation of FXY number to which this entry belongs.
Definition: cfe.h:51
struct code_flag_entry * cfe
Master Code/Flag table entries.
This structure contains array and variable declarations used to store a master Code/Flag table entry.
Definition: cfe.h:33
void srchtbf(f77int *ifxyi, f77int *ivali, f77int *ifxyd, f77int *mxfxyd, f77int *ivald, char *meaning, f77int *mxmng, f77int *lnmng, f77int *iret)
This subroutine searches for a specified FXY number and associated value (code figure or bit number) ...
Definition: srchtbf.c:74