2021-02-20 18:16:10 +01:00
|
|
|
#include "trio.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int test_read();
|
|
|
|
int test_write();
|
|
|
|
|
2021-02-23 18:20:14 +01:00
|
|
|
int test_h5read();
|
2021-03-02 11:27:09 +01:00
|
|
|
int test_h5write();
|
2021-02-20 18:16:10 +01:00
|
|
|
|
|
|
|
int main() {
|
2021-03-02 11:27:09 +01:00
|
|
|
test_h5write();
|
2021-02-23 18:20:14 +01:00
|
|
|
test_h5read();
|
2021-02-20 18:16:10 +01:00
|
|
|
test_write();
|
|
|
|
test_read();
|
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
|
2021-02-23 18:20:14 +01:00
|
|
|
|
2021-03-02 11:27:09 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-02-23 18:20:14 +01:00
|
|
|
int test_h5read() {
|
|
|
|
const char* file_name = "test.h5";
|
|
|
|
|
|
|
|
trio_t* file = NULL;
|
|
|
|
trio_exit_code rc;
|
|
|
|
|
|
|
|
uint64_t num;
|
|
|
|
//double* charge;
|
|
|
|
double* coord;
|
|
|
|
|
|
|
|
file = trio_create(file_name, TRIO_HDF5);
|
|
|
|
|
2021-03-02 11:27:09 +01:00
|
|
|
rc = trio_read_nucleus_num(file,&num);
|
|
|
|
assert (num == 4);
|
2021-02-23 18:20:14 +01:00
|
|
|
|
2021-03-02 11:27:09 +01:00
|
|
|
/*
|
2021-02-23 18:20:14 +01:00
|
|
|
charge = (double*) calloc(num, sizeof(double));
|
|
|
|
rc = trio_read_nucleus_charge(file,charge);
|
2021-03-02 11:27:09 +01:00
|
|
|
assert(charge[] == 1.);
|
|
|
|
*/
|
2021-02-23 18:20:14 +01:00
|
|
|
|
|
|
|
coord = (double*) calloc(3*num, sizeof(double));
|
|
|
|
rc = trio_read_nucleus_coord(file,coord);
|
|
|
|
|
2021-03-02 11:27:09 +01:00
|
|
|
/*for (size_t i=0; i<3*num; i++){
|
2021-02-23 18:20:14 +01:00
|
|
|
printf("%lf \n", coord[i]);
|
2021-03-02 11:27:09 +01:00
|
|
|
}*/
|
2021-02-23 18:20:14 +01:00
|
|
|
|
2021-03-02 11:27:09 +01:00
|
|
|
double x = coord[0] - 1.2;
|
|
|
|
assert( x*x < 1.e-12);
|
2021-02-23 18:20:14 +01:00
|
|
|
|
|
|
|
if (rc == TRIO_SUCCESS) {
|
|
|
|
printf("SUCCESS\n");
|
|
|
|
} else {
|
|
|
|
printf("FAILURE\n");
|
|
|
|
}
|
|
|
|
|
2021-03-02 11:27:09 +01:00
|
|
|
|
2021-02-23 18:20:14 +01:00
|
|
|
trio_close(file);
|
2021-03-02 11:27:09 +01:00
|
|
|
free(coord);
|
2021-02-23 18:20:14 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-20 18:16:10 +01:00
|
|
|
int test_write() {
|
|
|
|
const char* file_name = "trio_test";
|
|
|
|
|
|
|
|
trio_t* file = NULL;
|
|
|
|
trio_exit_code rc;
|
|
|
|
|
|
|
|
|
2021-02-23 18:20:14 +01:00
|
|
|
uint64_t num = 12;
|
2021-02-20 18:16:10 +01:00
|
|
|
|
|
|
|
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_TEXT);
|
|
|
|
|
|
|
|
rc = trio_write_nucleus_num(file,num);
|
|
|
|
rc = trio_write_nucleus_charge(file,charge);
|
|
|
|
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_read() {
|
|
|
|
const char* file_name = "trio_test";
|
|
|
|
|
|
|
|
trio_t* file = NULL;
|
|
|
|
trio_exit_code rc;
|
|
|
|
|
2021-02-23 18:20:14 +01:00
|
|
|
uint64_t num;
|
2021-02-20 18:16:10 +01:00
|
|
|
double* charge;
|
|
|
|
double* coord;
|
|
|
|
|
|
|
|
file = trio_create(file_name, TRIO_TEXT);
|
|
|
|
|
|
|
|
rc = trio_read_nucleus_num(file,&num);
|
|
|
|
assert (num == 12);
|
|
|
|
|
|
|
|
charge = (double*) calloc(num, sizeof(double));
|
|
|
|
rc = trio_read_nucleus_charge(file,charge);
|
|
|
|
assert(charge[10] == 1.);
|
|
|
|
|
|
|
|
coord = (double*) calloc(3*num, sizeof(double));
|
|
|
|
rc = trio_read_nucleus_coord(file,coord);
|
|
|
|
double x = coord[30] - 2.14171677;
|
|
|
|
assert( x*x < 1.e-12);
|
|
|
|
|
|
|
|
if (rc == TRIO_SUCCESS) {
|
|
|
|
printf("SUCCESS\n");
|
|
|
|
} else {
|
|
|
|
printf("FAILURE\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
trio_close(file);
|
|
|
|
|
2021-03-02 11:27:09 +01:00
|
|
|
free(charge);
|
|
|
|
free(coord);
|
|
|
|
|
2021-02-20 18:16:10 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|