/***************************************************************

   NBLKPRF.C  Number of Blocks and Profiles

      These are a pair of routines (used by LSTBLOCK) that
      return the number of profiles in the current block,
      and the number of blocks in an open database.

         Header: use_db.h
         Library: use_db_x.h

                        Eric Firing
                        88-03-13

     91/09/18 - JR - Added function BPCMP() for comparing two
                     BLKPRF_INDEX_TYPEs

***************************************************************/

#include "dbinc.h"    /* BLOCK_HDR_TYPE, BLOCK_DIR_HDR_TYPE, DB*(), ... */
#include "use_db.h"   /* BLKPRF_INDEX_TYPE */
/***************************************************************

   get_nprof

      returns the number of profiles in the current block

*/

#if PROTOTYPE_ALLOWED
int get_nprofs(void)
#else
int get_nprofs()
#endif
{
   BLOCK_HDR_TYPE bh;
   int type = BLOCK_HDR, ierr;
   unsigned int n = sizeof(BLOCK_HDR_TYPE);

   DBGET(&type, (char *) &bh, &n, &ierr);
   if (DBERROR(&ierr, "in get_nprof")) return(-1);
   return(bh.dir_nentries);    /* normal exit */
}
/***************************************************************

   get_nblocks

      returns the number of blocks in the database

*/

#if PROTOTYPE_ALLOWED
int get_nblocks(void)
#else
int get_nblocks()
#endif
{
   BLOCK_DIR_HDR_TYPE bdh;
   int type = BLOCK_DIR_HDR, ierr;
   unsigned int n = sizeof(BLOCK_DIR_HDR_TYPE);

   DBGET(&type, (char *) &bdh, &n, &ierr);
   if (DBERROR(&ierr, "in get_nblocks")) return(-1);
   return(bdh.dir_nentries);    /* normal exit */
}
/*-----------------------------------------------------------------------------

   FUNCTION: BPCMP

      It compares two BLKPRF_INDEX_TYPE structures/arrays.

      Note:  This is a block-profile version of TIMCMP but the
             return values have been modified for easier testing =
             signof(bp1 - bp2)

   PARAMETERS:  bp1 = pointer to first block-profile index
                bp2 = pointer to second block-profile index

   RETURNS:  -1 if bp1 < bp2
              0 if bp1 = bp2
              1 if bp1 > bp2

   CALLED FROM:  C, FORTRAN

*/

#if PROTOTYPE_ALLOWED
int BPCMP(BLKPRF_INDEX_TYPE *bp1, BLKPRF_INDEX_TYPE *bp2)
#else
int BPCMP(bp1, bp2)
BLKPRF_INDEX_TYPE *bp1, *bp2;
#endif
{
   if (bp1->block < bp2->block) return(-1);
   if (bp1->block > bp2->block) return(1);
   if (bp1->profile < bp2->profile) return(-1);
   if (bp1->profile > bp2->profile) return(1);
   return(0);
}
