Exemplo n.º 1
0
/*
   ** NAME
   **   DFnumber -- return number of occurrences of given tag in the HDF file
   ** USAGE
   **   DFnumber(dfile, tag)
   **   DF *dfile;              IN: pointer to open DF file
   **   uint16 tag;             IN: tag to count occurrences of
   ** RETURNS
   **   Number of occurrences on success, -1 on failure with DFerror set.
   ** DESCRIPTION
   **   Returns the number of occurrences of the specified tag in the HDF file.
   **   If tag is DFTAG_WILDCARD, all tags are counted.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   ** EXAMPLES
   ** REVISION LOG
 */
int
DFnumber(DF * dfile, uint16 tag)
{
    int         num;

    if (DFIcheck(dfile) != 0)
      {
          DFerror = DFE_NOTOPEN;
          return (-1);
      }
    else
        DFerror = DFE_NONE;

    num = Hnumber(DFid, tag);
    return (num);
}
Exemplo n.º 2
0
Arquivo: dfp.c Projeto: schwehr/hdf4
/*--------------------------------------------------------------------------
 NAME
    DFPnpals -- determine # of palettes in a file
 USAGE
    intn DFPnpals(filename)
        char *filename;         IN: name of HDF file
 RETURNS
    SUCCEED on success, FAIL on failure.
 DESCRIPTION
    Determines the number of unique palettes in a file.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
intn
DFPnpals(const char *filename)
{
  CONSTR(FUNC, "DFPnpals");
  int32       file_id;
  intn        curr_pal;       /* current palette count */
  int32       nip8, nlut;     /* number of IP8s & number of LUTs */
  intn        npals;          /* total number of palettes */
  uint16      find_tag, find_ref;     /* storage for tag/ref pairs found */
  int32       find_off, find_len;     /* storage for offset/lengths of tag/refs found */
  int32      *pal_off;        /* storage for an array of palette offsets */
  intn        i, j;           /* local counting variable */
  intn        ret_value = SUCCEED;

  HEclear();

  /* should use reopen if same file as last time - more efficient */
  if ((file_id = DFPIopen(filename, DFACC_READ)) == FAIL)
    HGOTO_ERROR(DFE_BADOPEN, FAIL);

    /* count number of IPs */
  if ((nip8 = Hnumber(file_id, DFTAG_IP8)) == FAIL)
    {
      ret_value = (HDerr(file_id));
      goto done;
    }

  /* count number of LUTs */
  if ((nlut = Hnumber(file_id, DFTAG_LUT)) == FAIL)
    {
      ret_value = (HDerr(file_id));
      goto done;
    }
  npals = (intn) (nip8 + nlut);

  /* if no palettes just return zero and get out */
  if (npals == 0)
    {
      if (Hclose(file_id) == FAIL)
        {
          ret_value = FAIL;
          goto done;
        }

      ret_value = npals;
      goto done;
    }

  /* Get space to store the palette offsets */
  if ((pal_off = (int32 *) HDmalloc(npals * sizeof(int32))) == NULL)
    HGOTO_ERROR(DFE_NOSPACE, FAIL);

  /* go through the IP8s */
  curr_pal = 0;
  find_tag = find_ref = 0;
  while (Hfind(file_id, DFTAG_IP8, DFREF_WILDCARD, &find_tag, &find_ref, &find_off, &find_len, DF_FORWARD) == SUCCEED)
    {
      pal_off[curr_pal] = find_off;     /* store offset */
      curr_pal++;
    }     /* end while */

  /* go through the LUTs */
  find_tag = find_ref = 0;
  while (Hfind(file_id, DFTAG_LUT, DFREF_WILDCARD, &find_tag, &find_ref, &find_off, &find_len, DF_FORWARD) == SUCCEED)
    {
      pal_off[curr_pal] = find_off;     /* store offset */
      curr_pal++;
    }     /* end while */

  npals = curr_pal;   /* reset the number of palettes we really have */
  for (i = 1; i < curr_pal; i++)
    {     /* go through the palettes looking for duplicates */
      if(pal_off[i]!=(-1))
          for (j = 0; j < i; j++)
            {
              if (pal_off[i] == pal_off[j])
                {
                    npals--;    /* if duplicate found, decrement the number of palettes */
                    pal_off[j]=(-1); /* mark as used, so we don't count it too... */
                } /* end if */
            }   /* end for */
    }     /* end for */

  HDfree(pal_off);   /* free offsets */

  if (Hclose(file_id) == FAIL)
    HGOTO_ERROR(DFE_CANTCLOSE, FAIL);

  ret_value = npals;

done:
  if(ret_value == FAIL)   
    { /* Error condition cleanup */

    } /* end if */

  /* Normal function cleanup */
  return ret_value;
}   /* end DFPnpals() */