/****if* H5If/h5iget_name_c * NAME * h5iget_name_c * PURPOSE * Call H5Iget_name to get object's name * INPUTS * obj_id - object identifier * buf_size - size of the buffer * OUTPUTS * buf - buffer to hold the name * RETURNS * length of the name on success, -1 on failure * AUTHOR * Elena Pourmal * Wednesday, March 12, 2003 * HISTORY * * Changed the size of c_buf_size to c_buf_size + 1, which * fixes the problem of truncating the string by 1 if the * exact size of the string (buf_size) is passed in. * M. Scot Breitenfeld, April 21, 2008 * SOURCE */ int_f h5iget_name_c(hid_t_f *obj_id, _fcd buf, size_t_f *buf_size, size_t_f *name_size) /******/ { int ret_value = -1; hid_t c_obj_id; ssize_t c_size; size_t c_buf_size; char *c_buf =NULL; /* * Allocate buffer to hold name of an object */ c_buf_size = (size_t)*buf_size +1; c_buf = (char *)HDmalloc(c_buf_size); if (c_buf == NULL) return ret_value; /* * Call H5IAget_name function */ c_obj_id = (hid_t)*obj_id; c_size = H5Iget_name(c_obj_id, c_buf, c_buf_size); if (c_size < 0) goto DONE; /* * Convert C name to FORTRAN and place it in the given buffer */ HD5packFstring(c_buf, _fcdtocp(buf), c_buf_size-1); *name_size = (size_t_f)c_size; ret_value = 0; DONE: HDfree(c_buf); return ret_value; }
/*---------------------------------------------------------------------------- * Name: h5aget_name_c * Purpose: Call H5Aget_name to get attribute's name * Inputs: attr_id - attribute identifier * bufsize -size of the buffer * Outputs: buf - buffer to hold the name * Returns: 0 on success, -1 on failure * Programmer: Elena Pourmal * Thursday, August 12, 1999 * Modifications: *---------------------------------------------------------------------------*/ int_f nh5aget_name_c(hid_t_f *attr_id, size_t_f *bufsize, _fcd buf) { char *c_buf=NULL; /* Buffer to hold C string */ int_f ret_value=0; /* Return value */ /* * Allocate buffer to hold name of an attribute */ if ((c_buf = HDmalloc((size_t)*bufsize +1)) == NULL) HGOTO_DONE(FAIL); /* * Call H5Aget_name function */ if ((ret_value = (int_f)H5Aget_name((hid_t)*attr_id, (size_t)*bufsize, c_buf)) < 0) HGOTO_DONE(FAIL); /* * Convert C name to FORTRAN and place it in the given buffer */ HD5packFstring(c_buf, _fcdtocp(buf), (size_t)*bufsize); done: if(c_buf) HDfree(c_buf); return ret_value; }
/****if* H5Ff/h5fget_name_c * NAME * h5fget_name_c * PURPOSE * Call H5Fget_name to get file's name * INPUTS * obj_id - object identifier * buflen -size of the buffer * OUTPUTS * buf - buffer to hold the name * size - size of the file's name * RETURNS * 0 on success, -1 on failure * AUTHOR * Elena Pourmal * Tuesday, July 6, 2004 * SOURCE */ int_f nh5fget_name_c(hid_t_f *obj_id, size_t_f *size, _fcd buf, size_t_f *buflen) /******/ { char *c_buf = NULL; /* Buffer to hold C string */ ssize_t size_c = -1; int_f ret_value = 0; /* Return value */ /* * Allocate buffer to hold name of an attribute */ if(NULL == (c_buf = (char *)HDmalloc((size_t)*buflen + 1))) HGOTO_DONE(FAIL); /* * Call H5Fget_name function */ if ((size_c = H5Fget_name((hid_t)*obj_id, c_buf, (size_t)*buflen)) < 0) HGOTO_DONE(FAIL); /* * Convert C name to FORTRAN and place it in the given buffer */ HD5packFstring(c_buf, _fcdtocp(buf), (size_t)*buflen); done: *size = (size_t_f)size_c; if(c_buf) HDfree(c_buf); return ret_value; }
/*---------------------------------------------------------------------------- * Name: h5_fixname_c * Purpose: Call h5_fixname to modify file name * Inputs: base_name - name of the file * base_namelen - name length * fapl - file access property list * full_name - buffer to return full name * full_namelen - name length * Returns: 0 on success, -1 on failure * Programmer: Elena Pourmal * Friday, September 13, 2002 * Modifications: *---------------------------------------------------------------------------*/ int_f nh5_fixname_c(_fcd base_name, size_t_f *base_namelen, hid_t_f* fapl, _fcd full_name, size_t_f *full_namelen) { int ret_value = -1; char *c_base_name; char *c_full_name; hid_t c_fapl; /* * Define ifile access property list */ c_fapl = (hid_t)*fapl; /* * Convert FORTRAN name to C name */ c_base_name = (char *)HD5f2cstring(base_name, (size_t)*base_namelen); if (c_base_name == NULL) goto DONE; c_full_name = (char *) HDmalloc((size_t)*full_namelen + 1); if (c_full_name == NULL) goto DONE; /* * Call h5_fixname function. */ if (NULL != h5_fixname(c_base_name, c_fapl, c_full_name, (size_t)*full_namelen + 1)) { HD5packFstring(c_full_name, _fcdtocp(full_name), (size_t)*full_namelen); ret_value = 0; goto DONE; } DONE: if (NULL != c_base_name) HDfree(c_base_name); if (NULL != c_full_name) HDfree(c_full_name); return ret_value; }
int_f h5dread_vl_string_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, _fcd 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; char *tmp, *tmp_p; size_t max_len; char **c_buf; hsize_t i; hsize_t num_elem; max_len = (size_t)dims[0]; num_elem = (hsize_t)dims[1]; 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; /* * Allocate array of character pointers */ c_buf = (char **)HDmalloc((size_t)num_elem * sizeof(char *)); 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) { HDfree(c_buf); return ret_value; } /* Copy data to long C string */ tmp = (char *)HDmalloc((size_t)(max_len*num_elem) +1); tmp_p = tmp; for (i=0; i<max_len*num_elem; i++) tmp[i] = ' '; tmp[max_len*num_elem] = '\0'; for (i=0; i < num_elem; i++) { memcpy(tmp_p, c_buf[i], strlen(c_buf[i])); len[i] = (size_t_f)strlen(c_buf[i]); tmp_p = tmp_p + max_len; } HD5packFstring(tmp, _fcdtocp(buf), (size_t)(max_len*num_elem)); ret_value = 0; H5Dvlen_reclaim(c_mem_type_id, c_mem_space_id, H5P_DEFAULT, c_buf); HDfree(c_buf); HDfree(tmp); return ret_value; }
int_f h5ltget_attribute_string_c(hid_t_f *loc_id, size_t_f *namelen, _fcd dsetname, size_t_f *attrnamelen, _fcd attrname, _fcd buf, size_t_f *buf_size) { int ret_value = -1; herr_t ret; char *c_name = NULL; char *c_attrname = NULL; char *c_buf = NULL; /* * Convert FORTRAN name to C name */ c_name = (char *)HD5f2cstring(dsetname, (size_t)*namelen); if (c_name == NULL) goto done; c_attrname = (char *)HD5f2cstring(attrname, (size_t)*attrnamelen); if (c_attrname == NULL) goto done; /* * Allocate buffer to hold C attribute string */ if ((c_buf = (char *)HDmalloc((size_t)*buf_size + 1)) == NULL) goto done; /* * Call H5LTget_attribute_int function. */ ret = H5LTget_attribute_string((hid_t)*loc_id,c_name,c_attrname,c_buf); if (ret < 0) goto done; /* * Convert C name to FORTRAN and place it in the given buffer */ HD5packFstring(c_buf, _fcdtocp(buf), (size_t)*buf_size); ret_value = 0; done: if(c_name!=NULL) HDfree(c_name); if(c_attrname!=NULL) HDfree(c_attrname); if(c_buf!=NULL) HDfree(c_buf); return ret_value; }
/****if* H5Of/h5oget_comment_by_name_c * NAME * h5oget_comment_by_name_c * PURPOSE * Calls H5Oget_comment_by_name * 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 * July 6, 2012 * SOURCE */ int_f nh5oget_comment_by_name_c (hid_t_f *loc_id, _fcd name, size_t_f *name_size, _fcd comment, size_t_f *commentsize, size_t_f *bufsize, hid_t_f *lapl_id) /******/ { char *c_comment = NULL; /* Buffer to hold C string */ char *c_name = NULL; /* Buffer to hold C string */ int_f ret_value = 0; /* Return value */ ssize_t c_bufsize; size_t c_commentsize; /* * Convert FORTRAN string to C string */ if((c_name = HD5f2cstring(name, (size_t)*name_size)) == NULL) HGOTO_DONE(FAIL); 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_by_name function. */ if((c_bufsize = H5Oget_comment_by_name((hid_t)*loc_id, c_name, c_comment, (size_t)*commentsize,(hid_t)*lapl_id )) < 0) HGOTO_DONE(FAIL); *bufsize = (size_t_f)c_bufsize; /* * 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); if(c_name) HDfree(c_name); 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: h5tbget_field_info_c * * Purpose: Call H5TBget_field_info * * Return: Success: 0, Failure: -1 * * Programmer: [email protected] * * Date: October 13, 2004 * * Comments: * * Modifications: * * *------------------------------------------------------------------------- */ int_f nh5tbget_field_info_c(hid_t_f *loc_id, int_f *namelen, _fcd name, hsize_t_f *nfields, size_t_f *field_sizes, size_t_f *field_offsets, size_t_f *type_size, int_f *namelen2, /* field_names lenghts */ _fcd field_names) /* field_names */ { int ret_value = -1; herr_t ret; char *c_name; int c_namelen; hsize_t num_elem; hsize_t i; int max_len=1; hid_t c_loc_id = *loc_id; hsize_t c_nfields = *nfields; size_t *c_field_sizes; size_t *c_field_offsets; size_t c_type_size; char **c_field_names; char *tmp, *tmp_p; int c_lenmax=HLTB_MAX_FIELD_LEN; size_t length = 0; num_elem = c_nfields; for (i=0; i < num_elem; i++) { if (namelen2[i] > max_len) max_len = namelen2[i]; } /* * Convert FORTRAN name to C name */ c_namelen = *namelen; c_name = (char *)HD5f2cstring(name, c_namelen); if (c_name == NULL) return ret_value; c_field_offsets = (size_t*)malloc(sizeof(size_t) * (size_t)c_nfields); if (!c_field_offsets) return ret_value; c_field_sizes = (size_t*)malloc(sizeof(size_t) * (size_t)c_nfields); if (!c_field_sizes) return ret_value; c_field_names = malloc( sizeof(char*) * (size_t)c_nfields ); if (!c_field_names) return ret_value; for ( i = 0; i < c_nfields; i++) { c_field_names[i] = malloc( sizeof(char) * HLTB_MAX_FIELD_LEN ); } /* * Call H5TBget_field_info function. */ ret = H5TBget_field_info(c_loc_id,c_name,c_field_names,c_field_sizes,c_field_offsets, &c_type_size); /* return values*/ /* names array */ tmp = (char *)malloc(c_lenmax* (size_t) c_nfields + 1); tmp_p = tmp; memset(tmp,' ', c_lenmax* (size_t) c_nfields); tmp[c_lenmax*c_nfields] = '\0'; for (i=0; i < c_nfields; i++) { memcpy(tmp_p, c_field_names[i], strlen(c_field_names[i])); namelen2[i] = (int_f)strlen(c_field_names[i]); length = MAX(length, strlen(c_field_names[i])); tmp_p = tmp_p + c_lenmax; } HD5packFstring(tmp, _fcdtocp(field_names), (int)(c_lenmax*c_nfields)); *type_size = (size_t_f)c_type_size; for (i=0; i < num_elem; i++) { field_sizes[i] = (size_t_f)c_field_sizes[i]; field_offsets[i] = (size_t_f)c_field_offsets[i]; } /* free */ for (i=0; i < num_elem; i++) { free (c_field_names[i]); } free(c_field_names); free(tmp); free(c_field_offsets); free(c_field_sizes); if (ret < 0) return ret_value; ret_value = 0; return ret_value; }