From 46664430862f2279c07207ca7dd3fc631a252655 Mon Sep 17 00:00:00 2001 From: Jeff Ator Date: Mon, 26 Aug 2024 15:40:55 +0000 Subject: [PATCH 1/3] adjust indentation in several C routines --- src/crwbmg.c | 5 +- src/restd.c | 82 +++++----- src/stseq.c | 428 +++++++++++++++++++++++++-------------------------- 3 files changed, 255 insertions(+), 260 deletions(-) diff --git a/src/crwbmg.c b/src/crwbmg.c index 184f94e5..a7936266 100644 --- a/src/crwbmg.c +++ b/src/crwbmg.c @@ -9,8 +9,7 @@ * other local filesystem notation. */ #define MXFNLEN 200 -/** File pointers; each element will automatically initialize to - * NULL */ +/** File pointers; each element will automatically initialize to NULL */ FILE *pbf[2]; /** @@ -60,7 +59,7 @@ rbytes(char *bmg, int mxmb, int isloc, int newbytes) * program written in either C or Fortran. It is functionally * equivalent to subroutine openbf(); however, there are some * important differences: - + * * - When using openbf(), the underlying file must already be * associated with a Fortran logical unit number on the local * system, typicially via a prior Fortran "OPEN" statement. This is diff --git a/src/restd.c b/src/restd.c index 1ff42ace..d2a1303d 100644 --- a/src/restd.c +++ b/src/restd.c @@ -28,9 +28,9 @@ wrdesc(int desc, int *descary, int *ndescary, int mxdescary) { char errstr[129]; -/* -** Is there room in descary for desc? -*/ + /* + ** Is there room in descary for desc? + */ if ( ( *ndescary + 1 ) < mxdescary ) { descary[(*ndescary)++] = desc; } @@ -77,30 +77,30 @@ restd(int lun, int tddesc, int *nctddesc, int *ctddesc) int iscl, iref, ibit; char tab, nemo[NEMO_STR_LEN+1], adn[FXY_STR_LEN+1], cunit[UNIT_STR_LEN+1], cwork[31]; -/* -** How many child descriptors does tddesc have? -*/ + /* + ** How many child descriptors does tddesc have? + */ numtbd_f(lun, tddesc, nemo, NEMO_STR_LEN+1, &tab, &itbd); uptdd_f(itbd, lun, 0, &inum); maxnc = igetprm_f("MAXNC"); *nctddesc = 0; -/* -** Examine each child descriptor one at a time. -*/ + /* + ** Examine each child descriptor one at a time. + */ for ( i = 1; i <= inum; i++ ) { uptdd_f(itbd, lun, i, &desc); if (! istdesc_f(desc)) { -/* -** desc is a local descriptor. -*/ + /* + ** desc is a local descriptor. + */ numtbd_f(lun, desc, nemo, NEMO_STR_LEN+1, &tab, &ictbd); if ( tab == 'D' ) { -/* -** desc is itself a local Table D descriptor, so resolve -** it now via a recursive call to this same routine. -*/ + /* + ** desc is itself a local Table D descriptor, so resolve + ** it now via a recursive call to this same routine. + */ if (!(cdesc = malloc(maxnc * sizeof(int)))) bort_f("RESTD FAILED ALLOCATING"); restd(lun, desc, &ncdesc, cdesc); @@ -108,11 +108,11 @@ restd(int lun, int tddesc, int *nctddesc, int *ctddesc) if ( ( *nctddesc > 0 ) && ( ctddesc[(*nctddesc)-1] > ifxy_f(MIN_FXY_REPL) ) && ( ctddesc[(*nctddesc)-1] <= ifxy_f("101255") ) ) { -/* -** desc is replicated using fixed replication, so write -** the number of child descriptors into the X value of -** the replication descriptor ctddesc[(*nctddesc)-1] -*/ + /* + ** desc is replicated using fixed replication, so write + ** the number of child descriptors into the X value of + ** the replication descriptor ctddesc[(*nctddesc)-1] + */ cadn30_f(ctddesc[(*nctddesc)-1], adn, FXY_STR_LEN+1); sprintf(cwork, "%c%02d%c%c%c", adn[0], ncdesc, adn[3], adn[4], adn[5]); @@ -121,20 +121,20 @@ restd(int lun, int tddesc, int *nctddesc, int *ctddesc) } else if ( ( *nctddesc > 1 ) && ( ctddesc[(*nctddesc)-2] == ifxy_f(MIN_FXY_REPL) ) ) { -/* -** desc is replicated using delayed replication, so write -** the number of child descriptors into the X value of -** the replication descriptor ctddesc[(*nctddesc)-2] -*/ + /* + ** desc is replicated using delayed replication, so write + ** the number of child descriptors into the X value of + ** the replication descriptor ctddesc[(*nctddesc)-2] + */ cadn30_f(ctddesc[(*nctddesc)-2], adn, FXY_STR_LEN+1); sprintf(cwork, "%c%02d%c%c%c", adn[0], ncdesc, adn[3], adn[4], adn[5]); strncpy(adn, cwork, 6); adn[6] = '\0'; ctddesc[(*nctddesc)-2] = ifxy_f(adn); } -/* -** Add the child descriptors to the output list. -*/ + /* + ** Add the child descriptors to the output list. + */ for ( j = 0; j < ncdesc; j++ ) { wrdesc(cdesc[j], ctddesc, nctddesc, maxnc); } @@ -142,17 +142,17 @@ restd(int lun, int tddesc, int *nctddesc, int *ctddesc) free(cdesc); } else if ( imrkopr_f(nemo) ) { -/* -** desc is a Table C marker operator, so append it "as is" to the -** output list. -*/ + /* + ** desc is a Table C marker operator, so append it "as is" to the + ** output list. + */ wrdesc(ifxy_f(nemo), ctddesc, nctddesc, maxnc); } else { -/* -** desc is a local Table B descriptor, so precede it with -** a 206YYY operator in the output list. -*/ + /* + ** desc is a local Table B descriptor, so precede it with + ** a 206YYY operator in the output list. + */ nemtbb_f(lun, ictbd, cunit, UNIT_STR_LEN+1, &iscl, &iref, &ibit); sprintf(cwork, "%c%c%c%03d", '2', '0', '6', ibit); strncpy(adn, cwork, 6); adn[6] = '\0'; @@ -161,10 +161,10 @@ restd(int lun, int tddesc, int *nctddesc, int *ctddesc) } } else { -/* -** desc is a standard Table B, Table D, operator or replicator -** descriptor, so append it "as is" to the output list. -*/ + /* + ** desc is a standard Table B, Table D, operator or replicator + ** descriptor, so append it "as is" to the output list. + */ wrdesc(desc, ctddesc, nctddesc, maxnc); } } diff --git a/src/stseq.c b/src/stseq.c index 61260f71..cba30f01 100644 --- a/src/stseq.c +++ b/src/stseq.c @@ -1,6 +1,5 @@ /** @file - * @brief Store information about a standard Table D descriptor - * within internal DX BUFR tables. + * @brief Store information about a Table D descriptor within internal DX BUFR tables. * * @author J. Ator @date 2009-03-23 */ @@ -14,25 +13,25 @@ * This routine defines a comparison between two integers * for use by the binary search function bsearch. * - * @param pf1 - first integer to be compared. - * @param pf2 - second integer to be compared. + * @param pf1 - First integer to be compared + * @param pf2 - Second integer to be compared * * @return - * - -1 PF1 is less than PF2 - * - 0 PF1 is equal to PF2 - * - 1 PF1 is greater than PF2 + * - -1 = pf1 is less than pf2 + * - 0 = pf1 is equal to pf2 + * - 1 = pf1 is greater than pf2 * * @author J. Ator @date 2009-03-23 */ int cmpia(const void *pf1, const void *pf2) { - int *mypf1 = ( int * ) pf1; - int *mypf2 = ( int * ) pf2; + int *mypf1 = ( int * ) pf1; + int *mypf2 = ( int * ) pf2; - if ( *mypf1 == *mypf2 ) return 0; + if ( *mypf1 == *mypf2 ) return 0; - return ( *mypf1 < *mypf2 ? -1 : 1 ); + return ( *mypf1 < *mypf2 ? -1 : 1 ); } /** @@ -44,47 +43,47 @@ cmpia(const void *pf1, const void *pf2) * table must be sorted in ascending order (by FXY number) in order * for this routine to work properly. * - * @param idn - WMO bit-wise representation of FXY number to be searched for. - * @param tab - table in which idn was found ('B' or 'D'). - * @param ipt - index of entry for idn in master table tab. + * @param idn - WMO bit-wise representation of FXY number to be searched for + * @param tab - Table in which idn was found ('B' or 'D') + * @param ipt - Index of entry for idn in master table tab * * @author J. Ator @date 2009-03-23 */ void nummtb(int *idn, char *tab, int *ipt) { - int *pifxyn, *pbs, nmt; + int *pifxyn, *pbs, nmt; - char adn[FXY_STR_LEN+1], errstr[129]; + char adn[FXY_STR_LEN+1], errstr[129]; - if ( *idn >= ifxy_f(MIN_FXY_TABLED) ) { - *tab = 'D'; - pifxyn = &idfxyn_c[0]; - nmt = nmtd_c; - } - else { - *tab = 'B'; - pifxyn = &ibfxyn_c[0]; - nmt = nmtb_c; - } + if ( *idn >= ifxy_f(MIN_FXY_TABLED) ) { + *tab = 'D'; + pifxyn = &idfxyn_c[0]; + nmt = nmtd_c; + } + else { + *tab = 'B'; + pifxyn = &ibfxyn_c[0]; + nmt = nmtb_c; + } - pbs = bsearch(idn, pifxyn, (size_t) nmt, sizeof(int), - (int (*) (const void *, const void *)) cmpia); - if ( pbs == NULL ) { - cadn30_f(*idn, adn, FXY_STR_LEN+1); - sprintf(errstr, "BUFRLIB: NUMMTB - COULD NOT FIND DESCRIPTOR " - "%s IN MASTER TABLE %c", adn, *tab); - bort_f(errstr); - } - *ipt = pbs - pifxyn; + pbs = bsearch(idn, pifxyn, (size_t) nmt, sizeof(int), + (int (*) (const void *, const void *)) cmpia); + if ( pbs == NULL ) { + cadn30_f(*idn, adn, FXY_STR_LEN+1); + sprintf(errstr, "BUFRLIB: NUMMTB - COULD NOT FIND DESCRIPTOR " + "%s IN MASTER TABLE %c", adn, *tab); + bort_f(errstr); + } + *ipt = pbs - pifxyn; - return; + return; } /** - * Store information about a standard Table D descriptor within internal DX BUFR tables. + * Store information about a Table D descriptor within internal DX BUFR tables. * - * Given the WMO bit-wise (integer) representation of a standard + * Given the WMO bit-wise (integer) representation of a * Table D descriptor, this subroutine uses the master BUFR tables * to store all of the necessary information for that descriptor * within the internal DX BUFR tables. Any child descriptors which @@ -95,17 +94,16 @@ nummtb(int *idn, char *tab, int *ipt) * @param irepct - Replication sequence counter for the current master table; used internally * to keep track of which sequence names have already been defined, and thereby avoid contention * within the internal DX BUFR Table D - * @param idn - WMO bit-wise representation of FXY value for standard Table D descriptor + * @param idn - WMO bit-wise representation of FXY value for Table D descriptor * @param nemo - Mnemonic corresponding to idn * @param cseq - Description corresponding to idn - * @param cdesc - Array of WMO-standard child descriptors equivalent to idn - * @param ncdesc - Number of WMO-standard child descriptors in cdesc + * @param cdesc - Array of child descriptors equivalent to idn + * @param ncdesc - Number of child descriptors in cdesc * * @author J. Ator @date 2009-03-23 */ void -stseq(int lun, int *irepct, int idn, char *nemo, - char *cseq, int *cdesc, int ncdesc) +stseq(int lun, int *irepct, int idn, char *nemo, char *cseq, int *cdesc, int ncdesc) { int i, j, nb, nd, ix, iy, iret, nbits; int rpidn, pkint, ilen, imxcd, imxnf, ipt, *rpdesc; @@ -113,30 +111,30 @@ stseq(int lun, int *irepct, int idn, char *nemo, char tab, adn[FXY_STR_LEN+1], adn2[FXY_STR_LEN+1], units[10], errstr[129]; char nemo2[NEMO_STR_LEN+1], rpseq[56], card[80], ctmp[4], cblk = ' ', czero = '0'; -/* -** The following variable is declared as static so that it automatically initializes -** to zero and remains unchanged between recursive calls to this subroutine. -*/ + /* + ** The following variable is declared as static so that it automatically initializes + ** to zero and remains unchanged between recursive calls to this subroutine. + */ static int naf; -/* -** Is idn already listed as an entry in the internal Table D? -** If so, then there's no need to proceed any further. -*/ + /* + ** Is idn already listed as an entry in the internal Table D? + ** If so, then there's no need to proceed any further. + */ numtbd_f(lun, idn, nemo2, NEMO_STR_LEN+1, &tab, &iret); if ( ( iret > 0 ) && ( tab == 'D' ) ) return; -/* -** Start a new Table D entry for idn. -*/ + /* + ** Start a new Table D entry for idn. + */ tab = 'D'; nd = igetntbi_f(lun, &tab); cadn30_f(idn, adn, FXY_STR_LEN+1); stntbi_f(nd, lun, adn, nemo, cseq); -/* -** Now, go through the list of child descriptors corresponding to idn. -*/ + /* + ** Now, go through the list of child descriptors corresponding to idn. + */ imxcd = igetprm_f("MAXCD"); imxnf = igetprm_f("MXNAF"); @@ -147,19 +145,19 @@ stseq(int lun, int *irepct, int idn, char *nemo, strncpy(ctmp, &adn[3], 4); /* trailing null will be included in this copy */ strnum_f(ctmp, &iy, &iret); if ( adn[0] == '3' ) { -/* -** cdesc[i] is itself a Table D descriptor, so locate it within the -** master table D and then store the contents within the internal -** Table D via a recursive call to this same routine. -*/ + /* + ** cdesc[i] is itself a Table D descriptor, so locate it within the + ** master table D and then store the contents within the internal + ** Table D via a recursive call to this same routine. + */ nummtb(&cdesc[i], &tab, &ipt); if ( naf > 0 ) { -/* -** There are associated fields in effect which will modify this -** descriptor when storing it within the internal Table D. So -** create a new sequence to store the contents of this descriptor -** along with its associated fields. -*/ + /* + ** There are associated fields in effect which will modify this + ** descriptor when storing it within the internal Table D. So + ** create a new sequence to store the contents of this descriptor + ** along with its associated fields. + */ rpidn = igettdi_f(lun); sprintf(rpseq, "REPLICATION SEQUENCE %.3d", ++(*irepct)); @@ -170,12 +168,11 @@ stseq(int lun, int *irepct, int idn, char *nemo, &idefxy_c[icvidx(ipt,0,imxcd)], ndelem_c[ipt]); pkint = rpidn; - } else { -/* -** Store cdesc[i] as is directly within the internal Table D. -*/ + /* + ** Store cdesc[i] as is directly within the internal Table D. + */ stseq(lun, irepct, cdesc[i], &cdmnem_c[ipt][0], &cdseq_c[ipt][0], &idefxy_c[icvidx(ipt,0,imxcd)], @@ -184,23 +181,23 @@ stseq(int lun, int *irepct, int idn, char *nemo, } } else if ( adn[0] == '2' ) { -/* -** cdesc[i] is an operator descriptor. -*/ + /* + ** cdesc[i] is an operator descriptor. + */ if ( ( ( ix >= 4 ) && ( ix <= 6 ) ) || ( imrkopr_f(adn) ) ) { -/* -** This is a 204YYY, 205YYY, 206YYY operator, or else a 223255, -** 224255, 225255 or 232255 marker operator. In any case, -** generate a Table B mnemonic to hold the corresponding data. -*/ + /* + ** This is a 204YYY, 205YYY, 206YYY operator, or else a 223255, + ** 224255, 225255 or 232255 marker operator. In any case, + ** generate a Table B mnemonic to hold the corresponding data. + */ strncpy(nemo2, adn, 6); memset(&nemo2[6], (int) cblk, 2); nemo2[8] = '\0'; if ( ( ix == 4 ) && ( iy == 0 ) ) { -/* -** Cancel the most-recently added associated field. -*/ + /* + ** Cancel the most-recently added associated field. + */ if ( naf-- <= 0 ) { sprintf(errstr, "BUFRLIB: STSEQ - TOO MANY ASSOCIATED" " FIELD CANCELLATION OPERATORS"); @@ -208,94 +205,94 @@ stseq(int lun, int *irepct, int idn, char *nemo, } } else { -/* -** Is nemo2 already listed as an entry within the internal -** Table B? -*/ - nemtab_f(lun, nemo2, &pkint, &tab, &iret); - if ( ( iret == 0 ) || ( tab != 'B' ) ) { -/* -** No, so create and store a new Table B entry for nemo2. -*/ - tab = 'B'; - nb = igetntbi_f(lun, &tab); - - if ( ix == 4 ) { - sprintf(rpseq, "Associated field of %3d bits", iy); - nbits = iy; - strcpy(units, "NUMERIC"); - } - else if ( ix == 5 ) { - sprintf(rpseq, "Text string of %3d bytes", iy); - nbits = iy*8; - strcpy(units, "CCITT IA5"); - } - else if ( ix == 6 ) { - sprintf(rpseq, "Local descriptor of %3d bits", iy); - nbits = iy; - if ( nbits > 32 ) { - strcpy(units, "CCITT IA5"); - } - else { + /* + ** Is nemo2 already listed as an entry within the internal + ** Table B? + */ + nemtab_f(lun, nemo2, &pkint, &tab, &iret); + if ( ( iret == 0 ) || ( tab != 'B' ) ) { + /* + ** No, so create and store a new Table B entry for nemo2. + */ + tab = 'B'; + nb = igetntbi_f(lun, &tab); + + if ( ix == 4 ) { + sprintf(rpseq, "Associated field of %3d bits", iy); + nbits = iy; strcpy(units, "NUMERIC"); } - } - else { // 2-XX-255 marker operator - if ( ix == 23 ) { - sprintf(rpseq, "Substituted value"); - } - else if ( ix == 24 ) { - sprintf(rpseq, "First-order statistical value"); + else if ( ix == 5 ) { + sprintf(rpseq, "Text string of %3d bytes", iy); + nbits = iy*8; + strcpy(units, "CCITT IA5"); } - else if ( ix == 25 ) { - sprintf(rpseq, "Difference statistical value"); + else if ( ix == 6 ) { + sprintf(rpseq, "Local descriptor of %3d bits", iy); + nbits = iy; + if ( nbits > 32 ) { + strcpy(units, "CCITT IA5"); + } + else { + strcpy(units, "NUMERIC"); + } } - else if ( ix == 32 ) { - sprintf(rpseq, "Replaced/retained value"); + else { // 2-XX-255 marker operator + if ( ix == 23 ) { + sprintf(rpseq, "Substituted value"); + } + else if ( ix == 24 ) { + sprintf(rpseq, "First-order statistical value"); + } + else if ( ix == 25 ) { + sprintf(rpseq, "Difference statistical value"); + } + else if ( ix == 32 ) { + sprintf(rpseq, "Replaced/retained value"); + } + /* For now, set a default bit width and units. */ + nbits = 8; + strcpy(units, "NUMERIC"); } - /* For now, set a default bit width and units. */ - nbits = 8; - strcpy(units, "NUMERIC"); + ilen = ( int ) strlen(rpseq); + memset(&rpseq[ilen], (int) cblk, 55 - ilen); + /* + ** Note that 49152 = 3*(2**14), so subtracting 49152 in the + ** following statement changes a WMO Table D bit-wise FXY value into + ** a WMO Table B bit-wise FXY value. + */ + pkint = (igettdi_f(lun) - 49152); + cadn30_f(pkint, adn2, FXY_STR_LEN+1); + + stntbi_f(nb, lun, adn2, nemo2, rpseq); + + /* Initialize card to all blanks. */ + memset(card, (int) cblk, sizeof( card )); + + strncpy(&card[2], nemo2, 8); + memcpy(&card[16], &czero, 1); + memcpy(&card[30], &czero, 1); + sprintf(&card[33], "%4d", nbits); + strcpy(&card[40], units); + card[40+strlen(units)] = cblk; /* overwrite trailing null */ + elemdx_f(card, lun); } - ilen = ( int ) strlen(rpseq); - memset(&rpseq[ilen], (int) cblk, 55 - ilen); -/* -** Note that 49152 = 3*(2**14), so subtracting 49152 in the -** following statement changes a WMO Table D bit-wise FXY value into -** a WMO Table B bit-wise FXY value. -*/ - pkint = (igettdi_f(lun) - 49152); - cadn30_f(pkint, adn2, FXY_STR_LEN+1); - - stntbi_f(nb, lun, adn2, nemo2, rpseq); - - /* Initialize card to all blanks. */ - memset(card, (int) cblk, sizeof( card )); - - strncpy(&card[2], nemo2, 8); - memcpy(&card[16], &czero, 1); - memcpy(&card[30], &czero, 1); - sprintf(&card[33], "%4d", nbits); - strcpy(&card[40], units); - card[40+strlen(units)] = cblk; /* overwrite trailing null */ - elemdx_f(card, lun); - } - if ( ix == 4 ) { -/* -** Add an associated field. -*/ - if ( naf >= imxnf ) { - sprintf(errstr, "BUFRLIB: STSEQ - TOO MANY ASSOCIATED" - " FIELDS ARE IN EFFECT AT THE SAME TIME"); - bort_f(errstr); + if ( ix == 4 ) { + /* + ** Add an associated field. + */ + if ( naf >= imxnf ) { + sprintf(errstr, "BUFRLIB: STSEQ - TOO MANY ASSOCIATED" + " FIELDS ARE IN EFFECT AT THE SAME TIME"); + bort_f(errstr); + } + iafpk[naf++] = pkint; } - iafpk[naf++] = pkint; - } } if ( ix == 6 ) { -/* -** Skip over the local descriptor placeholder. -*/ + /* + ** Skip over the local descriptor placeholder. + */ if ( ++i >= ncdesc ) { sprintf(errstr, "BUFRLIB: STSEQ - COULD NOT FIND LOCAL" " DESCRIPTOR PLACEHOLDER FOR %s", adn); @@ -308,17 +305,17 @@ stseq(int lun, int *irepct, int idn, char *nemo, } } else if ( adn[0] == '1' ) { -/* -** cdesc[i] is a replication descriptor, so create a sequence -** consisting of the set of replicated descriptors and then immediately -** store that sequence within the internal Table D via a recursive call -** to this same routine. -** -** See module @ref modv_vars for the source of the FXY values referenced -** in the following block. Note we are guaranteed that 0 <= iy <= 255, -** since adn was generated using subroutine cadn30_f(). -*/ - if ( iy == 0 ) { /* delayed replication */ + /* + ** cdesc[i] is a replication descriptor, so create a sequence + ** consisting of the set of replicated descriptors and then immediately + ** store that sequence within the internal Table D via a recursive call + ** to this same routine. + ** + ** See module @ref modv_vars for the source of the FXY values referenced + ** in the following block. Note we are guaranteed that 0 <= iy <= 255, + ** since adn was generated using subroutine cadn30_f(). + */ + if ( iy == 0 ) { /* delayed replication */ if ( ( i+1 ) >= ncdesc ) { sprintf(errstr, "BUFRLIB: STSEQ - COULD NOT FIND DELAYED " "DESCRIPTOR REPLICATION FACTOR FOR %s", adn); @@ -340,14 +337,14 @@ stseq(int lun, int *irepct, int idn, char *nemo, } i += 2; } - else { /* regular replication */ + else { /* regular replication */ pkint = ifxy_f(MIN_FXY_REPL) + iy; i++; } -/* -** Store this replication descriptor within the table D entry for -** this parent. -*/ + /* + ** Store this replication descriptor within the table D entry for + ** this parent. + */ pktdd_f(nd, lun, pkint, &iret); if ( iret < 0 ) { strncpy(nemo2, nemo, 8); @@ -356,21 +353,21 @@ stseq(int lun, int *irepct, int idn, char *nemo, "STORING REPLICATOR FOR PARENT MNEMONIC %s", nemo2); bort_f(errstr); } -/* -** Note we are guaranteed that 0 < ix <= 63 since adn was generated -** using subroutine cadn30_f(). -*/ + /* + ** Note we are guaranteed that 0 < ix <= 63 since adn was generated + ** using subroutine cadn30_f(). + */ if ( ix > ( ncdesc - i ) ) { sprintf(errstr, "BUFRLIB: STSEQ - NOT ENOUGH REMAINING CHILD " "DESCRIPTORS TO COMPLETE REPLICATION FOR %s", adn); bort_f(errstr); } else if ( ( ix == 1 ) && ( cdesc[i] >= ifxy_f(MIN_FXY_TABLED) ) ) { -/* -** The only thing being replicated is a single Table D descriptor, -** so there's no need to invent a new sequence for this replication -** (this is a special case!) -*/ + /* + ** The only thing being replicated is a single Table D descriptor, + ** so there's no need to invent a new sequence for this replication + ** (this is a special case!) + */ nummtb(&cdesc[i], &tab, &ipt); stseq(lun, irepct, cdesc[i], &cdmnem_c[ipt][0], &cdseq_c[ipt][0], @@ -379,12 +376,11 @@ stseq(int lun, int *irepct, int idn, char *nemo, pkint = cdesc[i]; } else { -/* -** Store the ix descriptors to be replicated in a local list, then -** get an FXY value to use with this list and generate a unique -** mnemonic and description as well. -*/ - + /* + ** Store the ix descriptors to be replicated in a local list, then + ** get an FXY value to use with this list and generate a unique + ** mnemonic and description as well. + */ if ( ( rpdesc = malloc( imxcd * sizeof(int) ) ) == NULL ) { sprintf(errstr, "BUFRLIB: STSEQ - UNABLE TO ALLOCATE SPACE" " FOR RPDESC"); @@ -410,20 +406,20 @@ stseq(int lun, int *irepct, int idn, char *nemo, } } else { -/* -** cdesc[i] is a Table B descriptor. -** -** Is cdesc[i] already listed as an entry in the internal Table B? -*/ + /* + ** cdesc[i] is a Table B descriptor. + ** + ** Is cdesc[i] already listed as an entry in the internal Table B? + */ numtbd_f(lun, cdesc[i], nemo2, NEMO_STR_LEN+1, &tab, &iret); if ( ( iret == 0 ) || ( tab != 'B' ) ) { -/* -** No, so search for it within the master table B. -*/ + /* + ** No, so search for it within the master table B. + */ nummtb(&cdesc[i], &tab, &ipt); -/* -** Start a new Table B entry for cdesc[i]. -*/ + /* + ** Start a new Table B entry for cdesc[i]. + */ nb = igetntbi_f(lun, &tab); cadn30_f(cdesc[i], adn2, FXY_STR_LEN+1); stntbi_f(nb, lun, adn2, &cbmnem_c[ipt][0], &cbelem_c[ipt][0]); @@ -440,15 +436,15 @@ stseq(int lun, int *irepct, int idn, char *nemo, } pkint = cdesc[i]; } - if (strncmp( adn, "204", 3) != 0 ) { -/* -** Store this child descriptor within the table D entry for this -** parent, preceding it with any associated fields that are currently -** in effect. -** -** Note that associated fields are only applied to Table B descriptors, -** except for those in Class 31. -*/ + if ( strncmp( adn, "204", 3 ) != 0 ) { + /* + ** Store this child descriptor within the table D entry for this + ** parent, preceding it with any associated fields that are currently + ** in effect. + ** + ** Note that associated fields are only applied to Table B descriptors, + ** except for those in Class 31. + */ if ( ( naf > 0 ) && ( pkint <= ifxy_f(MAX_FXY_TABLEB) ) && ( ( pkint < ifxy_f("031000") ) || ( pkint > ifxy_f("031255") ) ) ) { @@ -461,9 +457,9 @@ stseq(int lun, int *irepct, int idn, char *nemo, } } } -/* -** Store the child descriptor. -*/ + /* + ** Store the child descriptor. + */ pktdd_f(nd, lun, pkint, &iret); if ( iret < 0 ) { strncpy(nemo2, nemo, 8); From 8fb702f847794e5367c04230d1b81373b82922fd Mon Sep 17 00:00:00 2001 From: Jeff Ator Date: Thu, 29 Aug 2024 19:08:25 +0000 Subject: [PATCH 2/3] add stseq caching for regular replication sequences --- src/CMakeLists.txt | 2 +- src/arallocc.c | 22 ++++----- src/restd.c | 21 ++++---- src/rpseqs.h | 39 +++++++++++++++ src/stseq.c | 120 +++++++++++++++++++++++++++++++++++++++------ 5 files changed, 164 insertions(+), 40 deletions(-) create mode 100644 src/rpseqs.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f65fff2b..75514aa6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,7 +14,7 @@ list(APPEND c_src arallocc.c cpmstabs.c cread.c crwbmg.c cfe.c icvidx.c restd.c stseq.c) list(APPEND c_hdr - cread.h mstabs.h bufr_interface.h bufrlib.h) + cread.h mstabs.h rpseqs.h bufr_interface.h bufrlib.h) # Create the misc.F90 file configure_file(${CMAKE_CURRENT_SOURCE_DIR}/misc.F90.in ${CMAKE_CURRENT_BINARY_DIR}/misc.F90 @ONLY) diff --git a/src/arallocc.c b/src/arallocc.c index 110d5033..2910ff7f 100644 --- a/src/arallocc.c +++ b/src/arallocc.c @@ -10,6 +10,7 @@ #include "cread.h" #include "mstabs.h" +#include "rpseqs.h" /** * Dynamically allocate C language arrays. @@ -42,7 +43,6 @@ arallocc(void) nfiles = igetprm_f("NFILES"); if (!(pb = malloc((nfiles+1) * sizeof(FILE *)))) bort_f(brtstr); - if (!(lstpos = malloc((nfiles+1) * sizeof(fpos_t)))) bort_f(brtstr); /* mstabs arrays */ @@ -53,30 +53,22 @@ arallocc(void) mxnaf = igetprm_f("MXNAF"); if (!(ibfxyn_c = malloc(mxmtbb * sizeof(int)))) bort_f(brtstr); - if (!(cbscl_c = malloc(mxmtbb * 4 * sizeof(char)))) bort_f(brtstr); - if (!(cbsref_c = malloc(mxmtbb * 12 * sizeof(char)))) bort_f(brtstr); - if (!(cbbw_c = malloc(mxmtbb * 4 * sizeof(char)))) bort_f(brtstr); - if (!(cbunit_c = malloc(mxmtbb * 24 * sizeof(char)))) bort_f(brtstr); - if (!(cbmnem_c = malloc(mxmtbb * 8 * sizeof(char)))) bort_f(brtstr); - if (!(cbelem_c = malloc(mxmtbb * 120 * sizeof(char)))) bort_f(brtstr); - if (!(idfxyn_c = malloc(mxmtbd * sizeof(int)))) bort_f(brtstr); - if (!(cdseq_c = malloc(mxmtbd * 120 * sizeof(char)))) bort_f(brtstr); - if (!(cdmnem_c = malloc(mxmtbd * 8 * sizeof(char)))) bort_f(brtstr); - if (!(ndelem_c = malloc(mxmtbd * sizeof(int)))) bort_f(brtstr); - if (!(idefxy_c = malloc(mxmtbd * maxcd * sizeof(int)))) bort_f(brtstr); - if (!(iafpk = malloc(mxnaf * sizeof(int)))) bort_f(brtstr); + + /* rpseqs arrays */ + + if (!(cdescs = malloc(MAX_RPSQ * maxcd * sizeof(int)))) bort_f(brtstr); } /** @@ -109,4 +101,8 @@ ardllocc(void) free( ndelem_c ); free( idefxy_c ); free( iafpk ); + + /* rpseqs arrays */ + + free( cdescs ); } diff --git a/src/restd.c b/src/restd.c index d2a1303d..6116858e 100644 --- a/src/restd.c +++ b/src/restd.c @@ -47,12 +47,12 @@ wrdesc(int desc, int *descary, int *ndescary, int mxdescary) * Standardize a local Table D descriptor. * * Given the bit-wise (integer) representation of a local (not - * WMO-standard) Table D descriptor, this subroutine returns an + * WMO-standard) Table D descriptor, this function returns an * equivalent array of WMO-standard child descriptors. * * Any child descriptors which are themselves local Table D * descriptors are automatically resolved via a recursive call to this - * same subroutine. This recursive process continues until all child + * same function. This recursive process continues until all child * descriptors are either WMO-standard descriptors (from Table B, * Table C, Table D, or replication descriptors) or else are local * Table B descriptors, in which case they are preceded with an @@ -77,6 +77,7 @@ restd(int lun, int tddesc, int *nctddesc, int *ctddesc) int iscl, iref, ibit; char tab, nemo[NEMO_STR_LEN+1], adn[FXY_STR_LEN+1], cunit[UNIT_STR_LEN+1], cwork[31]; + /* ** How many child descriptors does tddesc have? */ @@ -91,7 +92,14 @@ restd(int lun, int tddesc, int *nctddesc, int *ctddesc) */ for ( i = 1; i <= inum; i++ ) { uptdd_f(itbd, lun, i, &desc); - if (! istdesc_f(desc)) { + if ( istdesc_f(desc) ) { + /* + ** desc is a standard Table B, Table D, operator or replicator + ** descriptor, so append it "as is" to the output list. + */ + wrdesc(desc, ctddesc, nctddesc, maxnc); + } + else { /* ** desc is a local descriptor. */ @@ -160,13 +168,6 @@ restd(int lun, int tddesc, int *nctddesc, int *ctddesc) wrdesc(desc, ctddesc, nctddesc, maxnc); } } - else { - /* - ** desc is a standard Table B, Table D, operator or replicator - ** descriptor, so append it "as is" to the output list. - */ - wrdesc(desc, ctddesc, nctddesc, maxnc); - } } return; diff --git a/src/rpseqs.h b/src/rpseqs.h new file mode 100644 index 00000000..4a9fb639 --- /dev/null +++ b/src/rpseqs.h @@ -0,0 +1,39 @@ +/** @file + * @brief Declare variables for internal storage of replication sequences. + * + * These variables are used within functions strrpsq() and srchrpsq() to + * maintain an internal cache of replication sequences generated by function stseq(). + * + * @author J. Ator @date 2024-08-26 + */ + +/** Maximum number of entries in internal replication sequences cache. + * + * Note that this value is constrained by the fact that any new rpidns value would + * have been generated by a previous call to function igettdi(). +*/ +#define MAX_RPSQ 256 + +/** @var nrpsq + * Number of entries in internal replication sequences cache + * + * @var rpidns + * WMO bit-wise representation of FXY number for each entry + * + * @var ncdescs + * Number of child descriptors for each entry + * + * @var cdescs + * Child descriptors for each entry + */ +#ifdef IN_ARALLOCC + int nrpsq; + int rpidns[MAX_RPSQ]; + int ncdescs[MAX_RPSQ]; + int *cdescs; +#else + extern int nrpsq; + extern int rpidns[MAX_RPSQ]; + extern int ncdescs[MAX_RPSQ]; + extern int *cdescs; +#endif diff --git a/src/stseq.c b/src/stseq.c index cba30f01..2af9f8e0 100644 --- a/src/stseq.c +++ b/src/stseq.c @@ -6,6 +6,7 @@ #include "bufrlib.h" #include "mstabs.h" +#include "rpseqs.h" /** * Define a comparison between two integers. @@ -80,15 +81,83 @@ nummtb(int *idn, char *tab, int *ipt) return; } +/** + * Store a new entry in the internal replication sequences cache. + * + * @param rpidn - WMO bit-wise representation of FXY number for replication sequence + * @param maxcd - Maximum number of child descriptors in any replication sequence + * @param ncdesc - Number of child descriptors in replication sequence + * @param cdesc - Child descriptors in replication sequence + * + * @author J. Ator @date 2024-08-26 +*/ +void +strrpsq(int rpidn, int maxcd, int ncdesc, int *cdesc) +{ + int j; + + if ( nrpsq < MAX_RPSQ ) { + rpidns[nrpsq] = rpidn; + ncdescs[nrpsq] = ncdesc; + for ( j = 0; j < ncdesc; j++ ) { + cdescs[icvidx(nrpsq,j,maxcd)] = cdesc[j]; + } + nrpsq++; + } +} + +/** + * Check whether a replication sequence already exists within the internal cache. + * + * Given a replication sequence, this function searches the internal cache to see + * if that sequence already exists in the cache, and if so returns the WMO bit-wise + * representation of the corresponding FXY number. + * + * @param maxcd - Maximum number of child descriptors in any replication sequence + * @param ncdesc - Number of child descriptors in replication sequence + * @param cdesc - Child descriptors in replication sequence + * + * @return - WMO bit-wise representation of FXY number for replication sequence, if + * found in the internal cache + * - -1 = The replication sequence was not found in the internal cache + * + * @author J. Ator @date 2024-08-26 +*/ +int +srchrpsq(int maxcd, int ncdesc, int *cdesc) +{ + int i, j, rpidn; + + rpidn = -1; + + for ( i = 0; i < nrpsq; i++ ) { + if ( ncdesc == ncdescs[i] ) { + for ( j = 0; j < ncdesc; j++ ) { + if ( cdesc[j] != cdescs[icvidx(i,j,maxcd)] ) break; + } + if ( j == ncdesc ) { + /* + ** We made it all the way through the previous loop, so we've found + ** a matching sequence in the cache. + */ + rpidn = rpidns[i]; + break; + } + } + } + + return rpidn; +} + /** * Store information about a Table D descriptor within internal DX BUFR tables. * * Given the WMO bit-wise (integer) representation of a - * Table D descriptor, this subroutine uses the master BUFR tables + * Table D descriptor, this function uses the master BUFR tables * to store all of the necessary information for that descriptor * within the internal DX BUFR tables. Any child descriptors which * are themselves Table D descriptors are automatically resolved via - * a recursive call to this same subroutine. + * a recursive call to this same function. * * @param lun - File ID * @param irepct - Replication sequence counter for the current master table; used internally @@ -106,17 +175,23 @@ void stseq(int lun, int *irepct, int idn, char *nemo, char *cseq, int *cdesc, int ncdesc) { int i, j, nb, nd, ix, iy, iret, nbits; - int rpidn, pkint, ilen, imxcd, imxnf, ipt, *rpdesc; + int rpidn, pkint, ilen, ipt, *rpdesc; char tab, adn[FXY_STR_LEN+1], adn2[FXY_STR_LEN+1], units[10], errstr[129]; char nemo2[NEMO_STR_LEN+1], rpseq[56], card[80], ctmp[4], cblk = ' ', czero = '0'; /* ** The following variable is declared as static so that it automatically initializes - ** to zero and remains unchanged between recursive calls to this subroutine. + ** to zero and remains unchanged between recursive calls to this function. */ static int naf; + /* + ** The following variables are declared as static so that function igetprm_f() doesn't + ** need to be called during every call to this function. + */ + static int imxcd, imxnf; + /* ** Is idn already listed as an entry in the internal Table D? ** If so, then there's no need to proceed any further. @@ -124,6 +199,15 @@ stseq(int lun, int *irepct, int idn, char *nemo, char *cseq, int *cdesc, int ncd numtbd_f(lun, idn, nemo2, NEMO_STR_LEN+1, &tab, &iret); if ( ( iret > 0 ) && ( tab == 'D' ) ) return; + if ( *irepct == 0 ) { + /* + ** Initialize or reset some variables. + */ + imxcd = igetprm_f("MAXCD"); + imxnf = igetprm_f("MXNAF"); + nrpsq = 0; + } + /* ** Start a new Table D entry for idn. */ @@ -135,9 +219,6 @@ stseq(int lun, int *irepct, int idn, char *nemo, char *cseq, int *cdesc, int ncd /* ** Now, go through the list of child descriptors corresponding to idn. */ - imxcd = igetprm_f("MAXCD"); - imxnf = igetprm_f("MXNAF"); - for ( i = 0; i < ncdesc; i++ ) { cadn30_f(cdesc[i], adn, FXY_STR_LEN+1); adn[6] = '\0'; strncpy(ctmp, &adn[1], 2); ctmp[2] = '\0'; @@ -377,27 +458,34 @@ stseq(int lun, int *irepct, int idn, char *nemo, char *cseq, int *cdesc, int ncd } else { /* - ** Store the ix descriptors to be replicated in a local list, then - ** get an FXY value to use with this list and generate a unique - ** mnemonic and description as well. + ** Store the ix descriptors to be replicated in a local list. */ if ( ( rpdesc = malloc( imxcd * sizeof(int) ) ) == NULL ) { sprintf(errstr, "BUFRLIB: STSEQ - UNABLE TO ALLOCATE SPACE" " FOR RPDESC"); bort_f(errstr); } - for ( j = 0; j < ix; j++ ) { rpdesc[j] = cdesc[i+j]; } - rpidn = igettdi_f(lun); + /* + ** Is this list already stored in the internal replication sequences cache? + */ + if ( ( rpidn = srchrpsq(imxcd, ix, rpdesc) ) == -1 ) { + /* + ** No, so get an FXY value to use with this list and generate a unique + ** new mnemonic and description as well. + */ + rpidn = igettdi_f(lun); + strrpsq(rpidn, imxcd, ix, rpdesc); - sprintf(rpseq, "REPLICATION SEQUENCE %.3d", ++(*irepct)); - memset(&rpseq[24], (int) cblk, 31); - sprintf(nemo2, "RPSEQ%.3d", *irepct); + sprintf(rpseq, "REPLICATION SEQUENCE %.3d", ++(*irepct)); + memset(&rpseq[24], (int) cblk, 31); + sprintf(nemo2, "RPSEQ%.3d", *irepct); - stseq(lun, irepct, rpidn, nemo2, rpseq, rpdesc, ix); + stseq(lun, irepct, rpidn, nemo2, rpseq, rpdesc, ix); + } free(rpdesc); From 488799d8b1033b07075e42649dd76598a041e2b5 Mon Sep 17 00:00:00 2001 From: Jeff Ator Date: Fri, 30 Aug 2024 16:12:50 +0000 Subject: [PATCH 3/3] add stseq caching for replication sequences containing associated fields --- .github/workflows/Intel.yml | 2 +- .github/workflows/Linux.yml | 2 +- .github/workflows/MacOS.yml | 2 +- .github/workflows/Spack.yml | 2 +- .github/workflows/developer.yml | 2 +- src/arallocc.c | 6 +++ src/arallocf.F90 | 3 -- src/bufr_interface.F90 | 10 ----- src/bufrlib.h | 1 + src/rpseqs.h | 10 +++++ src/stseq.c | 71 ++++++++++++++++++++++----------- test/intest5.F90 | 2 - 12 files changed, 69 insertions(+), 44 deletions(-) diff --git a/.github/workflows/Intel.yml b/.github/workflows/Intel.yml index 3ebd2c12..e21861e4 100644 --- a/.github/workflows/Intel.yml +++ b/.github/workflows/Intel.yml @@ -54,7 +54,7 @@ jobs: uses: actions/cache@v4 with: path: ~/data - key: data-15 + key: data-16 - name: build run: | diff --git a/.github/workflows/Linux.yml b/.github/workflows/Linux.yml index 2463d22c..972af4af 100644 --- a/.github/workflows/Linux.yml +++ b/.github/workflows/Linux.yml @@ -40,7 +40,7 @@ jobs: uses: actions/cache@v4 with: path: ~/data - key: data-15 + key: data-16 - name: build run: | diff --git a/.github/workflows/MacOS.yml b/.github/workflows/MacOS.yml index 086a187a..ff9a3c1f 100644 --- a/.github/workflows/MacOS.yml +++ b/.github/workflows/MacOS.yml @@ -45,7 +45,7 @@ jobs: uses: actions/cache@v4 with: path: ~/data - key: data-15 + key: data-16 - name: build-bufr run: | diff --git a/.github/workflows/Spack.yml b/.github/workflows/Spack.yml index f557075b..8c0597c9 100644 --- a/.github/workflows/Spack.yml +++ b/.github/workflows/Spack.yml @@ -42,7 +42,7 @@ jobs: uses: actions/cache@v4 with: path: ~/data - key: data-15 + key: data-16 - name: spack-build-and-test run: | diff --git a/.github/workflows/developer.yml b/.github/workflows/developer.yml index 7b8e6243..4aee2fa9 100644 --- a/.github/workflows/developer.yml +++ b/.github/workflows/developer.yml @@ -38,7 +38,7 @@ jobs: uses: actions/cache@v4 with: path: ~/data - key: data-15 + key: data-16 - name: build-docs run: | diff --git a/src/arallocc.c b/src/arallocc.c index 2910ff7f..239cf68f 100644 --- a/src/arallocc.c +++ b/src/arallocc.c @@ -69,6 +69,7 @@ arallocc(void) /* rpseqs arrays */ if (!(cdescs = malloc(MAX_RPSQ * maxcd * sizeof(int)))) bort_f(brtstr); + if (!(iafpks = malloc(MAX_RPSQ * mxnaf * sizeof(int)))) bort_f(brtstr); } /** @@ -105,4 +106,9 @@ ardllocc(void) /* rpseqs arrays */ free( cdescs ); + free( iafpks ); + + /* master Code/Flag table entries */ + + dlloctbf(); } diff --git a/src/arallocf.F90 b/src/arallocf.F90 index 3272da16..0d56070a 100644 --- a/src/arallocf.F90 +++ b/src/arallocf.F90 @@ -905,7 +905,6 @@ subroutine exitbufr use moda_stbfr use moda_s01cm - use moda_tablef ! Close any logical units that are open to the library. @@ -917,8 +916,6 @@ subroutine exitbufr call ardllocf - if ( cdmf == 'Y' ) call dlloctbf_c - ! Reset the library. ns01v = 0 diff --git a/src/bufr_interface.F90 b/src/bufr_interface.F90 index f8ae2449..ff61d985 100644 --- a/src/bufr_interface.F90 +++ b/src/bufr_interface.F90 @@ -75,16 +75,6 @@ subroutine ccbfl_c() bind(C, name='ccbfl') use iso_c_binding end subroutine ccbfl_c - !> @fn bufr_interface::dlloctbf_c::dlloctbf_c() - !> Free all memory allocated via inittbf_c(). - !> - !> Wraps dlloctbf() function. - !> - !> @author J. Ator @date 2017-11-03 - subroutine dlloctbf_c() bind(C, name='dlloctbf') - use iso_c_binding - end subroutine dlloctbf_c - end interface end module bufr_interface diff --git a/src/bufrlib.h b/src/bufrlib.h index 8e8b48da..714b0e35 100644 --- a/src/bufrlib.h +++ b/src/bufrlib.h @@ -18,6 +18,7 @@ void arallocc(void); void ardllocc(void); +void dlloctbf(void); void openrb(int nfile, char *ufile); void openwb(int nfile, char *ufile); void openab(int nfile, char *ufile); diff --git a/src/rpseqs.h b/src/rpseqs.h index 4a9fb639..8498d6fe 100644 --- a/src/rpseqs.h +++ b/src/rpseqs.h @@ -20,6 +20,12 @@ * @var rpidns * WMO bit-wise representation of FXY number for each entry * + * @var nafs + * Number of associated fields in effect for each entry + * + * @var iafpks + * Associated fields in effect for each entry + * * @var ncdescs * Number of child descriptors for each entry * @@ -29,11 +35,15 @@ #ifdef IN_ARALLOCC int nrpsq; int rpidns[MAX_RPSQ]; + int nafs[MAX_RPSQ]; + int *iafpks; int ncdescs[MAX_RPSQ]; int *cdescs; #else extern int nrpsq; extern int rpidns[MAX_RPSQ]; + extern int nafs[MAX_RPSQ]; + extern int *iafpks; extern int ncdescs[MAX_RPSQ]; extern int *cdescs; #endif diff --git a/src/stseq.c b/src/stseq.c index 2af9f8e0..9a397be2 100644 --- a/src/stseq.c +++ b/src/stseq.c @@ -85,6 +85,9 @@ nummtb(int *idn, char *tab, int *ipt) * Store a new entry in the internal replication sequences cache. * * @param rpidn - WMO bit-wise representation of FXY number for replication sequence + * @param maxnf - Maximum number of associated fields in any replication sequence + * @param naf - Number of associated fields in replication sequence + * @param iafpk - Associated fields in replication sequence * @param maxcd - Maximum number of child descriptors in any replication sequence * @param ncdesc - Number of child descriptors in replication sequence * @param cdesc - Child descriptors in replication sequence @@ -92,12 +95,16 @@ nummtb(int *idn, char *tab, int *ipt) * @author J. Ator @date 2024-08-26 */ void -strrpsq(int rpidn, int maxcd, int ncdesc, int *cdesc) +strrpsq(int rpidn, int maxnf, int naf, int *iafpk, int maxcd, int ncdesc, int *cdesc) { int j; if ( nrpsq < MAX_RPSQ ) { rpidns[nrpsq] = rpidn; + nafs[nrpsq] = naf; + for ( j = 0; j < naf; j++ ) { + iafpks[icvidx(nrpsq,j,maxnf)] = iafpk[j]; + } ncdescs[nrpsq] = ncdesc; for ( j = 0; j < ncdesc; j++ ) { cdescs[icvidx(nrpsq,j,maxcd)] = cdesc[j]; @@ -113,6 +120,9 @@ strrpsq(int rpidn, int maxcd, int ncdesc, int *cdesc) * if that sequence already exists in the cache, and if so returns the WMO bit-wise * representation of the corresponding FXY number. * + * @param maxnf - Maximum number of associated fields in any replication sequence + * @param naf - Number of associated fields in replication sequence + * @param iafpk - Associated fields in replication sequence * @param maxcd - Maximum number of child descriptors in any replication sequence * @param ncdesc - Number of child descriptors in replication sequence * @param cdesc - Child descriptors in replication sequence @@ -124,24 +134,28 @@ strrpsq(int rpidn, int maxcd, int ncdesc, int *cdesc) * @author J. Ator @date 2024-08-26 */ int -srchrpsq(int maxcd, int ncdesc, int *cdesc) +srchrpsq(int maxnf, int naf, int *iafpk, int maxcd, int ncdesc, int *cdesc) { int i, j, rpidn; rpidn = -1; for ( i = 0; i < nrpsq; i++ ) { - if ( ncdesc == ncdescs[i] ) { - for ( j = 0; j < ncdesc; j++ ) { - if ( cdesc[j] != cdescs[icvidx(i,j,maxcd)] ) break; + if ( ncdesc == ncdescs[i] && naf == nafs[i] ) { + /* Check whether all of the associated fields match */ + for ( j = 0; j < naf; j++ ) { + if ( iafpk[j] != iafpks[icvidx(i,j,maxnf)] ) break; } - if ( j == ncdesc ) { - /* - ** We made it all the way through the previous loop, so we've found - ** a matching sequence in the cache. - */ - rpidn = rpidns[i]; - break; + if ( j == naf ) { + /* Check whether all of the child descriptors match */ + for ( j = 0; j < ncdesc; j++ ) { + if ( cdesc[j] != cdescs[icvidx(i,j,maxcd)] ) break; + } + if ( j == ncdesc ) { + /* We've found a matching sequence in the cache! */ + rpidn = rpidns[i]; + break; + } } } } @@ -235,19 +249,28 @@ stseq(int lun, int *irepct, int idn, char *nemo, char *cseq, int *cdesc, int ncd if ( naf > 0 ) { /* ** There are associated fields in effect which will modify this - ** descriptor when storing it within the internal Table D. So - ** create a new sequence to store the contents of this descriptor - ** along with its associated fields. + ** descriptor when storing it within the internal Table D. So we can't + ** just store it as is, but it may already exist in the internal + ** replication sequences cache with the same associated fields. */ - rpidn = igettdi_f(lun); + if ( ( rpidn = srchrpsq(imxnf, naf, iafpk, imxcd, ndelem_c[ipt], + &idefxy_c[icvidx(ipt,0,imxcd)] ) ) == -1 ) { + /* + ** We haven't seen this sequence with the same associated fields before, so + ** we'll have to store it using a new FXY value, mnemonic and description. + */ + rpidn = igettdi_f(lun); + strrpsq(rpidn, imxnf, naf, iafpk, imxcd, ndelem_c[ipt], + &idefxy_c[icvidx(ipt,0,imxcd)]); - sprintf(rpseq, "REPLICATION SEQUENCE %.3d", ++(*irepct)); - memset(&rpseq[24], (int) cblk, 31); - sprintf(nemo2, "RPSEQ%.3d", *irepct); + sprintf(rpseq, "REPLICATION SEQUENCE %.3d", ++(*irepct)); + memset(&rpseq[24], (int) cblk, 31); + sprintf(nemo2, "RPSEQ%.3d", *irepct); - stseq(lun, irepct, rpidn, nemo2, rpseq, - &idefxy_c[icvidx(ipt,0,imxcd)], - ndelem_c[ipt]); + stseq(lun, irepct, rpidn, nemo2, rpseq, + &idefxy_c[icvidx(ipt,0,imxcd)], + ndelem_c[ipt]); + } pkint = rpidn; } else { @@ -472,13 +495,13 @@ stseq(int lun, int *irepct, int idn, char *nemo, char *cseq, int *cdesc, int ncd /* ** Is this list already stored in the internal replication sequences cache? */ - if ( ( rpidn = srchrpsq(imxcd, ix, rpdesc) ) == -1 ) { + if ( ( rpidn = srchrpsq(imxnf, naf, iafpk, imxcd, ix, rpdesc) ) == -1 ) { /* ** No, so get an FXY value to use with this list and generate a unique ** new mnemonic and description as well. */ rpidn = igettdi_f(lun); - strrpsq(rpidn, imxcd, ix, rpdesc); + strrpsq(rpidn, imxnf, naf, iafpk, imxcd, ix, rpdesc); sprintf(rpseq, "REPLICATION SEQUENCE %.3d", ++(*irepct)); memset(&rpseq[24], (int) cblk, 31); diff --git a/test/intest5.F90 b/test/intest5.F90 index 38eb6a60..aa1f5b44 100644 --- a/test/intest5.F90 +++ b/test/intest5.F90 @@ -70,8 +70,6 @@ program intest5 if ( ( nlv /= 3 ) .or. ( nint(r8vals(1,1)) /= 7 ) .or. ( nint(r8vals(2,1)) /= 38 ) .or. & ( nint(r8vals(2,2)) /= 61 ) .or. ( nint(r8vals(2,3)) /= 60 ) ) stop 12 - ! Free the memory that was dynamically allocated when reading the code and flag tables. - call dlloctbf_c() close ( 11 ) ! Test ufbinx's openbf/closbf calls.