summaryrefslogtreecommitdiffstats
path: root/hl/fortran/src/H5TBfc.c
diff options
context:
space:
mode:
Diffstat (limited to 'hl/fortran/src/H5TBfc.c')
-rwxr-xr-xhl/fortran/src/H5TBfc.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/hl/fortran/src/H5TBfc.c b/hl/fortran/src/H5TBfc.c
index 76a3f1c..0efc9a8 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,14 +49,14 @@ 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;
@@ -63,9 +65,6 @@ nh5tbmake_table_c(int_f *namelen1,
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,19 @@ 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_p, (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_p = tmp_p + *max_char_size_field_names;
} /* end for */
/*
@@ -125,7 +123,7 @@ done:
if(c_field_names[i])
HDfree(c_field_names[i]);
} /* end for */
- HDfree(c_field_names);
+ HDfree(c_field_names);
} /* end if */
if(tmp)
HDfree(tmp);
@@ -616,10 +614,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 +769,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 +810,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 +854,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 +880,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);