28 cmpia(
const void *pf1,
const void *pf2)
30 int *mypf1 = (
int * ) pf1;
31 int *mypf2 = (
int * ) pf2;
33 if ( *mypf1 == *mypf2 )
return 0;
35 return ( *mypf1 < *mypf2 ? -1 : 1 );
54 nummtb(
int *idn,
char *tab,
int *ipt)
56 int *pifxyn, *pbs, nmt;
71 pbs = bsearch(idn, pifxyn, (
size_t) nmt,
sizeof(
int),
72 (
int (*) (
const void *,
const void *))
cmpia);
75 sprintf(errstr,
"BUFRLIB: NUMMTB - COULD NOT FIND DESCRIPTOR "
76 "%s IN MASTER TABLE %c", adn, *tab);
111 stseq(
int lun,
int *irepct,
int idn,
char *nemo,
112 char *cseq,
int *cdesc,
int ncdesc)
114 int i, j, nb, nd, ix, iy, iret, nbits;
115 int rpidn, pkint, ilen, imxcd, ipt, *rpdesc;
118 char nemo2[
NEMO_STR_LEN+1], rpseq[56], card[80], ctmp[4], cblk =
' ', czero =
'0';
125 static int naf, iafpk[
MXNAF];
132 if ( ( iret > 0 ) && ( tab ==
'D' ) )
return;
147 for ( i = 0; i < ncdesc; i++ ) {
149 strncpy(ctmp, &adn[1], 2); ctmp[2] =
'\0';
151 strncpy(ctmp, &adn[3], 4);
153 if ( adn[0] ==
'3' ) {
159 nummtb(&cdesc[i], &tab, &ipt);
169 sprintf(rpseq,
"REPLICATION SEQUENCE %.3d", ++(*irepct));
170 memset(&rpseq[24], (
int) cblk, 31);
171 sprintf(nemo2,
"RPSEQ%.3d", *irepct);
173 stseq(lun, irepct, rpidn, nemo2, rpseq,
190 else if ( adn[0] ==
'2' ) {
194 if ( ( ( ix >= 4 ) && ( ix <= 6 ) ) || (
imrkopr_f(adn) ) ) {
200 strncpy(nemo2, adn, 6);
201 memset(&nemo2[6], (
int) cblk, 2);
204 if ( ( ix == 4 ) && ( iy == 0 ) ) {
209 sprintf(errstr,
"BUFRLIB: STSEQ - TOO MANY ASSOCIATED"
210 " FIELD CANCELLATION OPERATORS");
219 nemtab_f(lun, nemo2, &pkint, &tab, &iret);
220 if ( ( iret == 0 ) || ( tab !=
'B' ) ) {
228 sprintf(rpseq,
"Associated field of %3d bits", iy);
230 strcpy(units,
"NUMERIC");
232 else if ( ix == 5 ) {
233 sprintf(rpseq,
"Text string of %3d bytes", iy);
235 strcpy(units,
"CCITT IA5");
237 else if ( ix == 6 ) {
238 sprintf(rpseq,
"Local descriptor of %3d bits", iy);
241 strcpy(units,
"CCITT IA5");
244 strcpy(units,
"NUMERIC");
249 sprintf(rpseq,
"Substituted value");
251 else if ( ix == 24 ) {
252 sprintf(rpseq,
"First-order statistical value");
254 else if ( ix == 25 ) {
255 sprintf(rpseq,
"Difference statistical value");
257 else if ( ix == 32 ) {
258 sprintf(rpseq,
"Replaced/retained value");
262 strcpy(units,
"NUMERIC");
264 ilen = ( int ) strlen(rpseq);
265 memset(&rpseq[ilen], (
int) cblk, 55 - ilen);
274 stntbi_f(nb, lun, adn2, nemo2, rpseq);
277 memset(card, (
int) cblk,
sizeof( card ));
279 strncpy(&card[2], nemo2, 8);
280 memcpy(&card[16], &czero, 1);
281 memcpy(&card[30], &czero, 1);
282 sprintf(&card[33],
"%4d", nbits);
283 strcpy(&card[40], units);
284 card[40+strlen(units)] = cblk;
291 if ( naf >=
MXNAF ) {
292 sprintf(errstr,
"BUFRLIB: STSEQ - TOO MANY ASSOCIATED"
293 " FIELDS ARE IN EFFECT AT THE SAME TIME");
296 iafpk[naf++] = pkint;
303 if ( ++i >= ncdesc ) {
304 sprintf(errstr,
"BUFRLIB: STSEQ - COULD NOT FIND LOCAL"
305 " DESCRIPTOR PLACEHOLDER FOR %s", adn);
314 else if ( adn[0] ==
'1' ) {
326 if ( ( i+1 ) >= ncdesc ) {
327 sprintf(errstr,
"BUFRLIB: STSEQ - COULD NOT FIND DELAYED "
328 "DESCRIPTOR REPLICATION FACTOR FOR %s", adn);
331 else if ( cdesc[i+1] ==
ifxy_f(
"031002") ) {
334 else if ( cdesc[i+1] ==
ifxy_f(
"031001") ) {
337 else if ( cdesc[i+1] ==
ifxy_f(
"031000") ) {
341 sprintf(errstr,
"BUFRLIB: STSEQ - UNKNOWN DELAYED "
342 "DESCRIPTOR REPLICATION FACTOR FOR %s", adn);
355 pktdd_f(nd, lun, pkint, &iret);
357 strncpy(nemo2, nemo, 8);
359 sprintf(errstr,
"BUFRLIB: STSEQ - BAD RETURN FROM PKTDD WHEN "
360 "STORING REPLICATOR FOR PARENT MNEMONIC %s", nemo2);
367 if ( ix > ( ncdesc - i ) ) {
368 sprintf(errstr,
"BUFRLIB: STSEQ - NOT ENOUGH REMAINING CHILD "
369 "DESCRIPTORS TO COMPLETE REPLICATION FOR %s", adn);
378 nummtb(&cdesc[i], &tab, &ipt);
392 if ( ( rpdesc = malloc( imxcd *
sizeof(
int) ) ) == NULL ) {
393 sprintf(errstr,
"BUFRLIB: STSEQ - UNABLE TO ALLOCATE SPACE"
398 for ( j = 0; j < ix; j++ ) {
399 rpdesc[j] = cdesc[i+j];
404 sprintf(rpseq,
"REPLICATION SEQUENCE %.3d", ++(*irepct));
405 memset(&rpseq[24], (
int) cblk, 31);
406 sprintf(nemo2,
"RPSEQ%.3d", *irepct);
408 stseq(lun, irepct, rpidn, nemo2, rpseq, rpdesc, ix);
423 if ( ( iret == 0 ) || ( tab !=
'B' ) ) {
427 nummtb(&cdesc[i], &tab, &ipt);
436 memset(card, (
int) cblk,
sizeof( card ));
438 strncpy(&card[2], &
cbmnem_c[ipt][0], 8);
439 strncpy(&card[13], &
cbscl_c[ipt][0], 4);
440 strncpy(&card[19], &
cbsref_c[ipt][0], 12);
441 strncpy(&card[33], &
cbbw_c[ipt][0], 4);
442 strncpy(&card[40], &
cbunit_c[ipt][0], 24);
447 if (strncmp( adn,
"204", 3) != 0 ) {
457 ( ( pkint <
ifxy_f(
"031000") ) ||
458 ( pkint >
ifxy_f(
"031255") ) ) ) {
459 for ( j = 0; j < naf; j++ ) {
460 pktdd_f(nd, lun, iafpk[j], &iret);
462 sprintf(errstr,
"BUFRLIB: STSEQ - BAD RETURN FROM PKTDD "
463 "WHEN STORING ASSOCIATED FIELDS");
471 pktdd_f(nd, lun, pkint, &iret);
473 strncpy(nemo2, nemo, 8);
475 sprintf(errstr,
"BUFRLIB: STSEQ - BAD RETURN FROM PKTDD WHEN "
476 "STORING CHILD FOR PARENT MNEMONIC %s", nemo2);
int igetprm_f(char *cprmnm)
Get the current value of a parameter.
void nemtab_f(int lun, const char *mnemonic, int *descriptor, char *table_type, int *table_idx)
Get information about a descriptor.
Enable a number of NCEPLIBS-bufr subprograms to be called from within the C part of the library.
int igettdi_f(int iflag)
Get the next usable Table D index for the current master table, or reset the index.
void cadn30_f(int idn, char *adn, int adn_str_len)
Convert an FXY value from its WMO bit-wise representation to its six-character representation.
#define FXY_STR_LEN
Size of a character string needed to store an FXY value.
void elemdx_f(char *card, int lun)
Decode the scale factor, reference value, bit width, and units from a Table B mnemonic definition.
int imrkopr_f(char *nemo)
Check whether a specified mnemonic is a Table C marker operator.
#define MXNAF
Maximum number of associated fields that can be in effect at any given time for a Table B descriptor.
void numtbd_f(int lun, int idn, char *nemo, int nemo_str_len, char *tab, int *iret)
Search for a Table B or Table D descriptor within the internal DX BUFR tables.
void bort_f(char *errstr)
Log one error message and abort application program.
void stntbi_f(int n, int lun, char *numb, char *nemo, char *celsq)
Store a new entry within the internal BUFR Table B or D.
#define MIN_FXY_REPL
Character string containing minimum FXY value for a replication descriptor.
#define MIN_FXY_TABLED
Character string containing minimum FXY value for a Table D descriptor.
int ifxy_f(char *cfxy)
Convert an FXY value from its 6 character representation to its WMO bit-wise representation.
void strnum_f(char *str, int *num, int *iret)
Decode an integer from a character string.
#define NEMO_STR_LEN
Size of a character string needed to store a mnemonic.
#define MAX_FXY_TABLEB
Character string containing maximum FXY value for a Table B descriptor.
void pktdd_f(int id, int lun, int idn, int *iret)
Store information about a child mnemonic within the internal arrays.
int igetntbi_f(int lun, char *table_type)
Get the next index for storing an entry within an internal DX BUFR table.
int icvidx(int ii, int jj, int numjj)
Computes a unique 1-dimensional array index from 2-dimensional indices.
Declare variables for internal storage of master Table B and Table D entries.
char(* cbunit_c)[24]
Master Table B units; copied from Fortran cbunit array.
int * idfxyn_c
Bit-wise representations of master Table D FXY numbers; copied from Fortran idfxyn array.
char(* cdmnem_c)[8]
Master Table D mnemonics; copied from Fortran cdmnem array.
char(* cbelem_c)[120]
Master Table B element names; copied from Fortran cbelem array.
int * ndelem_c
Number of child descriptors for master Table D sequence; copied from Fortran ndelem array.
int nmtd_c
Number of master Table D entries; copied from Fortran nmtd variable.
int * idefxy_c
Bit-wise representations of child descriptors for master Table D sequence; copied from Fortran idefxy...
char(* cbbw_c)[4]
Master Table B bit widths; copied from Fortran cbbw array.
char(* cbsref_c)[12]
Master Table B reference value; copied from Fortran cbsref array.
char(* cdseq_c)[120]
Master Table D sequence names; copied from Fortran cdseq array.
int * ibfxyn_c
Bit-wise representations of master Table B FXY numbers; copied from Fortran ibfxyn array.
int nmtb_c
Number of master Table B entries; copied from Fortran nmtb variable.
char(* cbscl_c)[4]
Master Table B scale factors; copied from Fortran cbscl array.
char(* cbmnem_c)[8]
Master Table B mnemonics; copied from Fortran cbmnem array.
void nummtb(int *idn, char *tab, int *ipt)
Search for an entry in the BUFR master table.
void stseq(int lun, int *irepct, int idn, char *nemo, char *cseq, int *cdesc, int ncdesc)
Store information about a standard Table D descriptor within internal DX BUFR tables.
int cmpia(const void *pf1, const void *pf2)
Define a comparison between two integers.