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);
107 stseq(
int lun,
int *irepct,
int idn,
char *nemo,
108 char *cseq,
int *cdesc,
int ncdesc)
110 int i, j, nb, nd, ix, iy, iret, nbits;
111 int rpidn, pkint, ilen, imxcd, imxnf, ipt, *rpdesc;
114 char nemo2[
NEMO_STR_LEN+1], rpseq[56], card[80], ctmp[4], cblk =
' ', czero =
'0';
127 if ( ( iret > 0 ) && ( tab ==
'D' ) )
return;
143 for ( i = 0; i < ncdesc; i++ ) {
145 strncpy(ctmp, &adn[1], 2); ctmp[2] =
'\0';
147 strncpy(ctmp, &adn[3], 4);
149 if ( adn[0] ==
'3' ) {
155 nummtb(&cdesc[i], &tab, &ipt);
165 sprintf(rpseq,
"REPLICATION SEQUENCE %.3d", ++(*irepct));
166 memset(&rpseq[24], (
int) cblk, 31);
167 sprintf(nemo2,
"RPSEQ%.3d", *irepct);
169 stseq(lun, irepct, rpidn, nemo2, rpseq,
186 else if ( adn[0] ==
'2' ) {
190 if ( ( ( ix >= 4 ) && ( ix <= 6 ) ) || (
imrkopr_f(adn) ) ) {
196 strncpy(nemo2, adn, 6);
197 memset(&nemo2[6], (
int) cblk, 2);
200 if ( ( ix == 4 ) && ( iy == 0 ) ) {
205 sprintf(errstr,
"BUFRLIB: STSEQ - TOO MANY ASSOCIATED"
206 " FIELD CANCELLATION OPERATORS");
215 nemtab_f(lun, nemo2, &pkint, &tab, &iret);
216 if ( ( iret == 0 ) || ( tab !=
'B' ) ) {
224 sprintf(rpseq,
"Associated field of %3d bits", iy);
226 strcpy(units,
"NUMERIC");
228 else if ( ix == 5 ) {
229 sprintf(rpseq,
"Text string of %3d bytes", iy);
231 strcpy(units,
"CCITT IA5");
233 else if ( ix == 6 ) {
234 sprintf(rpseq,
"Local descriptor of %3d bits", iy);
237 strcpy(units,
"CCITT IA5");
240 strcpy(units,
"NUMERIC");
245 sprintf(rpseq,
"Substituted value");
247 else if ( ix == 24 ) {
248 sprintf(rpseq,
"First-order statistical value");
250 else if ( ix == 25 ) {
251 sprintf(rpseq,
"Difference statistical value");
253 else if ( ix == 32 ) {
254 sprintf(rpseq,
"Replaced/retained value");
258 strcpy(units,
"NUMERIC");
260 ilen = ( int ) strlen(rpseq);
261 memset(&rpseq[ilen], (
int) cblk, 55 - ilen);
270 stntbi_f(nb, lun, adn2, nemo2, rpseq);
273 memset(card, (
int) cblk,
sizeof( card ));
275 strncpy(&card[2], nemo2, 8);
276 memcpy(&card[16], &czero, 1);
277 memcpy(&card[30], &czero, 1);
278 sprintf(&card[33],
"%4d", nbits);
279 strcpy(&card[40], units);
280 card[40+strlen(units)] = cblk;
287 if ( naf >= imxnf ) {
288 sprintf(errstr,
"BUFRLIB: STSEQ - TOO MANY ASSOCIATED"
289 " FIELDS ARE IN EFFECT AT THE SAME TIME");
292 iafpk[naf++] = pkint;
299 if ( ++i >= ncdesc ) {
300 sprintf(errstr,
"BUFRLIB: STSEQ - COULD NOT FIND LOCAL"
301 " DESCRIPTOR PLACEHOLDER FOR %s", adn);
310 else if ( adn[0] ==
'1' ) {
322 if ( ( i+1 ) >= ncdesc ) {
323 sprintf(errstr,
"BUFRLIB: STSEQ - COULD NOT FIND DELAYED "
324 "DESCRIPTOR REPLICATION FACTOR FOR %s", adn);
327 else if ( cdesc[i+1] ==
ifxy_f(
"031002") ) {
330 else if ( cdesc[i+1] ==
ifxy_f(
"031001") ) {
333 else if ( cdesc[i+1] ==
ifxy_f(
"031000") ) {
337 sprintf(errstr,
"BUFRLIB: STSEQ - UNKNOWN DELAYED "
338 "DESCRIPTOR REPLICATION FACTOR FOR %s", adn);
351 pktdd_f(nd, lun, pkint, &iret);
353 strncpy(nemo2, nemo, 8);
355 sprintf(errstr,
"BUFRLIB: STSEQ - BAD RETURN FROM PKTDD WHEN "
356 "STORING REPLICATOR FOR PARENT MNEMONIC %s", nemo2);
363 if ( ix > ( ncdesc - i ) ) {
364 sprintf(errstr,
"BUFRLIB: STSEQ - NOT ENOUGH REMAINING CHILD "
365 "DESCRIPTORS TO COMPLETE REPLICATION FOR %s", adn);
374 nummtb(&cdesc[i], &tab, &ipt);
388 if ( ( rpdesc = malloc( imxcd *
sizeof(
int) ) ) == NULL ) {
389 sprintf(errstr,
"BUFRLIB: STSEQ - UNABLE TO ALLOCATE SPACE"
394 for ( j = 0; j < ix; j++ ) {
395 rpdesc[j] = cdesc[i+j];
400 sprintf(rpseq,
"REPLICATION SEQUENCE %.3d", ++(*irepct));
401 memset(&rpseq[24], (
int) cblk, 31);
402 sprintf(nemo2,
"RPSEQ%.3d", *irepct);
404 stseq(lun, irepct, rpidn, nemo2, rpseq, rpdesc, ix);
419 if ( ( iret == 0 ) || ( tab !=
'B' ) ) {
423 nummtb(&cdesc[i], &tab, &ipt);
432 memset(card, (
int) cblk,
sizeof( card ));
434 strncpy(&card[2], &
cbmnem_c[ipt][0], 8);
435 strncpy(&card[13], &
cbscl_c[ipt][0], 4);
436 strncpy(&card[19], &
cbsref_c[ipt][0], 12);
437 strncpy(&card[33], &
cbbw_c[ipt][0], 4);
438 strncpy(&card[40], &
cbunit_c[ipt][0], 24);
443 if (strncmp( adn,
"204", 3) != 0 ) {
453 ( ( pkint <
ifxy_f(
"031000") ) ||
454 ( pkint >
ifxy_f(
"031255") ) ) ) {
455 for ( j = 0; j < naf; j++ ) {
458 sprintf(errstr,
"BUFRLIB: STSEQ - BAD RETURN FROM PKTDD "
459 "WHEN STORING ASSOCIATED FIELDS");
467 pktdd_f(nd, lun, pkint, &iret);
469 strncpy(nemo2, nemo, 8);
471 sprintf(errstr,
"BUFRLIB: STSEQ - BAD RETURN FROM PKTDD WHEN "
472 "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.
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.
int icvidx(int ii, int jj, int numjj)
Computes a unique 1-dimensional array index from 2-dimensional indices.
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.
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.
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.