NCEPLIBS-bufr  12.0.0
cfe.c File Reference

C language interface for processing master Code/Flag table entries. More...

#include "bufrlib.h"

Go to the source code of this file.

Macros

#define MAX_MEANING_LEN   150
 Maximum length of a meaning string for a Code/Flag table entry. More...
 

Functions

int cmpstia1 (const void *pe1, const void *pe2)
 Define a comparison between two master Code/Flag table entries. More...
 
int cmpstia2 (const void *pe1, const void *pe2)
 Define a comparison between two master Code/Flag table entries. More...
 
void dlloctbf (void)
 Free all dynamically-allocated memory for internal storage of master Code/Flag table entries. More...
 
void inittbf (void)
 Initialize memory for internal storage of master Code/Flag table entries. More...
 
void sorttbf (void)
 Sort entries within the master Code/Flag table. More...
 
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. More...
 
void strtbfe (int ifxyn, int ival, char *meaning, int lmeaning, int idfxy, int idval)
 Store a new master Code/Flag table entry. More...
 

Variables

struct code_flag_entry * cfe
 Master Code/Flag table entries. More...
 
int mxmtbf
 Maximum number of master Code/Flag table entries, counting across all individual Code/Flag tables, and counting each defined code figure (within each individual Code table) or defined bit number (within each individual Flag table) as a separate entry. More...
 
int nmtf
 Number of stored master Code/Flag table entries in cfe, up to a maximum of MXMTBF. More...
 

Detailed Description

C language interface for processing master Code/Flag table entries.

Author
J. Ator
Date
2017-11-16

Definition in file cfe.c.

Macro Definition Documentation

◆ MAX_MEANING_LEN

#define MAX_MEANING_LEN   150

Maximum length of a meaning string for a Code/Flag table entry.

Definition at line 11 of file cfe.c.

Function Documentation

◆ cmpstia1()

int cmpstia1 ( const void *  pe1,
const void *  pe2 
)

Define a comparison between two master Code/Flag table entries.

This function defines a comparison between two entries within the internal memory structure for storage of master Code/Flag table entries. The comparison is used by the intrinsic C functions qsort and bsearch, and it differs from the the comparison in function cmpstia2() because it compares all of the iffxyn, ifval, iffxynd and ifvald components of the structure, whereas cmpstia2() only compares the iffxyn and ifval components.

Parameters
pe1- First master Code/Flag table entry.
pe2- Second master Code/Flag table entry.
Returns
cmpstia1:
  • -1 = pe1 is less than pe2
  • 0 = pe1 is equal to pe2
  • 1 = pe1 is greater than pe2
Author
J. Ator
Date
2017-11-13

Definition at line 113 of file cfe.c.

Referenced by sorttbf(), and srchtbf().

◆ cmpstia2()

int cmpstia2 ( const void *  pe1,
const void *  pe2 
)

Define a comparison between two master Code/Flag table entries.

This function defines a comparison between two entries within the internal memory structure for storage of master Code/Flag table entries. The comparison is used by the intrinsic C function bsearch, and it differs from the the comparison in function cmpstia1() because it only compares the iffxyn and ifval components of the structure, whereas cmpstia1() compares all of the iffxyn, ifval, iffxynd and ifvald components of the structure.

Parameters
pe1- First master Code/Flag table entry.
pe2- Second master Code/Flag table entry.
Returns
cmpstia2:
  • -1 = pe1 is less than pe2
  • 0 = pe1 is equal to pe2
  • 1 = pe1 is greater than pe2
Author
J. Ator
Date
2017-11-13

Definition at line 158 of file cfe.c.

Referenced by srchtbf().

◆ dlloctbf()

void dlloctbf ( void  )

Free all dynamically-allocated memory for internal storage of master Code/Flag table entries.

This function frees any memory that was dynamically allocated during a previous call to function inittbf().

Author
J. Ator
Date
2017-11-03

Definition at line 85 of file cfe.c.

References cfe.

◆ inittbf()

void inittbf ( void  )

Initialize memory for internal storage of master Code/Flag table entries.

This function initializes the internal memory structure for storage of master Code/Flag table entries, including dynamically allocating space for this structure if needed.

Author
J. Ator
Date
2017-11-03

Definition at line 56 of file cfe.c.

References bort_f(), cfe, igetprm_f(), mxmtbf, and nmtf.

◆ sorttbf()

void sorttbf ( void  )

Sort entries within the master Code/Flag table.

This function sorts the entries within the internal memory structure for storage of master Code/Flag table entries, in preparation for future searches using function srchtbf().

Author
J. Ator
Date
2017-11-16

Definition at line 225 of file cfe.c.

References cfe, cmpstia1(), and nmtf.

◆ srchtbf()

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.

This function searches for a specified FXY number and associated value (code figure or bit number) within the internal memory structure for storage of master Code/Flag table entries, and if found returns the associated meaning as a character string.

The search may optionally include a specified second FXY number and associated value upon which the first FXY number and its associated value depend, for example when the meaning of an originating sub-center value depends on the identity of the originating center for which the sub-center in question is a member.

Parameters
ifxyi- Bit-wise representation of FXY number to search for.
ivali- Value (code figure or bit number) associated with ifxyi.
ifxyd- Dependence indicator:
  • On input, ifxyd[0] is set to the bit-wise representation of the FXY number upon which ifxyi and ivali depend, or else set to (-1) if ifxyi and ivali do not depend on the value associated with any other FXY number.
  • On output, if the initial search of the master Code/Flag table was unsuccessful, and if ifxyd[0] and ivald were both set to (-1) on input, and if a second search of the table determines that the meaning of ifxyi and ivali indeed depends on one or more other FXY numbers, then the bit-wise representations of those FXY numbers are returned within the first iret elements of ifxyd.
ivald- Value (code figure or bit number) associated with the FXY number in ifxyd[0]; set to (-1) whenever ifxyd[0] is also set to (-1).
mxfxyd- Number of elements in ifxyd array; used by the function to ensure that it doesn't overflow the array.
mxmng- Number of elements in meaning array; used by the function to ensure that it doesn't overflow the string.
meaning- Meaning corresponding to ifxyi and ivali (and to ifxyd[0] and ivald, if specified on input).
lnmng- Length (in bytes) of string returned in CMEANG.
iret- Return code:
  • 0 = Meaning found and stored in meaning string.
  • -1 = Meaning not found.
  • >0 = Meaning not found, and ifxyd[0] and ivald were both set to (-1) on input, and the meaning of ifxyi and ivali depends on the the value associated with one of the FXY numbers whose bit-wise representation is stored in the first iret elements of ifxyd.
Author
J. Ator
Date
2018-01-11

Definition at line 278 of file cfe.c.

References cfe, cmpstia1(), cmpstia2(), and nmtf.

◆ strtbfe()

void strtbfe ( int  ifxyn,
int  ival,
char *  meaning,
int  lmeaning,
int  idfxy,
int  idval 
)

Store a new master Code/Flag table entry.

This function adds a new entry to the internal memory structure for storage of master Code/Flag table entries.

Parameters
ifxyn- Bit-wise representation of FXY number for which ival is a defined code or flag table entry.
ival- Code figure or bit number.
meaning- Meaning associated with ifxyn and ival.
lmeaning- Length (in bytes) of meaning.
idfxy- Bit-wise representation of FXY number upon which ifxyn and ival depend (if any), or else set to a value of (-1).
idval- Code figure or bit number associated with idfxy and upon which ifxyn and ival depend (if any), or else set to (-1) whenever idfxy is also set to (-1).
Author
J. Ator
Date
2017-11-13

Definition at line 191 of file cfe.c.

References bort_f(), cfe, moda_ival::ival, MAX_MEANING_LEN, mxmtbf, and nmtf.

Variable Documentation

◆ cfe

struct code_flag_entry* cfe

Master Code/Flag table entries.

Definition at line 34 of file cfe.c.

Referenced by dlloctbf(), inittbf(), sorttbf(), srchtbf(), and strtbfe().

◆ mxmtbf

int mxmtbf

Maximum number of master Code/Flag table entries, counting across all individual Code/Flag tables, and counting each defined code figure (within each individual Code table) or defined bit number (within each individual Flag table) as a separate entry.

Definition at line 41 of file cfe.c.

Referenced by inittbf(), and strtbfe().

◆ nmtf

int nmtf

Number of stored master Code/Flag table entries in cfe, up to a maximum of MXMTBF.

Definition at line 44 of file cfe.c.

Referenced by inittbf(), sorttbf(), srchtbf(), and strtbfe().