1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-08-25 14:41:44 +02:00

use newline character as a delimeter for array of strings

This commit is contained in:
q-posev 2021-06-01 18:12:15 +02:00
parent 0f444074c9
commit 196224c63b
3 changed files with 14 additions and 8 deletions

View File

@ -1479,7 +1479,7 @@ trexio_read_$group_dset$ (trexio_t* const file, char* const dset)
strcpy(dset, ""); strcpy(dset, "");
for(size_t i=0; i<dims[0]; i++){ for(size_t i=0; i<dims[0]; i++){
strcat(dset, dset_str[i]); strcat(dset, dset_str[i]);
strcat(dset, " "); strcat(dset, "\n");
} }
for (int i=0; i<dims[0]; i++){ for (int i=0; i<dims[0]; i++){
@ -1520,10 +1520,10 @@ trexio_write_$group_dset$ (trexio_t* const file, const char* dset)
} }
char* pch; char* pch;
pch = strtok( (char*) dset, " "); pch = strtok( (char*) dset, "\n");
strcpy(dset_str[0], pch); strcpy(dset_str[0], pch);
for(size_t i=1; i<dims[0]; i++){ for(size_t i=1; i<dims[0]; i++){
pch = strtok (NULL, " "); pch = strtok (NULL, "\n");
strcpy(dset_str[i], pch); strcpy(dset_str[i], pch);
} }

View File

@ -63,7 +63,12 @@ int test_h5write() {
"H" , "H" ,
"H" }; "H" };
char labelxxx[] = "C C C Na C C H H H Ru H H"; //char labelxxx[] = "C C C Na C C H H H Ru H H";
char labelxxx[128] = "";
for (int i=0; i<num; i++){
strcat(labelxxx,label[i]);
strcat(labelxxx,"\n");
}
/*================= START OF TEST ==================*/ /*================= START OF TEST ==================*/
@ -175,7 +180,7 @@ int test_h5read() {
printf("%s\n", labelxxx); printf("%s\n", labelxxx);
//assert( strcmp(label[1], "Na") == 0 ); //assert( strcmp(label[1], "Na") == 0 );
char * pch; char * pch;
pch = strtok(labelxxx, " "); pch = strtok(labelxxx, "\n");
assert( strcmp(pch, "C") == 0 ); assert( strcmp(pch, "C") == 0 );
// close current session // close current session

View File

@ -10,7 +10,7 @@ subroutine test_write()
! ============ Test write functionality =============== ! ! ============ Test write functionality =============== !
use trexio use trexio
use, intrinsic :: iso_c_binding use, intrinsic :: iso_c_binding, only: c_new_line
implicit none implicit none
@ -46,7 +46,8 @@ subroutine test_write()
label_str='' label_str=''
do i = 1,num do i = 1,num
label_str=label_str//trim(label(i))//' ' ! label_str=label_str//trim(label(i))//' '
label_str=label_str//trim(label(i))//c_new_line
enddo enddo
@ -154,7 +155,7 @@ subroutine test_read()
tmp_str='' tmp_str=''
do j=ind,128 do j=ind,128
if ( (label_str(j)==" ") ) then if ( (label_str(j)==c_new_line) ) then
ind=j+1 ind=j+1
exit exit
endif endif