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