1!! Copyright (C) 2016 Micael Oliveira
2!! All rights reserved.
3!!
4!! This file is dual-licensed under a GPL and a BSD license
5!!
6!! MPL License:
7!!
8!! This Source Code Form is subject to the terms of the Mozilla Public
9!! License, v. 2.0. If a copy of the MPL was not distributed with this
10!! file, You can obtain one at mozilla.org/MPL/2.0/.
11!!
12!! BSD License:
13!!
14!! Redistribution and use in source and binary forms, with or without
15!! modification, are permitted provided that the following conditions
16!! are met:
17!!
18!! 1. Redistributions of source code must retain the above copyright
19!! notice, this list of conditions and the following disclaimer.
20!!
21!! 2. Redistributions in binary form must reproduce the above
22!! copyright notice, this list of conditions and the following
23!! disclaimer in the documentation and/or other materials provided
24!! with the distribution.
25!!
26!! 3. Neither the name of the copyright holder nor the names of its
27!! contributors may be used to endorse or promote products derived
28!! from this software without specific prior written permission.
29!!
30!! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31!! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32!! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33!! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34!! COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35!! INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36!! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37!! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38!! HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39!! STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40!! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41!! OF THE POSSIBILITY OF SUCH DAMAGE.
42
43
44module xc_f90_lib_m
45  use, intrinsic :: iso_c_binding
46  implicit none
47
48  private
49  public :: &
50    ! version
51    xc_f90_version, &
52    xc_f90_version_string, &
53    ! func_info
54    xc_f90_func_info_t, &
55    xc_f90_func_info_get_number, &
56    xc_f90_func_info_get_kind, &
57    xc_f90_func_info_get_name, &
58    xc_f90_func_info_get_family, &
59    xc_f90_func_info_get_references, &
60    xc_f90_func_info_get_flags, &
61    xc_f90_func_info_get_n_ext_params, &
62    xc_f90_func_info_get_ext_params_name, &
63    xc_f90_func_info_get_ext_params_description, &
64    xc_f90_func_info_get_ext_params_default_value, &
65    ! func_reference
66    xc_f90_func_reference_t, &
67    xc_f90_func_reference_get_ref, &
68    xc_f90_func_reference_get_doi, &
69    xc_f90_func_reference_get_bibtex, &
70    ! func
71    xc_f90_func_t, &
72    xc_f90_func_init, &
73    xc_f90_func_end, &
74    xc_f90_func_get_info, &
75    xc_f90_functional_get_name, &
76    xc_f90_functional_get_number, &
77    xc_f90_family_from_id, &
78    xc_f90_number_of_functionals, &
79    xc_f90_maximum_name_length, &
80    xc_f90_available_functional_numbers, &
81    xc_f90_available_functional_names, &
82    xc_f90_func_set_dens_threshold, &
83    xc_f90_func_set_ext_params, &
84    ! lda
85    xc_f90_lda, &
86    xc_f90_lda_exc, &
87    xc_f90_lda_exc_vxc, &
88    xc_f90_lda_exc_vxc_fxc, &
89    xc_f90_lda_exc_vxc_fxc_kxc, &
90    xc_f90_lda_vxc, &
91    xc_f90_lda_vxc_fxc, &
92    xc_f90_lda_vxc_fxc_kxc, &
93    xc_f90_lda_fxc, &
94    xc_f90_lda_kxc, &
95    ! gga
96    xc_f90_gga, &
97    xc_f90_gga_exc, &
98    xc_f90_gga_exc_vxc, &
99    xc_f90_gga_exc_vxc_fxc, &
100    xc_f90_gga_exc_vxc_fxc_kxc, &
101    xc_f90_gga_vxc, &
102    xc_f90_gga_vxc_fxc, &
103    xc_f90_gga_vxc_fxc_kxc, &
104    xc_f90_gga_fxc, &
105    xc_f90_gga_kxc, &
106    xc_f90_gga_ak13_get_asymptotic, &
107    xc_f90_hyb_exx_coef, &
108    xc_f90_hyb_cam_coef, &
109    xc_f90_nlc_coef, &
110    ! mgga
111    xc_f90_mgga, &
112    xc_f90_mgga_exc, &
113    xc_f90_mgga_exc_vxc, &
114    xc_f90_mgga_exc_vxc_fxc, &
115    xc_f90_mgga_exc_vxc_fxc_kxc, &
116    xc_f90_mgga_vxc, &
117    xc_f90_mgga_vxc_fxc, &
118    xc_f90_mgga_vxc_fxc_kxc, &
119    xc_f90_mgga_fxc, &
120    xc_f90_mgga_kxc
121
122  integer(c_int), parameter, public :: &
123    XC_UNPOLARIZED          =   1,     &  ! Spin unpolarized
124    XC_POLARIZED            =   2         ! Spin polarized
125
126    integer(c_int), parameter, public :: &
127    XC_NON_RELATIVISTIC     =   0,     &  ! Functional includes or not relativistic
128    XC_RELATIVISTIC         =   1         ! corrections. Only available in some functionals.
129
130  ! Kinds
131  integer(c_int), parameter, public :: &
132    XC_EXCHANGE             =   0,     &
133    XC_CORRELATION          =   1,     &
134    XC_EXCHANGE_CORRELATION =   2,     &
135    XC_KINETIC              =   3
136
137  ! Families of xc functionals
138  integer(c_int), parameter, public :: &
139    XC_FAMILY_UNKNOWN       =  -1,     &
140    XC_FAMILY_NONE          =   0,     &
141    XC_FAMILY_LDA           =   1,     &
142    XC_FAMILY_GGA           =   2,     &
143    XC_FAMILY_MGGA          =   4,     &
144    XC_FAMILY_LCA           =   8,     &
145    XC_FAMILY_OEP           =  16,     &
146    XC_FAMILY_HYB_GGA       =  32,     &
147    XC_FAMILY_HYB_MGGA      =  64,     &
148    XC_FAMILY_HYB_LDA       = 128
149
150  integer(c_int), parameter, public :: &
151    XC_FLAGS_HAVE_EXC        =     1,   &
152    XC_FLAGS_HAVE_VXC        =     2,   &
153    XC_FLAGS_HAVE_FXC        =     4,   &
154    XC_FLAGS_HAVE_KXC        =     8,   &
155    XC_FLAGS_HAVE_LXC        =    16,   &
156    XC_FLAGS_HAVE_ALL        =    31,   & ! The most common case
157    XC_FLAGS_1D              =    32,   &
158    XC_FLAGS_2D              =    64,   &
159    XC_FLAGS_3D              =   128,   &
160    XC_FLAGS_HYB_CAM         =   256,   &
161    XC_FLAGS_HYB_CAMY        =   512,   &
162    XC_FLAGS_VV10            =  1024,   &
163    XC_FLAGS_HYB_LC          =  2048,   &
164    XC_FLAGS_HYB_LCY         =  4096,   &
165    XC_FLAGS_STABLE          =  8192,   &
166    XC_FLAGS_DEVELOPMENT     = 16384,   &
167    XC_FLAGS_NEEDS_LAPLACIAN = 32768
168
169  integer(c_int), parameter, public :: &
170    XC_TAU_EXPLICIT         =     0,   &
171    XC_TAU_EXPANSION        =     1
172
173  integer(c_int), parameter, public :: &
174    XC_MAX_REFERENCES       =     5
175
176  ! List of functionals
177#include "libxc_inc.f90"
178
179  ! These are old names kept for compatibility
180  integer(c_int), parameter, public :: &
181    XC_LDA_X_1D             =  21,     &
182    XC_GGA_X_BGCP           =  38,     &
183    XC_GGA_C_BGCP           =  39,     &
184    XC_GGA_C_BCGP           =  39,     &
185    XC_GGA_C_VPBE           =  83,     &
186    XC_GGA_XC_LB            = 160,     &
187    XC_MGGA_C_CC06          = 229,     &
188    XC_GGA_K_ABSR1          = 506,     &
189    XC_GGA_K_ABSR2          = 507,     &
190    XC_LDA_C_LP_A           = 547,     &
191    XC_LDA_C_LP_B           = 548,     &
192    XC_MGGA_C_LP90          = 564
193
194  !----------------------------------------------------------------
195  interface
196    subroutine xc_version(major, minor, micro) bind(c)
197      import
198      integer(c_int), intent(out) :: major, minor, micro
199    end subroutine xc_version
200
201    type(c_ptr) function xc_version_string() bind(c)
202      import
203    end function xc_version_string
204  end interface
205
206
207  !----------------------------------------------------------------
208  type :: xc_f90_func_info_t
209    private
210    type(c_ptr) :: ptr = C_NULL_PTR
211  end type xc_f90_func_info_t
212
213  interface
214    integer(c_int) function xc_func_info_get_number(info) bind(c)
215      import
216      type(c_ptr), value :: info
217    end function xc_func_info_get_number
218
219    integer(c_int) function xc_func_info_get_kind(info) bind(c)
220      import
221      type(c_ptr), value :: info
222    end function xc_func_info_get_kind
223
224    type(c_ptr) function xc_func_info_get_name(info) bind(c)
225      import
226      type(c_ptr), value :: info
227    end function xc_func_info_get_name
228
229    integer(c_int) function xc_func_info_get_family(info) bind(c)
230      import
231      type(c_ptr), value :: info
232    end function xc_func_info_get_family
233
234    integer(c_int) function xc_func_info_get_flags(info) bind(c)
235      import
236      type(c_ptr), value :: info
237    end function xc_func_info_get_flags
238
239    type(c_ptr) function xc_func_info_get_references(info, number) bind(c)
240      import
241      type(c_ptr),    value :: info
242      integer(c_int), value :: number
243    end function xc_func_info_get_references
244
245    integer(c_int) function xc_func_info_get_n_ext_params(info) bind(c)
246      import
247      type(c_ptr), value :: info
248    end function xc_func_info_get_n_ext_params
249
250    type(c_ptr) function xc_func_info_get_ext_params_name(info, number) bind(c)
251      import
252      type(c_ptr),    value :: info
253      integer(c_int), value :: number
254    end function xc_func_info_get_ext_params_name
255
256    type(c_ptr) function xc_func_info_get_ext_params_description(info, number) bind(c)
257      import
258      type(c_ptr),    value :: info
259      integer(c_int), value :: number
260    end function xc_func_info_get_ext_params_description
261
262    real(c_double) function xc_func_info_get_ext_params_default_value(info, number) bind(c)
263      import
264      type(c_ptr),    value :: info
265      integer(c_int), value :: number
266    end function xc_func_info_get_ext_params_default_value
267
268  end interface
269
270  !----------------------------------------------------------------
271  type :: xc_f90_func_reference_t
272    private
273    type(c_ptr) :: ptr = C_NULL_PTR
274  end type xc_f90_func_reference_t
275
276  interface
277    type(c_ptr) function xc_func_reference_get_ref(reference) bind(c)
278      import
279      type(c_ptr), value :: reference
280    end function xc_func_reference_get_ref
281
282    type(c_ptr) function xc_func_reference_get_doi(reference) bind(c)
283      import
284      type(c_ptr), value :: reference
285    end function xc_func_reference_get_doi
286
287    type(c_ptr) function xc_func_reference_get_bibtex(reference) bind(c)
288      import
289      type(c_ptr), value :: reference
290    end function xc_func_reference_get_bibtex
291  end interface
292
293  !----------------------------------------------------------------
294  type :: xc_f90_func_t
295    private
296    type(c_ptr) :: ptr = C_NULL_PTR
297  end type xc_f90_func_t
298
299  interface
300    type(c_ptr) function xc_func_alloc() bind(c)
301      import
302    end function xc_func_alloc
303
304    integer(c_int) function xc_func_init(p, functional, nspin) bind(c)
305      import
306      type(c_ptr),    value :: p
307      integer(c_int), value :: functional, nspin
308    end function xc_func_init
309
310    subroutine xc_func_end(p) bind(c)
311      import
312      type(c_ptr), value :: p
313    end subroutine xc_func_end
314
315    subroutine xc_func_free(p) bind(c)
316      import
317      type(c_ptr), value :: p
318    end subroutine xc_func_free
319
320    type(c_ptr) function xc_func_get_info(p) bind(c)
321      import
322      type(c_ptr), value :: p
323    end function xc_func_get_info
324
325    type(c_ptr) function xc_functional_get_name(number) bind(c)
326      import
327      integer(c_int), value :: number
328    end function xc_functional_get_name
329
330    integer(c_int) function xc_functional_get_number(func_string) bind(c)
331      import
332      character(kind=c_char), intent(in) :: func_string(*)
333    end function xc_functional_get_number
334
335    integer(c_int) function xc_family_from_id(id, family, number) bind(c)
336      import
337      integer(c_int), value :: id
338      type(c_ptr),    value :: family, number
339    end function xc_family_from_id
340
341    integer(c_int) function xc_f90_number_of_functionals() bind(c, name="xc_number_of_functionals")
342      import
343    end function xc_f90_number_of_functionals
344
345    integer(c_int) function xc_f90_maximum_name_length() bind(c, name="xc_maximum_name_length")
346      import
347    end function xc_f90_maximum_name_length
348
349    subroutine xc_f90_available_functional_numbers(list) bind(c, name="xc_available_functional_numbers")
350      import
351      integer(c_int), intent(out) :: list(*)
352    end subroutine xc_f90_available_functional_numbers
353
354    subroutine xc_available_functional_names(list) bind(c)
355      import
356      type(c_ptr) :: list(*)
357    end subroutine xc_available_functional_names
358
359    subroutine xc_func_set_dens_threshold(p, dens_threshold) bind(c)
360      import
361      type(c_ptr), value :: p
362      real(c_double), value :: dens_threshold
363    end subroutine xc_func_set_dens_threshold
364
365    subroutine xc_func_set_ext_params(p, ext_params) bind(c)
366      import
367      type(c_ptr), value      :: p
368      real(c_double), intent(in) :: ext_params(*)
369    end subroutine xc_func_set_ext_params
370  end interface
371
372  ! LDAs
373  !----------------------------------------------------------------
374  interface
375    subroutine xc_lda(p, np, rho, zk, vrho, v2rho2, v3rho3, v4rho4) bind(c)
376      import
377      type(c_ptr),       value       :: p
378      integer(c_size_t), value       :: np
379      real(c_double),    intent(in)  :: rho(*)
380      real(c_double),    intent(out) :: zk(*), vrho(*), v2rho2(*), v3rho3(*), v4rho4(*)
381    end subroutine xc_lda
382
383    subroutine xc_lda_exc(p, np, rho, zk) bind(c)
384      import
385      type(c_ptr),       value       :: p
386      integer(c_size_t), value       :: np
387      real(c_double),    intent(in)  :: rho(*)
388      real(c_double),    intent(out) :: zk(*)
389    end subroutine xc_lda_exc
390
391    subroutine xc_lda_exc_vxc(p, np, rho, zk, vrho) bind(c)
392      import
393      type(c_ptr),       value       :: p
394      integer(c_size_t), value       :: np
395      real(c_double),    intent(in)  :: rho(*)
396      real(c_double),    intent(out) :: zk(*), vrho(*)
397    end subroutine xc_lda_exc_vxc
398
399    subroutine xc_lda_exc_vxc_fxc(p, np, rho, zk, vrho, v2rho2) bind(c)
400      import
401      type(c_ptr),       value       :: p
402      integer(c_size_t), value       :: np
403      real(c_double),    intent(in)  :: rho(*)
404      real(c_double),    intent(out) :: zk(*), vrho(*), v2rho2(*)
405    end subroutine xc_lda_exc_vxc_fxc
406
407    subroutine xc_lda_exc_vxc_fxc_kxc(p, np, rho, zk, vrho, v2rho2, v3rho3) bind(c)
408      import
409      type(c_ptr),       value       :: p
410      integer(c_size_t), value       :: np
411      real(c_double),    intent(in)  :: rho(*)
412      real(c_double),    intent(out) :: zk(*), vrho(*), v2rho2(*), v3rho3(*)
413    end subroutine xc_lda_exc_vxc_fxc_kxc
414
415    subroutine xc_lda_vxc(p, np, rho, vrho) bind(c)
416      import
417      type(c_ptr),       value       :: p
418      integer(c_size_t), value       :: np
419      real(c_double),    intent(in)  :: rho(*)
420      real(c_double),    intent(out) :: vrho(*)
421    end subroutine xc_lda_vxc
422
423    subroutine xc_lda_vxc_fxc(p, np, rho, vrho, v2rho2) bind(c)
424      import
425      type(c_ptr),       value       :: p
426      integer(c_size_t), value       :: np
427      real(c_double),    intent(in)  :: rho(*)
428      real(c_double),    intent(out) :: vrho(*), v2rho2(*)
429    end subroutine xc_lda_vxc_fxc
430
431    subroutine xc_lda_vxc_fxc_kxc(p, np, rho, vrho, v2rho2, v3rho3) bind(c)
432      import
433      type(c_ptr),       value       :: p
434      integer(c_size_t), value       :: np
435      real(c_double),    intent(in)  :: rho(*)
436      real(c_double),    intent(out) :: vrho(*), v2rho2(*), v3rho3(*)
437    end subroutine xc_lda_vxc_fxc_kxc
438
439    subroutine xc_lda_fxc(p, np, rho, v2rho2) bind(c)
440      import
441      type(c_ptr),       value       :: p
442      integer(c_size_t), value       :: np
443      real(c_double),    intent(in)  :: rho(*)
444      real(c_double),    intent(out) :: v2rho2(*)
445    end subroutine xc_lda_fxc
446
447    subroutine xc_lda_kxc(p, np, rho, v3rho3) bind(c)
448      import
449      type(c_ptr),       value       :: p
450      integer(c_size_t), value       :: np
451      real(c_double),    intent(in)  :: rho(*)
452      real(c_double),    intent(out) :: v3rho3(*)
453    end subroutine xc_lda_kxc
454
455    subroutine xc_lda_lxc(p, np, rho, v4rho4) bind(c)
456      import
457      type(c_ptr),       value       :: p
458      integer(c_size_t), value       :: np
459      real(c_double),    intent(in)  :: rho(*)
460      real(c_double),    intent(out) :: v4rho4(*)
461    end subroutine xc_lda_lxc
462  end interface
463
464
465  ! GGAs
466  !----------------------------------------------------------------
467  interface
468    subroutine xc_gga(p, np, rho, sigma, zk, vrho, vsigma,        &
469         v2rho2, v2rhosigma, v2sigma2,                            &
470         v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3,              &
471         v4rho4, v4rho3sigma, v4rho2sigma2, v4rhosigma3, v4sigma4 &
472         ) bind(c)
473      import
474      type(c_ptr),       value       :: p
475      integer(c_size_t), value       :: np
476      real(c_double),    intent(in)  :: rho(*), sigma(*)
477      real(c_double),    intent(out) :: zk(*), vrho(*), vsigma(*)
478      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
479      real(c_double),    intent(out) :: v3rho3(*), v3rho2sigma(*), v3rhosigma2(*), v3sigma3(*)
480      real(c_double),    intent(out) :: v4rho4(*), v4rho3sigma(*), v4rho2sigma2(*), v4rhosigma3(*), v4sigma4(*)
481    end subroutine xc_gga
482
483    subroutine xc_gga_exc(p, np, rho, sigma, zk) bind(c)
484      import
485      type(c_ptr),       value       :: p
486      integer(c_size_t), value       :: np
487      real(c_double),    intent(in)  :: rho(*), sigma(*)
488      real(c_double),    intent(out) :: zk(*)
489    end subroutine xc_gga_exc
490
491    subroutine xc_gga_exc_vxc(p, np, rho, sigma, zk, vrho, vsigma) bind(c)
492      import
493      type(c_ptr),       value       :: p
494      integer(c_size_t), value       :: np
495      real(c_double),    intent(in)  :: rho(*), sigma(*)
496      real(c_double),    intent(out) :: zk(*), vrho(*), vsigma(*)
497    end subroutine xc_gga_exc_vxc
498
499    subroutine xc_gga_exc_vxc_fxc(p, np, rho, sigma, zk, vrho, vsigma,        &
500         v2rho2, v2rhosigma, v2sigma2) bind(c)
501      import
502      type(c_ptr),       value       :: p
503      integer(c_size_t), value       :: np
504      real(c_double),    intent(in)  :: rho(*), sigma(*)
505      real(c_double),    intent(out) :: zk(*), vrho(*), vsigma(*)
506      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
507    end subroutine xc_gga_exc_vxc_fxc
508
509    subroutine xc_gga_exc_vxc_fxc_kxc(p, np, rho, sigma, zk, vrho, vsigma,        &
510         v2rho2, v2rhosigma, v2sigma2,                            &
511         v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3) bind(c)
512      import
513      type(c_ptr),       value       :: p
514      integer(c_size_t), value       :: np
515      real(c_double),    intent(in)  :: rho(*), sigma(*)
516      real(c_double),    intent(out) :: zk(*), vrho(*), vsigma(*)
517      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
518      real(c_double),    intent(out) :: v3rho3(*), v3rho2sigma(*), v3rhosigma2(*), v3sigma3(*)
519    end subroutine xc_gga_exc_vxc_fxc_kxc
520
521    subroutine xc_gga_vxc(p, np, rho, sigma, vrho, vsigma) bind(c)
522      import
523      type(c_ptr),       value       :: p
524      integer(c_size_t), value       :: np
525      real(c_double),    intent(in)  :: rho(*), sigma(*)
526      real(c_double),    intent(out) :: vrho(*), vsigma(*)
527    end subroutine xc_gga_vxc
528
529    subroutine xc_gga_vxc_fxc(p, np, rho, sigma, vrho, vsigma,    &
530         v2rho2, v2rhosigma, v2sigma2) bind(c)
531      import
532      type(c_ptr),       value       :: p
533      integer(c_size_t), value       :: np
534      real(c_double),    intent(in)  :: rho(*), sigma(*)
535      real(c_double),    intent(out) :: vrho(*), vsigma(*)
536      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
537    end subroutine xc_gga_vxc_fxc
538
539    subroutine xc_gga_vxc_fxc_kxc(p, np, rho, sigma, vrho, vsigma, &
540         v2rho2, v2rhosigma, v2sigma2,                             &
541         v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3) bind(c)
542      import
543      type(c_ptr),       value       :: p
544      integer(c_size_t), value       :: np
545      real(c_double),    intent(in)  :: rho(*), sigma(*)
546      real(c_double),    intent(out) :: vrho(*), vsigma(*)
547      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
548      real(c_double),    intent(out) :: v3rho3(*), v3rho2sigma(*), v3rhosigma2(*), v3sigma3(*)
549    end subroutine xc_gga_vxc_fxc_kxc
550
551    subroutine xc_gga_fxc(p, np, rho, sigma, v2rho2, v2rhosigma, v2sigma2) bind(c)
552      import
553      type(c_ptr),       value       :: p
554      integer(c_size_t), value       :: np
555      real(c_double),    intent(in)  :: rho(*), sigma(*)
556      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
557    end subroutine xc_gga_fxc
558
559    subroutine xc_gga_kxc(p, np, rho, sigma, v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3) bind(c)
560      import
561      type(c_ptr),       value       :: p
562      integer(c_size_t), value       :: np
563      real(c_double),    intent(in)  :: rho(*), sigma(*)
564      real(c_double),    intent(out) :: v3rho3(*), v3rho2sigma(*), v3rhosigma2(*), v3sigma3(*)
565    end subroutine xc_gga_kxc
566
567    subroutine xc_gga_lxc(p, np, rho, sigma, v4rho4, v4rho3sigma, v4rho2sigma2, v4rhosigma3, v4sigma4) bind(c)
568      import
569      type(c_ptr),       value       :: p
570      integer(c_size_t), value       :: np
571      real(c_double),    intent(in)  :: rho(*), sigma(*)
572      real(c_double),    intent(out) :: v4rho4(*), v4rho3sigma(*), v4rho2sigma2(*), v4rhosigma3(*), v4sigma4(*)
573    end subroutine xc_gga_lxc
574
575  end interface
576
577
578  interface
579    real(c_double) function xc_gga_ak13_get_asymptotic(homo) bind(c)
580      import
581      real(c_double), value :: homo
582    end function xc_gga_ak13_get_asymptotic
583  end interface
584
585
586  interface
587    real(c_double) function xc_hyb_exx_coef(p) bind(c)
588      import
589      type(c_ptr), value :: p
590    end function xc_hyb_exx_coef
591
592    subroutine xc_hyb_cam_coef(p, omega, alpha, beta) bind(c)
593      import
594      type(c_ptr), value       :: p
595      real(c_double), intent(out) :: omega, alpha, beta
596    end subroutine xc_hyb_cam_coef
597
598    subroutine xc_nlc_coef(p, nlc_b, nlc_c) bind(c)
599      import
600      type(c_ptr), value       :: p
601      real(c_double), intent(out) :: nlc_b, nlc_c
602    end subroutine xc_nlc_coef
603  end interface
604
605
606  ! the meta-GGAs
607  !----------------------------------------------------------------
608  interface
609    subroutine xc_mgga(p, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau,     &
610         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
611         v2lapl2, v2lapltau, v2tau2,                                                    &
612         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
613         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
614         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
615         v3lapltau2, v3tau3,                                                            &
616         v4rho4, v4rho3sigma, v4rho3lapl, v4rho3tau, v4rho2sigma2, v4rho2sigmalapl,     &
617         v4rho2sigmatau, v4rho2lapl2, v4rho2lapltau, v4rho2tau2, v4rhosigma3,           &
618         v4rhosigma2lapl, v4rhosigma2tau, v4rhosigmalapl2, v4rhosigmalapltau,           &
619         v4rhosigmatau2, v4rholapl3, v4rholapl2tau, v4rholapltau2, v4rhotau3, v4sigma4, &
620         v4sigma3lapl, v4sigma3tau, v4sigma2lapl2, v4sigma2lapltau, v4sigma2tau2,       &
621         v4sigmalapl3, v4sigmalapl2tau, v4sigmalapltau2, v4sigmatau3, v4lapl4,          &
622         v4lapl3tau, v4lapl2tau2, v4lapltau3, v4tau4 &
623         ) bind(c)
624      import
625      type(c_ptr),       value       :: p
626      integer(c_size_t), value       :: np
627      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
628      real(c_double),    intent(out) :: zk(*), vrho(*), vsigma(*), vlapl(*), vtau(*)
629      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
630           v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
631      real(c_double),    intent(out) :: v3rho3(*), v3rho2sigma(*), v3rho2lapl(*), v3rho2tau(*), &
632           v3rhosigma2(*), v3rhosigmalapl(*), v3rhosigmatau(*), v3rholapl2(*),                  &
633           v3rholapltau(*), v3rhotau2(*), v3sigma3(*), v3sigma2lapl(*), v3sigma2tau(*),         &
634           v3sigmalapl2(*), v3sigmalapltau(*), v3sigmatau2(*), v3lapl3(*), v3lapl2tau(*),       &
635           v3lapltau2(*), v3tau3(*)
636      real(c_double),    intent(out) :: &
637           v4rho4(*), v4rho3sigma(*), v4rho3lapl(*), v4rho3tau(*), v4rho2sigma2(*), v4rho2sigmalapl(*),     &
638           v4rho2sigmatau(*), v4rho2lapl2(*), v4rho2lapltau(*), v4rho2tau2(*), v4rhosigma3(*),              &
639           v4rhosigma2lapl(*), v4rhosigma2tau(*), v4rhosigmalapl2(*), v4rhosigmalapltau(*),                 &
640           v4rhosigmatau2(*), v4rholapl3(*), v4rholapl2tau(*), v4rholapltau2(*), v4rhotau3(*), v4sigma4(*), &
641           v4sigma3lapl(*), v4sigma3tau(*), v4sigma2lapl2(*), v4sigma2lapltau(*), v4sigma2tau2(*),          &
642           v4sigmalapl3(*), v4sigmalapl2tau(*), v4sigmalapltau2(*), v4sigmatau3(*), v4lapl4(*),             &
643           v4lapl3tau(*), v4lapl2tau2(*), v4lapltau3(*), v4tau4(*)
644    end subroutine xc_mgga
645
646    subroutine xc_mgga_exc(p, np, rho, sigma, lapl, tau, zk) bind(c)
647      import
648      type(c_ptr),       value       :: p
649      integer(c_size_t), value       :: np
650      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
651      real(c_double),    intent(out) :: zk(*)
652    end subroutine xc_mgga_exc
653
654    subroutine xc_mgga_exc_vxc(p, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau) bind(c)
655      import
656      type(c_ptr),       value       :: p
657      integer(c_size_t), value       :: np
658      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
659      real(c_double),    intent(out) :: zk(*), vrho(*), vsigma(*), vlapl(*), vtau(*)
660    end subroutine xc_mgga_exc_vxc
661
662    subroutine xc_mgga_exc_vxc_fxc(p, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau, &
663         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
664         v2lapl2, v2lapltau, v2tau2) bind(c)
665      import
666      type(c_ptr),       value       :: p
667      integer(c_size_t), value       :: np
668      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
669      real(c_double),    intent(out) :: zk(*), vrho(*), vsigma(*), vlapl(*), vtau(*)
670      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
671           v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
672    end subroutine xc_mgga_exc_vxc_fxc
673
674    subroutine xc_mgga_exc_vxc_fxc_kxc(p, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau,     &
675         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
676         v2lapl2, v2lapltau, v2tau2,                                                    &
677         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
678         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
679         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
680         v3lapltau2, v3tau3) bind(c)
681      import
682      type(c_ptr),       value       :: p
683      integer(c_size_t), value       :: np
684      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
685      real(c_double),    intent(out) :: zk(*), vrho(*), vsigma(*), vlapl(*), vtau(*)
686      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
687           v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
688      real(c_double),    intent(out) :: v3rho3(*), v3rho2sigma(*), v3rho2lapl(*), v3rho2tau(*), &
689           v3rhosigma2(*), v3rhosigmalapl(*), v3rhosigmatau(*), v3rholapl2(*),                  &
690           v3rholapltau(*), v3rhotau2(*), v3sigma3(*), v3sigma2lapl(*), v3sigma2tau(*),         &
691           v3sigmalapl2(*), v3sigmalapltau(*), v3sigmatau2(*), v3lapl3(*), v3lapl2tau(*),       &
692           v3lapltau2(*), v3tau3(*)
693    end subroutine xc_mgga_exc_vxc_fxc_kxc
694
695    subroutine xc_mgga_vxc(p, np, rho, sigma, lapl, tau, vrho, vsigma, vlapl, vtau) bind(c)
696      import
697      type(c_ptr),       value       :: p
698      integer(c_size_t), value       :: np
699      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
700      real(c_double),    intent(out) :: vrho(*), vsigma(*), vlapl(*), vtau(*)
701    end subroutine xc_mgga_vxc
702
703    subroutine xc_mgga_vxc_fxc(p, np, rho, sigma, lapl, tau, vrho, vsigma, vlapl, vtau, &
704         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
705         v2lapl2, v2lapltau, v2tau2) bind(c)
706      import
707      type(c_ptr),       value       :: p
708      integer(c_size_t), value       :: np
709      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
710      real(c_double),    intent(out) :: vrho(*), vsigma(*), vlapl(*), vtau(*)
711      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
712           v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
713    end subroutine xc_mgga_vxc_fxc
714
715    subroutine xc_mgga_vxc_fxc_kxc(p, np, rho, sigma, lapl, tau, vrho, vsigma, vlapl, vtau,     &
716         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
717         v2lapl2, v2lapltau, v2tau2,                                                    &
718         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
719         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
720         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
721         v3lapltau2, v3tau3) bind(c)
722      import
723      type(c_ptr),       value       :: p
724      integer(c_size_t), value       :: np
725      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
726      real(c_double),    intent(out) :: vrho(*), vsigma(*), vlapl(*), vtau(*)
727      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
728           v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
729      real(c_double),    intent(out) :: v3rho3(*), v3rho2sigma(*), v3rho2lapl(*), v3rho2tau(*), &
730           v3rhosigma2(*), v3rhosigmalapl(*), v3rhosigmatau(*), v3rholapl2(*),                  &
731           v3rholapltau(*), v3rhotau2(*), v3sigma3(*), v3sigma2lapl(*), v3sigma2tau(*),         &
732           v3sigmalapl2(*), v3sigmalapltau(*), v3sigmatau2(*), v3lapl3(*), v3lapl2tau(*),       &
733           v3lapltau2(*), v3tau3(*)
734    end subroutine xc_mgga_vxc_fxc_kxc
735
736    subroutine xc_mgga_fxc(p, np, rho, sigma, lapl, tau, &
737         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
738         v2lapl2, v2lapltau, v2tau2) bind(c)
739      import
740      type(c_ptr),       value       :: p
741      integer(c_size_t), value       :: np
742      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
743      real(c_double),    intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
744           v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
745    end subroutine xc_mgga_fxc
746
747    subroutine xc_mgga_kxc(p, np, rho, sigma, lapl, tau, &
748         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
749         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
750         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
751         v3lapltau2, v3tau3) bind(c)
752      import
753      type(c_ptr),       value       :: p
754      integer(c_size_t), value       :: np
755      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
756      real(c_double),    intent(out) :: v3rho3(*), v3rho2sigma(*), v3rho2lapl(*), v3rho2tau(*), &
757           v3rhosigma2(*), v3rhosigmalapl(*), v3rhosigmatau(*), v3rholapl2(*),               &
758           v3rholapltau(*), v3rhotau2(*), v3sigma3(*), v3sigma2lapl(*), v3sigma2tau(*),      &
759           v3sigmalapl2(*), v3sigmalapltau(*), v3sigmatau2(*), v3lapl3(*), v3lapl2tau(*),    &
760           v3lapltau2(*), v3tau3(*)
761    end subroutine xc_mgga_kxc
762
763    subroutine xc_mgga_lxc(p, np, rho, sigma, lapl, tau, &
764         v4rho4, v4rho3sigma, v4rho3lapl, v4rho3tau, v4rho2sigma2, v4rho2sigmalapl,     &
765         v4rho2sigmatau, v4rho2lapl2, v4rho2lapltau, v4rho2tau2, v4rhosigma3,           &
766         v4rhosigma2lapl, v4rhosigma2tau, v4rhosigmalapl2, v4rhosigmalapltau,           &
767         v4rhosigmatau2, v4rholapl3, v4rholapl2tau, v4rholapltau2, v4rhotau3, v4sigma4, &
768         v4sigma3lapl, v4sigma3tau, v4sigma2lapl2, v4sigma2lapltau, v4sigma2tau2,       &
769         v4sigmalapl3, v4sigmalapl2tau, v4sigmalapltau2, v4sigmatau3, v4lapl4,          &
770         v4lapl3tau, v4lapl2tau2, v4lapltau3, v4tau4 &
771         ) bind(c)
772      import
773      type(c_ptr),       value       :: p
774      integer(c_size_t), value       :: np
775      real(c_double),    intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
776      real(c_double),    intent(out) :: &
777           v4rho4(*), v4rho3sigma(*), v4rho3lapl(*), v4rho3tau(*), v4rho2sigma2(*), v4rho2sigmalapl(*),     &
778           v4rho2sigmatau(*), v4rho2lapl2(*), v4rho2lapltau(*), v4rho2tau2(*), v4rhosigma3(*),              &
779           v4rhosigma2lapl(*), v4rhosigma2tau(*), v4rhosigmalapl2(*), v4rhosigmalapltau(*),                 &
780           v4rhosigmatau2(*), v4rholapl3(*), v4rholapl2tau(*), v4rholapltau2(*), v4rhotau3(*), v4sigma4(*), &
781           v4sigma3lapl(*), v4sigma3tau(*), v4sigma2lapl2(*), v4sigma2lapltau(*), v4sigma2tau2(*),          &
782           v4sigmalapl3(*), v4sigmalapl2tau(*), v4sigmalapltau2(*), v4sigmatau3(*), v4lapl4(*),             &
783           v4lapl3tau(*), v4lapl2tau2(*), v4lapltau3(*), v4tau4(*)
784    end subroutine xc_mgga_lxc
785  end interface
786
787  contains
788
789  !----------------------------------------------------------------
790  subroutine xc_f90_version(major, minor, micro)
791    integer(c_int), intent(out) :: major, minor, micro
792
793    call xc_version(major, minor, micro)
794
795  end subroutine xc_f90_version
796
797  subroutine xc_f90_version_string(version)
798    character(len=*), intent(out) :: version
799
800    type(c_ptr) :: c_version
801
802    c_version = xc_version_string()
803    call c_to_f_string_ptr(c_version, version)
804
805  end subroutine xc_f90_version_string
806
807
808  !----------------------------------------------------------------
809  integer(c_int) function xc_f90_func_info_get_number(info) result(number)
810    type(xc_f90_func_info_t), intent(in) :: info
811
812    number = xc_func_info_get_number(info%ptr)
813
814  end function xc_f90_func_info_get_number
815
816  integer(c_int) function xc_f90_func_info_get_kind(info) result(kind)
817    type(xc_f90_func_info_t), intent(in) :: info
818
819    kind = xc_func_info_get_kind(info%ptr)
820
821  end function xc_f90_func_info_get_kind
822
823  character(len=128) function xc_f90_func_info_get_name(info) result(name)
824    type(xc_f90_func_info_t), intent(in) :: info
825
826    call c_to_f_string_ptr(xc_func_info_get_name(info%ptr), name)
827
828  end function xc_f90_func_info_get_name
829
830  integer(c_int) function xc_f90_func_info_get_family(info) result(family)
831    type(xc_f90_func_info_t), intent(in) :: info
832
833    family = xc_func_info_get_family(info%ptr)
834
835  end function xc_f90_func_info_get_family
836
837  integer(c_int) function xc_f90_func_info_get_flags(info) result(flags)
838    type(xc_f90_func_info_t), intent(in) :: info
839
840    flags = xc_func_info_get_flags(info%ptr)
841
842  end function xc_f90_func_info_get_flags
843
844  type(xc_f90_func_reference_t) function xc_f90_func_info_get_references(info, number) result(reference)
845    type(xc_f90_func_info_t), intent(in)    :: info
846    integer(c_int),           intent(inout) :: number ! number of the reference. Must be 0 in the first call
847
848    type(c_ptr) :: next_ref
849
850    reference%ptr = xc_func_info_get_references(info%ptr, number)
851    next_ref = xc_func_info_get_references(info%ptr, number + 1)
852    if (c_associated(next_ref)) then
853      number = number + 1
854    else
855      number = -1
856    end if
857
858  end function xc_f90_func_info_get_references
859
860  integer(c_int) function xc_f90_func_info_get_n_ext_params(info) result(n_ext_params)
861    type(xc_f90_func_info_t), intent(in) :: info
862
863    n_ext_params = xc_func_info_get_n_ext_params(info%ptr)
864
865  end function xc_f90_func_info_get_n_ext_params
866
867  character(len=128) function xc_f90_func_info_get_ext_params_name(info, number) result(name)
868    type(xc_f90_func_info_t), intent(in) :: info
869    integer(c_int),           intent(in) :: number
870
871    call c_to_f_string_ptr(xc_func_info_get_ext_params_name(info%ptr, number), name)
872
873  end function xc_f90_func_info_get_ext_params_name
874
875  character(len=128) function xc_f90_func_info_get_ext_params_description(info, number) result(description)
876    type(xc_f90_func_info_t), intent(in) :: info
877    integer(c_int),           intent(in) :: number
878
879    call c_to_f_string_ptr(xc_func_info_get_ext_params_description(info%ptr, number), description)
880
881  end function xc_f90_func_info_get_ext_params_description
882
883  real(c_double) function xc_f90_func_info_get_ext_params_default_value(info, number) result(val)
884    type(xc_f90_func_info_t), intent(in) :: info
885    integer(c_int),           intent(in) :: number
886
887    val = xc_func_info_get_ext_params_default_value(info%ptr, number)
888
889  end function xc_f90_func_info_get_ext_params_default_value
890
891  !----------------------------------------------------------------
892  character(len=120) function xc_f90_func_reference_get_ref(reference) result(ref)
893    type(xc_f90_func_reference_t), intent(in) :: reference
894
895    call c_to_f_string_ptr(xc_func_reference_get_ref(reference%ptr), ref)
896
897  end function xc_f90_func_reference_get_ref
898
899  character(len=120) function xc_f90_func_reference_get_doi(reference) result(doi)
900    type(xc_f90_func_reference_t), intent(in) :: reference
901
902    call c_to_f_string_ptr(xc_func_reference_get_doi(reference%ptr), doi)
903
904  end function xc_f90_func_reference_get_doi
905
906  character(len=120) function xc_f90_func_reference_get_bibtex(reference) result(bibtex)
907    type(xc_f90_func_reference_t), intent(in) :: reference
908
909    call c_to_f_string_ptr(xc_func_reference_get_bibtex(reference%ptr), bibtex)
910
911  end function xc_f90_func_reference_get_bibtex
912
913
914  !----------------------------------------------------------------
915  subroutine xc_f90_func_init(p, functional, nspin, err)
916    type(xc_f90_func_t),      intent(inout) :: p
917    integer(c_int),           intent(in)    :: functional
918    integer(c_int),           intent(in)    :: nspin
919    integer(c_int), optional, intent(out)   :: err
920
921    integer(c_int) :: ierr
922
923    p%ptr = xc_func_alloc()
924    ierr = xc_func_init(p%ptr, functional, nspin)
925
926    if(present(err)) err = ierr
927  end subroutine xc_f90_func_init
928
929  subroutine xc_f90_func_end(p)
930    type(xc_f90_func_t), intent(inout) :: p
931
932    call xc_func_end(p%ptr)
933    call xc_func_free(p%ptr)
934
935  end subroutine xc_f90_func_end
936
937  type(xc_f90_func_info_t) function xc_f90_func_get_info(p) result(info)
938    type(xc_f90_func_t), intent(in) :: p
939
940    info%ptr = xc_func_get_info(p%ptr)
941
942  end function xc_f90_func_get_info
943
944  character(len=128) function xc_f90_functional_get_name(number) result(name)
945    integer(c_int), intent(in) :: number
946
947    call c_to_f_string_ptr(xc_functional_get_name(number), name)
948
949  end function xc_f90_functional_get_name
950
951  integer(c_int) function xc_f90_functional_get_number(func_string) result(number)
952    character(len=*), intent(in) :: func_string
953
954    number = xc_functional_get_number(f_to_c_string(func_string))
955
956  end function xc_f90_functional_get_number
957
958  integer(c_int) function xc_f90_family_from_id(id, family, number)
959    integer(c_int), intent(in)                    :: id
960    integer(c_int), intent(out), optional, target :: family, number
961
962    type(c_ptr) c_family, c_number
963    integer(c_int), pointer :: f_family, f_number
964
965    if (present(family)) then
966      f_family => family
967      call c_f_pointer(c_family, f_family)
968    else
969      c_family = C_NULL_PTR
970    end if
971    if (present(number)) then
972      f_number => number
973      call c_f_pointer(c_number, f_number)
974    else
975      c_number = C_NULL_PTR
976    end if
977
978    xc_f90_family_from_id = xc_family_from_id(id, c_family, c_number)
979
980  end function xc_f90_family_from_id
981
982  subroutine xc_f90_available_functional_names(list)
983    character(len=*), intent(out) :: list(*)
984
985    integer(c_int) :: n, i, maxlen
986    character(kind=c_char), allocatable, target :: names(:,:)
987    type(c_ptr), allocatable :: c_list(:)
988
989    n = xc_f90_number_of_functionals()
990    maxlen = xc_f90_maximum_name_length()
991
992    allocate(names(maxlen, n))
993    allocate(c_list(n))
994    do i = 1, n
995      c_list(i) = c_loc(names(1,i))
996    end do
997
998    call xc_available_functional_names(c_list)
999
1000    do i = 1, n
1001      call c_to_f_string_ptr(c_list(i), list(i))
1002    end do
1003
1004    deallocate(c_list)
1005    deallocate(names)
1006
1007  end subroutine xc_f90_available_functional_names
1008
1009
1010  subroutine xc_f90_func_set_dens_threshold(p, dens_threshold)
1011    type(xc_f90_func_t), intent(in) :: p
1012    real(c_double),       intent(in) :: dens_threshold
1013
1014    call xc_func_set_dens_threshold(p%ptr, dens_threshold)
1015
1016  end subroutine xc_f90_func_set_dens_threshold
1017
1018  subroutine xc_f90_func_set_ext_params(p, ext_params)
1019    type(xc_f90_func_t), intent(in) :: p
1020    real(c_double),       intent(in) :: ext_params(*)
1021
1022    call xc_func_set_ext_params(p%ptr, ext_params)
1023
1024  end subroutine xc_f90_func_set_ext_params
1025
1026  ! LDAs
1027  !----------------------------------------------------------------
1028  subroutine xc_f90_lda(p, np, rho, zk, vrho, v2rho2, v3rho3, v4rho4)
1029    type(xc_f90_func_t), intent(in)  :: p
1030    integer(c_size_t),   intent(in)  :: np
1031    real(c_double),      intent(in)  :: rho(*)
1032    real(c_double),      intent(out) :: zk(*), vrho(*), v2rho2(*), v3rho3(*), v4rho4(*)
1033
1034    call xc_lda(p%ptr, np, rho, zk, vrho, v2rho2, v3rho3, v4rho4)
1035
1036  end subroutine xc_f90_lda
1037
1038  subroutine xc_f90_lda_exc(p, np, rho, zk)
1039    type(xc_f90_func_t), intent(in)  :: p
1040    integer(c_size_t),   intent(in)  :: np
1041    real(c_double),      intent(in)  :: rho(*)
1042    real(c_double),      intent(out) :: zk(*)
1043
1044    call xc_lda_exc(p%ptr, np, rho, zk)
1045
1046  end subroutine xc_f90_lda_exc
1047
1048  subroutine xc_f90_lda_exc_vxc(p, np, rho, zk, vrho)
1049    type(xc_f90_func_t), intent(in)  :: p
1050    integer(c_size_t),   intent(in)  :: np
1051    real(c_double),      intent(in)  :: rho(*)
1052    real(c_double),      intent(out) :: zk(*), vrho(*)
1053
1054    call xc_lda_exc_vxc(p%ptr, np, rho, zk, vrho)
1055
1056  end subroutine xc_f90_lda_exc_vxc
1057
1058  subroutine xc_f90_lda_exc_vxc_fxc(p, np, rho, zk, vrho, v2rho2)
1059    type(xc_f90_func_t), intent(in)  :: p
1060    integer(c_size_t),   intent(in)  :: np
1061    real(c_double),      intent(in)  :: rho(*)
1062    real(c_double),      intent(out) :: zk(*), vrho(*), v2rho2(*)
1063
1064    call xc_lda_exc_vxc_fxc(p%ptr, np, rho, zk, vrho, v2rho2)
1065
1066  end subroutine xc_f90_lda_exc_vxc_fxc
1067
1068  subroutine xc_f90_lda_exc_vxc_fxc_kxc(p, np, rho, zk, vrho, v2rho2, v3rho3)
1069    type(xc_f90_func_t), intent(in)  :: p
1070    integer(c_size_t),   intent(in)  :: np
1071    real(c_double),      intent(in)  :: rho(*)
1072    real(c_double),      intent(out) :: zk(*), vrho(*), v2rho2(*), v3rho3(*)
1073
1074    call xc_lda_exc_vxc_fxc_kxc(p%ptr, np, rho, zk, vrho, v2rho2, v3rho3)
1075
1076  end subroutine xc_f90_lda_exc_vxc_fxc_kxc
1077
1078  subroutine xc_f90_lda_vxc(p, np, rho, vrho)
1079    type(xc_f90_func_t), intent(in)  :: p
1080    integer(c_size_t),   intent(in)  :: np
1081    real(c_double),      intent(in)  :: rho(*)
1082    real(c_double),      intent(out) :: vrho(*)
1083
1084    call xc_lda_vxc(p%ptr, np, rho, vrho)
1085
1086  end subroutine xc_f90_lda_vxc
1087
1088  subroutine xc_f90_lda_vxc_fxc(p, np, rho, vrho, v2rho2)
1089    type(xc_f90_func_t), intent(in)  :: p
1090    integer(c_size_t),   intent(in)  :: np
1091    real(c_double),      intent(in)  :: rho(*)
1092    real(c_double),      intent(out) :: vrho(*), v2rho2(*)
1093
1094    call xc_lda_vxc_fxc(p%ptr, np, rho, vrho, v2rho2)
1095
1096  end subroutine xc_f90_lda_vxc_fxc
1097
1098  subroutine xc_f90_lda_vxc_fxc_kxc(p, np, rho, vrho, v2rho2, v3rho3)
1099    type(xc_f90_func_t), intent(in)  :: p
1100    integer(c_size_t),   intent(in)  :: np
1101    real(c_double),      intent(in)  :: rho(*)
1102    real(c_double),      intent(out) :: vrho(*), v2rho2(*), v3rho3(*)
1103
1104    call xc_lda_vxc_fxc_kxc(p%ptr, np, rho, vrho, v2rho2, v3rho3)
1105
1106  end subroutine xc_f90_lda_vxc_fxc_kxc
1107
1108  subroutine xc_f90_lda_fxc(p, np, rho, v2rho2)
1109    type(xc_f90_func_t), intent(in)  :: p
1110    integer(c_size_t),   intent(in)  :: np
1111    real(c_double),      intent(in)  :: rho(*)
1112    real(c_double),      intent(out) :: v2rho2(*)
1113
1114    call xc_lda_fxc(p%ptr, np, rho, v2rho2)
1115
1116  end subroutine xc_f90_lda_fxc
1117
1118  subroutine xc_f90_lda_kxc(p, np, rho, v3rho3)
1119    type(xc_f90_func_t), intent(in)  :: p
1120    integer(c_size_t),   intent(in)  :: np
1121    real(c_double),      intent(in)  :: rho(*)
1122    real(c_double),      intent(out) :: v3rho3(*)
1123
1124    call xc_lda_kxc(p%ptr, np, rho, v3rho3)
1125
1126  end subroutine xc_f90_lda_kxc
1127
1128  subroutine xc_f90_lda_lxc(p, np, rho, v4rho4)
1129    type(xc_f90_func_t), intent(in)  :: p
1130    integer(c_size_t),   intent(in)  :: np
1131    real(c_double),      intent(in)  :: rho(*)
1132    real(c_double),      intent(out) :: v4rho4(*)
1133
1134    call xc_lda_lxc(p%ptr, np, rho, v4rho4)
1135
1136  end subroutine xc_f90_lda_lxc
1137
1138  ! GGAs
1139  !----------------------------------------------------------------
1140  subroutine xc_f90_gga(p, np, rho, sigma, zk, vrho, vsigma,    &
1141       v2rho2, v2rhosigma, v2sigma2,                            &
1142       v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3,              &
1143       v4rho4, v4rho3sigma, v4rho2sigma2, v4rhosigma3, v4sigma4 &
1144    )
1145    type(xc_f90_func_t), intent(in)  :: p
1146    integer(c_size_t),   intent(in)  :: np
1147    real(c_double),      intent(in)  :: rho(*), sigma(*)
1148    real(c_double),      intent(out) :: zk(*), vrho(*), vsigma(*)
1149    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
1150    real(c_double),      intent(out) :: v3rho3(*), v3rho2sigma(*), v3rhosigma2(*), v3sigma3(*)
1151    real(c_double),      intent(out) :: v4rho4(*), v4rho3sigma(*), v4rho2sigma2(*), v4rhosigma3(*), v4sigma4(*)
1152
1153    call xc_gga(p%ptr, np, rho, sigma, zk, vrho, vsigma,          &
1154         v2rho2, v2rhosigma, v2sigma2,                            &
1155         v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3,              &
1156         v4rho4, v4rho3sigma, v4rho2sigma2, v4rhosigma3, v4sigma4 &
1157         )
1158
1159  end subroutine xc_f90_gga
1160
1161  subroutine xc_f90_gga_exc(p, np, rho, sigma, zk)
1162    type(xc_f90_func_t), intent(in)  :: p
1163    integer(c_size_t),   intent(in)  :: np
1164    real(c_double),      intent(in)  :: rho(*), sigma(*)
1165    real(c_double),      intent(out) :: zk(*)
1166
1167    call xc_gga_exc(p%ptr, np, rho, sigma, zk)
1168
1169  end subroutine xc_f90_gga_exc
1170
1171  subroutine xc_f90_gga_exc_vxc(p, np, rho, sigma, zk, vrho, vsigma)
1172    type(xc_f90_func_t), intent(in)  :: p
1173    integer(c_size_t),   intent(in)  :: np
1174    real(c_double),      intent(in)  :: rho(*), sigma(*)
1175    real(c_double),      intent(out) :: zk(*), vrho(*), vsigma(*)
1176
1177    call xc_gga_exc_vxc(p%ptr, np, rho, sigma, zk, vrho, vsigma)
1178
1179  end subroutine xc_f90_gga_exc_vxc
1180
1181  subroutine xc_f90_gga_exc_vxc_fxc(p, np, rho, sigma, zk, vrho, vsigma,    &
1182       v2rho2, v2rhosigma, v2sigma2)
1183    type(xc_f90_func_t), intent(in)  :: p
1184    integer(c_size_t),   intent(in)  :: np
1185    real(c_double),      intent(in)  :: rho(*), sigma(*)
1186    real(c_double),      intent(out) :: zk(*), vrho(*), vsigma(*)
1187    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
1188
1189    call xc_gga_exc_vxc_fxc(p%ptr, np, rho, sigma, zk, vrho, vsigma,          &
1190         v2rho2, v2rhosigma, v2sigma2)
1191
1192  end subroutine xc_f90_gga_exc_vxc_fxc
1193
1194  subroutine xc_f90_gga_exc_vxc_fxc_kxc(p, np, rho, sigma, zk, vrho, vsigma,    &
1195       v2rho2, v2rhosigma, v2sigma2,                            &
1196       v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3)
1197    type(xc_f90_func_t), intent(in)  :: p
1198    integer(c_size_t),   intent(in)  :: np
1199    real(c_double),      intent(in)  :: rho(*), sigma(*)
1200    real(c_double),      intent(out) :: zk(*), vrho(*), vsigma(*)
1201    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
1202    real(c_double),      intent(out) :: v3rho3(*), v3rho2sigma(*), v3rhosigma2(*), v3sigma3(*)
1203
1204    call xc_gga_exc_vxc_fxc_kxc(p%ptr, np, rho, sigma, zk, vrho, vsigma,          &
1205         v2rho2, v2rhosigma, v2sigma2,                            &
1206         v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3)
1207
1208  end subroutine xc_f90_gga_exc_vxc_fxc_kxc
1209
1210  subroutine xc_f90_gga_vxc(p, np, rho, sigma, vrho, vsigma)
1211    type(xc_f90_func_t), intent(in)  :: p
1212    integer(c_size_t),   intent(in)  :: np
1213    real(c_double),      intent(in)  :: rho(*), sigma(*)
1214    real(c_double),      intent(out) :: vrho(*), vsigma(*)
1215
1216    call xc_gga_vxc(p%ptr, np, rho, sigma, vrho, vsigma)
1217
1218  end subroutine xc_f90_gga_vxc
1219
1220  subroutine xc_f90_gga_vxc_fxc(p, np, rho, sigma, vrho, vsigma,    &
1221       v2rho2, v2rhosigma, v2sigma2)
1222    type(xc_f90_func_t), intent(in)  :: p
1223    integer(c_size_t),   intent(in)  :: np
1224    real(c_double),      intent(in)  :: rho(*), sigma(*)
1225    real(c_double),      intent(out) :: vrho(*), vsigma(*)
1226    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
1227
1228    call xc_gga_vxc_fxc(p%ptr, np, rho, sigma, vrho, vsigma, &
1229         v2rho2, v2rhosigma, v2sigma2)
1230
1231  end subroutine xc_f90_gga_vxc_fxc
1232
1233  subroutine xc_f90_gga_vxc_fxc_kxc(p, np, rho, sigma, vrho, vsigma,    &
1234       v2rho2, v2rhosigma, v2sigma2,                            &
1235       v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3)
1236    type(xc_f90_func_t), intent(in)  :: p
1237    integer(c_size_t),   intent(in)  :: np
1238    real(c_double),      intent(in)  :: rho(*), sigma(*)
1239    real(c_double),      intent(out) :: vrho(*), vsigma(*)
1240    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
1241    real(c_double),      intent(out) :: v3rho3(*), v3rho2sigma(*), v3rhosigma2(*), v3sigma3(*)
1242
1243    call xc_gga_vxc_fxc_kxc(p%ptr, np, rho, sigma, vrho, vsigma,  &
1244         v2rho2, v2rhosigma, v2sigma2,                            &
1245         v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3)
1246
1247  end subroutine xc_f90_gga_vxc_fxc_kxc
1248
1249  subroutine xc_f90_gga_fxc(p, np, rho, sigma, v2rho2, v2rhosigma, v2sigma2)
1250    type(xc_f90_func_t), intent(in)  :: p
1251    integer(c_size_t),   intent(in)  :: np
1252    real(c_double),      intent(in)  :: rho(*), sigma(*)
1253    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2sigma2(*)
1254
1255    call xc_gga_fxc(p%ptr, np, rho, sigma, v2rho2, v2rhosigma, v2sigma2)
1256
1257  end subroutine xc_f90_gga_fxc
1258
1259  subroutine xc_f90_gga_kxc(p, np, rho, sigma, v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3)
1260    type(xc_f90_func_t), intent(in)  :: p
1261    integer(c_size_t),   intent(in)  :: np
1262    real(c_double),      intent(in)  :: rho(*), sigma(*)
1263    real(c_double),      intent(out) :: v3rho3(*), v3rho2sigma(*), v3rhosigma2(*), v3sigma3(*)
1264
1265    call xc_gga_kxc(p%ptr, np, rho, sigma, v3rho3, v3rho2sigma, v3rhosigma2, v3sigma3)
1266
1267  end subroutine xc_f90_gga_kxc
1268
1269  subroutine xc_f90_gga_lxc(p, np, rho, sigma, v4rho4, v4rho3sigma, v4rho2sigma2, v4rhosigma3, v4sigma4)
1270    type(xc_f90_func_t), intent(in)  :: p
1271    integer(c_size_t),   intent(in)  :: np
1272    real(c_double),      intent(in)  :: rho(*), sigma(*)
1273    real(c_double),      intent(out) :: v4rho4(*), v4rho3sigma(*), v4rho2sigma2(*), v4rhosigma3(*), v4sigma4(*)
1274
1275    call xc_gga_lxc(p%ptr, np, rho, sigma, v4rho4, v4rho3sigma, v4rho2sigma2, v4rhosigma3, v4sigma4)
1276  end subroutine xc_f90_gga_lxc
1277
1278  real(c_double) function xc_f90_gga_ak13_get_asymptotic(homo) result(asymptotic)
1279    real(c_double), intent(in) :: homo
1280
1281    asymptotic = xc_gga_ak13_get_asymptotic(homo)
1282
1283  end function xc_f90_gga_ak13_get_asymptotic
1284
1285  real(c_double) function xc_f90_hyb_exx_coef(p) result(coef)
1286    type(xc_f90_func_t), intent(in) :: p
1287
1288    coef = xc_hyb_exx_coef(p%ptr)
1289
1290  end function xc_f90_hyb_exx_coef
1291
1292  subroutine xc_f90_hyb_cam_coef(p, omega, alpha, beta)
1293    type(xc_f90_func_t), intent(in)  :: p
1294    real(c_double),       intent(out) :: omega, alpha, beta
1295
1296    call xc_hyb_cam_coef(p%ptr, omega, alpha, beta)
1297
1298  end subroutine xc_f90_hyb_cam_coef
1299
1300  subroutine xc_f90_nlc_coef(p, nlc_b, nlc_c)
1301    type(xc_f90_func_t), intent(in)  :: p
1302    real(c_double),       intent(out) :: nlc_b, nlc_c
1303
1304    call xc_nlc_coef(p%ptr, nlc_b, nlc_c)
1305
1306  end subroutine xc_f90_nlc_coef
1307
1308
1309  ! the meta-GGAs
1310  !----------------------------------------------------------------
1311  subroutine xc_f90_mgga(p, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau,   &
1312         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1313         v2lapl2, v2lapltau, v2tau2,                                                    &
1314         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
1315         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
1316         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
1317         v3lapltau2, v3tau3,                                                            &
1318         v4rho4, v4rho3sigma, v4rho3lapl, v4rho3tau, v4rho2sigma2, v4rho2sigmalapl,     &
1319         v4rho2sigmatau, v4rho2lapl2, v4rho2lapltau, v4rho2tau2, v4rhosigma3,           &
1320         v4rhosigma2lapl, v4rhosigma2tau, v4rhosigmalapl2, v4rhosigmalapltau,           &
1321         v4rhosigmatau2, v4rholapl3, v4rholapl2tau, v4rholapltau2, v4rhotau3, v4sigma4, &
1322         v4sigma3lapl, v4sigma3tau, v4sigma2lapl2, v4sigma2lapltau, v4sigma2tau2,       &
1323         v4sigmalapl3, v4sigmalapl2tau, v4sigmalapltau2, v4sigmatau3, v4lapl4,          &
1324         v4lapl3tau, v4lapl2tau2, v4lapltau3, v4tau4 &
1325         )
1326    type(xc_f90_func_t), intent(in)  :: p
1327    integer(c_size_t),   intent(in)  :: np
1328    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1329    real(c_double),      intent(out) :: zk(*), vrho(*), vsigma(*), vlapl(*), vtau(*)
1330    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
1331         v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
1332    real(c_double),      intent(out) :: v3rho3(*), v3rho2sigma(*), v3rho2lapl(*), v3rho2tau(*), &
1333         v3rhosigma2(*), v3rhosigmalapl(*), v3rhosigmatau(*), v3rholapl2(*),               &
1334         v3rholapltau(*), v3rhotau2(*), v3sigma3(*), v3sigma2lapl(*), v3sigma2tau(*),      &
1335         v3sigmalapl2(*), v3sigmalapltau(*), v3sigmatau2(*), v3lapl3(*), v3lapl2tau(*),    &
1336         v3lapltau2(*), v3tau3(*)
1337    real(c_double),    intent(out) :: &
1338           v4rho4(*), v4rho3sigma(*), v4rho3lapl(*), v4rho3tau(*), v4rho2sigma2(*), v4rho2sigmalapl(*),     &
1339           v4rho2sigmatau(*), v4rho2lapl2(*), v4rho2lapltau(*), v4rho2tau2(*), v4rhosigma3(*),              &
1340           v4rhosigma2lapl(*), v4rhosigma2tau(*), v4rhosigmalapl2(*), v4rhosigmalapltau(*),                 &
1341           v4rhosigmatau2(*), v4rholapl3(*), v4rholapl2tau(*), v4rholapltau2(*), v4rhotau3(*), v4sigma4(*), &
1342           v4sigma3lapl(*), v4sigma3tau(*), v4sigma2lapl2(*), v4sigma2lapltau(*), v4sigma2tau2(*),          &
1343           v4sigmalapl3(*), v4sigmalapl2tau(*), v4sigmalapltau2(*), v4sigmatau3(*), v4lapl4(*),             &
1344           v4lapl3tau(*), v4lapl2tau2(*), v4lapltau3(*), v4tau4(*)
1345
1346    call xc_mgga(p%ptr, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau,       &
1347         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1348         v2lapl2, v2lapltau, v2tau2,                                                    &
1349         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
1350         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
1351         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
1352         v3lapltau2, v3tau3,                                                            &
1353         v4rho4, v4rho3sigma, v4rho3lapl, v4rho3tau, v4rho2sigma2, v4rho2sigmalapl,     &
1354         v4rho2sigmatau, v4rho2lapl2, v4rho2lapltau, v4rho2tau2, v4rhosigma3,           &
1355         v4rhosigma2lapl, v4rhosigma2tau, v4rhosigmalapl2, v4rhosigmalapltau,           &
1356         v4rhosigmatau2, v4rholapl3, v4rholapl2tau, v4rholapltau2, v4rhotau3, v4sigma4, &
1357         v4sigma3lapl, v4sigma3tau, v4sigma2lapl2, v4sigma2lapltau, v4sigma2tau2,       &
1358         v4sigmalapl3, v4sigmalapl2tau, v4sigmalapltau2, v4sigmatau3, v4lapl4,          &
1359         v4lapl3tau, v4lapl2tau2, v4lapltau3, v4tau4 &
1360         )
1361  end subroutine xc_f90_mgga
1362
1363  subroutine xc_f90_mgga_exc(p, np, rho, sigma, lapl, tau, zk)
1364    type(xc_f90_func_t), intent(in)  :: p
1365    integer(c_size_t),   intent(in)  :: np
1366    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1367    real(c_double),      intent(out) :: zk(*)
1368
1369    call xc_mgga_exc(p%ptr, np, rho, sigma, lapl, tau, zk)
1370
1371  end subroutine xc_f90_mgga_exc
1372
1373  subroutine xc_f90_mgga_exc_vxc(p, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau)
1374    type(xc_f90_func_t), intent(in)  :: p
1375    integer(c_size_t),   intent(in)  :: np
1376    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1377    real(c_double),      intent(out) :: zk(*), vrho(*), vsigma(*), vlapl(*), vtau(*)
1378
1379    call xc_mgga_exc_vxc(p%ptr, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau)
1380
1381  end subroutine xc_f90_mgga_exc_vxc
1382
1383  subroutine xc_f90_mgga_exc_vxc_fxc(p, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau,   &
1384         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1385         v2lapl2, v2lapltau, v2tau2)
1386    type(xc_f90_func_t), intent(in)  :: p
1387    integer(c_size_t),   intent(in)  :: np
1388    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1389    real(c_double),      intent(out) :: zk(*), vrho(*), vsigma(*), vlapl(*), vtau(*)
1390    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
1391         v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
1392
1393    call xc_mgga_exc_vxc_fxc(p%ptr, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau,       &
1394         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1395         v2lapl2, v2lapltau, v2tau2)
1396  end subroutine xc_f90_mgga_exc_vxc_fxc
1397
1398  subroutine xc_f90_mgga_exc_vxc_fxc_kxc(p, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau,   &
1399         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1400         v2lapl2, v2lapltau, v2tau2,                                                    &
1401         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
1402         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
1403         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
1404         v3lapltau2, v3tau3)
1405    type(xc_f90_func_t), intent(in)  :: p
1406    integer(c_size_t),   intent(in)  :: np
1407    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1408    real(c_double),      intent(out) :: zk(*), vrho(*), vsigma(*), vlapl(*), vtau(*)
1409    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
1410         v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
1411    real(c_double),      intent(out) :: v3rho3(*), v3rho2sigma(*), v3rho2lapl(*), v3rho2tau(*), &
1412         v3rhosigma2(*), v3rhosigmalapl(*), v3rhosigmatau(*), v3rholapl2(*),               &
1413         v3rholapltau(*), v3rhotau2(*), v3sigma3(*), v3sigma2lapl(*), v3sigma2tau(*),      &
1414         v3sigmalapl2(*), v3sigmalapltau(*), v3sigmatau2(*), v3lapl3(*), v3lapl2tau(*),    &
1415         v3lapltau2(*), v3tau3(*)
1416
1417    call xc_mgga_exc_vxc_fxc_kxc(p%ptr, np, rho, sigma, lapl, tau, zk, vrho, vsigma, vlapl, vtau,       &
1418         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1419         v2lapl2, v2lapltau, v2tau2,                                                    &
1420         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
1421         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
1422         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
1423         v3lapltau2, v3tau3)
1424  end subroutine xc_f90_mgga_exc_vxc_fxc_kxc
1425
1426  subroutine xc_f90_mgga_vxc(p, np, rho, sigma, lapl, tau, vrho, vsigma, vlapl, vtau)
1427    type(xc_f90_func_t), intent(in)  :: p
1428    integer(c_size_t),   intent(in)  :: np
1429    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1430    real(c_double),      intent(out) :: vrho(*), vsigma(*), vlapl(*), vtau(*)
1431
1432    call xc_mgga_vxc(p%ptr, np, rho, sigma, lapl, tau, vrho, vsigma, vlapl, vtau)
1433
1434  end subroutine xc_f90_mgga_vxc
1435
1436  subroutine xc_f90_mgga_vxc_fxc(p, np, rho, sigma, lapl, tau, vrho, vsigma, vlapl, vtau,   &
1437         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1438         v2lapl2, v2lapltau, v2tau2)
1439    type(xc_f90_func_t), intent(in)  :: p
1440    integer(c_size_t),   intent(in)  :: np
1441    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1442    real(c_double),      intent(out) :: vrho(*), vsigma(*), vlapl(*), vtau(*)
1443    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
1444         v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
1445
1446    call xc_mgga_vxc_fxc(p%ptr, np, rho, sigma, lapl, tau, vrho, vsigma, vlapl, vtau,       &
1447         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1448         v2lapl2, v2lapltau, v2tau2)
1449  end subroutine xc_f90_mgga_vxc_fxc
1450
1451  subroutine xc_f90_mgga_vxc_fxc_kxc(p, np, rho, sigma, lapl, tau, vrho, vsigma, vlapl, vtau,   &
1452         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1453         v2lapl2, v2lapltau, v2tau2,                                                    &
1454         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
1455         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
1456         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
1457         v3lapltau2, v3tau3)
1458    type(xc_f90_func_t), intent(in)  :: p
1459    integer(c_size_t),   intent(in)  :: np
1460    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1461    real(c_double),      intent(out) :: vrho(*), vsigma(*), vlapl(*), vtau(*)
1462    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
1463         v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
1464    real(c_double),      intent(out) :: v3rho3(*), v3rho2sigma(*), v3rho2lapl(*), v3rho2tau(*), &
1465         v3rhosigma2(*), v3rhosigmalapl(*), v3rhosigmatau(*), v3rholapl2(*),               &
1466         v3rholapltau(*), v3rhotau2(*), v3sigma3(*), v3sigma2lapl(*), v3sigma2tau(*),      &
1467         v3sigmalapl2(*), v3sigmalapltau(*), v3sigmatau2(*), v3lapl3(*), v3lapl2tau(*),    &
1468         v3lapltau2(*), v3tau3(*)
1469
1470    call xc_mgga_vxc_fxc_kxc(p%ptr, np, rho, sigma, lapl, tau, vrho, vsigma, vlapl, vtau,       &
1471         v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1472         v2lapl2, v2lapltau, v2tau2,                                                    &
1473         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
1474         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
1475         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
1476         v3lapltau2, v3tau3)
1477  end subroutine xc_f90_mgga_vxc_fxc_kxc
1478
1479  subroutine xc_f90_mgga_fxc(p, np, rho, sigma, lapl, tau, &
1480       v2rho2, v2rhosigma, v2rholapl, v2rhotau, v2sigma2, v2sigmalapl, v2sigmatau,    &
1481       v2lapl2, v2lapltau, v2tau2)
1482    type(xc_f90_func_t), intent(in)  :: p
1483    integer(c_size_t),   intent(in)  :: np
1484    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1485    real(c_double),      intent(out) :: v2rho2(*), v2rhosigma(*), v2rholapl(*), v2rhotau(*),    &
1486         v2sigma2(*), v2sigmalapl(*), v2sigmatau(*), v2lapl2(*), v2lapltau(*), v2tau2(*)
1487
1488    call xc_mgga_fxc(p%ptr, np, rho, sigma, lapl, tau,   &
1489      v2rho2, v2rhosigma, v2rholapl, v2rhotau,           &
1490      v2sigma2, v2sigmalapl, v2sigmatau, v2lapl2, v2lapltau, v2tau2)
1491
1492  end subroutine xc_f90_mgga_fxc
1493
1494  subroutine xc_f90_mgga_kxc(p, np, rho, sigma, lapl, tau, &
1495       v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
1496       v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
1497       v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
1498       v3lapltau2, v3tau3)
1499    type(xc_f90_func_t), intent(in)  :: p
1500    integer(c_size_t),   intent(in)  :: np
1501    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1502    real(c_double),      intent(out) :: v3rho3(*), v3rho2sigma(*), v3rho2lapl(*), v3rho2tau(*), &
1503           v3rhosigma2(*), v3rhosigmalapl(*), v3rhosigmatau(*), v3rholapl2(*),               &
1504           v3rholapltau(*), v3rhotau2(*), v3sigma3(*), v3sigma2lapl(*), v3sigma2tau(*),      &
1505           v3sigmalapl2(*), v3sigmalapltau(*), v3sigmatau2(*), v3lapl3(*), v3lapl2tau(*),    &
1506           v3lapltau2(*), v3tau3(*)
1507
1508    call xc_mgga_kxc(p%ptr, np, rho, sigma, lapl, tau,  &
1509         v3rho3, v3rho2sigma, v3rho2lapl, v3rho2tau, v3rhosigma2, v3rhosigmalapl,       &
1510         v3rhosigmatau, v3rholapl2, v3rholapltau, v3rhotau2, v3sigma3, v3sigma2lapl,    &
1511         v3sigma2tau, v3sigmalapl2, v3sigmalapltau, v3sigmatau2, v3lapl3, v3lapl2tau,   &
1512         v3lapltau2, v3tau3)
1513  end subroutine xc_f90_mgga_kxc
1514
1515  subroutine xc_f90_mgga_lxc(p, np, rho, sigma, lapl, tau, &
1516       v4rho4, v4rho3sigma, v4rho3lapl, v4rho3tau, v4rho2sigma2, v4rho2sigmalapl,     &
1517       v4rho2sigmatau, v4rho2lapl2, v4rho2lapltau, v4rho2tau2, v4rhosigma3,           &
1518       v4rhosigma2lapl, v4rhosigma2tau, v4rhosigmalapl2, v4rhosigmalapltau,           &
1519       v4rhosigmatau2, v4rholapl3, v4rholapl2tau, v4rholapltau2, v4rhotau3, v4sigma4, &
1520       v4sigma3lapl, v4sigma3tau, v4sigma2lapl2, v4sigma2lapltau, v4sigma2tau2,       &
1521       v4sigmalapl3, v4sigmalapl2tau, v4sigmalapltau2, v4sigmatau3, v4lapl4,          &
1522       v4lapl3tau, v4lapl2tau2, v4lapltau3, v4tau4 &
1523       )
1524    type(xc_f90_func_t), intent(in)  :: p
1525    integer(c_size_t),   intent(in)  :: np
1526    real(c_double),      intent(in)  :: rho(*), sigma(*), lapl(*), tau(*)
1527    real(c_double),      intent(out) :: &
1528         v4rho4(*), v4rho3sigma(*), v4rho3lapl(*), v4rho3tau(*), v4rho2sigma2(*), v4rho2sigmalapl(*),     &
1529         v4rho2sigmatau(*), v4rho2lapl2(*), v4rho2lapltau(*), v4rho2tau2(*), v4rhosigma3(*),              &
1530         v4rhosigma2lapl(*), v4rhosigma2tau(*), v4rhosigmalapl2(*), v4rhosigmalapltau(*),                 &
1531         v4rhosigmatau2(*), v4rholapl3(*), v4rholapl2tau(*), v4rholapltau2(*), v4rhotau3(*), v4sigma4(*), &
1532         v4sigma3lapl(*), v4sigma3tau(*), v4sigma2lapl2(*), v4sigma2lapltau(*), v4sigma2tau2(*),          &
1533         v4sigmalapl3(*), v4sigmalapl2tau(*), v4sigmalapltau2(*), v4sigmatau3(*), v4lapl4(*),             &
1534         v4lapl3tau(*), v4lapl2tau2(*), v4lapltau3(*), v4tau4(*)
1535
1536    call xc_mgga_lxc(p%ptr, np, rho, sigma, lapl, tau,  &
1537         v4rho4, v4rho3sigma, v4rho3lapl, v4rho3tau, v4rho2sigma2, v4rho2sigmalapl,     &
1538         v4rho2sigmatau, v4rho2lapl2, v4rho2lapltau, v4rho2tau2, v4rhosigma3,           &
1539         v4rhosigma2lapl, v4rhosigma2tau, v4rhosigmalapl2, v4rhosigmalapltau,           &
1540         v4rhosigmatau2, v4rholapl3, v4rholapl2tau, v4rholapltau2, v4rhotau3, v4sigma4, &
1541         v4sigma3lapl, v4sigma3tau, v4sigma2lapl2, v4sigma2lapltau, v4sigma2tau2,       &
1542         v4sigmalapl3, v4sigmalapl2tau, v4sigmalapltau2, v4sigmatau3, v4lapl4,          &
1543         v4lapl3tau, v4lapl2tau2, v4lapltau3, v4tau4 &
1544         )
1545  end subroutine xc_f90_mgga_lxc
1546
1547
1548  ! Helper functions to convert between C and Fortran strings
1549  ! Based on the routines by Joseph M. Krahn
1550  function f_to_c_string(f_string) result(c_string)
1551    character(len=*), intent(in) :: f_string
1552    character(kind=c_char,len=1) :: c_string(len_trim(f_string)+1)
1553
1554    integer :: i, strlen
1555
1556    strlen = len_trim(f_string)
1557
1558    forall (i=1:strlen)
1559      c_string(i) = f_string(i:i)
1560    end forall
1561    c_string(strlen+1) = C_NULL_CHAR
1562
1563  end function f_to_c_string
1564
1565  subroutine c_to_f_string(c_string, f_string)
1566    character(kind=c_char,len=1), intent(in)  :: c_string(*)
1567    character(len=*),             intent(out) :: f_string
1568
1569    integer :: i
1570
1571    i = 1
1572    do while(c_string(i) /= C_NULL_CHAR .and. i <= len(f_string))
1573      f_string(i:i) = c_string(i)
1574      i = i + 1
1575    end do
1576    if (i < len(f_string)) f_string(i:) = ' '
1577
1578  end subroutine c_to_f_string
1579
1580  subroutine c_to_f_string_ptr(c_string, f_string)
1581    type(c_ptr),      intent(in)  :: c_string
1582    character(len=*), intent(out) :: f_string
1583
1584    character(len=1, kind=c_char), pointer :: p_chars(:)
1585    integer :: i
1586
1587    if (.not. c_associated(c_string)) then
1588      f_string = ' '
1589    else
1590      call c_f_pointer(c_string, p_chars, [huge(0)])
1591      i = 1
1592      do while(p_chars(i) /= C_NULL_CHAR .and. i <= len(f_string))
1593        f_string(i:i) = p_chars(i)
1594        i = i + 1
1595      end do
1596      if (i < len(f_string)) f_string(i:) = ' '
1597    end if
1598
1599  end subroutine c_to_f_string_ptr
1600
1601end module xc_f90_lib_m
1602
1603!! Local Variables:
1604!! mode: f90
1605!! coding: utf-8
1606!! End:
1607