1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-07-22 10:47:43 +02:00

added write_h5 test

This commit is contained in:
q-posev 2021-03-02 11:27:09 +01:00
parent ff28a435d9
commit cbb936564e
2 changed files with 71 additions and 9 deletions

View File

@ -44,9 +44,10 @@ libtrio.so: $(OBJECT_FILES) $(HEADER_FILES)
test: libtrio.so test.c
$(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrio $(LIBS) -o test
rm test_write.h5
clean:
rm -f *.o libtrio.so
rm -f *.o libtrio.so test test_write.h5
%.o: %.c $(HEADER_FILES)
$(CC) $(CFLAGS) $(INCLUDE) -c $*.c -o $*.o

View File

@ -8,8 +8,10 @@ int test_read();
int test_write();
int test_h5read();
int test_h5write();
int main() {
test_h5write();
test_h5read();
test_write();
test_read();
@ -17,6 +19,59 @@ int main() {
}
int test_h5write() {
const char* file_name = "test_write.h5";
trio_t* file = NULL;
trio_exit_code rc;
rc = TRIO_SUCCESS;
uint64_t num = 12;
//double charge[12] = {6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1.};
double coord[36] = {
0.00000000 , 1.39250319 , 0.00000000 ,
-1.20594314 , 0.69625160 , 0.00000000 ,
-1.20594314 , -0.69625160 , 0.00000000 ,
0.00000000 , -1.39250319 , 0.00000000 ,
1.20594314 , -0.69625160 , 0.00000000 ,
1.20594314 , 0.69625160 , 0.00000000 ,
-2.14171677 , 1.23652075 , 0.00000000 ,
-2.14171677 , -1.23652075 , 0.00000000 ,
0.00000000 , -2.47304151 , 0.00000000 ,
2.14171677 , -1.23652075 , 0.00000000 ,
2.14171677 , 1.23652075 , 0.00000000 ,
0.00000000 , 2.47304151 , 0.00000000 ,
};
file = trio_create(file_name, TRIO_HDF5);
// works: try writing info in an empty file
rc = trio_write_nucleus_num(file,num);
// rc = trio_write_nucleus_charge(file,charge);
rc = trio_write_nucleus_coord(file,coord);
// should not work: try to rewrite the nucleus_num
rc = trio_write_nucleus_num(file,25);
// works: try to rewrite the nucleus_coord
// coord[0] = 666.0;
// rc = trio_write_nucleus_coord(file,coord);
if (rc == TRIO_SUCCESS) {
printf("SUCCESS\n");
} else {
printf("FAILURE\n");
}
trio_close(file);
return 0;
}
int test_h5read() {
const char* file_name = "test.h5";
@ -29,23 +84,24 @@ int test_h5read() {
file = trio_create(file_name, TRIO_HDF5);
/*rc = trio_read_nucleus_num(file,&num);
assert (num == 12);
rc = trio_read_nucleus_num(file,&num);
assert (num == 4);
/*
charge = (double*) calloc(num, sizeof(double));
rc = trio_read_nucleus_charge(file,charge);
assert(charge[10] == 1.);*/
num = 4;
assert(charge[] == 1.);
*/
coord = (double*) calloc(3*num, sizeof(double));
rc = trio_read_nucleus_coord(file,coord);
for (size_t i=0; i<3*num; i++){
/*for (size_t i=0; i<3*num; i++){
printf("%lf \n", coord[i]);
}
}*/
double x = coord[0] - 2.14171677;
assert( x*x < 1000.);
double x = coord[0] - 1.2;
assert( x*x < 1.e-12);
if (rc == TRIO_SUCCESS) {
printf("SUCCESS\n");
@ -53,7 +109,9 @@ int test_h5read() {
printf("FAILURE\n");
}
trio_close(file);
free(coord);
return 0;
}
@ -134,6 +192,9 @@ int test_read() {
trio_close(file);
free(charge);
free(coord);
return 0;
}