NCEPLIBS-bufr  12.2.0
All Data Structures Namespaces Files Functions Variables Macros Pages
restd.c
Go to the documentation of this file.
1 
7 #include "bufrlib.h"
8 
26 void
27 wrdesc(int desc, int *descary, int *ndescary, int mxdescary)
28 {
29  char errstr[129];
30 
31  /*
32  ** Is there room in descary for desc?
33  */
34  if ( ( *ndescary + 1 ) < mxdescary ) {
35  descary[(*ndescary)++] = desc;
36  }
37  else {
38  sprintf(errstr, "BUFRLIB: WRDESC - EXPANDED SECTION 3 CONTAINS"
39  " MORE THAN %d DESCRIPTORS", mxdescary);
40  bort_f(errstr);
41  }
42 
43  return;
44 }
45 
72 void
73 restd(int lun, int tddesc, int *nctddesc, int *ctddesc)
74 {
75  int maxnc, desc, ncdesc, *cdesc;
76  int i, j, inum, itbd, ictbd;
77  int iscl, iref, ibit;
78 
79  char tab, nemo[NEMO_STR_LEN+1], adn[FXY_STR_LEN+1], cunit[UNIT_STR_LEN+1], cwork[31];
80 
81  /*
82  ** How many child descriptors does tddesc have?
83  */
84  numtbd_f(lun, tddesc, nemo, NEMO_STR_LEN+1, &tab, &itbd);
85  uptdd_f(itbd, lun, 0, &inum);
86 
87  maxnc = igetprm_f("MAXNC");
88 
89  *nctddesc = 0;
90  /*
91  ** Examine each child descriptor one at a time.
92  */
93  for ( i = 1; i <= inum; i++ ) {
94  uptdd_f(itbd, lun, i, &desc);
95  if ( istdesc_f(desc) ) {
96  /*
97  ** desc is a standard Table B, Table D, operator or replicator
98  ** descriptor, so append it "as is" to the output list.
99  */
100  wrdesc(desc, ctddesc, nctddesc, maxnc);
101  }
102  else {
103  /*
104  ** desc is a local descriptor.
105  */
106  numtbd_f(lun, desc, nemo, NEMO_STR_LEN+1, &tab, &ictbd);
107  if ( tab == 'D' ) {
108  /*
109  ** desc is itself a local Table D descriptor, so resolve
110  ** it now via a recursive call to this same routine.
111  */
112  if (!(cdesc = malloc(maxnc * sizeof(int)))) bort_f("RESTD FAILED ALLOCATING");
113 
114  restd(lun, desc, &ncdesc, cdesc);
115 
116  if ( ( *nctddesc > 0 ) &&
117  ( ctddesc[(*nctddesc)-1] > ifxy_f(FXY_MINR) ) &&
118  ( ctddesc[(*nctddesc)-1] <= ifxy_f("101255") ) ) {
119  /*
120  ** desc is replicated using fixed replication, so write
121  ** the number of child descriptors into the X value of
122  ** the replication descriptor ctddesc[(*nctddesc)-1]
123  */
124  cadn30_f(ctddesc[(*nctddesc)-1], adn, FXY_STR_LEN+1);
125  sprintf(cwork, "%c%02d%c%c%c",
126  adn[0], ncdesc, adn[3], adn[4], adn[5]);
127  strncpy(adn, cwork, 6); adn[6] = '\0';
128  ctddesc[(*nctddesc)-1] = ifxy_f(adn);
129  }
130  else if ( ( *nctddesc > 1 ) &&
131  ( ctddesc[(*nctddesc)-2] == ifxy_f(FXY_MINR) ) ) {
132  /*
133  ** desc is replicated using delayed replication, so write
134  ** the number of child descriptors into the X value of
135  ** the replication descriptor ctddesc[(*nctddesc)-2]
136  */
137  cadn30_f(ctddesc[(*nctddesc)-2], adn, FXY_STR_LEN+1);
138  sprintf(cwork, "%c%02d%c%c%c",
139  adn[0], ncdesc, adn[3], adn[4], adn[5]);
140  strncpy(adn, cwork, 6); adn[6] = '\0';
141  ctddesc[(*nctddesc)-2] = ifxy_f(adn);
142  }
143  /*
144  ** Add the child descriptors to the output list.
145  */
146  for ( j = 0; j < ncdesc; j++ ) {
147  wrdesc(cdesc[j], ctddesc, nctddesc, maxnc);
148  }
149 
150  free(cdesc);
151  }
152  else if ( imrkopr_f(nemo) ) {
153  /*
154  ** desc is a Table C marker operator, so append it "as is" to the
155  ** output list.
156  */
157  wrdesc(ifxy_f(nemo), ctddesc, nctddesc, maxnc);
158  }
159  else {
160  /*
161  ** desc is a local Table B descriptor, so precede it with
162  ** a 206YYY operator in the output list.
163  */
164  nemtbb_f(lun, ictbd, cunit, UNIT_STR_LEN+1, &iscl, &iref, &ibit);
165  sprintf(cwork, "%c%c%c%03d", '2', '0', '6', ibit);
166  strncpy(adn, cwork, 6); adn[6] = '\0';
167  wrdesc(ifxy_f(adn), ctddesc, nctddesc, maxnc);
168  wrdesc(desc, ctddesc, nctddesc, maxnc);
169  }
170  }
171  }
172 
173  return;
174 }
int igetprm_f(char *cprmnm)
Get the current value of a parameter.
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:34
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.
Definition: bufrlib.h:37
#define UNIT_STR_LEN
Size of a character string needed to store the units of a Table B descriptor.
Definition: bufrlib.h:67
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:64
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 wrdesc(int desc, int *descary, int *ndescary, int mxdescary)
Maintain an array of descriptors.
Definition: restd.c:27
void restd(int lun, int tddesc, int *nctddesc, int *ctddesc)
Standardize a local Table D descriptor.
Definition: restd.c:73