11 #define MAX_MEANING_LEN 150
16 struct code_flag_entry {
34 struct code_flag_entry *
cfe;
55 char brtstr[50] =
"BUFRLIB: INITTBF FAILED ALLOCATING CFE";
65 if ( (
cfe = malloc(
mxmtbf *
sizeof(
struct code_flag_entry)) ) == NULL ) {
109 struct code_flag_entry *mype1 = (
struct code_flag_entry * ) pe1;
110 struct code_flag_entry *mype2 = (
struct code_flag_entry * ) pe2;
112 if ( mype1->iffxyn == mype2->iffxyn ) {
113 if ( mype1->ifval == mype2->ifval ) {
114 if ( mype1->iffxynd == mype2->iffxynd ) {
115 if ( mype1->ifvald == mype2->ifvald )
return 0;
116 return ( mype1->ifvald < mype2->ifvald ? -1 : 1 );
119 return ( mype1->iffxynd < mype2->iffxynd ? -1 : 1 );
123 return ( mype1->ifval < mype2->ifval ? -1 : 1 );
127 return ( mype1->iffxyn < mype2->iffxyn ? -1 : 1 );
152 struct code_flag_entry *mype1 = (
struct code_flag_entry * ) pe1;
153 struct code_flag_entry *mype2 = (
struct code_flag_entry * ) pe2;
155 if ( mype1->iffxyn == mype2->iffxyn ) {
156 if ( mype1->ifval == mype2->ifval )
return 0;
157 return ( mype1->ifval < mype2->ifval ? -1 : 1 );
160 return ( mype1->iffxyn < mype2->iffxyn ? -1 : 1 );
180 strtbfe(
int ifxyn,
int ival,
char *meaning,
int lmeaning,
int idfxy,
int idval)
184 static char brtstr[50] =
"BUFRLIB: STRTBFE - MXMTBF OVERFLOW";
197 strncpy(&
cfe[
nmtf].ifmeaning[0], meaning, mnlen);
198 cfe[
nmtf].ifmeaning[mnlen] =
'\0';
213 qsort(&
cfe[0], (
size_t)
nmtf,
sizeof(
struct code_flag_entry),
214 (
int (*) (
const void *,
const void *))
cmpstia1);
264 srchtbf(
int ifxyi,
int ivali,
int *ifxyd,
int mxfxyd,
int ivald,
265 char *meaning,
int mxmng,
int *lnmng,
int *iret)
267 struct code_flag_entry key, *pkey, *pcfe, *pbs;
278 key.iffxynd = ifxyd[0];
287 pbs = (
struct code_flag_entry *) bsearch(pkey, pcfe, (
size_t)
nmtf,
288 sizeof(
struct code_flag_entry),
289 (int (*) (
const void *,
const void *))
cmpstia1);
296 slmng = strlen(
cfe[ipt].ifmeaning);
297 *lnmng = ( mxmng > slmng ? slmng : mxmng );
298 strncpy(meaning, &
cfe[ipt].ifmeaning[0], *lnmng);
306 if ( key.iffxynd != -1 ) {
317 pbs = (
struct code_flag_entry *) bsearch(pkey, pcfe, (
size_t)
nmtf,
318 sizeof(
struct code_flag_entry),
319 (int (*) (
const void *,
const void *))
cmpstia2);
334 ifxyd[(*iret)++] =
cfe[ipt].iffxynd;
344 while ( ( ii >= 0 ) &&
345 ( *iret < mxfxyd ) &&
346 (
cfe[ii].iffxyn == key.iffxyn ) &&
347 (
cfe[ii].ifval == key.ifval ) ) {
348 if (
cfe[ii].iffxynd < ifxyd[(*iret)-1] )
349 ifxyd[(*iret)++] =
cfe[ii].iffxynd;
353 while ( ( ii <
nmtf ) &&
354 ( *iret < mxfxyd ) &&
355 (
cfe[ii].iffxyn == key.iffxyn ) &&
356 (
cfe[ii].ifval == key.ifval ) ) {
357 if ( (
cfe[ii].iffxynd > ifxyd[(*iret)-1] ) &&
358 (
cfe[ii].iffxynd >
cfe[ipt].iffxynd ) )
359 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, including dynamically alloc...
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, in preparation for future searches using function src...
integer *8, dimension(:), allocatable ival
BUFR data subset values.