Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / var / external / bufr / restd.c
blob300ea8c34093eac24bab779b8cd01ae4f733fae5
1 /*$$$ SUBPROGRAM DOCUMENTATION BLOCK
3 C SUBPROGRAM: RESTD
4 C PRGMMR: ATOR ORG: NP12 DATE: 2004-08-18
6 C ABSTRACT: GIVEN THE BIT-WISE REPRESENTATION OF A LOCAL
7 C (I.E. NON-STANDARD) TABLE D DESCRIPTOR, THIS ROUTINE RETURNS
8 C AN EQUIVALENT LIST OF STANDARDIZED CHILD DESCRIPTORS. ANY CHILD
9 C DESCRIPTORS WHICH ARE THEMSELVES LOCAL TABLE D DESCRIPTORS ARE
10 C AUTOMATICALLY RESOLVED VIA A RECURSIVE CALL TO THIS SAME ROUTINE.
11 C THE RECURSIVE PROCESS CONTINUES UNTIL ALL CHILD DESCRIPTORS ARE
12 C EITHER WMO-STANDARD DESCRIPTORS (I.E. FROM TABLE B, TABLE C, OR
13 C TABLE D, OR REPLICATION DESCRIPTORS) OR ELSE ARE LOCAL TABLE B
14 C DESCRIPTORS, IN WHICH CASE THEY ARE PRECEDED WITH AN APPROPRIATE
15 C 206YYY TABLE C OPERATOR IN THE OUTPUT LIST. IN ANY EVENT, THE
16 C FINAL OUTPUT LIST OF EQUIVALENT CHILD DESCRIPTORS IS USABLE BY
17 C ANY STANDARD BUFR DECODER PROGRAM IN ORDER TO INTERPRET THE SAME
18 C DATA VALUES AS WERE REPRESENTED BY THE INITIAL LOCAL TABLE D
19 C DESCRIPTOR THAT WAS INPUT.
21 C PROGRAM HISTORY LOG:
22 C 2004-08-18 J. ATOR -- ORIGINAL AUTHOR
23 C 2012-04-30 J. ATOR -- USE LONG CAST FOR IBIT IN SPRINTF STMT
25 C USAGE: CALL RESTD( LUN, TDDESC, NCTDDESC, CTDDESC )
26 C INPUT ARGUMENT LIST:
27 C LUN - INTEGER: I/O STREAM INDEX INTO INTERNAL MEMORY ARRAYS
28 C TDDESC - INTEGER: BIT-WISE REPRESENTATION OF FXY VALUE FOR
29 C LOCAL TABLE D DESCRIPTOR
31 C OUTPUT ARGUMENT LIST:
32 C NCTDDESC - INTEGER: NUMBER OF STANDARDIZED CHILD DESCRIPTORS
33 C RETURNED IN CTDDESC
34 C CTDDESC - INTEGER: ARRAY OF STANDARDIZED CHILD DESCRIPTORS
36 C REMARKS:
37 C THIS ROUTINE CALLS: RESTD NUMTBD NEMTBB IFXY
38 C CADN30 ISTDESC WRDESC UPTDD
39 C THIS ROUTINE IS CALLED BY: RESTD STNDRD
40 C Normally not called by application
41 C programs but it could be.
43 C ATTRIBUTES:
44 C LANGUAGE: C
45 C MACHINE: PORTABLE TO ALL PLATFORMS
47 C$$$*/
49 #include "bufrlib.h"
51 void restd( f77int *lun, f77int *tddesc, f77int *nctddesc, f77int ctddesc[] )
53 f77int i0 = 0;
55 f77int desc, ncdesc, cdesc[MAXNC];
56 f77int i, j, inum, itbd, ictbd;
57 f77int iscl, iref, ibit;
59 char tab, nemo[9], adn[7], cunit[25];
62 ** How many child descriptors does *tddesc have?
64 numtbd( lun, tddesc, nemo, &tab, &itbd, 9, 1 );
65 uptdd( &itbd, lun, &i0, &inum );
67 *nctddesc = 0;
69 ** Examine each child descriptor one at a time.
71 for ( i = 1; i <= inum; i++ ) {
72 uptdd( &itbd, lun, &i, &desc );
73 if (! istdesc( &desc ) ) {
75 ** desc is a local descriptor.
76 */
77 numtbd( lun, &desc, nemo, &tab, &ictbd, 9, 1 );
78 if ( tab == 'D' ) {
80 ** desc is itself a local Table D descriptor, so resolve
81 ** it now via a recursive call to this same routine.
82 */
83 restd( lun, &desc, &ncdesc, cdesc );
85 if ( ( *nctddesc > 0 ) &&
86 ( ctddesc[(*nctddesc)-1] > ifxy( "101000", 6 ) ) &&
87 ( ctddesc[(*nctddesc)-1] <= ifxy( "101255", 6 ) ) ) {
89 ** desc is replicated using fixed replication, so write
90 ** the number of child descriptors into the X value of
91 ** the replication descriptor ctddesc[(*nctddesc)-1]
93 cadn30( &ctddesc[(*nctddesc)-1], adn, 7 );
94 sprintf( adn, "%c%02ld%c%c%c",
95 adn[0], (long) ncdesc, adn[3], adn[4], adn[5] );
96 ctddesc[(*nctddesc)-1] = ifxy( adn, 7 );
98 else if ( ( *nctddesc > 1 ) &&
99 ( ctddesc[(*nctddesc)-2] == ifxy( "101000", 6 ) ) ) {
101 ** desc is replicated using delayed replication, so write
102 ** the number of child descriptors into the X value of
103 ** the replication descriptor ctddesc[(*nctddesc)-2]
105 cadn30( &ctddesc[(*nctddesc)-2], adn, 7 );
106 sprintf( adn, "%c%02ld%c%c%c",
107 adn[0], (long) ncdesc, adn[3], adn[4], adn[5] );
108 ctddesc[(*nctddesc)-2] = ifxy( adn, 7 );
111 ** Add the child descriptors to the output list.
113 for ( j = 0; j < ncdesc; j++ ) {
114 wrdesc( cdesc[j], ctddesc, nctddesc );
118 else if ( tab == 'B' ) {
120 ** desc is a local Table B descriptor, so precede it with
121 ** a 206YYY operator in the output list.
123 nemtbb( lun, &ictbd, cunit, &iscl, &iref, &ibit, 25 );
124 sprintf( adn, "%c%c%c%03ld", '2', '0', '6', (long) ibit );
125 wrdesc( ifxy( adn, 7 ), ctddesc, nctddesc );
126 wrdesc( desc, ctddesc, nctddesc );
129 else {
131 ** desc is a standard Table B, Table D, operator or replicator
132 ** descriptor, so append it "as is" to the output list.
134 wrdesc( desc, ctddesc, nctddesc );
138 return;