NCEPLIBS-bufr  12.0.0
restd.c
Go to the documentation of this file.
1 
7 #include "bufrlib.h"
8 
38 void
39 restd(int lun, int tddesc, int *nctddesc, int *ctddesc)
40 {
41  int desc, ncdesc, cdesc[MAXNC];
42  int i, j, inum, itbd, ictbd;
43  int iscl, iref, ibit;
44 
45  char tab, nemo[NEMO_STR_LEN+1], adn[FXY_STR_LEN+1], cunit[UNIT_STR_LEN+1], cwork[31];
46 
47 /*
48 ** How many child descriptors does tddesc have?
49 */
50  numtbd_f(lun, tddesc, nemo, NEMO_STR_LEN+1, &tab, &itbd);
51  uptdd_f(itbd, lun, 0, &inum);
52 
53  *nctddesc = 0;
54 /*
55 ** Examine each child descriptor one at a time.
56 */
57  for ( i = 1; i <= inum; i++ ) {
58  uptdd_f(itbd, lun, i, &desc);
59  if (! istdesc_f(desc)) {
60 /*
61 ** desc is a local descriptor.
62 */
63  numtbd_f(lun, desc, nemo, NEMO_STR_LEN+1, &tab, &ictbd);
64  if ( tab == 'D' ) {
65 /*
66 ** desc is itself a local Table D descriptor, so resolve
67 ** it now via a recursive call to this same routine.
68 */
69  restd(lun, desc, &ncdesc, cdesc);
70 
71  if ( ( *nctddesc > 0 ) &&
72  ( ctddesc[(*nctddesc)-1] > ifxy_f(MIN_FXY_REPL) ) &&
73  ( ctddesc[(*nctddesc)-1] <= ifxy_f("101255") ) ) {
74 /*
75 ** desc is replicated using fixed replication, so write
76 ** the number of child descriptors into the X value of
77 ** the replication descriptor ctddesc[(*nctddesc)-1]
78 */
79  cadn30_f(ctddesc[(*nctddesc)-1], adn, FXY_STR_LEN+1);
80  sprintf(cwork, "%c%02d%c%c%c",
81  adn[0], ncdesc, adn[3], adn[4], adn[5]);
82  strncpy(adn, cwork, 6); adn[6] = '\0';
83  ctddesc[(*nctddesc)-1] = ifxy_f(adn);
84  }
85  else if ( ( *nctddesc > 1 ) &&
86  ( ctddesc[(*nctddesc)-2] == ifxy_f(MIN_FXY_REPL) ) ) {
87 /*
88 ** desc is replicated using delayed replication, so write
89 ** the number of child descriptors into the X value of
90 ** the replication descriptor ctddesc[(*nctddesc)-2]
91 */
92  cadn30_f(ctddesc[(*nctddesc)-2], adn, FXY_STR_LEN+1);
93  sprintf(cwork, "%c%02d%c%c%c",
94  adn[0], ncdesc, adn[3], adn[4], adn[5]);
95  strncpy(adn, cwork, 6); adn[6] = '\0';
96  ctddesc[(*nctddesc)-2] = ifxy_f(adn);
97  }
98 /*
99 ** Add the child descriptors to the output list.
100 */
101  for ( j = 0; j < ncdesc; j++ ) {
102  wrdesc(cdesc[j], ctddesc, nctddesc);
103  }
104 
105  }
106  else if ( tab == 'B' ) {
107 /*
108 ** desc is a local Table B descriptor, so precede it with
109 ** a 206YYY operator in the output list.
110 */
111  nemtbb_f(lun, ictbd, cunit, UNIT_STR_LEN+1, &iscl, &iref, &ibit);
112  sprintf(cwork, "%c%c%c%03d", '2', '0', '6', ibit);
113  strncpy(adn, cwork, 6); adn[6] = '\0';
114  wrdesc(ifxy_f(adn), ctddesc, nctddesc);
115  wrdesc(desc, ctddesc, nctddesc);
116  }
117  }
118  else {
119 /*
120 ** desc is a standard Table B, Table D, operator or replicator
121 ** descriptor, so append it "as is" to the output list.
122 */
123  wrdesc(desc, ctddesc, nctddesc);
124  }
125  }
126 
127  return;
128 }
void nemtbb_f(int lun, int table_idx, char *unit_str, int unit_str_len, int *scale, int *reference, int *bits)
Get information about a Table B descriptor.
Enable a number of NCEPLIBS-bufr subprograms to be called from within the C part of the library.
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.
Definition: bufrlib.h:54
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.
#define MIN_FXY_REPL
Character string containing minimum FXY value for a replication descriptor.
Definition: bufrlib.h:57
#define UNIT_STR_LEN
Size of a character string needed to store the units of a Table B descriptor.
Definition: bufrlib.h:69
int ifxy_f(char *cfxy)
Convert an FXY value from its 6 character representation to its WMO bit-wise representation.
#define NEMO_STR_LEN
Size of a character string needed to store a mnemonic.
Definition: bufrlib.h:66
#define MAXNC
Maximum number of descriptors within Section 3 of a BUFR message.
Definition: bufrlib.h:47
void uptdd_f(int id, int lun, int ient, int *iret)
Get the WMO bit-wise representation of the FXY value corresponding to a child mnemonic of a Table D s...
int istdesc_f(int idn)
Check whether a descriptor is WMO-standard.
integer ibit
Bit pointer within IBAY.
void restd(int lun, int tddesc, int *nctddesc, int *ctddesc)
Standardize a local Table D descriptor.
Definition: restd.c:39
void wrdesc(int desc, int *descary, int *ndescary)
Maintain an array of descriptors.
Definition: wrdesc.c:27