Skip to content

Commit d6e9b47

Browse files
fix reading ids
1 parent c6d8337 commit d6e9b47

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

h5mdplugin.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int read_h5md_timestep(void *_file, int natoms, molfile_timestep_t *ts) {
7171
h5md_get_ntime(file,&ntime);
7272
if(current_time>=ntime)
7373
return MOLFILE_ERROR;
74-
if ((ts != NULL ||current_time==0)) { //skip reading if ts is NULL pointer (needs modification of the timestep below)
74+
if (ts != NULL) { //skip reading if ts is NULL pointer (needs modification of the timestep below)
7575
h5md_get_natoms(file, &natoms);
7676

7777
//read boxinformation
@@ -94,14 +94,12 @@ static int read_h5md_timestep(void *_file, int natoms, molfile_timestep_t *ts) {
9494

9595
}
9696

97-
9897
int status_seek=h5md_seek_timestep(file, current_time+1); //modify timestep in the internal state of the plugin for this file
9998
if(status_seek!=0){
10099
status= MOLFILE_SUCCESS;
101100
}else if(status_seek!=0 ){
102101
status= MOLFILE_ERROR;
103102
}
104-
105103
return status;
106104
}
107105

@@ -156,7 +154,6 @@ int check_consistency_species_index_of_species(struct h5md_file *file, int len_d
156154

157155
//load whole VMD structure
158156
int read_h5md_structure_vmd_structure(void *_file, int *optflags,molfile_atom_t *atoms) {
159-
printf("read structure\n");
160157
molfile_atom_t *atom;
161158
*optflags = MOLFILE_ATOMICNUMBER | MOLFILE_MASS | MOLFILE_RADIUS | MOLFILE_INSERTION | MOLFILE_CHARGE; // we read the optional attributes atomicnumber, mass, radius and charge
162159
struct h5md_file* file=_file;
@@ -306,7 +303,7 @@ int read_h5md_structure_vmd_structure(void *_file, int *optflags,molfile_atom_t
306303
//After assignment free used resources
307304
if(status_index_species==0)
308305
h5md_free_timeindependent_dataset_automatically(type_class_index_species,data_index_species, 0);
309-
if(status_read_species==0)
306+
if(status_read_species>=0)
310307
h5md_free_timeindependent_dataset_automatically(type_class_species,data_species_float, 0);
311308
if(status_read_name==0)
312309
h5md_free_timeindependent_dataset_automatically(type_class_name,data_name, len_data_index_species);

libh5md.c

+31-11
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void sort_data_according_to_id_dataset(struct h5md_file* file, int group_number,
344344
int i= group_number;
345345
/////////////////
346346
//read in id_data of group
347-
if(file->groups[i].id_dataset_id>0){
347+
if(file->groups[i].id_dataset_id>=0){
348348
int data_out_local_id[file->groups[i].natoms_group];
349349
hid_t dataspace_id_id=H5Dget_space(file->groups[i].id_dataset_id); //Define dataset dataspace (for id_dataset) in file.
350350
/*
@@ -354,17 +354,37 @@ void sort_data_according_to_id_dataset(struct h5md_file* file, int group_number,
354354
hsize_t dataset_slab_offset[rank_dataset];
355355
dataset_slab_offset[0]=file->current_time;
356356
dataset_slab_offset[1]=0;
357+
if(rank_dataset==3)
358+
dataset_slab_offset[2]=0;
357359

358360
hsize_t dataset_slab_count[rank_dataset];
359361
dataset_slab_count[0] = 1;
360362
dataset_slab_count[1] = file->groups[i].natoms_group;
363+
if(rank_dataset==3)
364+
dataset_slab_count[2]=1;
361365
H5Sselect_hyperslab(dataspace_id_id, H5S_SELECT_SET, dataset_slab_offset, NULL, dataset_slab_count, NULL);
366+
/*
367+
* Define memory dataspace.
368+
*/
369+
int rank=1; //linear data representation
370+
hsize_t dimsm[rank];
371+
dimsm[0]=file->groups[i].natoms_group;
372+
373+
hid_t memspace_id = H5Screate_simple(rank,dimsm,NULL);
362374

375+
/*
376+
* Define memory hyperslab.
377+
*/
378+
hsize_t offset_out[rank];
379+
hsize_t count_out[rank];
380+
offset_out[0]=0;
381+
count_out[0]=file->groups[i].natoms_group;
382+
H5Sselect_hyperslab(memspace_id, H5S_SELECT_SET, offset_out, NULL, count_out, NULL);
363383
/*
364384
* Read data from hyperslab in the file into the hyperslab in memory
365385
*/
366386
hid_t wanted_memory_datatype = H5T_NATIVE_INT;
367-
H5Dread (file->groups[i].id_dataset_id, wanted_memory_datatype, H5S_SELECT_SET, dataspace_id_id, H5P_DEFAULT, data_out_local_id);
387+
H5Dread (file->groups[i].id_dataset_id, wanted_memory_datatype, memspace_id, dataspace_id_id, H5P_DEFAULT, data_out_local_id);
368388
H5Sclose(dataspace_id_id);
369389
//use id data to sort particle positions (use binary tree)
370390
//create binary tree
@@ -491,7 +511,7 @@ int h5md_unfold_positions(struct h5md_file* file, float* unsorted_folded_pos){
491511
/////////////////
492512
//read in image_data of group
493513
int data_out_local_image[file->groups[i].natoms_group*file->groups[i].nspacedims];
494-
if(file->groups[i].image_dataset_id>0){
514+
if(file->groups[i].image_dataset_id>=0){
495515
hid_t dataspace_image_id=H5Dget_space(file->groups[i].image_dataset_id); //Define dataset dataspace (for image_dataset) in file.
496516
if(dataspace_image_id<0)
497517
continue;
@@ -572,7 +592,7 @@ int get_box_vectors(struct h5md_file* file, int group_i, int time_i, float* vec
572592
hid_t box_timeindependent_dataset_id=H5Dopen2(file->file_id, full_path_box_dataset_timeindependent ,H5P_DEFAULT);
573593

574594

575-
if(box_timedependent_dataset_id>0){
595+
if(box_timedependent_dataset_id>=0){
576596
//timedependent dataset exists, use it
577597
//read timedependent dataset
578598
float *data_box = malloc(file->ntime*3*3*sizeof(float));
@@ -588,7 +608,7 @@ int get_box_vectors(struct h5md_file* file, int group_i, int time_i, float* vec
588608
vector_c[2]=data_box[time_i*9+8];
589609
free (data_box);
590610
status=0;
591-
}else if(box_timeindependent_dataset_id>0){
611+
}else if(box_timeindependent_dataset_id>=0){
592612
//read timeindependent dataset
593613
//decided whether box is cubic (dataset contains a vector) or triclinic (dataset contains a matrix)
594614
int dims_box;
@@ -660,7 +680,7 @@ int get_box_information(struct h5md_file* file, int group_number, int time_i, h5
660680
float vector_a[3];
661681
float vector_b[3];
662682
float vector_c[3];
663-
if(box_timedependent_dataset_id>0){
683+
if(box_timedependent_dataset_id>=0){
664684
//timedependent dataset exists, use it
665685
//read timedependent dataset
666686
status=get_box_vectors(file, group_number, time_i, vector_a,vector_b,vector_c);
@@ -673,7 +693,7 @@ int get_box_information(struct h5md_file* file, int group_number, int time_i, h5
673693
box->beta= calculate_angle_between_vectors(vector_a,vector_c,3);
674694
box->gamma= calculate_angle_between_vectors(vector_a,vector_b,3);
675695
}else{
676-
if(box_timeindependent_dataset_id>0){
696+
if(box_timeindependent_dataset_id>=0){
677697
time_i=FALSE;
678698
//read timeindependent dataset
679699
//decided whether box is cubic (dataset contains a vector) or triclinic (dataset contains a matrix)
@@ -962,7 +982,7 @@ void h5md_show_hdf5_error_messages(){
962982

963983
int h5md_get_file_id(struct h5md_file *file, hid_t *file_id){
964984
*file_id=file->file_id;
965-
if(file_id !=0)
985+
if(file_id != NULL)
966986
return 0;
967987
else
968988
return -1;
@@ -1056,7 +1076,7 @@ int h5md_append_dataset(struct h5md_file *file, char* absolute_name_of_dataset,
10561076
int status;
10571077
//check existence of dataset
10581078
hid_t dataset_id = H5Dopen2(file->file_id, absolute_name_of_dataset, H5P_DEFAULT);
1059-
if(dataset_id>0){
1079+
if(dataset_id>=0){
10601080
hid_t datatype_read = H5Dget_type(dataset_id); // datatype handle
10611081
H5T_class_t type_class_read = H5Tget_class(datatype_read);
10621082
hid_t dataspace_id = H5Dget_space(dataset_id); //dataspace handle
@@ -1178,7 +1198,7 @@ int h5md_set_author(struct h5md_file* file, char* name, char* email_address){
11781198
status_email=H5LTset_attribute_string(file->file_id, "/h5md/author", "email", email_address);
11791199
}
11801200

1181-
if( status_name>0 && status_email>0 )
1201+
if( status_name>=0 && status_email>=0 )
11821202
return 0;
11831203
else
11841204
return -1;
@@ -1204,7 +1224,7 @@ int h5md_set_creator(struct h5md_file* file, char* name, char* version){
12041224
status_version=H5LTset_attribute_string(file->file_id, "/h5md/creator", "version", version);
12051225
}
12061226

1207-
if(status_name>0 && status_version>0 )
1227+
if(status_name>=0 && status_version>=0 )
12081228
return 0;
12091229
else
12101230
return -1;

tests/libh5md_test.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int test_appending_to_dataset_position_style(){//depends on test_create_file() s
210210
{1, 1, 1.6} };
211211
hid_t datatype3= H5T_NATIVE_FLOAT;
212212

213-
h5md_append_dataset(file, "/testappend", datatype3, (void*) data_in3, rank_in3, dims_in3);
213+
h5md_append_dataset(file, "testappend", datatype3, (void*) data_in3, rank_in3, dims_in3);
214214

215215

216216
int rank_in4=3; //should be 3 for positions : time_i, atom_i, x_i
@@ -219,7 +219,7 @@ int test_appending_to_dataset_position_style(){//depends on test_create_file() s
219219
{5, 6.0, 2},
220220
{5, 5, 5.6} };
221221
hid_t datatype4= H5T_NATIVE_FLOAT;
222-
int status=h5md_append_dataset(file, "/testappend", datatype4, (void*) data_in4, rank_in4, dims_in4);
222+
int status=h5md_append_dataset(file, "testappend", datatype4, (void*) data_in4, rank_in4, dims_in4);
223223
h5md_close(file);
224224
return status;
225225
}
@@ -299,12 +299,12 @@ int test_appending_to_onedimensional_string_dataset(){
299299
}
300300

301301

302-
int test_h5md_read_timestep(){
302+
int test_h5md_get_timestep(){
303303
struct h5md_file* file;
304304
h5md_open(&file, "../samples/full_vmd_structure.h5", -1);
305305
h5md_seek_timestep(file, 1);
306-
float* coords= (float*) malloc(100*3*sizeof(float));
307-
h5md_read_timestep(file, 100, coords);
306+
float* coords= (float*) malloc(3*sizeof(float));
307+
h5md_get_timestep(file, coords);
308308
int status;
309309
if(coords[3*2+0]-0.109156<0.0001)
310310
status= 0;

tests/libh5md_test.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef GTEST_LIBH5MD_H_
22
#define GTEST_LIBH5MD_H_
33

4-
int test_h5md_read_timestep();
4+
int test_h5md_get_timestep();
55
int test_create_file();
66
int test_write_file_with_datasets();
77
int test_write_fixed_length_string_dataset();

tests/libh5md_unittest.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ TEST(h5mdWriteTest, test_get_fill_value_float) {
5454
EXPECT_EQ(-1, test_get_fill_value_float());
5555
}
5656

57-
TEST(h5mdReadTest, test_read_timestep){
58-
EXPECT_EQ(0, test_h5md_read_timestep());
57+
TEST(h5mdReadTest, test_h5md_get_timestep){
58+
EXPECT_EQ(0, test_h5md_get_timestep());
5959
}
6060

6161

0 commit comments

Comments
 (0)