示例#1
0
文件: dfp.c 项目: schwehr/hdf4
/*--------------------------------------------------------------------------
 NAME
    DFPputpal -- Write palette to file
 USAGE
    intn DFPputpal(filename,palette,overwrite,filemode)
        char *filename;         IN: name of HDF file
        void * palette;          IN: ptr to the buffer retrieve the palette from
        intn overwrite;         IN: whether to (1) overwrite last palette written,
                                    or (0) write it as a fresh palette
        char *filemode;         IN: if "a" append palette to file, "w" create
                                    new file
 RETURNS
    SUCCEED on success, FAIL on failure.
 DESCRIPTION
    Stores a palette in an HDF file, with options for creating new file or appending,
    and overwriting last palette written.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    To overwrite, the filename must be the same as for the previous call.
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
intn
DFPputpal(const char *filename, const void * palette, intn overwrite, const char *filemode)
{
  CONSTR(FUNC, "DFPputpal");
  int32       file_id;
  intn        ret_value = SUCCEED;

  HEclear();

  if (!palette)
    HGOTO_ERROR(DFE_ARGS, FAIL);

  if (overwrite && HDstrcmp(filename, Lastfile))
    HGOTO_ERROR(DFE_BADCALL, FAIL);

  file_id = DFPIopen(filename, (*filemode == 'w') ? DFACC_CREATE : DFACC_WRITE);
  if (file_id == FAIL)
    HGOTO_ERROR(DFE_BADOPEN, FAIL);

    /* if we want to overwrite, Lastref is the ref to write.  If not, if
       Writeref is set, we use that ref.  If not we get a fresh ref. The
       ref to write is placed in Lastref */
  if (!overwrite)
    Lastref = (uint16) (Writeref ? Writeref : Htagnewref(file_id,DFTAG_IP8));
  if (Lastref == 0)
    HGOTO_ERROR(DFE_NOREF, FAIL);

  Writeref = 0;   /* don't know ref to write after this */

  /* write out palette */
  if (Hputelement(file_id, DFTAG_IP8, Lastref, (const uint8 *) palette, (int32) 768) < 0)
    {
      ret_value = (HDerr(file_id));
      goto done;
    }

    /* Check for the tag/ref before creating it willy-nilly */
  if(Hexist(file_id,DFTAG_LUT,Lastref)==FAIL)
    Hdupdd(file_id, DFTAG_LUT, Lastref, DFTAG_IP8, Lastref);

  ret_value = (Hclose(file_id)); 

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

    } /* end if */

  /* Normal function cleanup */
  return ret_value;
}   /* end DFPputpal() */
示例#2
0
/*
   ** NAME
   **   DFdup -- create an additional descriptor for a data element
   ** USAGE
   **   int DFdup(dfile, itag, iref, otag, oref)
   **   DF *dfile;              IN: pointer to open DF file
   **   uint16 itag;            IN: new tag of data element
   **   uint16 iref;            IN: new ref number of data element
   **   uint16 otag;            IN: current tag of data element
   **   uint16 oref;            IN: current ref number of data element
   ** RETURNS
   **   0 on success, -1 on failure
   ** DESCRIPTION
   **   Add a new tag/ref for existing data.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   ** EXAMPLES
   ** REVISION LOG
 */
int
DFdup(DF * dfile, uint16 itag, uint16 iref, uint16 otag, uint16 oref)
{
    if (DFIcheck(dfile) != 0)
      {
          DFerror = DFE_NOTOPEN;
          return (-1);
      }
    else
        DFerror = DFE_NONE;

    if (Hdupdd(DFid, itag, iref, otag, oref) != SUCCEED)
      {
          DFerror = (int)HEvalue(1);
          return (-1);
      }
    else
        return (0);
}