11 #define MAX_MEANING_LEN 150
16 struct code_flag_entry {
34 struct code_flag_entry *
cfe;
58 char brtstr[50] =
"BUFRLIB: INITTBF FAILED ALLOCATING CFE";
68 if ( (
cfe = malloc(
mxmtbf *
sizeof(
struct code_flag_entry)) ) == NULL ) {
115 struct code_flag_entry *mype1 = (
struct code_flag_entry * ) pe1;
116 struct code_flag_entry *mype2 = (
struct code_flag_entry * ) pe2;
118 if ( mype1->iffxyn == mype2->iffxyn ) {
119 if ( mype1->ifval == mype2->ifval ) {
120 if ( mype1->iffxynd == mype2->iffxynd ) {
121 if ( mype1->ifvald == mype2->ifvald )
return 0;
122 return ( mype1->ifvald < mype2->ifvald ? -1 : 1 );
125 return ( mype1->iffxynd < mype2->iffxynd ? -1 : 1 );
129 return ( mype1->ifval < mype2->ifval ? -1 : 1 );
133 return ( mype1->iffxyn < mype2->iffxyn ? -1 : 1 );
160 struct code_flag_entry *mype1 = (
struct code_flag_entry * ) pe1;
161 struct code_flag_entry *mype2 = (
struct code_flag_entry * ) pe2;
163 if ( mype1->iffxyn == mype2->iffxyn ) {
164 if ( mype1->ifval == mype2->ifval )
return 0;
165 return ( mype1->ifval < mype2->ifval ? -1 : 1 );
168 return ( mype1->iffxyn < mype2->iffxyn ? -1 : 1 );
191 strtbfe(
int ifxyn,
int ival,
char *meaning,
int lmeaning,
int idfxy,
int idval)
195 static char brtstr[50] =
"BUFRLIB: STRTBFE - MXMTBF OVERFLOW";
208 strncpy(&
cfe[
nmtf].ifmeaning[0], meaning, mnlen);
209 cfe[
nmtf].ifmeaning[mnlen] =
'\0';
227 qsort(&
cfe[0], (
size_t)
nmtf,
sizeof(
struct code_flag_entry),
228 (
int (*) (
const void *,
const void *))
cmpstia1);
278 srchtbf(
int ifxyi,
int ivali,
int *ifxyd,
int mxfxyd,
int ivald,
279 char *meaning,
int mxmng,
int *lnmng,
int *iret)
281 struct code_flag_entry key, *pkey, *pcfe, *pbs;
292 key.iffxynd = ifxyd[0];
301 pbs = (
struct code_flag_entry *) bsearch(pkey, pcfe, (
size_t)
nmtf,
302 sizeof(
struct code_flag_entry),
303 (int (*) (
const void *,
const void *))
cmpstia1);
310 slmng = strlen(
cfe[ipt].ifmeaning);
311 *lnmng = ( mxmng > slmng ? slmng : mxmng );
312 strncpy(meaning, &
cfe[ipt].ifmeaning[0], *lnmng);
320 if ( key.iffxynd != -1 ) {
331 pbs = (
struct code_flag_entry *) bsearch(pkey, pcfe, (
size_t)
nmtf,
332 sizeof(
struct code_flag_entry),
333 (int (*) (
const void *,
const void *))
cmpstia2);
348 ifxyd[(*iret)++] =
cfe[ipt].iffxynd;
358 while ( ( ii >= 0 ) &&
359 ( *iret < mxfxyd ) &&
360 (
cfe[ii].iffxyn == key.iffxyn ) &&
361 (
cfe[ii].ifval == key.ifval ) ) {
362 if (
cfe[ii].iffxynd < ifxyd[(*iret)-1] )
363 ifxyd[(*iret)++] =
cfe[ii].iffxynd;
367 while ( ( ii <
nmtf ) &&
368 ( *iret < mxfxyd ) &&
369 (
cfe[ii].iffxyn == key.iffxyn ) &&
370 (
cfe[ii].ifval == key.ifval ) ) {
371 if ( (
cfe[ii].iffxynd > ifxyd[(*iret)-1] ) &&
372 (
cfe[ii].iffxynd >
cfe[ipt].iffxynd ) )
373 ifxyd[(*iret)++] =
cfe[ii].iffxynd;
int igetprm_f(char *cprmnm)
Get the current value of a parameter.
Enable a number of NCEPLIBS-bufr subprograms to be called from within the C part of the library.
void bort_f(char *errstr)
Log one error message and abort application program.
void dlloctbf(void)
Free all dynamically-allocated memory for internal storage of master Code/Flag table entries.
int cmpstia2(const void *pe1, const void *pe2)
Define a comparison between two master Code/Flag table entries.
#define MAX_MEANING_LEN
Maximum length of a meaning string for a Code/Flag table entry.
int cmpstia1(const void *pe1, const void *pe2)
Define a comparison between two master Code/Flag table entries.
void inittbf(void)
Initialize memory for internal storage of master Code/Flag table entries.
void srchtbf(int ifxyi, int ivali, int *ifxyd, int mxfxyd, int ivald, char *meaning, int mxmng, int *lnmng, int *iret)
Search for a specified master Code/Flag table entry.
struct code_flag_entry * cfe
Master Code/Flag table entries.
int mxmtbf
Maximum number of master Code/Flag table entries, counting across all individual Code/Flag tables,...
void strtbfe(int ifxyn, int ival, char *meaning, int lmeaning, int idfxy, int idval)
Store a new master Code/Flag table entry.
int nmtf
Number of stored master Code/Flag table entries in cfe, up to a maximum of MXMTBF.
void sorttbf(void)
Sort entries within the master Code/Flag table.
integer(8), dimension(:), allocatable ival
BUFR data subset values.