diff options
author | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2011-03-06 22:20:56 (GMT) |
---|---|---|
committer | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2011-03-06 22:20:56 (GMT) |
commit | 86f15d4a3326979f8a0b3898a0b7eccc453a6d38 (patch) | |
tree | 871143b399ffd612e6dc96fe56644e87d4b22481 /hl/fortran/src/H5TBfc.c | |
parent | 0619b155aaaa2ca002bcbadba081c137d9554d24 (diff) | |
download | hdf5-86f15d4a3326979f8a0b3898a0b7eccc453a6d38.zip hdf5-86f15d4a3326979f8a0b3898a0b7eccc453a6d38.tar.gz hdf5-86f15d4a3326979f8a0b3898a0b7eccc453a6d38.tar.bz2 |
[svn-r20192] Description: Bug 1939: h5tbget_field_info_f
* Fixed error in passing an array of characters with different length
field names for h5tbmake_table.
* Fixed error in h5tget_field_info_f with packing the C strings
into a fortran array of strings.
* Added optional arguement to h5tbget_field_info_f called maxlen
which returns the maximum string character length in a field name
element.
* Uncommented out test for h5tbget_field_info_f in the test program
and added additional checks for the output.
Tested: jam (intel and gnu compilers)
Diffstat (limited to 'hl/fortran/src/H5TBfc.c')
-rwxr-xr-x | hl/fortran/src/H5TBfc.c | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/hl/fortran/src/H5TBfc.c b/hl/fortran/src/H5TBfc.c index 76a3f1c..891f387 100755 --- a/hl/fortran/src/H5TBfc.c +++ b/hl/fortran/src/H5TBfc.c @@ -13,6 +13,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#include <math.h> + /* This files contains C stubs for H5D Fortran APIs */ #include "H5TBprivate.h" @@ -47,25 +49,22 @@ nh5tbmake_table_c(int_f *namelen1, hid_t_f *field_types, hsize_t_f *chunk_size, int_f *compress, - int_f *namelen2, /* field_names lenghts */ - _fcd field_names) /* field_names */ + int_f *char_len_field_names, /* field_names lenghts */ + int_f *max_char_size_field_names, /* char len of fields */ + char *field_names) /* field_names */ { char *c_name = NULL; char *c_name1 = NULL; hsize_t num_elem; hsize_t i; - int max_len = 1; hsize_t c_nfields = (hsize_t)*nfields; size_t *c_field_offset = NULL; hid_t *c_field_types = NULL; char **c_field_names = NULL; - char *tmp = NULL, *tmp_p; + char *tmp = NULL; int_f ret_value = 0; num_elem = *nfields; - for(i = 0; i < num_elem; i++) - if(namelen2[i] > max_len) - max_len = namelen2[i]; /* * convert FORTRAN name to C name @@ -91,20 +90,18 @@ nh5tbmake_table_c(int_f *namelen1, HGOTO_DONE(FAIL) /* copy data to long C string */ - if(NULL == (tmp = (char *)HD5f2cstring(field_names, (size_t)(max_len * num_elem)))) + if(NULL == (tmp = (char *)HD5f2cstring(field_names, (size_t)*(max_char_size_field_names)*(size_t)num_elem))) HGOTO_DONE(FAIL) - /* * move data from temorary buffer */ - tmp_p = tmp; for(i = 0; i < num_elem; i++) { - if(NULL == (c_field_names[i] = (char *)HDmalloc((size_t)namelen2[i] + 1))) + if(NULL == (c_field_names[i] = (char *)HDmalloc((size_t)char_len_field_names[i] + 1))) HGOTO_DONE(FAIL) + HDmemcpy(c_field_names[i], tmp, (size_t)char_len_field_names[i]); + c_field_names[i][char_len_field_names[i]] = '\0'; - HDmemcpy(c_field_names[i], tmp_p, (size_t)namelen2[i]); - c_field_names[i][namelen2[i]] = '\0'; - tmp_p = tmp_p + max_len; + tmp = tmp + *max_char_size_field_names; } /* end for */ /* @@ -125,10 +122,7 @@ done: if(c_field_names[i]) HDfree(c_field_names[i]); } /* end for */ - HDfree(c_field_names); } /* end if */ - if(tmp) - HDfree(tmp); if(c_field_offset) HDfree(c_field_offset); if(c_field_types) @@ -616,10 +610,10 @@ nh5tbinsert_field_c(hid_t_f *loc_id, HGOTO_DONE(FAIL) if(NULL == (c_name1 = (char *)HD5f2cstring(field_name, (size_t)*namelen1))) HGOTO_DONE(FAIL) - /* * call H5TBinsert_field function. */ + if(H5TBinsert_field((hid_t)*loc_id, c_name, c_name1, (hid_t)*field_type, (hsize_t)*position, NULL, buf) < 0) HGOTO_DONE(FAIL) @@ -771,13 +765,14 @@ nh5tbget_table_info_c(hid_t_f *loc_id, if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen))) HGOTO_DONE(FAIL) + /* * call H5TBread_fields_index function. */ + if(H5TBget_table_info((hid_t)*loc_id, c_name, &c_nfields, &c_nrecords) < 0) HGOTO_DONE(FAIL) - - *nfields = (hsize_t_f) c_nfields;; + *nfields = (hsize_t_f) c_nfields; *nrecords = (hsize_t_f) c_nrecords; done: @@ -811,26 +806,27 @@ nh5tbget_field_info_c(hid_t_f *loc_id, size_t_f *field_offsets, size_t_f *type_size, int_f *namelen2, /* field_names lenghts */ - _fcd field_names) /* field_names */ + int_f *lenmax, /* character len max */ + _fcd field_names, /* field_names */ + int_f *maxlen_out) { char *c_name = NULL; hsize_t num_elem; - int max_len = 1; hsize_t c_nfields = *nfields; size_t *c_field_sizes = NULL; size_t *c_field_offsets = NULL; size_t c_type_size; char **c_field_names = NULL; char *tmp = NULL, *tmp_p; - int c_lenmax = HLTB_MAX_FIELD_LEN; hsize_t i; int_f ret_value = 0; + size_t c_lenmax; + size_t length = 0; + + c_lenmax = (size_t)*lenmax; 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 @@ -854,24 +850,25 @@ nh5tbget_field_info_c(hid_t_f *loc_id, if(H5TBget_field_info((hid_t)*loc_id, c_name, c_field_names, c_field_sizes, c_field_offsets, &c_type_size) < 0) HGOTO_DONE(FAIL) - + /* return values */ /* names array */ if(NULL == (tmp = (char *)HDmalloc((c_lenmax * (size_t)c_nfields) + 1))) HGOTO_DONE(FAIL) - tmp_p = tmp; HDmemset(tmp, ' ', c_lenmax * (size_t)c_nfields); tmp[c_lenmax * c_nfields] = '\0'; for(i = 0; i < c_nfields; i++) { - size_t field_name_len = HDstrlen(c_field_names[i]); + size_t field_name_len = HDstrlen(c_field_names[i]); - HDmemcpy(tmp_p, c_field_names[i], field_name_len); - namelen2[i] = (int_f)field_name_len; - tmp_p += c_lenmax; + HDmemcpy(tmp_p, c_field_names[i], field_name_len); + namelen2[i] = (int_f)field_name_len; + length = MAX(length, strlen((c_field_names[i]))); + tmp_p = tmp_p + c_lenmax; } /* end for */ - HD5packFstring(tmp, _fcdtocp(field_names), (int)(c_lenmax * c_nfields)); + + HD5packFstring(tmp, _fcdtocp(field_names), (size_t)( c_lenmax* c_nfields)); *type_size = (size_t_f)c_type_size; for(i = 0; i < num_elem; i++) { @@ -879,6 +876,8 @@ nh5tbget_field_info_c(hid_t_f *loc_id, field_offsets[i] = (size_t_f)c_field_offsets[i]; } /* end for */ + *maxlen_out = (int_f)length; + done: if(c_name) HDfree(c_name); |