diff options
author | Takanori Nakane <nakane.t@gmail.com> | 2015-01-06 15:35:00 +0900 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2015-02-12 12:42:17 +0100 |
commit | 5f6b5ffcd560f056ae3af56a50d7662460652ba8 (patch) | |
tree | 19038292e75b27c8f7f7be17269776dbf2eeb936 /libcrystfel/src | |
parent | e22c8ae67ab6af53d21984ff3c602529f2770526 (diff) |
Avoid libhdf5 runtime warnings when photon_energy contains %.
Diffstat (limited to 'libcrystfel/src')
-rw-r--r-- | libcrystfel/src/events.c | 2 | ||||
-rw-r--r-- | libcrystfel/src/hdf5-file.c | 71 |
2 files changed, 36 insertions, 37 deletions
diff --git a/libcrystfel/src/events.c b/libcrystfel/src/events.c index 29cb9495..5de60b66 100644 --- a/libcrystfel/src/events.c +++ b/libcrystfel/src/events.c @@ -356,7 +356,7 @@ char *get_event_string(struct event *ev) strncpy(&ret_string[ret_string_len],"/", 1); strncpy(&ret_string[ret_string_len+1], num_buf, - strlen(num_buf)); + strlen(num_buf)); ret_string_len += 1+strlen(num_buf); } diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c index 85d4af72..daaacd9f 100644 --- a/libcrystfel/src/hdf5-file.c +++ b/libcrystfel/src/hdf5-file.c @@ -1668,7 +1668,7 @@ static int get_ev_based_f_value(struct hdfile *f, const char *name, return 1; } - dh = H5Dopen2(f->fh, name, H5P_DEFAULT); + dh = H5Dopen2(f->fh, subst_name, H5P_DEFAULT); type = H5Dget_type(dh); class = H5Tget_class(type); @@ -1947,9 +1947,15 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name, hid_t class; int buf_i; double buf_f; - char *tmp; + char *tmp = NULL, *subst_name = NULL; - dh = H5Dopen2(f->fh, name, H5P_DEFAULT); + if (ev != NULL && ev->path_length != 0 ) { + subst_name = partial_event_substitution(ev, name); + } else { + subst_name = strdup(name); + } + + dh = H5Dopen2(f->fh, subst_name, H5P_DEFAULT); if ( dh < 0 ) return NULL; type = H5Dget_type(dh); class = H5Tget_class(type); @@ -1957,7 +1963,6 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name, if ( class == H5T_STRING ) { herr_t r; - char *tmp; hid_t sh; size = H5Tget_size(type); @@ -1966,46 +1971,40 @@ char *hdfile_get_string_value(struct hdfile *f, const char *name, sh = H5Screate(H5S_SCALAR); r = H5Dread(dh, type, sh, sh, H5P_DEFAULT, tmp); - if ( r < 0 ) goto fail; - - /* Two possibilities: - * String is already zero-terminated - * String is not terminated. - * Make sure things are done properly... */ - tmp[size] = '\0'; - chomp(tmp); - - return tmp; - - } - - switch ( class ) { - - case H5T_FLOAT : - if ( ev != NULL ) { - if ( get_ev_based_f_value(f, name, ev, &buf_f) ) goto fail; + if ( r < 0 ) { + free(tmp); + tmp = NULL; } else { - if ( get_f_value(f, name, &buf_f) ) goto fail; - } - tmp = malloc(256); - snprintf(tmp, 255, "%f", buf_f); - return tmp; - case H5T_INTEGER : - if ( get_i_value(f, name, &buf_i) ) goto fail; - tmp = malloc(256); - snprintf(tmp, 255, "%d", buf_i); - return tmp; + /* Two possibilities: + * String is already zero-terminated + * String is not terminated. + * Make sure things are done properly... */ + tmp[size] = '\0'; + chomp(tmp); + } + } else { - default : - goto fail; + switch ( class ) { + case H5T_FLOAT : + if ( get_f_value(f, subst_name, &buf_f) ) break; + tmp = malloc(256); + snprintf(tmp, 255, "%f", buf_f); + break; + + case H5T_INTEGER : + if ( get_i_value(f, subst_name, &buf_i) ) break; + tmp = malloc(256); + snprintf(tmp, 255, "%d", buf_i); + break; + } } -fail: H5Tclose(type); H5Dclose(dh); - return NULL; + free(subst_name); + return tmp; } |