Skip to content

Commit 630fdee

Browse files
authored
Merge pull request #113 from robertodr/hotfix-get-api
Fix xcfun_get API function
2 parents 84814d2 + 0d4fee9 commit 630fdee

File tree

7 files changed

+36
-9
lines changed

7 files changed

+36
-9
lines changed

.readthedocs.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
3+
sphinx:
4+
configuration: doc/conf.py
5+
6+
formats:
7+
- html
8+
- pdf
9+
10+
python:
11+
version: 3.6

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
7+
- The API function `xcfun_get` accepts a single in-out `double` parameter. It
8+
was erroneously declared to accept an array of `double`-s instead.
9+
10+
## [Version 2.0.0a3] - 2020-01-31
11+
512
We have introduced a number of breaking changes, motivated by the need to
613
modernize the library. See the [migration guide](docs/migration.rst).
714

@@ -51,7 +58,8 @@ modernize the library. See the [migration guide](docs/migration.rst).
5158
- **BREAKING** The Fortran interface is no longer build with the code, but
5259
shipped as a separate file to be compiled within your own Fortran code.
5360

54-
[Unreleased]: https://github.com/dftlibs/xcfun/compare/v2.0.0a2...HEAD
61+
[Unreleased]: https://github.com/dftlibs/xcfun/compare/v2.0.0a3...HEAD
62+
[Version 2.0.0a2]: https://github.com/dftlibs/xcfun/compare/v2.0.0a2...v2.0.0a3
5563
[Version 2.0.0a2]: https://github.com/dftlibs/xcfun/compare/v2.0.0a1...v2.0.0a2
5664
[Version 2.0.0a1]: https://github.com/dftlibs/xcfun/releases/tag/v2.0.0a1
5765

api/xcfun.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function xcfun_get_C(fun, name, val) result(err) &
168168
import
169169
type(c_ptr), intent(in), value :: fun
170170
character(kind=c_char, len=1), intent(in) :: name(*)
171-
real(c_double), intent(inout) :: val(*)
171+
real(c_double), intent(inout) :: val
172172
integer(c_int) :: err
173173
end function
174174

@@ -347,7 +347,7 @@ function xcfun_set(fun, param, val) result(err)
347347
function xcfun_get(fun, param, val) result(err)
348348
type(c_ptr), value :: fun
349349
character(kind=c_char, len=*), intent(in) :: param
350-
real(c_double), intent(inout) :: val(*)
350+
real(c_double), intent(inout) :: val
351351
integer(c_int) :: err
352352

353353
err = xcfun_get_C(fun, fstring_to_carray(param), val)

api/xcfun.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ XCFun_API void xcfun_delete(xcfun_t * fun);
145145

146146
XCFun_API int xcfun_set(xcfun_t * fun, const char * name, double value);
147147

148-
XCFun_API int xcfun_get(const xcfun_t * fun, const char * name, double value[]);
148+
XCFun_API int xcfun_get(const xcfun_t * fun, const char * name, double * value);
149149

150150
XCFun_API bool xcfun_is_gga(const xcfun_t * fun);
151151

examples/Fortran_host/example.f90

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ program xc_example
2626
xcfun_splash, &
2727
xcfun_new, &
2828
xcfun_set, &
29+
xcfun_get, &
2930
xcfun_eval_setup, &
3031
xcfun_eval, &
3132
xcfun_delete
@@ -46,7 +47,7 @@ program xc_example
4647

4748
integer :: order, ierr, ipoint
4849
integer :: vector_length
49-
real(8) :: res
50+
real(8) :: res, weight
5051

5152
real(8), allocatable :: density(:, :, :)
5253

@@ -64,6 +65,13 @@ program xc_example
6465
print *, 'Setting up PBE'
6566
ierr = xcfun_set(fun, 'pbe', 1.0d0)
6667
call assert(ierr == 0, "functional name not recognized")
68+
! let's get back the weight of exchange and correlation components
69+
ierr = xcfun_get(fun, 'pbex', weight)
70+
call assert(ierr == 0, "functional name not recognized")
71+
print *, 'PBE exchange weight is ', weight
72+
ierr = xcfun_get(fun, 'pbec', weight)
73+
call assert(ierr == 0, "functional name not recognized")
74+
print *, 'PBE correlation weight is ', weight
6775

6876

6977
!-----------------------------------------------------------------------------

src/XCFunctional.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ int xcfun_set(XCFunctional * fun, const char * name, double value) {
406406
return -1;
407407
}
408408

409-
int xcfun_get(const XCFunctional * fun, const char * name, double value[]) {
409+
int xcfun_get(const XCFunctional * fun, const char * name, double * value) {
410410
xcint_assure_setup();
411411
int item;
412412
if ((item = xcint_lookup_functional(name)) >= 0) {
@@ -820,12 +820,12 @@ int xcfun_set(xcfun_t * fun, const char * name, double value) {
820820
*
821821
* param[in] fun the functional object
822822
* param[in] name functional name to test, aliases not supported
823-
* param[out] value weight of functional
823+
* param[in,out] value weight of functional
824824
*
825825
* Returns 0 if name is a valid functional, -1 if not.
826826
* See list_of_functionals.hpp for valid functional names.
827827
*/
828-
int xcfun_get(const xcfun_t * fun, const char * name, double value[]) {
828+
int xcfun_get(const xcfun_t * fun, const char * name, double * value) {
829829
return xcfun::xcfun_get(AS_CTYPE(XCFunctional, fun), name, value);
830830
}
831831

src/XCFunctional.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace xcfun {
3737
XCFunctional * xcfun_new();
3838
void xcfun_delete(XCFunctional *);
3939
int xcfun_set(XCFunctional * fun, const char * name, double value);
40-
int xcfun_get(const XCFunctional * fun, const char * name, double value[]);
40+
int xcfun_get(const XCFunctional * fun, const char * name, double * value);
4141
bool xcfun_is_gga(const XCFunctional * fun);
4242
bool xcfun_is_metagga(const XCFunctional * fun);
4343
int xcfun_eval_setup(XCFunctional * fun,

0 commit comments

Comments
 (0)