1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-08-25 06:31:43 +02:00

make file names consistent with the C test

This commit is contained in:
q-posev 2021-06-08 14:39:04 +02:00
parent 3331cc0591
commit 36e85039d5
3 changed files with 74 additions and 34 deletions

View File

@ -1520,13 +1520,13 @@ trexio_read_chunk_ao_2e_int_eri_value_64(trexio_t* const file,
#+begin_src c :tangle hrw_dset_str_front.h :exports none
trexio_exit_code trexio_has_$group_dset$(trexio_t* const file);
trexio_exit_code trexio_read_$group_dset$(trexio_t* const file, char* const dset, const uint32_t max_str_len);
trexio_exit_code trexio_read_$group_dset$(trexio_t* const file, char* dset, const uint32_t max_str_len);
trexio_exit_code trexio_write_$group_dset$(trexio_t* const file, const char* dset, const uint32_t max_str_len);
#+end_src
#+begin_src c :tangle read_dset_str_front.c
trexio_exit_code
trexio_read_$group_dset$ (trexio_t* const file, char* const dset, const uint32_t max_str_len)
trexio_read_$group_dset$ (trexio_t* const file, char* dset, const uint32_t max_str_len)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -1546,22 +1546,70 @@ trexio_read_$group_dset$ (trexio_t* const file, char* const dset, const uint32_t
assert(file->back_end < TREXIO_INVALID_BACK_END);
char* tmp_str = CALLOC(dims[0]*(128+1)+1, char);
if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED;
switch (file->back_end) {
case TREXIO_TEXT:
//return trexio_text_read_$group_dset$(file, dset_str, rank, dims);
//rc = trexio_text_read_$group_dset$(file, dset_str, rank, dims);
break;
case TREXIO_HDF5:
return trexio_hdf5_read_$group_dset$(file, dset, rank, dims, max_str_len);
rc = trexio_hdf5_read_$group_dset$(file, tmp_str, rank, dims);
break;
/*
case TREXIO_JSON:
return trexio_json_read_$group_dset$(file, dset, rank, dims);
rc = trexio_json_read_$group_dset$(file, dset, rank, dims);
break;
,*/
}
if (rc != TREXIO_SUCCESS) {
FREE(tmp_str);
return rc;
}
size_t len_read;
size_t len_accum = 0;
char * pch;
char buf[32];
printf("%s\n", tmp_str);
strcpy(dset, "");
for(uint64_t i=0; i<dims[0]; i++) {
//pch = i == 0 ? strtok(dset, TREXIO_DELIM) : strtok(NULL, TREXIO_DELIM) ;
if(i==0) {
pch = strtok(tmp_str, TREXIO_DELIM);
} else {
pch = strtok(NULL, TREXIO_DELIM);
}
len_read = strlen(pch);
//printf("Len [%ld] = %ld\n", i, len_read);
if (max_str_len < len_read) {
/*for(size_t i = len_accum + max_str_len; i < len_accum + len_read; i++) {
tmp_str[i] = '\0';
}*/
for(size_t i = len_accum; i < len_accum + max_str_len; i++) {
buf[i-len_accum] = tmp_str[i];
}
strcat(dset, buf);
} else {
strcat(dset, pch);
}
strcat(dset, TREXIO_DELIM);
len_accum += len_read + 1;
}
FREE(tmp_str);
return TREXIO_SUCCESS;
}
#+end_src
@ -1615,7 +1663,7 @@ trexio_write_$group_dset$ (trexio_t* const file, const char* dset, const uint32_
if (pch_len > max_str_len) {
FREE(dset_str[0]);
FREE(dset_str);
return TREXIO_INVALID_STR_LEN;
return TREXIO_INVALID_ARG_3;
}
dset_str[i]=tmp_str;

View File

@ -414,13 +414,13 @@ trexio_hdf5_has_$group_dset$ (trexio_t* const file)
#+begin_src c :tangle hrw_dset_str_hdf5.h :exports none
trexio_exit_code trexio_hdf5_has_$group_dset$(trexio_t* const file);
trexio_exit_code trexio_hdf5_read_$group_dset$(trexio_t* const file, char* const $group_dset$, const uint32_t rank, const uint64_t* dims, const uint32_t max_str_len);
trexio_exit_code trexio_hdf5_read_$group_dset$(trexio_t* const file, char* const $group_dset$, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_hdf5_write_$group_dset$(trexio_t* const file, const char** $group_dset$, const uint32_t rank, const uint64_t* dims);
#+end_src
#+begin_src c :tangle read_dset_str_hdf5.c
trexio_exit_code
trexio_hdf5_read_$group_dset$ (trexio_t* const file, char* const $group_dset$, const uint32_t rank, const uint64_t* dims, const uint32_t max_str_len)
trexio_hdf5_read_$group_dset$ (trexio_t* const file, char* const $group_dset$, const uint32_t rank, const uint64_t* dims)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -495,22 +495,14 @@ trexio_hdf5_read_$group_dset$ (trexio_t* const file, char* const $group_dset$, c
// copy contents of temporary rdata buffer into the group_dset otherwise they are lost
// after calling H5Treclaim or H5Dvlen_reclaim functions
size_t max_str_len = 2;
strcpy($group_dset$, "");
for (uint64_t i=0; i<dims[0]; i++) {
if (strlen(rdata[i]) > max_str_len) {
// this function is introduced in HDF5 v.1.12.0
//status = H5Treclaim (memtype, dspace, H5P_DEFAULT, rdata);
// this function is deprecated but used in v.<1.12.0
status = H5Dvlen_reclaim (memtype, dspace, H5P_DEFAULT, rdata);
FREE(rdata);
H5Dclose(dset_id);
H5Sclose(dspace);
H5Tclose(memtype);
return TREXIO_INVALID_STR_LEN;
}
if (max_str_len < strlen(rdata[i])) {
strncat($group_dset$, rdata[i], max_str_len);
} else {
strcat($group_dset$, rdata[i]);
}
strcat($group_dset$, TREXIO_DELIM);
}

View File

@ -2,19 +2,19 @@ program test_trexio
use trexio
implicit none
call system('rm -rf trexio_test_fort')
print *, 'call test_write(''trexio_test_fort'', TREXIO_TEXT)'
call test_write('trexio_test_fort', TREXIO_TEXT)
print *, 'call test_read(''trexio_test_fort'', TREXIO_TEXT)'
call test_read('trexio_test_fort', TREXIO_TEXT)
call system('rm -rf trexio_test_fort')
call system('rm -rf test_write_f.dir')
print *, 'call test_write(''test_write_f.dir'', TREXIO_TEXT)'
call test_write('test_write_f.dir', TREXIO_TEXT)
print *, 'call test_read(''test_write_f.dir'', TREXIO_TEXT)'
call test_read('test_write_f.dir', TREXIO_TEXT)
call system('rm -rf test_write_f.dir')
call system('rm -rf trexio_test_fort')
print *, 'call test_write(''trexio_test_fort.h5'', TREXIO_HDF5)'
call test_write('trexio_test_fort.h5', TREXIO_HDF5)
print *, 'call test_read(''trexio_test_fort.h5'', TREXIO_HDF5)'
call test_read('trexio_test_fort.h5', TREXIO_HDF5)
call system('rm -rf trexio_test_fort.h5')
call system('rm -rf test_write_f.h5')
print *, 'call test_write(''test_write_f.h5'', TREXIO_HDF5)'
call test_write('test_write_f.h5', TREXIO_HDF5)
print *, 'call test_read(''test_write_f.h5'', TREXIO_HDF5)'
call test_read('test_write_f.h5', TREXIO_HDF5)
call system('rm -rf test_write_f.h5')
end program test_trexio