1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-11-03 20:54:07 +01:00

Merge branch 'master' of github.com:TREX-CoE/trexio into generator-1

This commit is contained in:
q-posev 2021-03-12 15:00:49 +01:00
commit 4c40b33d1b
5 changed files with 280 additions and 96 deletions

View File

@ -245,16 +245,13 @@ trexio_exit_code trexio_read_nucleus_coord(trexio_t* file, double* coord) {
trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num);
if (rc != TREXIO_SUCCESS) return rc;
int64_t dim_coord = nucleus_num*3;
if (dim_coord < 0) return TREXIO_FAILURE;
uint32_t rank = 2;
uint64_t dims[2] = {nucleus_num, 3};
switch (file->back_end) {
case TREXIO_TEXT:
return trexio_text_read_nucleus_coord(file, coord, (uint64_t) dim_coord);
return trexio_text_read_nucleus_coord(file, coord, rank, dims);
break;
case TREXIO_HDF5:
@ -278,16 +275,13 @@ trexio_exit_code trexio_write_nucleus_coord(trexio_t* file, const double* coord)
trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num);
if (rc != TREXIO_SUCCESS) return rc;
int64_t dim_coord = nucleus_num*3;
if (dim_coord < 0) return TREXIO_FAILURE;
uint32_t rank = 2;
uint64_t dims[2] = {nucleus_num, 3};
switch (file->back_end) {
case TREXIO_TEXT:
return trexio_text_write_nucleus_coord(file, coord, (uint64_t) dim_coord);
return trexio_text_write_nucleus_coord(file, coord, rank, dims);
break;
case TREXIO_HDF5:
@ -311,13 +305,13 @@ trexio_exit_code trexio_read_nucleus_charge(trexio_t* file, double* charge) {
trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num);
if (rc != TREXIO_SUCCESS) return rc;
int64_t dim_charge = nucleus_num;
if (dim_charge < 0) return TREXIO_FAILURE;
uint32_t rank = 1;
uint64_t dims[1] = {nucleus_num};
switch (file->back_end) {
case TREXIO_TEXT:
return trexio_text_read_nucleus_charge(file, charge, (uint64_t) dim_charge);
return trexio_text_read_nucleus_charge(file, charge, rank, dims);
break;
/*
case TREXIO_HDF5:
@ -341,13 +335,13 @@ trexio_exit_code trexio_write_nucleus_charge(trexio_t* file, const double* charg
trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num);
if (rc != TREXIO_SUCCESS) return rc;
int64_t dim_charge = nucleus_num;
if (dim_charge < 0) return TREXIO_FAILURE;
uint32_t rank = 1;
uint64_t dims[1] = {nucleus_num};
switch (file->back_end) {
case TREXIO_TEXT:
return trexio_text_write_nucleus_charge(file, charge, (uint64_t) dim_charge);
return trexio_text_write_nucleus_charge(file, charge, rank, dims);
break;
/*
case TREXIO_HDF5:

View File

@ -410,16 +410,13 @@ trexio_exit_code trexio_read_nucleus_coord(trexio_t* file, double* coord) {
trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num);
if (rc != TREXIO_SUCCESS) return rc;
int64_t dim_coord = nucleus_num*3;
if (dim_coord < 0) return TREXIO_FAILURE;
uint32_t rank = 2;
uint64_t dims[2] = {nucleus_num, 3};
switch (file->back_end) {
case TREXIO_TEXT:
return trexio_text_read_nucleus_coord(file, coord, (uint64_t) dim_coord);
return trexio_text_read_nucleus_coord(file, coord, rank, dims);
break;
case TREXIO_HDF5:
@ -443,16 +440,13 @@ trexio_exit_code trexio_write_nucleus_coord(trexio_t* file, const double* coord)
trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num);
if (rc != TREXIO_SUCCESS) return rc;
int64_t dim_coord = nucleus_num*3;
if (dim_coord < 0) return TREXIO_FAILURE;
uint32_t rank = 2;
uint64_t dims[2] = {nucleus_num, 3};
switch (file->back_end) {
case TREXIO_TEXT:
return trexio_text_write_nucleus_coord(file, coord, (uint64_t) dim_coord);
return trexio_text_write_nucleus_coord(file, coord, rank, dims);
break;
case TREXIO_HDF5:
@ -484,13 +478,13 @@ trexio_exit_code trexio_read_nucleus_charge(trexio_t* file, double* charge) {
trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num);
if (rc != TREXIO_SUCCESS) return rc;
int64_t dim_charge = nucleus_num;
if (dim_charge < 0) return TREXIO_FAILURE;
uint32_t rank = 1;
uint64_t dims[1] = {nucleus_num};
switch (file->back_end) {
case TREXIO_TEXT:
return trexio_text_read_nucleus_charge(file, charge, (uint64_t) dim_charge);
return trexio_text_read_nucleus_charge(file, charge, rank, dims);
break;
/*
case TREXIO_HDF5:
@ -514,13 +508,13 @@ trexio_exit_code trexio_write_nucleus_charge(trexio_t* file, const double* charg
trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num);
if (rc != TREXIO_SUCCESS) return rc;
int64_t dim_charge = nucleus_num;
if (dim_charge < 0) return TREXIO_FAILURE;
uint32_t rank = 1;
uint64_t dims[1] = {nucleus_num};
switch (file->back_end) {
case TREXIO_TEXT:
return trexio_text_write_nucleus_charge(file, charge, (uint64_t) dim_charge);
return trexio_text_write_nucleus_charge(file, charge, rank, dims);
break;
/*
case TREXIO_HDF5:

View File

@ -108,7 +108,9 @@ nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) {
nucleus->file = NULL;
nucleus->num = 0;
nucleus->coord = NULL;
nucleus->dims_coord = NULL;
nucleus->charge = NULL;
nucleus->dims_charge = NULL;
nucleus->to_flush = 0;
/* Try to open the file. If the file does not exist, return */
@ -134,23 +136,55 @@ nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) {
int rc;
rc = fscanf(f, "%s", buffer);
assert (rc == 1);
assert (strcmp(buffer, "dim_charge") == 0);
assert (strcmp(buffer, "rank_charge") == 0);
rc = fscanf(f, "%lu", &(nucleus->dim_charge));
rc = fscanf(f, "%u", &(nucleus->rank_charge));
assert (rc == 1);
nucleus->dims_charge = (uint64_t*) calloc(nucleus->rank_charge, sizeof(uint64_t));
assert (nucleus->dims_charge != NULL);
uint64_t size_charge = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
rc = fscanf(f, "%s", buffer);
assert (rc == 1);
assert (strcmp(buffer, "dim_coord") == 0);
//assert (strcmp(buffer, "dims_charge") == 0);
rc = fscanf(f, "%lu", &(nucleus->dim_coord));
rc = fscanf(f, "%lu", &(nucleus->dims_charge[i]));
assert (rc == 1);
size_charge *= nucleus->dims_charge[i];
}
rc = fscanf(f, "%s", buffer);
assert (rc == 1);
assert (strcmp(buffer, "rank_coord") == 0);
rc = fscanf(f, "%u", &(nucleus->rank_coord));
assert (rc == 1);
nucleus->dims_coord = (uint64_t*) calloc(nucleus->rank_coord, sizeof(uint64_t));
assert (nucleus->dims_coord != NULL);
uint64_t size_coord = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
rc = fscanf(f, "%s", buffer);
assert (rc == 1);
//assert (strcmp(buffer, "dims_coord") == 0);
rc = fscanf(f, "%lu", &(nucleus->dims_coord[i]));
assert (rc == 1);
size_coord *= nucleus->dims_coord[i];
}
/* Allocate arrays */
nucleus->charge = (double*) calloc(nucleus->dim_charge, sizeof(double));
nucleus->charge = (double*) calloc(size_charge, sizeof(double));
assert (nucleus->charge != NULL);
nucleus->coord = (double*) calloc(nucleus->dim_coord, sizeof(double));
nucleus->coord = (double*) calloc(size_coord, sizeof(double));
assert (nucleus->coord != NULL);
/* Read data */
@ -165,7 +199,7 @@ nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) {
assert (rc == 1);
assert (strcmp(buffer, "charge") == 0);
for (uint64_t i=0 ; i<nucleus->dim_charge ; i++) {
for (uint64_t i=0 ; i<size_charge ; i++) {
rc = fscanf(f, "%lf", &(nucleus->charge[i]));
assert (rc == 1);
}
@ -174,7 +208,7 @@ nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) {
assert (rc == 1);
assert (strcmp(buffer, "coord") == 0);
for (uint64_t i=0 ; i<nucleus->dim_coord ; i++) {
for (uint64_t i=0 ; i<size_coord ; i++) {
rc = fscanf(f, "%lf", &(nucleus->coord[i]));
assert (rc == 1);
}
@ -208,18 +242,31 @@ trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file) {
rewind(f);
/* Write the dimensioning variables */
fprintf(f, "dim_charge %ld\n", nucleus->dim_charge);
fprintf(f, "dim_coord %ld\n", nucleus->dim_coord );
fprintf(f, "rank_charge %d\n", nucleus->rank_charge);
uint64_t size_charge = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
fprintf(f, "dims_charge[%d] %ld\n", i, nucleus->dims_charge[i]);
size_charge *= nucleus->dims_charge[i];
}
fprintf(f, "rank_coord %d\n", nucleus->rank_coord);
uint64_t size_coord = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
fprintf(f, "dims_coord[%d] %ld\n", i, nucleus->dims_coord[i]);
size_coord *= nucleus->dims_coord[i];
}
/* Write arrays */
fprintf(f, "num %ld\n", nucleus->num);
fprintf(f, "charge\n");
for (uint64_t i=0 ; i<nucleus->dim_charge ; i++) {
for (uint64_t i=0 ; i<size_charge ; i++) {
fprintf(f, "%lf\n", nucleus->charge[i]);
}
fprintf(f, "coord\n");
for (uint64_t i=0 ; i<nucleus->dim_coord ; i++) {
for (uint64_t i=0 ; i<size_coord ; i++) {
fprintf(f, "%lf\n", nucleus->coord[i]);
}
fflush(f);
@ -245,11 +292,21 @@ trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file) {
nucleus->file = NULL;
}
if (nucleus->dims_coord != NULL) {
free (nucleus->dims_coord);
nucleus->dims_coord = NULL;
}
if (nucleus->coord != NULL) {
free (nucleus->coord);
nucleus->coord = NULL;
}
if (nucleus->dims_charge != NULL) {
free (nucleus->dims_charge);
nucleus->dims_charge = NULL;
}
if (nucleus->charge != NULL) {
free (nucleus->charge);
nucleus->charge = NULL;
@ -289,7 +346,7 @@ trexio_exit_code trexio_text_write_nucleus_num(const trexio_t* file, const uint6
return TREXIO_SUCCESS;
}
trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint64_t dim_coord) {
trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (coord == NULL) return TREXIO_INVALID_ARG_2;
@ -297,9 +354,15 @@ trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* co
nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file);
if (nucleus == NULL) return TREXIO_FAILURE;
if (dim_coord != nucleus->dim_coord) return TREXIO_INVALID_ARG_3;
if (rank != nucleus->rank_coord) return TREXIO_INVALID_ARG_3;
for (uint64_t i=0 ; i<dim_coord ; i++) {
uint64_t dim_size = 1;
for (uint i=0; i<rank; i++){
if (dims[i] != nucleus->dims_coord[i]) return TREXIO_INVALID_ARG_4;
dim_size *= dims[i];
}
for (uint64_t i=0 ; i<dim_size ; i++) {
coord[i] = nucleus->coord[i];
}
@ -307,7 +370,7 @@ trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* co
}
trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint64_t dim_coord) {
trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (coord == NULL) return TREXIO_INVALID_ARG_2;
@ -321,10 +384,23 @@ trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const dou
nucleus->coord = NULL;
}
nucleus->dim_coord = dim_coord;
nucleus->coord = (double*) calloc(dim_coord, sizeof(double));
if (nucleus->dims_coord != NULL) {
free(nucleus->dims_coord);
nucleus->dims_coord = NULL;
}
for (uint64_t i=0 ; i<dim_coord ; i++) {
nucleus->rank_coord = rank;
nucleus->dims_coord = (uint64_t*) calloc(rank, sizeof(uint64_t));
uint64_t dim_size = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
nucleus->dims_coord[i] = dims[i];
dim_size *= dims[i];
}
nucleus->coord = (double*) calloc(dim_size, sizeof(double));
for (uint64_t i=0 ; i<dim_size ; i++) {
nucleus->coord[i] = coord[i];
}
@ -332,7 +408,7 @@ trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const dou
return TREXIO_SUCCESS;
}
trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint64_t dim_charge) {
trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (charge == NULL) return TREXIO_INVALID_ARG_2;
@ -340,9 +416,15 @@ trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* c
nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file);
if (nucleus == NULL) return TREXIO_FAILURE;
if (dim_charge != nucleus->dim_charge) return TREXIO_INVALID_ARG_3;
if (rank != nucleus->rank_charge) return TREXIO_INVALID_ARG_3;
for (uint64_t i=0 ; i<dim_charge ; i++) {
uint64_t dim_size = 1;
for (uint i=0; i<rank; i++){
if (dims[i] != nucleus->dims_charge[i]) return TREXIO_INVALID_ARG_4;
dim_size *= dims[i];
}
for (uint64_t i=0 ; i<dim_size ; i++) {
charge[i] = nucleus->charge[i];
}
@ -350,7 +432,7 @@ trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* c
}
trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint64_t dim_charge) {
trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (charge == NULL) return TREXIO_INVALID_ARG_2;
@ -364,10 +446,24 @@ trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const do
nucleus->charge = NULL;
}
nucleus->dim_charge = dim_charge;
nucleus->charge = (double*) calloc(dim_charge, sizeof(double));
if (nucleus->dims_charge != NULL) {
free(nucleus->dims_charge);
nucleus->dims_charge = NULL;
}
for (uint64_t i=0 ; i<dim_charge ; i++) {
nucleus->rank_charge = rank;
nucleus->dims_charge = (uint64_t*) calloc(rank, sizeof(uint64_t));
uint64_t dim_size = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
nucleus->dims_charge[i] = dims[i];
dim_size *= dims[i];
}
nucleus->charge = (double*) calloc(dim_size, sizeof(double));
for (uint64_t i=0 ; i<dim_size ; i++) {
nucleus->charge[i] = charge[i];
}

View File

@ -22,11 +22,13 @@
typedef struct nucleus_s {
FILE* file;
uint64_t dim_coord;
uint64_t dim_charge;
double* coord;
double* charge;
uint64_t num;
uint64_t* dims_charge;
uint64_t* dims_coord;
uint32_t rank_charge;
uint32_t rank_coord;
int to_flush;
} nucleus_t;
@ -71,11 +73,11 @@ trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file);
trexio_exit_code trexio_text_read_nucleus_num(const trexio_t* file, uint64_t* num);
trexio_exit_code trexio_text_write_nucleus_num(const trexio_t* file, const uint64_t num);
trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint64_t dim_coord);
trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint64_t dim_coord);
trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint64_t dim_charge);
trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint64_t dim_charge);
trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint32_t rank, const uint64_t* dims);
rdm_t* trexio_text_read_rdm(trexio_text_t* file);

View File

@ -55,11 +55,13 @@
#+begin_src c :tangle trexio_text.h
typedef struct nucleus_s {
FILE* file;
uint64_t dim_coord;
uint64_t dim_charge;
double* coord;
double* charge;
uint64_t num;
uint64_t* dims_charge;
uint64_t* dims_coord;
uint32_t rank_charge;
uint32_t rank_coord;
int to_flush;
} nucleus_t;
@ -238,7 +240,9 @@ nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) {
nucleus->file = NULL;
nucleus->num = 0;
nucleus->coord = NULL;
nucleus->dims_coord = NULL;
nucleus->charge = NULL;
nucleus->dims_charge = NULL;
nucleus->to_flush = 0;
/* Try to open the file. If the file does not exist, return */
@ -264,23 +268,55 @@ nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) {
int rc;
rc = fscanf(f, "%s", buffer);
assert (rc == 1);
assert (strcmp(buffer, "dim_charge") == 0);
assert (strcmp(buffer, "rank_charge") == 0);
rc = fscanf(f, "%lu", &(nucleus->dim_charge));
rc = fscanf(f, "%u", &(nucleus->rank_charge));
assert (rc == 1);
nucleus->dims_charge = (uint64_t*) calloc(nucleus->rank_charge, sizeof(uint64_t));
assert (nucleus->dims_charge != NULL);
uint64_t size_charge = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
rc = fscanf(f, "%s", buffer);
assert (rc == 1);
assert (strcmp(buffer, "dim_coord") == 0);
//assert (strcmp(buffer, "dims_charge") == 0);
rc = fscanf(f, "%lu", &(nucleus->dim_coord));
rc = fscanf(f, "%lu", &(nucleus->dims_charge[i]));
assert (rc == 1);
size_charge *= nucleus->dims_charge[i];
}
rc = fscanf(f, "%s", buffer);
assert (rc == 1);
assert (strcmp(buffer, "rank_coord") == 0);
rc = fscanf(f, "%u", &(nucleus->rank_coord));
assert (rc == 1);
nucleus->dims_coord = (uint64_t*) calloc(nucleus->rank_coord, sizeof(uint64_t));
assert (nucleus->dims_coord != NULL);
uint64_t size_coord = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
rc = fscanf(f, "%s", buffer);
assert (rc == 1);
//assert (strcmp(buffer, "dims_coord") == 0);
rc = fscanf(f, "%lu", &(nucleus->dims_coord[i]));
assert (rc == 1);
size_coord *= nucleus->dims_coord[i];
}
/* Allocate arrays */
nucleus->charge = (double*) calloc(nucleus->dim_charge, sizeof(double));
nucleus->charge = (double*) calloc(size_charge, sizeof(double));
assert (nucleus->charge != NULL);
nucleus->coord = (double*) calloc(nucleus->dim_coord, sizeof(double));
nucleus->coord = (double*) calloc(size_coord, sizeof(double));
assert (nucleus->coord != NULL);
/* Read data */
@ -295,7 +331,7 @@ nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) {
assert (rc == 1);
assert (strcmp(buffer, "charge") == 0);
for (uint64_t i=0 ; i<nucleus->dim_charge ; i++) {
for (uint64_t i=0 ; i<size_charge ; i++) {
rc = fscanf(f, "%lf", &(nucleus->charge[i]));
assert (rc == 1);
}
@ -304,7 +340,7 @@ nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) {
assert (rc == 1);
assert (strcmp(buffer, "coord") == 0);
for (uint64_t i=0 ; i<nucleus->dim_coord ; i++) {
for (uint64_t i=0 ; i<size_coord ; i++) {
rc = fscanf(f, "%lf", &(nucleus->coord[i]));
assert (rc == 1);
}
@ -346,18 +382,31 @@ trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file) {
rewind(f);
/* Write the dimensioning variables */
fprintf(f, "dim_charge %ld\n", nucleus->dim_charge);
fprintf(f, "dim_coord %ld\n", nucleus->dim_coord );
fprintf(f, "rank_charge %d\n", nucleus->rank_charge);
uint64_t size_charge = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
fprintf(f, "dims_charge[%d] %ld\n", i, nucleus->dims_charge[i]);
size_charge *= nucleus->dims_charge[i];
}
fprintf(f, "rank_coord %d\n", nucleus->rank_coord);
uint64_t size_coord = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
fprintf(f, "dims_coord[%d] %ld\n", i, nucleus->dims_coord[i]);
size_coord *= nucleus->dims_coord[i];
}
/* Write arrays */
fprintf(f, "num %ld\n", nucleus->num);
fprintf(f, "charge\n");
for (uint64_t i=0 ; i<nucleus->dim_charge ; i++) {
for (uint64_t i=0 ; i<size_charge ; i++) {
fprintf(f, "%lf\n", nucleus->charge[i]);
}
fprintf(f, "coord\n");
for (uint64_t i=0 ; i<nucleus->dim_coord ; i++) {
for (uint64_t i=0 ; i<size_coord ; i++) {
fprintf(f, "%lf\n", nucleus->coord[i]);
}
fflush(f);
@ -393,11 +442,21 @@ trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file) {
nucleus->file = NULL;
}
if (nucleus->dims_coord != NULL) {
free (nucleus->dims_coord);
nucleus->dims_coord = NULL;
}
if (nucleus->coord != NULL) {
free (nucleus->coord);
nucleus->coord = NULL;
}
if (nucleus->dims_charge != NULL) {
free (nucleus->dims_charge);
nucleus->dims_charge = NULL;
}
if (nucleus->charge != NULL) {
free (nucleus->charge);
nucleus->charge = NULL;
@ -452,12 +511,12 @@ trexio_exit_code trexio_text_write_nucleus_num(const trexio_t* file, const uint6
The ~coord~ array is assumed allocated with the appropriate size.
#+begin_src c :tangle trexio_text.h
trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint64_t dim_coord);
trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint64_t dim_coord);
trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint32_t rank, const uint64_t* dims);
#+end_src
#+begin_src c :tangle trexio_text.c
trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint64_t dim_coord) {
trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (coord == NULL) return TREXIO_INVALID_ARG_2;
@ -465,9 +524,15 @@ trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* co
nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file);
if (nucleus == NULL) return TREXIO_FAILURE;
if (dim_coord != nucleus->dim_coord) return TREXIO_INVALID_ARG_3;
if (rank != nucleus->rank_coord) return TREXIO_INVALID_ARG_3;
for (uint64_t i=0 ; i<dim_coord ; i++) {
uint64_t dim_size = 1;
for (uint i=0; i<rank; i++){
if (dims[i] != nucleus->dims_coord[i]) return TREXIO_INVALID_ARG_4;
dim_size *= dims[i];
}
for (uint64_t i=0 ; i<dim_size ; i++) {
coord[i] = nucleus->coord[i];
}
@ -475,7 +540,7 @@ trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* co
}
trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint64_t dim_coord) {
trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (coord == NULL) return TREXIO_INVALID_ARG_2;
@ -489,10 +554,23 @@ trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const dou
nucleus->coord = NULL;
}
nucleus->dim_coord = dim_coord;
nucleus->coord = (double*) calloc(dim_coord, sizeof(double));
if (nucleus->dims_coord != NULL) {
free(nucleus->dims_coord);
nucleus->dims_coord = NULL;
}
for (uint64_t i=0 ; i<dim_coord ; i++) {
nucleus->rank_coord = rank;
nucleus->dims_coord = (uint64_t*) calloc(rank, sizeof(uint64_t));
uint64_t dim_size = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
nucleus->dims_coord[i] = dims[i];
dim_size *= dims[i];
}
nucleus->coord = (double*) calloc(dim_size, sizeof(double));
for (uint64_t i=0 ; i<dim_size ; i++) {
nucleus->coord[i] = coord[i];
}
@ -505,12 +583,12 @@ trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const dou
The ~charge~ array is assumed allocated with the appropriate size.
#+begin_src c :tangle trexio_text.h
trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint64_t dim_charge);
trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint64_t dim_charge);
trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint32_t rank, const uint64_t* dims);
#+end_src
#+begin_src c :tangle trexio_text.c
trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint64_t dim_charge) {
trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (charge == NULL) return TREXIO_INVALID_ARG_2;
@ -518,9 +596,15 @@ trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* c
nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file);
if (nucleus == NULL) return TREXIO_FAILURE;
if (dim_charge != nucleus->dim_charge) return TREXIO_INVALID_ARG_3;
if (rank != nucleus->rank_charge) return TREXIO_INVALID_ARG_3;
for (uint64_t i=0 ; i<dim_charge ; i++) {
uint64_t dim_size = 1;
for (uint i=0; i<rank; i++){
if (dims[i] != nucleus->dims_charge[i]) return TREXIO_INVALID_ARG_4;
dim_size *= dims[i];
}
for (uint64_t i=0 ; i<dim_size ; i++) {
charge[i] = nucleus->charge[i];
}
@ -528,7 +612,7 @@ trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* c
}
trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint64_t dim_charge) {
trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (charge == NULL) return TREXIO_INVALID_ARG_2;
@ -542,10 +626,24 @@ trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const do
nucleus->charge = NULL;
}
nucleus->dim_charge = dim_charge;
nucleus->charge = (double*) calloc(dim_charge, sizeof(double));
if (nucleus->dims_charge != NULL) {
free(nucleus->dims_charge);
nucleus->dims_charge = NULL;
}
for (uint64_t i=0 ; i<dim_charge ; i++) {
nucleus->rank_charge = rank;
nucleus->dims_charge = (uint64_t*) calloc(rank, sizeof(uint64_t));
uint64_t dim_size = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
nucleus->dims_charge[i] = dims[i];
dim_size *= dims[i];
}
nucleus->charge = (double*) calloc(dim_size, sizeof(double));
for (uint64_t i=0 ; i<dim_size ; i++) {
nucleus->charge[i] = charge[i];
}