Skip to content

Commit

Permalink
solve some bugs in ASDF read and write (wrong type and pointers)
Browse files Browse the repository at this point in the history
those bugs prevented compatibility with HDF5 >= v1.10.0
now compatible with v1.12
also correct some bugs examples
  • Loading branch information
1sbeller committed Jun 21, 2020
1 parent a850580 commit f282338
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
3 changes: 2 additions & 1 deletion examples/read_example.f90
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ program read_example
character(len=MAX_STRING_LENGTH) :: station_name, waveform_name, path

!-- ASDF variables
integer :: file_id ! HDF5 file id, also root group "/"
integer(kind=8) :: file_id ! HDF5 file id, also root group "/"
integer :: station_exists, waveform_exists
integer :: nsamples_infered

Expand Down Expand Up @@ -126,6 +126,7 @@ program read_example
!--------------------------------------------------------
! Clean up
!--------------------------------------------------------
call ASDF_close_file_f(file_id, ier)
call ASDF_finalize_hdf5_f(ier);
call MPI_Finalize(ier)

Expand Down
2 changes: 1 addition & 1 deletion examples/write_ASDF.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) {
free(waveforms[i]);
}
free(waveform_names);
free(waveforms);
free(waveforms);

/*------------------------------------*/
H5Fclose(file_id);
Expand Down
10 changes: 6 additions & 4 deletions examples/write_example.f90
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ program write_example
!-- ASDF variables
! These variables are used to know where further writes should be done.
! They have to be cleaned as soon as they become useless
integer :: file_id ! HDF5 file id, also root group "/"
integer :: waveforms_grp ! Group "/Waveforms/"
integer, dimension(:, :, :), allocatable :: data_ids
! They need to be integer(kind=8) as hid_t type is long long int
integer(kind=8) :: file_id ! HDF5 file id, also root group "/"
integer(kind=8) :: waveforms_grp ! Group "/Waveforms/"
integer(kind=8), dimension(:, :, :), allocatable :: data_ids

!--- MPI variables
integer :: myrank, mysize, comm
Expand Down Expand Up @@ -174,7 +175,7 @@ program write_example
! write ASDF
!--------------------------------------------------------
call ASDF_initialize_hdf5_f(ier);
call ASDF_create_new_file_f(trim(filename), comm, file_id)
call ASDF_create_new_file_f(trim(filename) // C_NULL_CHAR, comm, file_id)

call ASDF_write_string_attribute_f(file_id, "file_format" // C_NULL_CHAR, &
"ASDF" // C_NULL_CHAR, ier)
Expand Down Expand Up @@ -232,6 +233,7 @@ program write_example
enddo

call ASDF_close_group_f(waveforms_grp, ier)
call ASDF_close_file_f(file_id, ier)
call ASDF_finalize_hdf5_f(ier);

deallocate(data_ids)
Expand Down
2 changes: 1 addition & 1 deletion inc/ASDF_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ hid_t ASDF_define_waveform(hid_t loc_id, int nsamples,
herr_t ASDF_define_waveforms(hid_t loc_id, int num_waveforms, int nsamples,
long long int start_time, double sampling_rate,
char *event_name, char **waveform_names,
int *data_id);
hid_t *data_id);

/**
* @brief Write the station xml in data_id
Expand Down
28 changes: 14 additions & 14 deletions src/ASDF_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ void asdf_close_file_f(hid_t *file_id, int* err) {
* Wrappers for ASDF_write *
**********************************************************/

void asdf_create_new_file_f_(char *filename, MPI_Fint *f_comm, int *file_id) {
void asdf_create_new_file_f_(char *filename, MPI_Fint *f_comm, hid_t *file_id) {
/* Convert MPI communicator from Fortran to C. */
MPI_Comm comm= MPI_Comm_f2c(*f_comm);
*file_id = ASDF_create_new_file(filename, comm);
}

void asdf_create_new_file_serial_f_(char *filename, int *file_id) {
void asdf_create_new_file_serial_f_(char *filename, hid_t *file_id) {
*file_id = ASDF_create_new_file_serial(filename);
}

Expand Down Expand Up @@ -105,7 +105,7 @@ void asdf_define_station_xml_f_(hid_t *group_id, int *StationXML_length,
void asdf_define_waveform_f_(hid_t *loc_id, int *nsamples,
long long int *start_time, double *sampling_rate,
char *event_name, char *waveform_name,
int *data_id) {
hid_t *data_id) {
*data_id = ASDF_define_waveform(*loc_id, *nsamples, *start_time,
*sampling_rate, event_name, waveform_name);
}
Expand All @@ -114,7 +114,7 @@ void asdf_define_waveform_f_(hid_t *loc_id, int *nsamples,
void asdf_define_waveforms_f_(hid_t *loc_id, int *num_waveforms, int *nsamples,
long long int *start_time, double *sampling_rate,
char *event_name, char **waveform_names,
int *data_id, int *err) {
hid_t *data_id, int *err) {
*err = ASDF_define_waveforms(*loc_id, *num_waveforms, *nsamples,
*start_time, *sampling_rate,
event_name, waveform_names,
Expand Down Expand Up @@ -168,13 +168,13 @@ void asdf_close_dataset_f_(hid_t *dataset_id, int *err) {

// Wrapper without "_"

void asdf_create_new_file_f(char *filename, MPI_Fint *f_comm, int *file_id) {
void asdf_create_new_file_f(char *filename, MPI_Fint *f_comm, hid_t *file_id) {
/* Convert MPI communicator from Fortran to C. */
MPI_Comm comm= MPI_Comm_f2c(*f_comm);
*file_id = ASDF_create_new_file(filename, comm);
}

void asdf_create_new_file_serial_f(char *filename, int *file_id) {
void asdf_create_new_file_serial_f(char *filename, hid_t *file_id) {
*file_id = ASDF_create_new_file_serial(filename);
}

Expand Down Expand Up @@ -212,7 +212,7 @@ void asdf_define_station_xml_f(hid_t *group_id, int *StationXML_length,
void asdf_define_waveform_f(hid_t *loc_id, int *nsamples,
long long int *start_time, double *sampling_rate,
char *event_name, char *waveform_name,
int *data_id) {
hid_t *data_id) {
*data_id = ASDF_define_waveform(*loc_id, *nsamples, *start_time,
*sampling_rate, event_name, waveform_name);
}
Expand All @@ -221,7 +221,7 @@ void asdf_define_waveform_f(hid_t *loc_id, int *nsamples,
void asdf_define_waveforms_f(hid_t *loc_id, int *num_waveforms, int *nsamples,
long long int *start_time, double *sampling_rate,
char *event_name, char **waveform_names,
int *data_id, int *err) {
hid_t *data_id, int *err) {
*err = ASDF_define_waveforms(*loc_id, *num_waveforms, *nsamples,
*start_time, *sampling_rate,
event_name, waveform_names,
Expand Down Expand Up @@ -278,17 +278,17 @@ void asdf_close_dataset_f(hid_t *dataset_id, int *err) {
* Wrappers for ASDF_read *
**********************************************************/

void asdf_open_read_only_f_(char *filename, MPI_Fint *f_comm, int *file_id) {
void asdf_open_read_only_f_(char *filename, MPI_Fint *f_comm, hid_t *file_id) {
MPI_Comm comm= MPI_Comm_f2c(*f_comm);
*file_id = ASDF_open_read_only(filename, comm);
}

void asdf_open_f_(char *filename, MPI_Fint *f_comm, int *file_id) {
void asdf_open_f_(char *filename, MPI_Fint *f_comm, hid_t *file_id) {
MPI_Comm comm= MPI_Comm_f2c(*f_comm);
*file_id = ASDF_open(filename, comm);
}

void asdf_open_serial_f_(char *filename, int *file_id) {
void asdf_open_serial_f_(char *filename, hid_t *file_id) {
*file_id = ASDF_open_serial(filename);
}

Expand Down Expand Up @@ -340,17 +340,17 @@ void asdf_waveform_exists_f_(hid_t *file_id, char *station_name,

// Wrappers without "_"

void asdf_open_read_only_f(char *filename, MPI_Fint *f_comm, int *file_id) {
void asdf_open_read_only_f(char *filename, MPI_Fint *f_comm, hid_t *file_id) {
MPI_Comm comm= MPI_Comm_f2c(*f_comm);
*file_id = ASDF_open_read_only(filename, comm);
}

void asdf_open_f(char *filename, MPI_Fint *f_comm, int *file_id) {
void asdf_open_f(char *filename, MPI_Fint *f_comm, hid_t *file_id) {
MPI_Comm comm= MPI_Comm_f2c(*f_comm);
*file_id = ASDF_open(filename, comm);
}

void asdf_open_serial_f(char *filename, int *file_id) {
void asdf_open_serial_f(char *filename, hid_t *file_id) {
*file_id = ASDF_open_serial(filename);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ASDF_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ hid_t ASDF_define_waveform(hid_t loc_id, int nsamples,
herr_t ASDF_define_waveforms(hid_t loc_id, int num_waveforms, int nsamples,
long long int start_time, double sampling_rate,
char *event_name, char **waveform_names,
int *data_id) {
hid_t *data_id) {
int i;
char char_sampling_rate[10];
char char_start_time[10];
Expand Down

0 comments on commit f282338

Please sign in to comment.