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);
98 strrpsq(
int rpidn,
int maxnf,
int naf,
int *
iafpk,
int maxcd,
int ncdesc,
int *cdesc)
105 for ( j = 0; j < naf; j++ ) {
109 for ( j = 0; j < ncdesc; j++ ) {
143 for ( i = 0; i <
nrpsq; i++ ) {
146 for ( j = 0; j < naf; j++ ) {
151 for ( j = 0; j < ncdesc; j++ ) {
189 stseq(
int lun,
int *irepct,
int idn,
char *nemo,
char *cseq,
int *cdesc,
int ncdesc)
191 int i, j, nb, nd, ix, iy, iret, nbits;
192 int rpidn, pkint, ilen, ipt, *rpdesc;
195 char nemo2[
NEMO_STR_LEN+1], rpseq[56], card[80], ctmp[4], cblk =
' ', czero =
'0';
207 static int imxcd, imxnf;
214 if ( ( iret > 0 ) && ( tab ==
'D' ) )
return;
216 if ( *irepct == 0 ) {
236 for ( i = 0; i < ncdesc; i++ ) {
238 strncpy(ctmp, &adn[1], 2); ctmp[2] =
'\0';
240 strncpy(ctmp, &adn[3], 4);
242 if ( adn[0] ==
'3' ) {
248 nummtb(&cdesc[i], &tab, &ipt);
266 sprintf(rpseq,
"REPLICATION SEQUENCE %.3d", ++(*irepct));
267 memset(&rpseq[24], (
int) cblk, 31);
268 sprintf(nemo2,
"RPSEQ%.3d", *irepct);
270 stseq(lun, irepct, rpidn, nemo2, rpseq,
287 else if ( adn[0] ==
'2' ) {
291 if ( ( ( ix >= 4 ) && ( ix <= 6 ) ) || (
imrkopr_f(adn) ) ) {
297 strncpy(nemo2, adn, 6);
298 memset(&nemo2[6], (
int) cblk, 2);
301 if ( ( ix == 4 ) && ( iy == 0 ) ) {
306 sprintf(errstr,
"BUFRLIB: STSEQ - TOO MANY ASSOCIATED"
307 " FIELD CANCELLATION OPERATORS");
316 nemtab_f(lun, nemo2, &pkint, &tab, &iret);
317 if ( ( iret == 0 ) || ( tab !=
'B' ) ) {
325 sprintf(rpseq,
"Associated field of %3d bits", iy);
327 strcpy(units,
"NUMERIC");
329 else if ( ix == 5 ) {
330 sprintf(rpseq,
"Text string of %3d bytes", iy);
332 strcpy(units,
"CCITT IA5");
334 else if ( ix == 6 ) {
335 sprintf(rpseq,
"Local descriptor of %3d bits", iy);
338 strcpy(units,
"CCITT IA5");
341 strcpy(units,
"NUMERIC");
346 sprintf(rpseq,
"Substituted value");
348 else if ( ix == 24 ) {
349 sprintf(rpseq,
"First-order statistical value");
351 else if ( ix == 25 ) {
352 sprintf(rpseq,
"Difference statistical value");
354 else if ( ix == 32 ) {
355 sprintf(rpseq,
"Replaced/retained value");
359 strcpy(units,
"NUMERIC");
361 ilen = ( int ) strlen(rpseq);
362 memset(&rpseq[ilen], (
int) cblk, 55 - ilen);
371 stntbi_f(nb, lun, adn2, nemo2, rpseq);
374 memset(card, (
int) cblk,
sizeof( card ));
376 strncpy(&card[2], nemo2, 8);
377 memcpy(&card[16], &czero, 1);
378 memcpy(&card[30], &czero, 1);
379 sprintf(&card[33],
"%4d", nbits);
380 strcpy(&card[40], units);
381 card[40+strlen(units)] = cblk;
388 if ( naf >= imxnf ) {
389 sprintf(errstr,
"BUFRLIB: STSEQ - TOO MANY ASSOCIATED"
390 " FIELDS ARE IN EFFECT AT THE SAME TIME");
393 iafpk[naf++] = pkint;
400 if ( ++i >= ncdesc ) {
401 sprintf(errstr,
"BUFRLIB: STSEQ - COULD NOT FIND LOCAL"
402 " DESCRIPTOR PLACEHOLDER FOR %s", adn);
411 else if ( adn[0] ==
'1' ) {
423 if ( ( i+1 ) >= ncdesc ) {
424 sprintf(errstr,
"BUFRLIB: STSEQ - COULD NOT FIND DELAYED "
425 "DESCRIPTOR REPLICATION FACTOR FOR %s", adn);
438 sprintf(errstr,
"BUFRLIB: STSEQ - UNKNOWN DELAYED "
439 "DESCRIPTOR REPLICATION FACTOR FOR %s", adn);
452 pktdd_f(nd, lun, pkint, &iret);
454 strncpy(nemo2, nemo, 8);
456 sprintf(errstr,
"BUFRLIB: STSEQ - BAD RETURN FROM PKTDD WHEN "
457 "STORING REPLICATOR FOR PARENT MNEMONIC %s", nemo2);
464 if ( ix > ( ncdesc - i ) ) {
465 sprintf(errstr,
"BUFRLIB: STSEQ - NOT ENOUGH REMAINING CHILD "
466 "DESCRIPTORS TO COMPLETE REPLICATION FOR %s", adn);
475 nummtb(&cdesc[i], &tab, &ipt);
486 if ( ( rpdesc = malloc( imxcd *
sizeof(
int) ) ) == NULL ) {
487 sprintf(errstr,
"BUFRLIB: STSEQ - UNABLE TO ALLOCATE SPACE"
491 for ( j = 0; j < ix; j++ ) {
492 rpdesc[j] = cdesc[i+j];
498 if ( ( rpidn =
srchrpsq(imxnf, naf,
iafpk, imxcd, ix, rpdesc) ) == -1 ) {
506 sprintf(rpseq,
"REPLICATION SEQUENCE %.3d", ++(*irepct));
507 memset(&rpseq[24], (
int) cblk, 31);
508 sprintf(nemo2,
"RPSEQ%.3d", *irepct);
510 stseq(lun, irepct, rpidn, nemo2, rpseq, rpdesc, ix);
526 if ( ( iret == 0 ) || ( tab !=
'B' ) ) {
530 nummtb(&cdesc[i], &tab, &ipt);
539 memset(card, (
int) cblk,
sizeof( card ));
541 strncpy(&card[2], &
cbmnem_c[ipt][0], 8);
542 strncpy(&card[13], &
cbscl_c[ipt][0], 4);
543 strncpy(&card[19], &
cbsref_c[ipt][0], 12);
544 strncpy(&card[33], &
cbbw_c[ipt][0], 4);
545 strncpy(&card[40], &
cbunit_c[ipt][0], 24);
550 if ( strncmp( adn,
"204", 3 ) != 0 ) {
561 ( pkint >
ifxy_f(
"031255") ) ) ) {
562 for ( j = 0; j < naf; j++ ) {
565 sprintf(errstr,
"BUFRLIB: STSEQ - BAD RETURN FROM PKTDD "
566 "WHEN STORING ASSOCIATED FIELDS");
574 pktdd_f(nd, lun, pkint, &iret);
576 strncpy(nemo2, nemo, 8);
578 sprintf(errstr,
"BUFRLIB: STSEQ - BAD RETURN FROM PKTDD WHEN "
579 "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_DRF8
Character string containing FXY value for medium (8-bit) delayed replication factor.
#define FXY_DRF1
Character string containing FXY value for short (1-bit) delayed replication factor.
#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.
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.
#define FXY_MINR
Character string containing minimum FXY value for a replication descriptor.
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 FXY_DRP1
Character string containing FXY value for NCEP Table D local descriptor denoting 1-bit delayed replic...
int ifxy_f(char *cfxy)
Convert an FXY value from its 6 character representation to its WMO bit-wise representation.
#define FXY_DRP8
Character string containing FXY value for NCEP Table D local descriptor denoting 8-bit delayed replic...
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.
void pktdd_f(int id, int lun, int idn, int *iret)
Store information about a child mnemonic within the internal arrays.
#define FXY_DRP16
Character string containing FXY value for NCEP Table D local descriptor denoting 16-bit delayed repli...
int igetntbi_f(int lun, char *table_type)
Get the next index for storing an entry within an internal DX BUFR table.
#define FXY_DRF16
Character string containing FXY value for long (16-bit) delayed replication factor.
#define FXY_MAXTB
Character string containing maximum FXY value for a Table B descriptor.
#define FXY_MINTD
Character string containing minimum FXY value for a Table D descriptor.
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.
int * idefxy_c
WMO bit-wise representations of child descriptors for master Table D sequences; copied from Fortran i...
char(* cbsref_c)[12]
Master Table B reference values; copied from Fortran cbsref array.
char(* cbelem_c)[120]
Master Table B element names; copied from Fortran cbelem array.
int * idfxyn_c
WMO 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(* cdseq_c)[120]
Master Table D sequence names; copied from Fortran cdseq array.
char(* cbscl_c)[4]
Master Table B scale factors; copied from Fortran cbscl array.
char(* cbunit_c)[24]
Master Table B units; copied from Fortran cbunit array.
char(* cbmnem_c)[8]
Master Table B mnemonics; copied from Fortran cbmnem array.
char(* cbbw_c)[4]
Master Table B bit widths; copied from Fortran cbbw array.
int nmtd_c
Number of master Table D entries; copied from Fortran nmtd variable.
int * iafpk
WMO bit-wise representations of associated fields within master Table D sequences.
int * ibfxyn_c
WMO 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.
int * ndelem_c
Number of child descriptors for master Table D sequences; copied from Fortran ndelem array.
Declare variables for internal storage of replication sequences.
int nrpsq
Number of entries in internal replication sequences cache.
int * cdescs
Child descriptors for each entry.
int ncdescs[MAX_RPSQ]
Number of child descriptors for each entry.
#define MAX_RPSQ
Maximum number of entries in internal replication sequences cache.
int * iafpks
Associated fields in effect for each entry.
int rpidns[MAX_RPSQ]
WMO bit-wise representation of FXY number for each entry.
int nafs[MAX_RPSQ]
Number of associated fields in effect for each entry.
void strrpsq(int rpidn, int maxnf, int naf, int *iafpk, int maxcd, int ncdesc, int *cdesc)
Store a new entry in the internal replication sequences cache.
int srchrpsq(int maxnf, int naf, int *iafpk, int maxcd, int ncdesc, int *cdesc)
Check whether a replication sequence already exists within the internal cache.
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 Table D descriptor within internal DX BUFR tables.
int cmpia(const void *pf1, const void *pf2)
Define a comparison between two integers.