From 7f3dc0879c9ee872f37006c5992c1528be055197 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 22 Mar 2021 16:15:07 +0100 Subject: [PATCH 01/15] wip: write nums --- src/templates_front/build.sh | 9 +++- src/templates_front/templator_front.org | 68 ++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/templates_front/build.sh b/src/templates_front/build.sh index 5a37440..3d5b5e4 100644 --- a/src/templates_front/build.sh +++ b/src/templates_front/build.sh @@ -2,14 +2,21 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +# prefixes cat $DIR/prefix_front.c > trexio.c cat $DIR/prefix_front.h > trexio.h cat $DIR/prefix_s_front.h > trexio_s.h +cat $DIR/prefix_fortran.f90 > trexio_f.f90 +# c front end cat $DIR/populated/pop_*.c >> trexio.c cat $DIR/populated/pop_*.h >> trexio.h +# fortran front end +cat $DIR/populated/pop_*.f90 >> trexio_f.f90 + +# suffixes cat $DIR/suffix_s_front.h >> trexio_s.h cat $DIR/suffix_front.h >> trexio.h - +cat $DIR/suffix_fortran.f90 >> trexio_f.f90 diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 278de8d..dc7867d 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -2,17 +2,24 @@ * Constant file prefixes (not used by generator) :noxport: -** Prefixes - #+NAME:header #+begin_src c -/* This file was generated from the trexio.org org-mode file. +/* This file was generated from the templator_front.org org-mode file. To generate it, open trexio.org in Emacs and execute M-x org-babel-tangle */ #+end_src + #+begin_src fortran :tangle prefix_fortran.f90 :noweb yes +<
> + +module trexio + + use, intrinsic :: iso_c_binding + + #+end_src + #+begin_src c :tangle prefix_front.h :noweb yes <
> #ifndef _TREXIO_H @@ -80,6 +87,7 @@ #define FREE(X) { free(X) ; (X)=NULL; } #+end_src + * Front end All calls to TREXIO are thread-safe. @@ -175,7 +183,7 @@ struct trexio_back_end_s { #+end_src ** File opening - + #+begin_src c :tangle prefix_front.h trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t back_end); #+end_src @@ -279,9 +287,20 @@ trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t b return result; } #+end_src + + #+begin_src fortran :tangle prefix_fortran.f90 +interface + type (c_ptr) function trexio_open (filename, mode, backend) bind(C) + use, intrinsic :: iso_c_binding + character(kind=c_char), dimension(*) :: filename + character(kind=c_char), intent(in) :: mode + integer (c_int32_t), intent(in), value :: backend + end function trexio_open +end interface + #+end_src ** File closing - + #+begin_src c :tangle prefix_front.h trexio_exit_code trexio_close(trexio_t* file); #+end_src @@ -354,9 +373,16 @@ trexio_exit_code trexio_close(trexio_t* file) { } #+end_src + #+begin_src fortran :tangle prefix_fortran.f90 +interface + type (c_int32_t) function trexio_close (trex_file) bind(C) + use, intrinsic :: iso_c_binding + type (c_ptr), intent(in), value :: trex_file + end function trexio_close +end interface + #+end_src * Templates for front end - ** Template for frontend read/write a number #+begin_src c :tangle rw_num_front.h @@ -424,6 +450,32 @@ trexio_exit_code trexio_write_$group_num$(trexio_t* file, const int64_t num) { #+end_src + #+begin_src fortran :tangle write_num_front_fortran.f90 + +interface + integer (c_int32_t) function trexio_write_$group_num$ (trex_file, num) bind(C) + use, intrinsic :: iso_c_binding + type (c_ptr), intent(in), value :: trex_file + integer (c_int64_t), intent(in), value :: num + end function trexio_write_$group_num$ +end interface + + #+end_src + + + #+begin_src fortran :tangle read_num_front_fortran.f90 + +interface + integer (c_int32_t) function trexio_read_$group_num$ (trex_file, num) bind(C) + use, intrinsic :: iso_c_binding + type (c_ptr), intent(in), value :: trex_file + integer (c_int64_t), intent(inout), value :: num + end function trexio_read_$group_num$ +end interface + + #+end_src + + ** Template for frontend read/write a dataset #+begin_src c :tangle rw_dset_front.h @@ -551,5 +603,9 @@ trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* file, const $group_ #endif #+end_src + #+begin_src fortran :tangle suffix_fortran.f90 +end module trexio + #+end_src + From baa50bdbe276a3966093ff47a84da3a13847c5c2 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 22 Mar 2021 16:15:37 +0100 Subject: [PATCH 02/15] adapt for fortran --- src/Makefile | 15 +++++++++++---- src/build_trex.sh | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index 2222872..7802faa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,7 +6,10 @@ ifeq ($(COMPILER),GNU) CC=gcc -g CFLAGS=-fPIC -fexceptions -Wall -Werror -Wpedantic -Wextra -LIBS= -L/usr/lib/x86_64-linux-gnu/hdf5/serial/ -lz -lm -lhdf5 -lhdf5_hl #-lgfortran +FS=gfortran -g +FFLAGS=-fPIC -fcheck=all -Waliasing -Wampersand -Wconversion -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -Wreal-q-constant -Wuninitialized -fbacktrace -ffpe-trap=zero,overflow,underflow -finit-real=nan + +LIBS= -L/usr/lib/x86_64-linux-gnu/hdf5/serial/ -lz -lm -lhdf5 -lhdf5_hl -lgfortran INCLUDE = -I/usr/include/hdf5/serial endif @@ -35,18 +38,22 @@ endif OBJECT_FILES= trexio.o trexio_text.o trexio_hdf5.o HEADER_FILES= trexio.h trexio_text.h trexio_hdf5.h trexio_s.h -export CC CFLAGS LIBS +export CC CFLAGS FC FFLAGS LIBS .PHONY: clean libtrexio.so: $(OBJECT_FILES) $(HEADER_FILES) $(CC) -shared $(OBJECT_FILES) -o libtrexio.so -test: libtrexio.so test.c +fortran: libtrexio.so trexio_f.f90 + $(FC) $(FFLAGS) -c trexio_f.f90 -o trexio_f.o + +test: libtrexio.so test.c test.f90 trexio_f.o $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LIBS) -o test + $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. trexio_f.o test.f90 -ltrexio $(LIBS) -o test_f clean: - rm -f *.o libtrexio.so test test_*.h5 + rm -f *.o libtrexio.so test test_*.h5 test_f rm -r trexio_test/ %.o: %.c $(HEADER_FILES) diff --git a/src/build_trex.sh b/src/build_trex.sh index 8d7b0ca..c10636f 100755 --- a/src/build_trex.sh +++ b/src/build_trex.sh @@ -17,7 +17,7 @@ mkdir -p templates_hdf5/populated # not options. It is safer. echo "remove existing templates" -rm -f -- templates_front/*.{c,h} +rm -f -- templates_front/*.{c,h,f90} rm -f -- templates_text/*.{c,h} rm -f -- templates_hdf5/*.{c,h} From ac44fc29a64b74d2b953103ce7b9a637663e75bc Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 22 Mar 2021 16:40:45 +0100 Subject: [PATCH 03/15] add test, works for h5 but failt for txt --- src/templates_front/templator_front.org | 11 +++++------ src/test.f90 | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 src/test.f90 diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index dc7867d..111184d 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -12,7 +12,6 @@ #+end_src #+begin_src fortran :tangle prefix_fortran.f90 :noweb yes -<
> module trexio @@ -292,9 +291,9 @@ trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t b interface type (c_ptr) function trexio_open (filename, mode, backend) bind(C) use, intrinsic :: iso_c_binding - character(kind=c_char), dimension(*) :: filename - character(kind=c_char), intent(in) :: mode - integer (c_int32_t), intent(in), value :: backend + character(kind=c_char), dimension(*) :: filename + character(kind=c_char), intent(in), value :: mode + integer (c_int32_t), intent(in), value :: backend end function trexio_open end interface #+end_src @@ -375,7 +374,7 @@ trexio_exit_code trexio_close(trexio_t* file) { #+begin_src fortran :tangle prefix_fortran.f90 interface - type (c_int32_t) function trexio_close (trex_file) bind(C) + integer (c_int32_t) function trexio_close (trex_file) bind(C) use, intrinsic :: iso_c_binding type (c_ptr), intent(in), value :: trex_file end function trexio_close @@ -469,7 +468,7 @@ interface integer (c_int32_t) function trexio_read_$group_num$ (trex_file, num) bind(C) use, intrinsic :: iso_c_binding type (c_ptr), intent(in), value :: trex_file - integer (c_int64_t), intent(inout), value :: num + integer (c_int64_t), value :: num end function trexio_read_$group_num$ end interface diff --git a/src/test.f90 b/src/test.f90 new file mode 100644 index 0000000..3e44ab8 --- /dev/null +++ b/src/test.f90 @@ -0,0 +1,24 @@ +program test_trexio + + use trexio + + implicit none + + type(c_ptr) :: file1 + + integer :: rc + integer (c_int64_t) :: num + + rc = 0 + num = 10 + + file1 = trexio_open('test_fort' // c_null_char, 'w', 1) +! file1 = trexio_open('test_fort.h5' // c_null_char, 'w', 0) + + rc = trexio_write_nucleus_num(file1, num) + if (rc == 0) write(*,*) 'SUCCESS 1' + + rc = trexio_close(file1) + if (rc == 0) write(*,*) 'SUCCESS 2' + +end program test_trexio From d680120efea6fa67791cc4028530b40d4eaba969 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 23 Mar 2021 14:57:11 +0100 Subject: [PATCH 04/15] working write_num [fortran] --- src/templates_text/templator_text.org | 10 ++++++++-- src/test.f90 | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/templates_text/templator_text.org b/src/templates_text/templator_text.org index 64ab70f..e8eccb8 100644 --- a/src/templates_text/templator_text.org +++ b/src/templates_text/templator_text.org @@ -314,7 +314,10 @@ DEBUG return NULL; } - uint64_t size_$group_dset$ = 1; + // workaround for the case of missing blocks in the file + uint64_t size_$group_dset$ = 0; + if ($group$->rank_$group_dset$ != 0) size_$group_dset$ = 1; + for (unsigned int i=0; i<$group$->rank_$group_dset$; i++){ unsigned int j=-1; @@ -462,7 +465,10 @@ trexio_exit_code trexio_text_flush_$group$(const trexio_text_t* file) { fprintf(f, "rank_$group_dset$ %d\n", $group$->rank_$group_dset$); - uint64_t size_$group_dset$ = 1; + // workaround for the case of missing blocks in the file + uint64_t size_$group_dset$ = 0; + if ($group$->rank_$group_dset$ != 0) size_$group_dset$ = 1; + for (unsigned int i=0; i<$group$->rank_$group_dset$; i++){ fprintf(f, "dims_$group_dset$ %d %ld\n", i, $group$->dims_$group_dset$[i]); size_$group_dset$ *= $group$->dims_$group_dset$[i]; diff --git a/src/test.f90 b/src/test.f90 index 3e44ab8..00e410f 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -12,7 +12,7 @@ program test_trexio rc = 0 num = 10 - file1 = trexio_open('test_fort' // c_null_char, 'w', 1) + file1 = trexio_open('trexio_test' // c_null_char, 'w', 1) ! file1 = trexio_open('test_fort.h5' // c_null_char, 'w', 0) rc = trexio_write_nucleus_num(file1, num) From 0a28b5e5a5812d56246b211798b774da06b7485e Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 23 Mar 2021 16:34:13 +0100 Subject: [PATCH 05/15] working read_num [fortran] --- src/templates_front/templator_front.org | 2 +- src/test.f90 | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 111184d..f1678b1 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -468,7 +468,7 @@ interface integer (c_int32_t) function trexio_read_$group_num$ (trex_file, num) bind(C) use, intrinsic :: iso_c_binding type (c_ptr), intent(in), value :: trex_file - integer (c_int64_t), value :: num + type (c_ptr), value :: num end function trexio_read_$group_num$ end interface diff --git a/src/test.f90 b/src/test.f90 index 00e410f..a95e6a1 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -7,18 +7,30 @@ program test_trexio type(c_ptr) :: file1 integer :: rc - integer (c_int64_t) :: num + integer (c_int64_t) :: num + + type(c_ptr) :: num_test + integer, pointer :: num_read + integer, target :: num666 rc = 0 num = 10 + num_test = c_loc(num666) + file1 = trexio_open('trexio_test' // c_null_char, 'w', 1) ! file1 = trexio_open('test_fort.h5' // c_null_char, 'w', 0) rc = trexio_write_nucleus_num(file1, num) - if (rc == 0) write(*,*) 'SUCCESS 1' + if (rc == 0) write(*,*) 'SUCCESS WRITE' + + rc = trexio_read_nucleus_num(file1, num_test) + + call c_f_pointer(num_test, num_read) + + if (rc == 0 .and. num_read == num) write(*,*) 'SUCCESS READ' rc = trexio_close(file1) - if (rc == 0) write(*,*) 'SUCCESS 2' + if (rc == 0) write(*,*) 'SUCCESS CLOSE' end program test_trexio From cf26966b70969c43f788f826ab6f14d4b7fde816 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 23 Mar 2021 18:12:53 +0100 Subject: [PATCH 06/15] working write_dset [fortran] --- src/templates_front/templator_front.org | 25 +++++++++++++++++- src/test.f90 | 35 +++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index f1678b1..d156a10 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -582,7 +582,30 @@ trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* file, const $group_ } } #+end_src - + + #+begin_src fortran :tangle write_dset_front_fortran.f90 + +interface + integer (c_int32_t) function trexio_write_$group$_$group_dset$ (trex_file, dset) bind(C) + use, intrinsic :: iso_c_binding + type (c_ptr), intent(in), value :: trex_file + type (c_ptr), value :: dset + end function trexio_write_$group$_$group_dset$ +end interface + + #+end_src + + #+begin_src fortran :tangle read_dset_front_fortran.f90 + +interface + integer (c_int32_t) function trexio_read_$group$_$group_dset$ (trex_file, dset) bind(C) + use, intrinsic :: iso_c_binding + type (c_ptr), intent(in), value :: trex_file + type (c_ptr), value :: dset + end function trexio_read_$group$_$group_dset$ +end interface + + #+end_src * Back ends diff --git a/src/test.f90 b/src/test.f90 index a95e6a1..15dd5a9 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -13,8 +13,34 @@ program test_trexio integer, pointer :: num_read integer, target :: num666 + real, dimension(12), target :: charge + real, dimension(36) :: coord + + type(c_ptr) :: charge_ptr + real(c_double), pointer :: charge_cp(:) + + num = 12 + + charge = (/6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /) + + allocate(charge_cp(size(charge))) + charge_cp = charge + charge_ptr = c_loc(charge_cp) + + coord = (/ 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 /) + rc = 0 - num = 10 num_test = c_loc(num666) @@ -22,7 +48,10 @@ program test_trexio ! file1 = trexio_open('test_fort.h5' // c_null_char, 'w', 0) rc = trexio_write_nucleus_num(file1, num) - if (rc == 0) write(*,*) 'SUCCESS WRITE' + if (rc == 0) write(*,*) 'SUCCESS WRITE NUM' + + rc = trexio_write_nucleus_charge(file1, charge_ptr) + if (rc == 0) write(*,*) 'SUCCESS WRITE CHARGE' rc = trexio_read_nucleus_num(file1, num_test) @@ -33,4 +62,6 @@ program test_trexio rc = trexio_close(file1) if (rc == 0) write(*,*) 'SUCCESS CLOSE' + deallocate(charge_cp) + end program test_trexio From 4bdd6ea8f395df36cb63247e76fd591be94fb584 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 23 Mar 2021 18:19:35 +0100 Subject: [PATCH 07/15] adapt for fortran interface --- src/.gitignore | 6 +++++- src/Makefile | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/.gitignore b/src/.gitignore index 9b3b867..a22dab1 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,5 +1,6 @@ templates_front/*.c templates_front/*.h +templates_front/*.f90 templates_front/populated/ templates_hdf5/*.c @@ -16,8 +17,11 @@ libtrexio.so trexio.c trexio_text.c trexio_hdf5.c +trexio_f.f90 +trexio.mod test -test_write.h5 +test_f +*.h5 trexio_test/ diff --git a/src/Makefile b/src/Makefile index 7802faa..f72ee11 100644 --- a/src/Makefile +++ b/src/Makefile @@ -49,8 +49,9 @@ fortran: libtrexio.so trexio_f.f90 $(FC) $(FFLAGS) -c trexio_f.f90 -o trexio_f.o test: libtrexio.so test.c test.f90 trexio_f.o + rm -f -r trexio_test/ $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LIBS) -o test - $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. trexio_f.o test.f90 -ltrexio $(LIBS) -o test_f + $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.f90 -ltrexio $(LIBS) -o test_f clean: rm -f *.o libtrexio.so test test_*.h5 test_f From 8d3b35736cf776875d8981556a9a62e4ed3b9a91 Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 24 Mar 2021 11:14:47 +0100 Subject: [PATCH 08/15] working read_dset + structured test file [fortran] --- src/Makefile | 4 +- src/test.f90 | 122 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 103 insertions(+), 23 deletions(-) diff --git a/src/Makefile b/src/Makefile index f72ee11..53d4a3f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -49,13 +49,13 @@ fortran: libtrexio.so trexio_f.f90 $(FC) $(FFLAGS) -c trexio_f.f90 -o trexio_f.o test: libtrexio.so test.c test.f90 trexio_f.o - rm -f -r trexio_test/ + rm -f -r test_text_fort/ $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LIBS) -o test $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.f90 -ltrexio $(LIBS) -o test_f clean: rm -f *.o libtrexio.so test test_*.h5 test_f - rm -r trexio_test/ + rm -r test_text_fort/ %.o: %.c $(HEADER_FILES) $(CC) $(CFLAGS) $(INCLUDE) -c $*.c -o $*.o diff --git a/src/test.f90 b/src/test.f90 index 15dd5a9..1072eb1 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -1,24 +1,31 @@ program test_trexio - use trexio + call test_write() + call test_read() +end program test_trexio + +subroutine test_write() + + use trexio + use, intrinsic :: iso_c_binding implicit none - type(c_ptr) :: file1 + type(c_ptr) :: trex_file integer :: rc integer (c_int64_t) :: num - type(c_ptr) :: num_test - integer, pointer :: num_read - integer, target :: num666 - real, dimension(12), target :: charge - real, dimension(36) :: coord + real, dimension(36), target :: coord type(c_ptr) :: charge_ptr real(c_double), pointer :: charge_cp(:) + type(c_ptr) :: coord_ptr + real(c_double), pointer :: coord_cp(:) + + num = 12 charge = (/6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /) @@ -40,28 +47,101 @@ program test_trexio 2.14171677 , 1.23652075 , 0.00000000 , & 0.00000000 , 2.47304151 , 0.00000000 /) + allocate(coord_cp(size(coord))) + coord_cp = coord + coord_ptr = c_loc(coord_cp) + + rc = 0 + + trex_file = trexio_open('test_text_fort' // c_null_char, 'w', 1) +! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'w', 0) + + rc = trexio_write_nucleus_num(trex_file, num) + if (rc == 0) write(*,*) 'SUCCESS WRITE NUM' + + rc = trexio_write_nucleus_charge(trex_file, charge_ptr) + if (rc == 0) write(*,*) 'SUCCESS WRITE CHARGE' + + rc = trexio_write_nucleus_coord(trex_file, coord_ptr) + if (rc == 0) write(*,*) 'SUCCESS WRITE COORD' + + rc = trexio_close(trex_file) + if (rc == 0) write(*,*) 'SUCCESS CLOSE' + +! ---------------------------------- ! +! to modify fiels of existing file: +! text backend -> open with 'w' +! hdf5 backend -> open with 'a' +! ---------------------------------- ! + + trex_file = trexio_open('test_text_fort' // c_null_char, 'w', 1); +! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'a', 0) + + coord(1) = 666.666 + coord_cp = coord + coord_ptr = c_loc(coord_cp) + + rc = trexio_write_nucleus_coord(trex_file,coord_ptr) + if (rc == 0) write(*,*) 'SUCCESS MODIFY COORD' + + rc = trexio_close(trex_file) + if (rc == 0) write(*,*) 'SUCCESS CLOSE 2' + + + deallocate(charge_cp) + deallocate(coord_cp) + +end subroutine test_write + +subroutine test_read() + + use trexio + use, intrinsic :: iso_c_binding + implicit none + + type(c_ptr) :: trex_file + + integer :: rc + integer (c_int64_t) :: num + + type(c_ptr) :: num_test + integer, pointer :: num_read + integer, target :: num666 + + real, dimension(12) :: charge + + type(c_ptr) :: charge_ptr + real(c_double), pointer :: charge_read(:) + + num = 12 + + charge = (/0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0. /) + + allocate(charge_read(size(charge))) + charge_read = charge + charge_ptr = c_loc(charge_read) + rc = 0 num_test = c_loc(num666) - file1 = trexio_open('trexio_test' // c_null_char, 'w', 1) -! file1 = trexio_open('test_fort.h5' // c_null_char, 'w', 0) - - rc = trexio_write_nucleus_num(file1, num) - if (rc == 0) write(*,*) 'SUCCESS WRITE NUM' - - rc = trexio_write_nucleus_charge(file1, charge_ptr) - if (rc == 0) write(*,*) 'SUCCESS WRITE CHARGE' - - rc = trexio_read_nucleus_num(file1, num_test) + trex_file = trexio_open('test_text_fort' // c_null_char, 'r', 1) +! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'r', 0) + rc = trexio_read_nucleus_num(trex_file, num_test) call c_f_pointer(num_test, num_read) - if (rc == 0 .and. num_read == num) write(*,*) 'SUCCESS READ' + if (rc == 0 .and. num_read == num) write(*,*) 'SUCCESS READ NUM' - rc = trexio_close(file1) + rc = trexio_read_nucleus_charge(trex_file, charge_ptr) + call c_f_pointer(charge_ptr, charge_read, [num_read]) + + if (rc == 0 .and. (abs (charge_read(11) - 1.0) < 1.0D-8) ) write(*,*) 'SUCCESS READ CHARGE' + + rc = trexio_close(trex_file) if (rc == 0) write(*,*) 'SUCCESS CLOSE' - deallocate(charge_cp) + deallocate(charge_read) + +end subroutine test_read -end program test_trexio From f7c78e73d24395b760177882a85b367803b78ec3 Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 24 Mar 2021 16:05:38 +0100 Subject: [PATCH 09/15] more fortran-ic interface + flexible dtypes for dsets --- src/generator.py | 5 ++++ src/templates_front/templator_front.org | 40 ++++++++++++++----------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/generator.py b/src/generator.py index 973de2c..420523d 100644 --- a/src/generator.py +++ b/src/generator.py @@ -82,6 +82,7 @@ templ_path_front = join(fileDir,'templates_front') files_exclude = ['prefix_hdf5.c', 'prefix_hdf5.h', 'suffix_hdf5.h', 'prefix_text.c', 'prefix_text.h', 'suffix_text.h', 'prefix_front.c', 'prefix_front.h', 'suffix_front.h', + 'prefix_fortran.f90', 'suffix_fortran.f90', 'prefix_s_front.h', 'suffix_s_front.h', 'templator_front.org', 'templator_hdf5.org', 'templator_text.org'] @@ -259,12 +260,16 @@ for fname in files_funcs_dsets: if params['dtype'] == 'double': h5_dtype = 'double' + f_dtype = 'real(8)' elif params['dtype'] == 'int64_t': h5_dtype = 'long' + f_dtype = 'integer(8)' templine1 = templine2.replace('$group_dset_h5_dtype$', h5_dtype) templine2 = templine1.replace('$group_dset_h5_dtype$'.upper(), h5_dtype.upper()) + templine1 = templine2.replace('$group_dset_f_dtype$', f_dtype) + templine2 = templine1.replace('$group_dset_f_dtype$'.upper(), f_dtype.upper()) templine1 = templine2.replace('$group_dset_rank$', str(params['rank'])) templine2 = templine1 diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index d156a10..55fd1b1 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -16,7 +16,13 @@ module trexio use, intrinsic :: iso_c_binding + implicit none + integer, parameter :: TREXIO_HDF5 = 0 + integer, parameter :: TREXIO_TEXT = 1 +! integer, parameter :: TREXIO_JSON = 2 + integer, parameter :: TREXIO_INVALID_BACK_END = 3 + #+end_src #+begin_src c :tangle prefix_front.h :noweb yes @@ -289,11 +295,11 @@ trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t b #+begin_src fortran :tangle prefix_fortran.f90 interface - type (c_ptr) function trexio_open (filename, mode, backend) bind(C) + integer(8) function trexio_open (filename, mode, backend) bind(C) use, intrinsic :: iso_c_binding character(kind=c_char), dimension(*) :: filename - character(kind=c_char), intent(in), value :: mode - integer (c_int32_t), intent(in), value :: backend + character, intent(in), value :: mode + integer, intent(in), value :: backend end function trexio_open end interface #+end_src @@ -374,9 +380,9 @@ trexio_exit_code trexio_close(trexio_t* file) { #+begin_src fortran :tangle prefix_fortran.f90 interface - integer (c_int32_t) function trexio_close (trex_file) bind(C) + integer function trexio_close (trex_file) bind(C) use, intrinsic :: iso_c_binding - type (c_ptr), intent(in), value :: trex_file + integer(8), intent(in), value :: trex_file end function trexio_close end interface #+end_src @@ -452,10 +458,10 @@ trexio_exit_code trexio_write_$group_num$(trexio_t* file, const int64_t num) { #+begin_src fortran :tangle write_num_front_fortran.f90 interface - integer (c_int32_t) function trexio_write_$group_num$ (trex_file, num) bind(C) + integer function trexio_write_$group_num$ (trex_file, num) bind(C) use, intrinsic :: iso_c_binding - type (c_ptr), intent(in), value :: trex_file - integer (c_int64_t), intent(in), value :: num + integer(8), intent(in), value :: trex_file + integer(8), intent(in), value :: num end function trexio_write_$group_num$ end interface @@ -465,10 +471,10 @@ end interface #+begin_src fortran :tangle read_num_front_fortran.f90 interface - integer (c_int32_t) function trexio_read_$group_num$ (trex_file, num) bind(C) + integer function trexio_read_$group_num$ (trex_file, num) bind(C) use, intrinsic :: iso_c_binding - type (c_ptr), intent(in), value :: trex_file - type (c_ptr), value :: num + integer(8), intent(in), value :: trex_file + integer(8), intent(out) :: num end function trexio_read_$group_num$ end interface @@ -586,10 +592,10 @@ trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* file, const $group_ #+begin_src fortran :tangle write_dset_front_fortran.f90 interface - integer (c_int32_t) function trexio_write_$group$_$group_dset$ (trex_file, dset) bind(C) + integer function trexio_write_$group$_$group_dset$ (trex_file, dset) bind(C) use, intrinsic :: iso_c_binding - type (c_ptr), intent(in), value :: trex_file - type (c_ptr), value :: dset + integer(8), intent(in), value :: trex_file + $group_dset_f_dtype$, intent(in) :: dset(*) end function trexio_write_$group$_$group_dset$ end interface @@ -598,10 +604,10 @@ end interface #+begin_src fortran :tangle read_dset_front_fortran.f90 interface - integer (c_int32_t) function trexio_read_$group$_$group_dset$ (trex_file, dset) bind(C) + integer function trexio_read_$group$_$group_dset$ (trex_file, dset) bind(C) use, intrinsic :: iso_c_binding - type (c_ptr), intent(in), value :: trex_file - type (c_ptr), value :: dset + integer(8), intent(in), value :: trex_file + $group_dset_f_dtype$, intent(out) :: dset(*) end function trexio_read_$group$_$group_dset$ end interface From c0b6f95e5271313f1cde65849ff81998746e329a Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 24 Mar 2021 16:06:04 +0100 Subject: [PATCH 10/15] more fortran-ic test --- src/test.f90 | 81 ++++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 60 deletions(-) diff --git a/src/test.f90 b/src/test.f90 index 1072eb1..d6fe1b8 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -11,29 +11,20 @@ subroutine test_write() use, intrinsic :: iso_c_binding implicit none - type(c_ptr) :: trex_file + integer(8) :: trex_file integer :: rc - integer (c_int64_t) :: num + integer(8) :: num - real, dimension(12), target :: charge - real, dimension(36), target :: coord - - type(c_ptr) :: charge_ptr - real(c_double), pointer :: charge_cp(:) - - type(c_ptr) :: coord_ptr - real(c_double), pointer :: coord_cp(:) + double precision :: charge(12) + double precision :: coord(36) + rc = 0 num = 12 charge = (/6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /) - allocate(charge_cp(size(charge))) - charge_cp = charge - charge_ptr = c_loc(charge_cp) - coord = (/ 0.00000000 , 1.39250319 , 0.00000000 , & -1.20594314 , 0.69625160 , 0.00000000 , & -1.20594314 , -0.69625160 , 0.00000000 , & @@ -47,22 +38,17 @@ subroutine test_write() 2.14171677 , 1.23652075 , 0.00000000 , & 0.00000000 , 2.47304151 , 0.00000000 /) - allocate(coord_cp(size(coord))) - coord_cp = coord - coord_ptr = c_loc(coord_cp) - rc = 0 - - trex_file = trexio_open('test_text_fort' // c_null_char, 'w', 1) -! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'w', 0) + trex_file = trexio_open('test_text_fort' // c_null_char, 'w', TREXIO_TEXT) +! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'w', TREXIO_HDF5) rc = trexio_write_nucleus_num(trex_file, num) if (rc == 0) write(*,*) 'SUCCESS WRITE NUM' - rc = trexio_write_nucleus_charge(trex_file, charge_ptr) + rc = trexio_write_nucleus_charge(trex_file, charge) if (rc == 0) write(*,*) 'SUCCESS WRITE CHARGE' - rc = trexio_write_nucleus_coord(trex_file, coord_ptr) + rc = trexio_write_nucleus_coord(trex_file, coord) if (rc == 0) write(*,*) 'SUCCESS WRITE COORD' rc = trexio_close(trex_file) @@ -74,22 +60,16 @@ subroutine test_write() ! hdf5 backend -> open with 'a' ! ---------------------------------- ! - trex_file = trexio_open('test_text_fort' // c_null_char, 'w', 1); -! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'a', 0) + trex_file = trexio_open('test_text_fort' // c_null_char, 'w', TREXIO_TEXT); +! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'a', TREXIO_HDF5) coord(1) = 666.666 - coord_cp = coord - coord_ptr = c_loc(coord_cp) - rc = trexio_write_nucleus_coord(trex_file,coord_ptr) + rc = trexio_write_nucleus_coord(trex_file,coord) if (rc == 0) write(*,*) 'SUCCESS MODIFY COORD' rc = trexio_close(trex_file) - if (rc == 0) write(*,*) 'SUCCESS CLOSE 2' - - - deallocate(charge_cp) - deallocate(coord_cp) + if (rc == 0) write(*,*) 'SUCCESS CLOSE' end subroutine test_write @@ -99,49 +79,30 @@ subroutine test_read() use, intrinsic :: iso_c_binding implicit none - type(c_ptr) :: trex_file + integer(8) :: trex_file integer :: rc - integer (c_int64_t) :: num + integer(8) :: num, num_read - type(c_ptr) :: num_test - integer, pointer :: num_read - integer, target :: num666 - - real, dimension(12) :: charge - - type(c_ptr) :: charge_ptr - real(c_double), pointer :: charge_read(:) + double precision :: charge(12) num = 12 - charge = (/0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0. /) - - allocate(charge_read(size(charge))) - charge_read = charge - charge_ptr = c_loc(charge_read) - rc = 0 - num_test = c_loc(num666) + trex_file = trexio_open('test_text_fort' // c_null_char, 'r', TREXIO_TEXT) +! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'r', TREXIO_HDF5) - trex_file = trexio_open('test_text_fort' // c_null_char, 'r', 1) -! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'r', 0) - - rc = trexio_read_nucleus_num(trex_file, num_test) - call c_f_pointer(num_test, num_read) + rc = trexio_read_nucleus_num(trex_file, num_read) if (rc == 0 .and. num_read == num) write(*,*) 'SUCCESS READ NUM' - rc = trexio_read_nucleus_charge(trex_file, charge_ptr) - call c_f_pointer(charge_ptr, charge_read, [num_read]) + rc = trexio_read_nucleus_charge(trex_file, charge) - if (rc == 0 .and. (abs (charge_read(11) - 1.0) < 1.0D-8) ) write(*,*) 'SUCCESS READ CHARGE' + if (rc == 0 .and. (abs (charge(11) - 1.0) < 1.0D-8) ) write(*,*) 'SUCCESS READ CHARGE' rc = trexio_close(trex_file) if (rc == 0) write(*,*) 'SUCCESS CLOSE' - deallocate(charge_read) - end subroutine test_read From f8a28a037da81f1f0ede1ea390d367391f6576ff Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 24 Mar 2021 17:13:53 +0100 Subject: [PATCH 11/15] more fortran-ic trexio_open --- src/templates_front/templator_front.org | 29 ++++++++++++++++++++----- src/test.f90 | 21 +++++++++--------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 55fd1b1..6b00cd1 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -295,12 +295,12 @@ trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t b #+begin_src fortran :tangle prefix_fortran.f90 interface - integer(8) function trexio_open (filename, mode, backend) bind(C) + integer(8) function trexio_open_c (filename, mode, backend) bind(C, name="trexio_open") use, intrinsic :: iso_c_binding - character(kind=c_char), dimension(*) :: filename - character, intent(in), value :: mode - integer, intent(in), value :: backend - end function trexio_open + character(kind=c_char), dimension(*) :: filename + character, intent(in), value :: mode + integer, intent(in), value :: backend + end function trexio_open_c end interface #+end_src @@ -621,6 +621,25 @@ end interface - Text files: not to be used for production, but useful for debugging - JSON: for portability + +* Fortran helper/wrapper functions + + #+begin_src fortran :tangle suffix_fortran.f90 +contains + integer(8) function trexio_open (filename, mode, backend) + use, intrinsic :: iso_c_binding + implicit none + character(len=*) :: filename + character, intent(in), value :: mode + integer, intent(in), value :: backend + character(len=len_trim(filename)+1) :: filename_c + + filename_c = trim(filename) // c_null_char + trexio_open = trexio_open_c(filename_c, mode, backend) + end function trexio_open + #+end_src + + * File suffixes :noxport: #+begin_src c :tangle suffix_front.h diff --git a/src/test.f90 b/src/test.f90 index d6fe1b8..2085c48 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -38,9 +38,8 @@ subroutine test_write() 2.14171677 , 1.23652075 , 0.00000000 , & 0.00000000 , 2.47304151 , 0.00000000 /) - - trex_file = trexio_open('test_text_fort' // c_null_char, 'w', TREXIO_TEXT) -! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'w', TREXIO_HDF5) +! trex_file = trexio_open('test_text_fort', 'w', TREXIO_TEXT) + trex_file = trexio_open('test_hdf5_fort.h5', 'w', TREXIO_HDF5) rc = trexio_write_nucleus_num(trex_file, num) if (rc == 0) write(*,*) 'SUCCESS WRITE NUM' @@ -60,16 +59,16 @@ subroutine test_write() ! hdf5 backend -> open with 'a' ! ---------------------------------- ! - trex_file = trexio_open('test_text_fort' // c_null_char, 'w', TREXIO_TEXT); +! trex_file = trexio_open('test_text_fort' // c_null_char, 'w', TREXIO_TEXT); ! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'a', TREXIO_HDF5) - coord(1) = 666.666 +! coord(1) = 666.666 - rc = trexio_write_nucleus_coord(trex_file,coord) - if (rc == 0) write(*,*) 'SUCCESS MODIFY COORD' +! rc = trexio_write_nucleus_coord(trex_file,coord) +! if (rc == 0) write(*,*) 'SUCCESS MODIFY COORD' - rc = trexio_close(trex_file) - if (rc == 0) write(*,*) 'SUCCESS CLOSE' +! rc = trexio_close(trex_file) +! if (rc == 0) write(*,*) 'SUCCESS CLOSE' end subroutine test_write @@ -90,8 +89,8 @@ subroutine test_read() rc = 0 - trex_file = trexio_open('test_text_fort' // c_null_char, 'r', TREXIO_TEXT) -! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'r', TREXIO_HDF5) +! trex_file = trexio_open('test_text_fort', 'r', TREXIO_TEXT) + trex_file = trexio_open('test_hdf5_fort.h5', 'r', TREXIO_HDF5) rc = trexio_read_nucleus_num(trex_file, num_read) From 81810669ab3019e0dc14fce4f4315fbbbf6046e0 Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 24 Mar 2021 17:14:23 +0100 Subject: [PATCH 12/15] link module when compiling fortran test --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 53d4a3f..cd965b7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -51,7 +51,7 @@ fortran: libtrexio.so trexio_f.f90 test: libtrexio.so test.c test.f90 trexio_f.o rm -f -r test_text_fort/ $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LIBS) -o test - $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.f90 -ltrexio $(LIBS) -o test_f + $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.f90 trexio_f.o -ltrexio $(LIBS) -o test_f clean: rm -f *.o libtrexio.so test test_*.h5 test_f From 91fdbf20df5e09447d7dffbd009989b16cce5cca Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 24 Mar 2021 17:22:58 +0100 Subject: [PATCH 13/15] better test [fortran] --- src/test.f90 | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/test.f90 b/src/test.f90 index 2085c48..e8ec3f1 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -13,18 +13,14 @@ subroutine test_write() integer(8) :: trex_file - integer :: rc + integer :: rc = 1 integer(8) :: num double precision :: charge(12) double precision :: coord(36) - rc = 0 - num = 12 - charge = (/6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /) - coord = (/ 0.00000000 , 1.39250319 , 0.00000000 , & -1.20594314 , 0.69625160 , 0.00000000 , & -1.20594314 , -0.69625160 , 0.00000000 , & @@ -59,8 +55,8 @@ subroutine test_write() ! hdf5 backend -> open with 'a' ! ---------------------------------- ! -! trex_file = trexio_open('test_text_fort' // c_null_char, 'w', TREXIO_TEXT); -! trex_file = trexio_open('test_hdf5_fort.h5' // c_null_char, 'a', TREXIO_HDF5) +!! trex_file = trexio_open('test_text_fort', 'w', TREXIO_TEXT); +!! trex_file = trexio_open('test_hdf5_fort.h5', 'a', TREXIO_HDF5) ! coord(1) = 666.666 @@ -80,15 +76,14 @@ subroutine test_read() integer(8) :: trex_file - integer :: rc + integer :: rc = 1 integer(8) :: num, num_read double precision :: charge(12) + double precision :: coord(36) num = 12 - rc = 0 - ! trex_file = trexio_open('test_text_fort', 'r', TREXIO_TEXT) trex_file = trexio_open('test_hdf5_fort.h5', 'r', TREXIO_HDF5) @@ -100,6 +95,10 @@ subroutine test_read() if (rc == 0 .and. (abs (charge(11) - 1.0) < 1.0D-8) ) write(*,*) 'SUCCESS READ CHARGE' + rc = trexio_read_nucleus_coord(trex_file, coord) + + if (rc == 0 .and. (abs (coord(2) - 1.39250319) < 1.0D-8) ) write(*,*) 'SUCCESS READ COORD' + rc = trexio_close(trex_file) if (rc == 0) write(*,*) 'SUCCESS CLOSE' From aa160d9bea7c4746cb6b48aa7f8afa4435f8f70a Mon Sep 17 00:00:00 2001 From: q-posev Date: Thu, 25 Mar 2021 11:41:13 +0100 Subject: [PATCH 14/15] make build scripts consistent --- src/templates_front/build.sh | 22 ++++++++++------------ src/templates_hdf5/build.sh | 2 +- src/templates_text/build.sh | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/templates_front/build.sh b/src/templates_front/build.sh index 3d5b5e4..f20f78a 100644 --- a/src/templates_front/build.sh +++ b/src/templates_front/build.sh @@ -1,22 +1,20 @@ #!/bin/bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" - # prefixes -cat $DIR/prefix_front.c > trexio.c -cat $DIR/prefix_front.h > trexio.h -cat $DIR/prefix_s_front.h > trexio_s.h -cat $DIR/prefix_fortran.f90 > trexio_f.f90 +cat prefix_front.c > trexio.c +cat prefix_front.h > trexio.h +cat prefix_s_front.h > trexio_s.h +cat prefix_fortran.f90 > trexio_f.f90 # c front end -cat $DIR/populated/pop_*.c >> trexio.c -cat $DIR/populated/pop_*.h >> trexio.h +cat populated/pop_*.c >> trexio.c +cat populated/pop_*.h >> trexio.h # fortran front end -cat $DIR/populated/pop_*.f90 >> trexio_f.f90 +cat populated/pop_*.f90 >> trexio_f.f90 # suffixes -cat $DIR/suffix_s_front.h >> trexio_s.h -cat $DIR/suffix_front.h >> trexio.h -cat $DIR/suffix_fortran.f90 >> trexio_f.f90 +cat suffix_s_front.h >> trexio_s.h +cat suffix_front.h >> trexio.h +cat suffix_fortran.f90 >> trexio_f.f90 diff --git a/src/templates_hdf5/build.sh b/src/templates_hdf5/build.sh index 213bdb3..e9bb94b 100644 --- a/src/templates_hdf5/build.sh +++ b/src/templates_hdf5/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash cat prefix_hdf5.c > trexio_hdf5.c cat prefix_hdf5.h > trexio_hdf5.h diff --git a/src/templates_text/build.sh b/src/templates_text/build.sh index 2835dd3..e8e1918 100644 --- a/src/templates_text/build.sh +++ b/src/templates_text/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash cat prefix_text.c > trexio_text.c cat prefix_text.h > trexio_text.h From ebb5ff62d32c2b8e9a161d39933a5b7f033146e8 Mon Sep 17 00:00:00 2001 From: q-posev Date: Thu, 25 Mar 2021 11:42:13 +0100 Subject: [PATCH 15/15] better make for tests --- src/Makefile | 18 +++++++++++++----- src/test.f90 | 6 +++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Makefile b/src/Makefile index cd965b7..7cac3bc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,6 +34,7 @@ FFLAGS=fPIC -g -O2 LIBS=-lm endif +RM=rm -f OBJECT_FILES= trexio.o trexio_text.o trexio_hdf5.o HEADER_FILES= trexio.h trexio_text.h trexio_hdf5.h trexio_s.h @@ -48,14 +49,21 @@ libtrexio.so: $(OBJECT_FILES) $(HEADER_FILES) fortran: libtrexio.so trexio_f.f90 $(FC) $(FFLAGS) -c trexio_f.f90 -o trexio_f.o -test: libtrexio.so test.c test.f90 trexio_f.o - rm -f -r test_text_fort/ - $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LIBS) -o test +test_c: libtrexio.so test.c + $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LIBS) -o test_c + +test_f: libtrexio.so test.f90 trexio_f.o $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.f90 trexio_f.o -ltrexio $(LIBS) -o test_f +test: test_c test_f + $(RM) -r trexio_test + $(RM) -r trexio_test_fort + ./test_c + ./test_f + clean: - rm -f *.o libtrexio.so test test_*.h5 test_f - rm -r test_text_fort/ + $(RM) *.o libtrexio.so test_*.h5 test_f test_c + $(RM) -r trexio_test/ trexio_test_fort/ %.o: %.c $(HEADER_FILES) $(CC) $(CFLAGS) $(INCLUDE) -c $*.c -o $*.o diff --git a/src/test.f90 b/src/test.f90 index e8ec3f1..1116b08 100644 --- a/src/test.f90 +++ b/src/test.f90 @@ -34,7 +34,7 @@ subroutine test_write() 2.14171677 , 1.23652075 , 0.00000000 , & 0.00000000 , 2.47304151 , 0.00000000 /) -! trex_file = trexio_open('test_text_fort', 'w', TREXIO_TEXT) +! trex_file = trexio_open('trexio_test_fort', 'w', TREXIO_TEXT) trex_file = trexio_open('test_hdf5_fort.h5', 'w', TREXIO_HDF5) rc = trexio_write_nucleus_num(trex_file, num) @@ -55,7 +55,7 @@ subroutine test_write() ! hdf5 backend -> open with 'a' ! ---------------------------------- ! -!! trex_file = trexio_open('test_text_fort', 'w', TREXIO_TEXT); +!! trex_file = trexio_open('trexio_test_fort', 'w', TREXIO_TEXT); !! trex_file = trexio_open('test_hdf5_fort.h5', 'a', TREXIO_HDF5) ! coord(1) = 666.666 @@ -84,7 +84,7 @@ subroutine test_read() num = 12 -! trex_file = trexio_open('test_text_fort', 'r', TREXIO_TEXT) +! trex_file = trexio_open('trexio_test_fort', 'r', TREXIO_TEXT) trex_file = trexio_open('test_hdf5_fort.h5', 'r', TREXIO_HDF5) rc = trexio_read_nucleus_num(trex_file, num_read)