code-saturne / code_saturne

code_saturne public mirror
https://www.code-saturne.org
GNU General Public License v2.0
223 stars 82 forks source link

Obtain notebook parameters in fortran #34

Closed mathrack closed 5 years ago

mathrack commented 5 years ago

It would be interesting to have the possibility to obtain notebook parameters in fortran. The following addition to cs_c_bindings.f90 could do the job. It seems to work, but might need improvements as I have to trim the variable name when calling it.

function notebook_parameter_value_by_name(var_name) result (val) &
  bind(C, name='cs_notebook_parameter_value_by_name')                        
  use, intrinsic :: iso_c_binding
  implicit none
  character(kind=c_char, len=1), dimension(*), intent(in) :: var_name        
  real(kind=c_double) :: val
end function notebook_parameter_value_by_name
mathrack commented 5 years ago

This seems slightly better:

function cs_notebook_parameter_value_by_name(name) result(val) &
  bind(C, name='cs_notebook_parameter_value_by_name')
  use, intrinsic :: iso_c_binding
  implicit none
  character(kind=c_char, len=1), dimension(*), intent(in)  :: name
  real(kind=c_double) :: val
end function cs_notebook_parameter_value_by_name

Then

function notebook_parameter_value_by_name(name) result(val)

  use, intrinsic :: iso_c_binding
  implicit none

  ! Arguments

  character(len=*), intent(in) :: name
  double precision :: val

  ! Local variables

  character(len=len_trim(name)+1, kind=c_char) :: c_name
  real(kind=c_double) :: c_val 

  c_name = trim(name)//c_null_char

  c_val = cs_notebook_parameter_value_by_name(c_name)
  val = c_val

end function notebook_parameter_value_by_name
MartinFerrand commented 5 years ago

Thank you for that, it was included in commit 88a57c6 and merged on v6.0 branch.