Exemple #1
0
int_f
h5dread_vl_real_c ( hid_t_f *dset_id ,  hid_t_f *mem_type_id, hid_t_f *mem_space_id, hid_t_f *file_space_id, hid_t_f *xfer_prp, real_f *buf, hsize_t_f *dims, size_t_f *len)
/******/
{
  int ret_value = -1;
  hid_t c_dset_id;
  hid_t c_mem_type_id;
  hid_t c_mem_space_id;
  hid_t c_file_space_id;
  hid_t c_xfer_prp;
  herr_t status;
  size_t max_len;

  hvl_t *c_buf;
  hsize_t i;
  hssize_t num_elem;

  c_dset_id       = (hid_t)*dset_id;
  c_mem_type_id   = (hid_t)*mem_type_id;
  c_mem_space_id  = (hid_t)*mem_space_id;
  c_file_space_id = (hid_t)*file_space_id;
  c_xfer_prp      = (hid_t)*xfer_prp;

  max_len = (size_t)dims[0];
  num_elem = H5Sget_select_npoints(c_mem_space_id);
  if(num_elem != (hssize_t)dims[1]) return ret_value;

  c_buf = (hvl_t *)HDmalloc((size_t)num_elem * sizeof(hvl_t));
  if (c_buf == NULL) return ret_value;
  /*
   * Call H5Dread function.
   */
   status = H5Dread(c_dset_id, c_mem_type_id, c_mem_space_id, c_file_space_id, c_xfer_prp, c_buf);
 if ( status <0  )  goto DONE;
  for (i=0; i < (hsize_t)num_elem; i++) {
       len[i] = (size_t_f)c_buf[i].len;
       memcpy(&buf[i*max_len], c_buf[i].p, c_buf[i].len*sizeof(real_f));
  }

  H5Dvlen_reclaim(c_mem_type_id, c_mem_space_id, H5P_DEFAULT, c_buf);
  ret_value = 0;
DONE:
  HDfree(c_buf);
  return ret_value;
}
Exemple #2
0
/*-------------------------------------------------------------------------
 * Function: named_datatype_free
 *
 * Purpose: Frees the stack of named datatypes.
 *-------------------------------------------------------------------------
 */
int named_datatype_free(named_dt_t **named_dt_head_p, int ignore_err) {
    named_dt_t *dt = *named_dt_head_p;
    int         ret_value = -1;

    while (dt) {
        /* Pop the datatype off the stack and free it */
        if (H5Tclose(dt->id_out) < 0 && !ignore_err)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
        dt = dt->next;
        HDfree(*named_dt_head_p);
        *named_dt_head_p = dt;
    } /* end while */

    ret_value = 0;

done:
    return (ret_value);
} /* end named_datatype_free */
Exemple #3
0
/****************************************************************
**
**  test_vlstr_free_custom(): Test VL datatype custom memory
**      allocation routines.  This routine just uses free to
**      release the memory and decrements the amount of memory
**      allocated.
**
****************************************************************/
void test_vlstr_free_custom(void *_mem, void *info)
{
    unsigned char *mem;
    size_t *mem_used=(size_t *)info;  /* Get the pointer to the memory used */
    size_t extra;               /* Extra space needed */

    /*
     *  This weird contortion is required on the DEC Alpha to keep the
     *  alignment correct - QAK
     */
    extra=MAX(sizeof(void *),sizeof(size_t));

    if(_mem!=NULL) {
        mem=((unsigned char *)_mem)-extra;
        *mem_used-=*(size_t *)mem;
        HDfree(mem);
    } /* end if */
}
Exemple #4
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Oget_comment_by_name
 * Signature: (JLjava/lang/String;J)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL
Java_hdf_hdf5lib_H5_H5Oget_1comment_1by_1name
    (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_id)
{
    char       *oComment;
    const char *oName;
    ssize_t     buf_size;
    ssize_t     status;
    jstring     str = NULL;

    PIN_JAVA_STRING(name, oName);
    if (oName != NULL) {
        /* get the length of the comment */
        buf_size = H5Oget_comment_by_name((hid_t)loc_id, oName, NULL, 0, (hid_t)access_id);
        if (buf_size < 0) {
            h5badArgument( env, "H5Oget_comment_by_name:  buf_size < 0");
        } /* end if */
        else if (buf_size > 0) {
            buf_size++; /* add extra space for the null terminator */
            oComment = (char *)HDmalloc(sizeof(char) * (size_t)buf_size);
            if (oComment == NULL) {
                h5outOfMemory( env, "H5Oget_comment_by_name:  malloc failed");
            } /* end if */
            else {
                status = H5Oget_comment_by_name((hid_t)loc_id, oName, oComment, (size_t)buf_size, (hid_t)access_id);

                if (status < 0) {
                    h5libraryError(env);
                } /* end if */
                else {
                    /*  may throw OutOfMemoryError */
                    str = ENVPTR->NewStringUTF(ENVPAR oComment);
                    if (str == NULL) {
                        h5JNIFatalError( env, "H5Oget_comment_by_name:  return string not allocated");
                    } /* end if */
                } /* end else */
                HDfree(oComment);
            }
        } /* end if */
        UNPIN_JAVA_STRING(name, oName);
    }

    return (jstring)str;
} /* end Java_hdf_hdf5lib_H5_H5Oget_1comment_1by_1name */
Exemple #5
0
/****if* H5Df/h5dread_ref_reg_c
 * NAME
 *  h5dread_ref_reg_c
 * PURPOSE
 *  Call H5Dread to read a dataset of dataset region references
 * INPUTS
 *  dset_id - dataset identifier
 *  mem_type_id - memory datatype identifier
 *  mem_space_id - memory dataspace identifier
 *  file_space_id - memory dataspace identifier
 *  xfer_pr  - identifier of transfer property list
 *  buf      - data buffer to store references to the objects.
 *  n - number of references to be stored.
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Wednesday, May 15, 2002
 * HISTORY
 *  This function was added to accomodate h5dread_f subroutine
 *  with the dims parameter being of INTEGER(HSIZE_T_F) size.
 * SOURCE
*/
int_f
h5dread_ref_reg_c (hid_t_f *dset_id, hid_t_f *mem_type_id, hid_t_f *mem_space_id, hid_t_f *file_space_id, hid_t_f *xfer_prp, int_f * buf, hsize_t_f *dims)
/******/
{
     int ret_value = -1;
     herr_t ret = -1;
     hid_t c_dset_id;
     hid_t c_mem_type_id;
     hid_t c_mem_space_id;
     hid_t c_file_space_id;
     hid_t c_xfer_prp;
     hdset_reg_ref_t *buf_c = NULL;
     hsize_t i, n;
     n = (hsize_t)*dims;
     /*
      * Define transfer property
      */
     c_xfer_prp = (hid_t)*xfer_prp;

     /*
      * Allocate temporary buffer.
      */
     buf_c = (hdset_reg_ref_t *)HDmalloc(sizeof(hdset_reg_ref_t)*(size_t)n);
     if ( buf_c != NULL ) {
         /*
          * Call H5Dread function.
          */
         c_dset_id = (hid_t)*dset_id;
         c_mem_type_id = (hid_t)*mem_type_id;
         c_mem_space_id = (hid_t)*mem_space_id;
         c_file_space_id = (hid_t)*file_space_id;
         ret = H5Dread(c_dset_id, c_mem_type_id, c_mem_space_id, c_file_space_id, c_xfer_prp, buf_c);
         if (ret >=0) {
            for (i = 0; i < n; i++) {
               HDmemcpy(buf, &buf_c[i], H5R_DSET_REG_REF_BUF_SIZE);
               buf = buf + REF_REG_BUF_LEN_F;
            }
         }
         if ( buf_c != NULL ) HDfree(buf_c);
     }
     if (ret < 0) return ret_value;
     ret_value = 0;
     return ret_value;
}
Exemple #6
0
int
getR8(int xdim, int ydim, char *image, char *pal, int compress)
{
    FILE       *fp;
    int32       length;
    char       *buf;

    if (!fileOpen())
      {
          noFile();
          return FAIL;
      }
    if (pal)
        if (setPal(pal) < 0)
            /* Error already signalled by setPal */
            return FAIL;

    length = xdim * ydim;
    buf = (char *) HDmalloc(length);

    if ((fp = fopen(image, "r")) == NULL)
      {
          fprintf(stderr, "Error opening image file: %s.\n", image);
          return FAIL;
      }
    if (fread(buf, (size_t)xdim, (size_t)ydim, fp) < (size_t)ydim)
      {
          fprintf(stderr, "Error reading image file: %s.\n", image);
          return FAIL;
      }
    fclose(fp);

    if (DFR8addimage(he_file, buf, (int32) xdim, (int32) ydim, (uint16) compress) < 0)
      {
          HEprint(stderr, 0);
          return FAIL;
      }
    HDfree(buf);

    if (updateDesc() < 0)
        return FAIL;

    return HE_OK;
}
/****if* H5Ff/h5fopen_c
 * NAME
 *        h5fopen_c
 * PURPOSE
 *     Call H5Fopen to open the file
 * INPUTS
 *      name - name of the file
 *              namelen - name length
 *              access_flags - file access  flags
 *              acc_prp - identifier of access property list
 * OUTPUTS
 *     file_id - file identifier
 * RETURNS
 *     0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *              Tuesday, August 3, 1999
 * SOURCE
*/
int_f
nh5fopen_c (_fcd name, int_f *namelen, int_f *access_flags, hid_t_f *acc_prp, hid_t_f *file_id)
/******/
{
     int ret_value = -1;
     char *c_name;
     int_f c_namelen;
     hid_t c_file_id;
     unsigned c_access_flags;
     hid_t c_acc_prp;
     c_acc_prp = (hid_t)*acc_prp;

     /*
      * Define access flags
      */
     c_access_flags = (unsigned) *access_flags;

     /*
      * Define access property
      */
     c_acc_prp = *acc_prp;

     /*
      * Convert FORTRAN name to C name
      */
     c_namelen = *namelen;
     c_name = (char *)HD5f2cstring(name, (size_t)c_namelen);
     if(c_name == NULL)
         return ret_value;

     /*
      * Call H5Fopen function.
      */
     c_file_id = H5Fopen(c_name, c_access_flags, c_acc_prp);

     if(c_file_id >= 0) {
         ret_value = 0;
         *file_id = (hid_t_f)c_file_id;
     } /* end if */

     HDfree(c_name);
     return ret_value;
}
Exemple #8
0
int
initFile(char *file)
{
    if (he_file)
        HDfree(he_file);
    he_file = copyStr(file);

    if (updateDesc() < 0)
        return FAIL;

    /* if there are groups in this file, go to the first group tag */
    /* otherwise, just go to the first element */
    if (he_numGrp > 0)
        he_currDesc = he_grp[0].desc;
    else
        he_currDesc = 0;

    return resetPred();
}
Exemple #9
0
int_f
nh5sget_select_elem_pointlist_c( hid_t_f *space_id ,hsize_t_f * startpoint,
                                  hsize_t_f * numpoints, hsize_t_f * buf)
{
  int ret_value = -1;
  hid_t c_space_id;
  hsize_t c_num_points;
  hsize_t c_startpoint,* c_buf;
  hsize_t i, i1;
  int rank;
  int j,i2;

  c_space_id = *space_id;
  c_num_points = (hsize_t)* numpoints;

  rank = H5Sget_simple_extent_ndims(c_space_id);
  if (rank < 0 ) return ret_value;

  c_startpoint = (hsize_t)*startpoint;
  c_buf = (hsize_t*)malloc(sizeof(hsize_t)*(size_t)(c_num_points*rank));
  if (!c_buf) return ret_value;
  ret_value = H5Sget_select_elem_pointlist(c_space_id, c_startpoint,
                                            c_num_points, c_buf);

  /* re-arrange the return buffer to account for Fortran ordering of 2D arrays */
  /* and add 1 to account for array's starting at one in Fortran */
  i2 = 0;
  for( i = 0; i < c_num_points; i++) {
    i1 =  rank*(i+1);
    for(j = 0; j < rank; j++) {
      buf[i2] = (hsize_t_f)(c_buf[i1-1]+1);
      i2 = i2 + 1;
      i1 = i1 - 1;
    }
  }

  if (ret_value  >= 0  ) ret_value = 0;

  HDfree(c_buf);

  return ret_value;
}
Exemple #10
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);
}
Exemple #11
0
/*--------------------------------------------------------------------------
 NAME
    HCIcszip_init -- Initialize a SZIP compressed data element.

 USAGE
    int32 HCIcszip_init(access_rec)
    accrec_t *access_rec;   IN: the access record of the data element

 RETURNS
    Returns SUCCEED or FAIL

 DESCRIPTION
    Common code called by HCIcszip_staccess and HCIcszip_seek

 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
PRIVATE int32
HCIcszip_init(accrec_t * access_rec)
{
    CONSTR(FUNC, "HCIcszip_init");
    compinfo_t *info;           /* special element information */
    comp_coder_szip_info_t *szip_info;    /* ptr to SZIP info */
    intn       ret_value = SUCCEED;

#ifdef H4_HAVE_LIBSZ
    /* Sanity check to make certain that we haven't drifted out of date with
     * the mask options from the SZIP ricehdf.h header */
    assert(H4_SZ_ALLOW_K13_OPTION_MASK==SZ_ALLOW_K13_OPTION_MASK);
    assert(H4_SZ_CHIP_OPTION_MASK==SZ_CHIP_OPTION_MASK);
    assert(H4_SZ_EC_OPTION_MASK==SZ_EC_OPTION_MASK);
    assert(H4_SZ_LSB_OPTION_MASK==SZ_LSB_OPTION_MASK);
    assert(H4_SZ_MSB_OPTION_MASK==SZ_MSB_OPTION_MASK);
    assert(H4_SZ_NN_OPTION_MASK==SZ_NN_OPTION_MASK);
    assert(H4_SZ_RAW_OPTION_MASK==SZ_RAW_OPTION_MASK);
#endif

    info = (compinfo_t *) access_rec->special_info;
    if (Hseek(info->aid, 0, DF_START) == FAIL)  /* seek to beginning of element */
        HGOTO_ERROR(DFE_SEEKERROR, FAIL);

    szip_info = &(info->cinfo.coder_info.szip_info);

    /* Initialize SZIP state information */
    szip_info->szip_state = SZIP_INIT;     /* start in initial state */
    if (szip_info->buffer_size != 0) {
        szip_info->buffer_size = 0;   /* offset into the file */
        if (szip_info->buffer != NULL) {
		HDfree(szip_info->buffer);
		szip_info->buffer = NULL;
        }
    }
    szip_info->offset = 0;   /* offset into the file */
    szip_info->szip_dirty=SZIP_CLEAN;

done:
    return(ret_value);
}   /* end HCIcszip_init() */
Exemple #12
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Oget_comment_by_name
 * Signature: (JLjava/lang/String;J)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL
Java_hdf_hdf5lib_H5_H5Oget_1comment_1by_1name
    (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_id)
{
    const char *objName = NULL;
    jstring     str = NULL;
    ssize_t     buf_size;
    ssize_t     status;
    char       *objComment = NULL;

    UNUSED(clss);

    if (NULL == name)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Oget_comment_by_name: object name is NULL");

    PIN_JAVA_STRING(ENVONLY, name, objName, NULL, "H5Oget_comment_by_name: object name not pinned");

    /* Get the length of the comment */
    if ((buf_size = H5Oget_comment_by_name((hid_t)loc_id, objName, NULL, 0, (hid_t)access_id)) < 0)
        H5_LIBRARY_ERROR(ENVONLY);

    if (buf_size) {
        if (NULL == (objComment = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1)))
            H5_JNI_FATAL_ERROR(ENVONLY, "H5Oget_comment_by_name: failed to allocate buffer for object comment");

        if ((status = H5Oget_comment_by_name((hid_t)loc_id, objName, objComment, (size_t)buf_size + 1, (hid_t)access_id)) < 0)
            H5_LIBRARY_ERROR(ENVONLY);
        objComment[buf_size] = '\0';

        if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, objComment)))
            CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
    }

done:
    if (objComment)
        HDfree(objComment);
    if (objName)
        UNPIN_JAVA_STRING(ENVONLY, name, objName);

    return (jstring)str;
} /* end Java_hdf_hdf5lib_H5_H5Oget_1comment_1by_1name */
Exemple #13
0
/*-------------------------------------------------------------------------
 * Function: symlink_visit_add
 *
 * Purpose: Add an symbolic link to visited data structure
 *
 * Return: 0 on success, -1 on failure
 *
 * Programmer: Neil Fortner, [email protected]
 *             Adapted from trav_addr_add in h5trav.c by Quincey Koziol
 *
 * Date: September 5, 2008
 *
 * Modified: 
 *  Jonathan Kim
 *   - Moved from h5ls.c to share among tools.  (Sep 16, 2010)
 *   - Renamed from elink_trav_add to symlink_visit_add for both soft and 
 *     external links.   (May 25, 2010)
 *   - Add type parameter to distingush between soft and external link for 
 *     sure, which prevent from mixing up visited link when the target names
 *     are same between the soft and external link, as code marks with the
 *     target name.  (May 25,2010) 
 *
 *-------------------------------------------------------------------------
 */
herr_t
symlink_visit_add(symlink_trav_t *visited, H5L_type_t type, const char *file, const char *path)
{
    size_t  idx;         /* Index of address to use */
    void    *tmp_ptr;

    /* Allocate space if necessary */
    if(visited->nused == visited->nalloc) 
    {
        visited->nalloc = MAX(1, visited->nalloc * 2);
        if(NULL == (tmp_ptr = HDrealloc(visited->objs, visited->nalloc * sizeof(visited->objs[0]))))
            return -1;
        visited->objs = tmp_ptr;
    } /* end if */

    /* Append it */
    idx = visited->nused++;

    visited->objs[idx].type = type;
    visited->objs[idx].file = NULL;
    visited->objs[idx].path = NULL;

    if (type == H5L_TYPE_EXTERNAL)
    {
        if(NULL == (visited->objs[idx].file = HDstrdup(file))) 
        {
            visited->nused--;
            return -1;
        }
    }

    if(NULL == (visited->objs[idx].path = HDstrdup(path))) 
    {
        visited->nused--;
        if (visited->objs[idx].file)
            HDfree (visited->objs[idx].file);
        return -1;
    }

    return 0;
} /* end symlink_visit_add() */
Exemple #14
0
/*-------------------------------------------------------------------------
 * Function: symlink_visit_add
 *
 * Purpose: Add an symbolic link to visited data structure
 *
 * Return:   0 on success,
 *          -1 on failure
 *-------------------------------------------------------------------------
 */
herr_t
symlink_visit_add(symlink_trav_t *visited, H5L_type_t type, const char *file, const char *path)
{
    herr_t    ret_value = SUCCEED;
    size_t    idx;         /* Index of address to use */

    /* Allocate space if necessary */
    if(visited->nused == visited->nalloc) {
        void    *tmp_ptr;

        visited->nalloc = MAX(1, visited->nalloc * 2);
        if(NULL == (tmp_ptr = HDrealloc(visited->objs, visited->nalloc * sizeof(symlink_trav_path_t))))
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "visited data structure realloc failed");
        visited->objs = (symlink_trav_path_t *)tmp_ptr;
    } /* end if */

    /* Append it */
    idx = visited->nused++;

    visited->objs[idx].type = type;
    visited->objs[idx].file = NULL;
    visited->objs[idx].path = NULL;

    if(type == H5L_TYPE_EXTERNAL) {
        if(NULL == (visited->objs[idx].file = HDstrdup(file))) {
            visited->nused--;
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "visited data structure name allocation failed");
        } /* end if */
    } /* end if */

    if(NULL == (visited->objs[idx].path = HDstrdup(path))) {
        visited->nused--;
        if(visited->objs[idx].file)
            HDfree (visited->objs[idx].file);
        HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "visited data structure path allocation failed");
    } /* end if */

done:
    return ret_value;
} /* end symlink_visit_add() */
Exemple #15
0
PRIVATE float
find_med(struct box *ptr, int dim)
{
    int         i, j, count, next, prev;
    int        *rank;
    float32     median;

    rank = (int *) HDmalloc((unsigned) ptr->nmbr_distinct * sizeof(int));
    for (i = 0; i < ptr->nmbr_distinct; i++)
        rank[i] = ptr->pts[i];

    sort(0, ptr->nmbr_distinct - 1, dim, rank);
    /*
       for (i=0; i<ptr->nmbr_distinct; i++)
       printf("find_med: sorted list is %d\n",distinct_pt[rank[i]].c[dim]);
     */

    count = 0;
    prev = i = 0;
    while ((i < ptr->nmbr_distinct) && (count < ptr->nmbr_pts / 2))
      {
          next = next_pt(dim, i, rank, ptr->nmbr_distinct);
          for (j = i; j < next; j++)
              count = count + hist[rank[j]];

          prev = i;
          i = next;
      }

    if (prev == 0)
      {
          /* the first distinct point overshot the median */
          median = (float32) distinct_pt[rank[prev]].c[dim] + (float32) EPSILON;
      }
    else
        median = (float32) distinct_pt[rank[prev - 1]].c[dim] + (float32) EPSILON;

    HDfree((VOIDP) rank);
    return median;
}   /* end of find_med */
Exemple #16
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Oget_comment
 * Signature: (J)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL
Java_hdf_hdf5lib_H5_H5Oget_1comment
    (JNIEnv *env, jclass clss, jlong loc_id)
{
    char    *oComment;
    ssize_t  buf_size;
    ssize_t  status;
    jstring  str = NULL;

    /* get the length of the comment */
    buf_size = H5Oget_comment((hid_t)loc_id, NULL, 0);
    if (buf_size < 0) {
        h5badArgument( env, "H5Oget_comment:  buf_size < 0");
    } /* end if */
    else if (buf_size > 0) {
        buf_size++; /* add extra space for the null terminator */
        oComment = (char *)HDmalloc(sizeof(char) * (size_t)buf_size);
        if (oComment == NULL) {
            /* exception -- out of memory */
            h5outOfMemory( env, "H5Oget_comment:  malloc failed");
        } /* end if */
        else {
            status = H5Oget_comment((hid_t)loc_id, oComment, (size_t)buf_size);

            if (status < 0) {
                h5libraryError(env);
            } /* end if */
            else {
                /*  may throw OutOfMemoryError */
                str = ENVPTR->NewStringUTF(ENVPAR oComment);
                if (str == NULL) {
                    h5JNIFatalError( env, "H5Oget_comment:  return string not allocated");
                } /* end if */
            } /* end else */
            HDfree(oComment);
        }
    } /* end else if */

    return (jstring)str;
} /* end Java_hdf_hdf5lib_H5_H5Oget_1comment */
Exemple #17
0
int_f
h5ltread_dataset_c (hid_t_f *loc_id,
                     size_t_f *namelen,
                     _fcd name,
                     hid_t_f *type_id,
                     void *buf)
{
    int     ret_value = -1;
    herr_t  ret;
    hid_t   c_loc_id;
    hid_t   c_type_id;
    char    *c_name = NULL;

    /*
    * convert FORTRAN name to C name
    */
    c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
    if (c_name == NULL)
        goto done;

    /*
    * call H5LTread_dataset function.
    */
    c_loc_id = (hid_t)*loc_id;
    c_type_id = (hid_t)*type_id;

    ret = H5LTread_dataset(c_loc_id, c_name, c_type_id, buf );

    if (ret < 0)
        goto done;

    ret_value = 0;

done:
    if(c_name!=NULL)
        HDfree(c_name);

    return ret_value;
}
Exemple #18
0
int_f
h5ltget_dataset_ndims_c(hid_t_f *loc_id,
                         size_t_f *namelen,
                         _fcd name,
                         int_f *rank)
{
    int     ret_value = -1;
    herr_t  ret;
    hid_t   c_loc_id;
    char    *c_name = NULL;
    int     c_rank;

    /*
    * Convert FORTRAN name to C name
    */
    c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
    if (c_name == NULL)
        goto done;

    /*
    * Call H5LTget_dataset_ndims function.
    */
    c_loc_id = (hid_t)*loc_id;

    ret = H5LTget_dataset_ndims(c_loc_id, c_name, &c_rank);

    if (ret < 0)
        goto done;

    *rank = (int_f)c_rank;
    ret_value = 0;


done:
    if(c_name!=NULL)
        HDfree(c_name);

    return ret_value;
}
/****if* H5Ff/h5fmount_c
 * NAME
 *        h5fmount_c
 * PURPOSE
 *     Call H5Fmount to mount the file
 * INPUTS
 *      loc_id - Identifier for file or group
 *              dsetname - name of dataset
 *              namelen - dsetname length
 *              file_id - file identifier for the file to be mounted
 *              acc_prp - identifier of access property list
 * RETURNS
 *     0 on success, -1 on failure
 * AUTHOR
 *  Xiangyang Su
 *              Monday, October 25, 1999
 * HISTORY
*/
int_f
nh5fmount_c (hid_t_f *loc_id, _fcd dsetname, int_f *namelen, hid_t_f *file_id, hid_t_f *acc_prp)
/******/
{
     int ret_value = -1;
     char *c_name;
     int_f c_namelen;
     hid_t c_loc_id;
     hid_t c_file_id;
     hid_t c_acc_prp;
     htri_t status;

     /*
      * Define access property
      */
     c_acc_prp = *acc_prp;
/*
     if ( H5P_DEFAULT_F == c_acc_prp ) c_acc_prp = H5P_DEFAULT;
*/

     c_loc_id = *loc_id;
     c_file_id = *file_id;
     /*
      * Convert FORTRAN name to C name
      */
     c_namelen = *namelen;
     c_name = (char *)HD5f2cstring(dsetname, (size_t)c_namelen);
     if (c_name == NULL) return ret_value;

     /*
      * Call H5Fmount function.
      */
     status = H5Fmount(c_loc_id, c_name, c_file_id, c_acc_prp);

     if (status >= 0)  ret_value = 0;

     HDfree(c_name);
     return ret_value;
}
Exemple #20
0
/*----------------------------------------------------------------------------
 * Name:        h5adelete_c
 * Purpose:     Call H5Adelete to delete an attribute
 * Inputs:      obj_id - object identifier
 *              name - name of the attribute
 *              namelen - name length
 * Returns:     0 on success, -1 on failure
 * Programmer:  Elena Pourmal
 *              Thursday, August 12, 1999
 * Modifications:
 *---------------------------------------------------------------------------*/
int_f
nh5adelete_c (hid_t_f *obj_id, _fcd name, size_t_f *namelen)
{
    char *c_name=NULL;          /* Buffer to hold C string */
    int_f ret_value=0;          /* Return value */

     /*
      * Convert FORTRAN name to C name
      */
     if ((c_name = HD5f2cstring(name, (size_t)*namelen)) == NULL)
        HGOTO_DONE(FAIL);

     /*
      * Call H5Adelete function.
      */
     if (H5Adelete((hid_t)*obj_id, c_name) < 0)
         HGOTO_DONE(FAIL);

done:
    if(c_name) HDfree(c_name);
    return ret_value;
}
Exemple #21
0
/*----------------------------------------------------------------------------
 * Name:        h5acreate_c
 * Purpose:     Call H5Acreate to create an attribute
 * Inputs:      obj_id - object identifier
 *              name - name of the attribute
 *              namelen - name length
 *              type_id - datatype identifier
 *              space_id - dataspace identifier
 *              crt_pr  - identifier of creation property list
 * Outputs:     attr_id - attribute identifier
 * Returns:     0 on success, -1 on failure
 * Programmer:  Elena Pourmal
 *              Thursday, August 12, 1999
 * Modifications:
 *---------------------------------------------------------------------------*/
int_f
nh5acreate_c (hid_t_f *obj_id, _fcd name, size_t_f *namelen, hid_t_f *type_id, hid_t_f *space_id, hid_t_f *crt_prp,  hid_t_f *attr_id)
{
    char *c_name=NULL;          /* Buffer to hold C string */
    int_f ret_value=0;          /* Return value */

     /*
      * Convert FORTRAN name to C name
      */
    if ((c_name = HD5f2cstring(name, (size_t)*namelen)) == NULL)
        HGOTO_DONE(FAIL);

     /*
      * Call H5Acreate function.
      */
    if((*attr_id = (hid_t_f)H5Acreate((hid_t)*obj_id, c_name, (hid_t)*type_id, (hid_t)*space_id, (hid_t)*crt_prp))<0)
        HGOTO_DONE(FAIL);

done:
    if(c_name) HDfree(c_name);
    return ret_value;
}
Exemple #22
0
/****************************************************************
**
**  test_chksum_large(): Checksum larger buffer
**
****************************************************************/
static void
test_chksum_large(void)
{
    uint8_t *large_buf;         /* Buffer for checksum calculations */
    uint32_t chksum;            /* Checksum value */
    size_t u;                   /* Local index variable */

    /* Allocate the buffer */
    large_buf = (uint8_t *)HDmalloc((size_t)BUF_LEN);
    CHECK_PTR(large_buf, "HDmalloc");

    /* Initialize buffer w/known data */
    for(u = 0; u < BUF_LEN; u++)
        large_buf[u] = (uint8_t)(u * 3);

    /* Buffer w/real data */
    chksum = H5_checksum_fletcher32(large_buf, (size_t)BUF_LEN);
    VERIFY(chksum, 0x85b4e2a, "H5_checksum_fletcher32");

    chksum = H5_checksum_crc(large_buf, (size_t)BUF_LEN);
    VERIFY(chksum, 0xfbd0f7c0, "H5_checksum_crc");

    chksum = H5_checksum_lookup3(large_buf, (size_t)BUF_LEN, 0);
    VERIFY(chksum, 0x1bd2ee7b, "H5_checksum_lookup3");

    /* Buffer w/zero(s) for data */
    HDmemset(large_buf, 0, (size_t)BUF_LEN);
    chksum = H5_checksum_fletcher32(large_buf, (size_t)BUF_LEN);
    VERIFY(chksum, 0, "H5_checksum_fletcher32");

    chksum = H5_checksum_crc(large_buf, (size_t)BUF_LEN);
    VERIFY(chksum, 0xfac8b4c4, "H5_checksum_crc");

    chksum = H5_checksum_lookup3(large_buf, (size_t)BUF_LEN, 0);
    VERIFY(chksum, 0x930c7afc, "H5_checksum_lookup3");

    /* Release memory for buffer */
    HDfree(large_buf);
} /* test_chksum_large() */
Exemple #23
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Pget_elink_prefix
 * Signature: (J[Ljava/lang/String;)J
 */
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix
    (JNIEnv *env, jclass clss, jlong lapl_id, jobjectArray prefix)
{
    ssize_t  prefix_size = -1;
    size_t   size = 0;
    char    *pre = NULL;
    jstring  str = NULL;

    UNUSED(clss);

    if (NULL == prefix)
        H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Pget_elink_prefix: prefix is NULL");

    if ((prefix_size = H5Pget_elink_prefix((hid_t)lapl_id, (char *)NULL, size)) < 0)
        H5_LIBRARY_ERROR(ENVONLY);

    if (NULL == (pre = (char *) HDmalloc(sizeof(char) * (size_t) prefix_size + 1)))
        H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_elink_prefix: memory allocation failed");

    if (H5Pget_elink_prefix((hid_t)lapl_id, (char *)pre, (size_t) prefix_size + 1) < 0)
        H5_LIBRARY_ERROR(ENVONLY);
    pre[prefix_size] = '\0';

    if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, pre))) {
        CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
        H5_JNI_FATAL_ERROR(ENVONLY, "H5Pget_elink_prefix: out of memory - unable to construct string from UTF characters");
    }

    ENVPTR->SetObjectArrayElement(ENVONLY, prefix, 0, str);
    CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);

done:
    if (pre)
        HDfree(pre);

    return (jlong)prefix_size;
} /* end Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix */
Exemple #24
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);
}
Exemple #25
0
PRIVATE     VOID
classify(struct box * ptr, struct box * child)
{
    int         i, j;
    int        *temp;
    int         distinct, total;

    temp = (int *) HDmalloc((unsigned) ptr->nmbr_distinct * sizeof(int));

    distinct = 0;
    total = 0;
    for (i = 0; i < ptr->nmbr_distinct; i++)
      {
          j = ptr->pts[i];
          if ((((float) distinct_pt[j].c[RED] >= child->bnd[RED][LO]) &&
               ((float) distinct_pt[j].c[RED] <= child->bnd[RED][HI])) &&
              (((float) distinct_pt[j].c[GREEN] >= child->bnd[GREEN][LO]) &&
               ((float) distinct_pt[j].c[GREEN] <= child->bnd[GREEN][HI])) &&
              (((float) distinct_pt[j].c[BLUE] >= child->bnd[BLUE][LO]) &&
               ((float) distinct_pt[j].c[BLUE] <= child->bnd[BLUE][HI])))
            {
                /* pt is in new box */
                temp[distinct] = j;
                distinct++;
                total = total + hist[j];
            }   /* end of if */
      }     /* end of for i */

    /* assign points */
    child->nmbr_pts = total;
    child->nmbr_distinct = distinct;
    child->pts = (int *) HDmalloc((unsigned) distinct * sizeof(int));
    for (i = 0; i < distinct; i++)
        child->pts[i] = temp[i];

    HDfree((VOIDP) temp);

}   /* end of classify */
Exemple #26
0
int_f
h5dvlen_get_max_len_c ( hid_t_f *dset_id ,  hid_t_f *type_id, hid_t_f *space_id, size_t_f *len)
/******/
{
  int ret_value = -1;
  size_t c_len;
  hid_t c_dset_id;
  hid_t c_type_id;
  hid_t c_space_id;
  hvl_t *c_buf;
  int i;
  hssize_t num_elem;
  herr_t status;

  c_dset_id = (hid_t)*dset_id;
  c_type_id = (hid_t)*type_id;
  c_space_id = (hid_t)*space_id;

  num_elem = H5Sget_select_npoints(c_space_id);
  if( num_elem < 0) return ret_value;

  c_buf = (hvl_t *)HDmalloc(sizeof(hvl_t)*(size_t)num_elem);
  if (c_buf == NULL) return ret_value;
  status = H5Dread(c_dset_id, c_type_id, H5S_ALL, c_space_id, H5P_DEFAULT, c_buf);
  if(status < 0) goto DONE;

  c_len = 0;
  for (i=0; i < num_elem; i++) c_len = H5_MAX(c_len, c_buf[i].len);
  *len = (size_t_f)c_len;
  H5Dvlen_reclaim(c_type_id, c_space_id, H5P_DEFAULT, c_buf);
  ret_value = 0;

DONE:

  HDfree(c_buf);
  return ret_value;
}
/****if* H5Of/h5oget_comment_c
 * NAME
 *  h5oget_comment_c
 * PURPOSE
 *  Calls  H5Oget_comment
 * INPUTS
 *  object_id  - Identifier for the target object.
 *  bufsize    - Anticipated required size of the comment buffer.
 * OUTPUTS
 *  comment    - The comment.
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  M. Scot Breitenfeld
 *  June 24, 2012
 * SOURCE
*/
int_f
nh5oget_comment_c (hid_t_f *object_id, _fcd comment, size_t_f *commentsize,  hssize_t_f *bufsize)
/******/
{
  char *c_comment = NULL;  /* Buffer to hold C string */
  int_f ret_value = 0;     /* Return value */
  size_t c_commentsize;

  c_commentsize = (size_t)*commentsize + 1;

  /*
   * Allocate buffer to hold comment name
   */
  
  if(NULL == (c_comment = (char *)HDmalloc(c_commentsize)))
    HGOTO_DONE(FAIL);

  /*
   * Call H5Oget_comment function.
   */ 

  if((*bufsize = (hssize_t_f)H5Oget_comment((hid_t)*object_id, c_comment, (size_t)*commentsize)) < 0)
    HGOTO_DONE(FAIL);

  /*
   * Convert C name to FORTRAN and place it in the given buffer
   */
  if(c_comment)
    HD5packFstring(c_comment, _fcdtocp(comment), c_commentsize - 1);
  return ret_value;

 done:
  if(c_comment)
    HDfree(c_comment);

  return ret_value;
}
/*-------------------------------------------------------------------------
 * Function: options_table_init
 *
 * Purpose: init options table
 *
 * Return: 0, ok, -1, fail
 *
 *-------------------------------------------------------------------------
 */
int options_table_init(pack_opttbl_t **tbl) {
	unsigned int i;
	pack_opttbl_t *table;

	if (NULL == (table = (pack_opttbl_t *) HDmalloc(sizeof(pack_opttbl_t)))) {
		error_msg("not enough memory for options table\n");
		return -1;
	}

	table->size = 30;
	table->nelems = 0;
	if (NULL == (table->objs =
			(pack_info_t*) HDmalloc(table->size * sizeof(pack_info_t)))) {
		error_msg("not enough memory for options table\n");
		HDfree(table);
		return -1;
	}

	for (i = 0; i < table->size; i++)
		init_packobject(&table->objs[i]);

	*tbl = table;
	return 0;
}
Exemple #29
0
/****if* H5Of/h5oopen_c
 * NAME
 *  h5oopen_c
 * PURPOSE
 *  Calls H5Oopen
 * INPUTS
 *  loc_id  - File or group identifier
 *  name    - Attribute access property list
 *  namelen - Size of name
 *  lapl_id - Link access property list
 * OUTPUTS
 *  obj_id  - Dataset identifier
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  M. Scot Breitenfeld
 *  April 18, 2008
 * SOURCE
*/
int_f
nh5oopen_c (hid_t_f *loc_id, _fcd name, size_t_f *namelen, hid_t_f *lapl_id, hid_t_f *obj_id)
/******/
{
  char *c_name = NULL;          /* Buffer to hold C string */
  int_f ret_value = 0;          /* Return value */

  /*
   * Convert FORTRAN name to C name
   */
  if((c_name = HD5f2cstring(name, (size_t)*namelen)) == NULL)
    HGOTO_DONE(FAIL);

  /*
   * Call H5Oopen function.
   */
  if((*obj_id = (hid_t_f)H5Oopen((hid_t)*loc_id, c_name, (hid_t)*lapl_id)) < 0)
    HGOTO_DONE(FAIL);

 done:
  if(c_name)
    HDfree(c_name);
  return ret_value;
}
Exemple #30
0
int_f
nh5sselect_elements_c ( hid_t_f *space_id , int_f *op, size_t_f *nelements,  hsize_t_f *coord)
{
  int ret_value = -1;
  hid_t c_space_id;
  H5S_seloper_t c_op;
  herr_t  status;
  int rank;
  int i, j;
  hsize_t *c_coord;
  size_t c_nelements;
/*
  if (*op != H5S_SELECT_SET_F) return ret_value;
*/
/*   if (*op != H5S_SELECT_SET) return ret_value; */
/*   c_op =  H5S_SELECT_SET; */

  c_op = (H5S_seloper_t)*op;

  c_space_id = *space_id;
  rank = H5Sget_simple_extent_ndims(c_space_id);

  c_coord = malloc(sizeof(hsize_t)*rank*(*nelements));
  if(!c_coord) return ret_value;
  for (i=0; i< *nelements; i++) {
      for (j = 0; j < rank; j++) {
          c_coord[j+i*rank] = (hsize_t)coord[j + i*rank];
      }
  }

  c_nelements = *nelements;
  status = H5Sselect_elements(c_space_id, c_op, c_nelements, c_coord);
  if ( status >= 0  ) ret_value = 0;
  HDfree(c_coord);
  return ret_value;
}