Exemplo n.º 1
0
/*
   ** NAME
   **   DFdescriptors -- return a list of the data descriptors in the file
   ** USAGE
   **   int DFdescriptors(dfile, ptr, begin, num)
   **   DF *dfile;              IN: pointer to an open DF file
   **   DFdesc ptr[];           IN: pointer to space for the list of DDs
   **   int begin;              IN: starting DD number
   **   int num;                IN: number of entries
   ** RETURNS
   **   number of DDs returned in the list
   ** DESCRIPTION
   **   Fills in a list of all DDs in the file beginning with DD begin and
   **   including a maximum of num entries.  The number of DDs actually entered
   **   into the list is returned.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   ** EXAMPLES
   ** REVISION LOG
 */
int
DFdescriptors(DF * dfile, DFdesc ptr[], int begin, int num)
{
    int         i, ret;
    int32       aid;

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

    aid = Hstartread(DFid, DFTAG_WILDCARD, DFREF_WILDCARD);

    if (aid == FAIL)
      {
          DFerror = (int)HEvalue(1);
          return (-1);
      }

    for (i = 2; i <= begin; i++)
      {
          ret = Hnextread(aid, DFTAG_WILDCARD, DFREF_WILDCARD, DF_CURRENT);
          if (ret == FAIL)
            {
                Hendaccess(aid);
                DFerror = (int)HEvalue(1);
                return (-1);
            }
      }

    Hinquire(aid, NULL, &ptr[0].tag, &ptr[0].ref, &ptr[0].length,
             &ptr[0].offset, NULL, NULL, NULL);

    for (i = 1; i < num; i++)
      {
          ret = Hnextread(aid, DFTAG_WILDCARD, DFREF_WILDCARD, DF_CURRENT);
          if (ret == FAIL)
            {
              Hendaccess(aid);
              return (i);
            }
          Hinquire(aid, NULL, &ptr[i].tag, &ptr[i].ref, &ptr[i].length,
                   &ptr[i].offset, NULL, NULL, NULL);
      }
    Hendaccess(aid);

    return (i);
}
Exemplo n.º 2
0
/*
   ** NAME
   **   DFopen -- open HDF file
   ** USAGE
   **   DF *DFopen(name, acc_mode, ndds)
   **   char* name;             IN: name of file to open
   **   int acc_mode;           IN: DFACC_READ, DFACC_WRITE, DFACC_CREATE,
   **                               DFACC_ALL
   **   int ndds;               IN: number of DDs in a block
   ** RETURNS
   **   DF ptr to open file on success, NULL on failure with DFerror set
   ** DESCRIPTION
   **   Open an HDF file, if it exists.  If file does not exist and write
   **   access requested, create file.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   **   The pointer returned by DFopen is NOT a reference to a DF.  It is
   **   just a place keeper for the new type of file handle.  Any program that
   **   relies on the contents of a DF returned by DFopen must be re-written.
   ** EXAMPLES
   ** REVISION LOG
 */
DF         *
DFopen(char *name, int acc_mode, int ndds)
{
    if (DFIcheck(DFlist) == 0)
      {
          DFerror = DFE_TOOMANY;
          return (NULL);
      }
    else
        DFerror = DFE_NONE;

    DFaccmode = acc_mode | DFACC_READ;
    DFid = Hopen(name, DFaccmode, (int16) ndds);

    if (DFid == -1)
      {
          DFerror = (int)HEvalue(1);
          return (NULL);
      }
    else
      {
          /*
             DFlist = makedf(DFid);
           */
          DFlist = (DF *) & DFid;
          return (DFlist);
      }
}
Exemplo n.º 3
0
/*
   ** NAME
   **   DFputelement -- write an entire data element
   ** USAGE
   **   int DFputelement(dfile, tag, ref, ptr, len)
   **   DF *dfile;              IN: pointer to open DF file
   **   uint16 tag;             IN: tag of data element
   **   uint16 ref;             IN: ref number of data element
   **   char *ptr;              IN: pointer to data element
   **   int32 len;              IN: length of data element
   ** RETURNS
   **   Number of bytes written on success, -1 on failure
   ** DESCRIPTION
   **   Write an entire data element to HDF file.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   ** EXAMPLES
   ** REVISION LOG
 */
int32
DFputelement(DF * dfile, uint16 tag, uint16 ref, char *ptr, int32 len)
{
    if (DFIcheck(dfile) != 0)
      {
          DFerror = DFE_NOTOPEN;
          return (-1);
      }
    else
        DFerror = DFE_NONE;

    /* test
       if (DFelstat == DFEL_RESIDENT) {
       Hputelement(DFid, acc_tag, acc_ref, DFelement, DFelsize);
       HDfree(DFelement);
       DFIclearacc();
       }
       test */

    if (Hputelement(DFid, tag, ref, (unsigned char *) ptr, len) == FAIL)
      {
          DFerror = (int)HEvalue(1);
          return (-1);
      }
    else
        return (Hlength(DFid, tag, ref));
}
Exemplo n.º 4
0
/*
   ** NAME
   **   DFseek -- seek a new position within a data element
   ** USAGE
   **   int32 DFseek(dfile, offset)
   **   DF *dfile;              IN: pointer to open DF file
   **   int32 offset;           IN: offset from beginning of element
   ** RETURNS
   **   offset of actual position seek'ed to from beginning of element
   ** DESCRIPTION
   **   Seek position within element specified by DFaccess.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   ** EXAMPLES
   ** REVISION LOG
 */
int32
DFseek(DF * dfile, int32 offset)
{
    int         ret;

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

    /* assuming no blank space can be forced by seeking past end of element
       and writing more data */
    if (offset > DFelsize)
      {
          DFerror = DFE_BADSEEK;
          return (-1);
      }
    else
      {
          ret = Hseek(DFaid, offset, DF_START);
          if (ret == FAIL)
            {
                DFerror = (int)HEvalue(1);
                return (-1);
            }
          DFelseekpos = offset;
      }

    return (0);
}
Exemplo n.º 5
0
static void hdf_error(const char *filename, int status,
                      const char *sourcefile, int lineno)
{
    fprintf(stderr, "%s:%i: ", sourcefile, lineno);
    fprintf(stderr, "Error reading %s: %s\n", filename, HEstring(HEvalue(1)));
    exit(2);
}
Exemplo n.º 6
0
void coda_hdf4_add_error_message(void)
{
    int error = HEvalue(1);

    if (error != 0)
    {
        coda_add_error_message("[HDF4] %s", HEstring(error));
    }
}
Exemplo n.º 7
0
/* HDF Error Reporting. If there is an HDF error, then print all the
 * errors via CuError and clear the HDF error stack.
 */
void cuerrorreport_hdf() {
	int32 i=0, e;
	const char *estr;

	/* Print all errors stored in the error HDF stack. */
	while ((e = HEvalue(i)) != DFE_NONE) {
		estr = HEstring(e);
		CuError(CU_DRIVER,"HDF reported error(s) - (%s)", estr);
		++i;
	}
	HEclear(); /* Clear the HDF error stack. */
}
Exemplo n.º 8
0
/*
   ** NAME
   **   DFread -- read a portion of a data element
   ** USAGE
   **   int32 DFread(dfile, ptr, len)
   **   DF *dfile;              IN: pointer to open DF file
   **   char *ptr;              IN: pointer to space to read data into
   **   int32 len;              IN: number of bytes to read
   ** RETURNS
   **   number of bytes read on success, -1 on failure
   ** DESCRIPTION
   **   Read bytes from a DF file (part of element specified by DFaccess)
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   **   Space for data is assumed to be pre-allocated.
   ** EXAMPLES
   ** REVISION LOG
 */
int32
DFread(DF * dfile, char *ptr, int32 len)
{
    int32       ret;

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

    DFaid = Hstartread(DFid, acc_tag, acc_ref);
    ret = Hseek(DFaid, DFelseekpos, 0);
    if (ret == FAIL)
      {
          Hendaccess(DFaid);
          DFerror = (int)HEvalue(1);
          return (-1);
      }

    ret = Hread(DFaid, len, (unsigned char *) ptr);
    Hendaccess(DFaid);

    if (ret == FAIL)
      {
          DFerror = (int)HEvalue(1);
          return (-1);
      }
    else
      {
          DFelseekpos += ret;
          return (ret);
      }
}
Exemplo n.º 9
0
/*
   ** NAME
   **   DFdel -- delete a data element
   ** USAGE
   **   int DFdel(dfile, tag, ref)
   **   DF *dfile;              IN: pointer to open DF file
   **   uint16 tag;             IN: tag of element
   **   uint16 ref;             IN: ref number of element
   ** RETURNS
   **   0 on success, -1 on failure
   ** DESCRIPTION
   **   Delete a data element from HDF file.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   **   The data element is not actually deleted; it simply loses its DD.
   ** EXAMPLES
   ** REVISION LOG
 */
int
DFdel(DF * dfile, uint16 tag, uint16 ref)
{
    if (DFIcheck(dfile) != 0)
      {
          DFerror = DFE_NOTOPEN;
          return (-1);
      }
    else
        DFerror = DFE_NONE;

    if (Hdeldd(DFid, tag, ref) != 0)
      {
          DFerror = (int)HEvalue(1);
          return (-1);
      }
    else
        return (0);
}
Exemplo n.º 10
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);
}
Exemplo n.º 11
0
/*
   ** NAME
   **   DFishdf -- is this an HDF file?
   ** USAGE
   **   int DFishdf(filename)
   **   char *filename;         IN: name of file to check
   ** RETURNS
   **   0 if it is an HDF file, -1 if it is not.
   ** DESCRIPTION
   **   Determine whether file is an HDF file.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   ** EXAMPLES
   ** REVISION LOG
 */
int
DFishdf(char *filename)
{
    int32       dummy;

    DFerror = DFE_NONE;

    dummy = Hopen(filename, DFACC_READ, 0);
    if (dummy == -1)
      {
          DFerror = (int)HEvalue(1);
          return (-1);
      }
    else
      {
          Hclose(dummy);
          return (0);
      }
}
Exemplo n.º 12
0
/*
   ** NAME
   **   DFclose -- close HDF file
   ** USAGE
   **   int DFclose(dfile)
   **   DF *dfile;              IN: pointer to an open DF file
   ** RETURNS
   **   0 on success, -1 on failure with DFerror set
   ** DESCRIPTION
   **   Write out updated DDs; close DF file.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   ** EXAMPLES
   ** REVISION LOG
 */
int
DFclose(DF * dfile)
{
    int         ret;

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

    if (DFelstat == DFEL_RESIDENT)
      {
          Hputelement(DFid, acc_tag, acc_ref, (unsigned char *) DFelement, DFelsize);
          HDfree(DFelement);
      }
    else
        Hendaccess(DFaid);

    if (search_stat == DFSRCH_OLD)
      {
          Hendaccess(search_aid);
          search_aid = 0;
      }

    ret = Hclose(DFid);
    if (ret == 0)
      {
          dfile = 0;
          DFlist = (DF *) NULL;
          DFid = 0;
          DFaccmode = 0;
      }
    else
      {
          DFerror = (int)HEvalue(1);
      }

    return (ret);
}
Exemplo n.º 13
0
/*
   ** NAME
   **   DFnewref -- get an unused reference number
   ** USAGE
   **   uint16 DFnewref(dfile)
   **   DF *dfile;              IN: pointer to open DF file
   ** RETURNS
   **   unused reference number, or 0 if no reference numbers are free
   ** DESCRIPTION
   **   Get an unused reference number.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   ** EXAMPLES
   ** REVISION LOG
 */
uint16
DFnewref(DF * dfile)
{
    uint16      ret;

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

    ret = Hnewref(DFid);
    if (ret == 0xffff)
      {
          DFerror = (int)HEvalue(1);
          return (0);
      }

    return (ret);
}
Exemplo n.º 14
0
int
imconv(char *outfile, char *imfile, uint16 compress)
{
    int         ret;
    char       *space;
    FILE       *fp;

    if ((fp = fopen(imfile, "rb")) == NULL)
      {
          printf("Error opening image file\n");
          exit(1);
      }

    if ((space = (char *) HDmalloc((size_t) (xdim * ydim))) == NULL)
      {
          printf("Not enough memory to convert image\n");
          exit(1);
      }

    if ((ret = (int)fread(space, (size_t) xdim, (size_t) ydim, fp)) <= 0)
      {
          printf("Cannot read image file\n");
          fclose(fp);
          exit(1);
      }

    ret = DFR8addimage(outfile, space, xdim, ydim, compress);

    if (ret < 0)
      {
          printf(" Error: %d, in writing image %s\n", HEvalue(1), outfile);
          exit(1);
      }

    HDfree(space);
    fclose(fp);
    return (0);
}
Exemplo n.º 15
0
/*
   ** NAME
   **   DFaccess -- set up a read/write on a data element
   ** USAGE
   **   int DFaccess(dfile, tag, ref, acc_mode)
   **   DF *dfile;              IN: pointer to open HDF file
   **   uint16 tag;             IN: tag of element
   **   uint16 ref;             IN: ref number of element
   **   char *acc_mode;         IN: "r", "w", or "a" (read, write, append)
   ** RETURNS
   **   0 on success, -1 on failure
   ** DESCRIPTION
   **   Set up read or write access on data element.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   **   This function needs to call DFupdate and Hendaccess if there is already
   **   an active access element with a different tag/ref.
   **   Also, set up globals "acc_tag" and "acc_ref" to keep tabs on the data
   **   being referenced, and "in_mem" to keep track of whether the data for
   **   an element to be appended to has been read into memory.
   ** EXAMPLES
   ** REVISION LOG
 */
int
DFaccess(DF * dfile, uint16 tag, uint16 ref, char *acc_mode)
{
    int         accmode;
    /*
       DFdle *ptr;
       int dle_num, index, i;
     */

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

    switch (*acc_mode)
      {
          case 'r':
              accmode = DFACC_READ;
              break;
          case 'w':
              accmode = DFACC_WRITE;
              if (((DFaccmode & DFACC_WRITE) == 0) &&
                  ((DFaccmode & DFACC_CREATE) == 0))
                {
                    DFerror = DFE_BADACC;
                    return (-1);
                }
              break;
          case 'a':
              accmode = DFACC_APPEND;
              if (((DFaccmode & DFACC_WRITE) == 0) &&
                  ((DFaccmode & DFACC_CREATE) == 0))
                {
                    DFerror = DFE_BADACC;
                    return (-1);
                }
              break;
          default:
              DFerror = DFE_BADACC;
              return (-1);
      }

/* test
   if (((tag != acc_tag) || (ref != acc_ref)) || (accmode != DFelaccmode))
   if (DFelstat == DFEL_RESIDENT) {
   Hputelement(DFid, acc_tag, acc_ref, DFelement, DFelsize);
   HDfree(DFelement);
   }
   else
   Hendaccess(DFaid);
   test */

    acc_tag = tag;
    acc_ref = ref;
    DFelaccmode = accmode;
    DFelstat = DFEL_ABSENT;
    DFelseekpos = 0;
    DFelsize = 0;

    switch (*acc_mode)
      {
          case 'r':
              DFelsize = Hlength(DFid, acc_tag, acc_ref);
              if (DFelsize <= 0)
                {
                    DFIclearacc();
                    DFerror = (int)HEvalue(1);
                    return (-1);
                }
              /* test
                 DFaid = Hstartread(DFid, acc_tag, acc_ref);
                 if (DFaid != FAIL) {
                 Hinquire(DFaid, (int32*)NULL, (uint16*)NULL, (uint16*)NULL,
                 &DFelsize, (int32*)NULL, (int32*)NULL,
                 (int32*)NULL, (int32*)NULL);
                 inq_accid(DFaid, &dle_num, &index, &(dfile->up_access));
                 Hendaccess(DFaid);
                 ptr = dfile->list;
                 for (i=0; i<dle_num; i++)
                 ptr = ptr->next;
                 dfile->up_dd = &(ptr->dd[index]);
                 } else {
                 DFIclearacc();
                 DFerror = HEvalue(1);
                 return(-1);
                 }
                 test */
              break;
              /* _maybe_ treat 'w' and 'a' in the same general 'a'-way */
          case 'w':
              DFelsize = Hlength(DFid, acc_tag, acc_ref);
              if (DFelsize == FAIL)
                {
                    DFelsize = 0;
                }
              else
                  DFelstat = DFEL_RESIDENT;
              break;
          case 'a':
              DFelsize = Hlength(DFid, acc_tag, acc_ref);
              if (DFelsize == FAIL)
                {
                    DFIclearacc();
                    DFerror = (int)HEvalue(1);
                    return (-1);
                }
              DFelseekpos = DFelsize;
              break;
      }

    return (0);
}