Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert fortran-iso-c-binding real variable to real

With fortran-iso-c-binding I can interface C functions and get variables of types like

real(c_float)
integer(c_int)

But in the rest of a program I would like to use basic types (simply because I do not want to replace many real variables with real(c_float) variables just because of one interface function)

Is there a safe, platform/compiler independent and reliable way how to cast fortran-iso-c-binding types back to fortran (primitive) types? equivalent to REAL()

like image 729
Peter Avatar asked Sep 06 '25 03:09

Peter


1 Answers

The REAL intrinsic is what you want. Or equivalently, simple assignment.

REAL(C_FLOAT) :: r_c
REAL :: r_default
r_default = r_c

If the value being converted is out of range for the destination kind, your program is non-conforming.

like image 51
IanH Avatar answered Sep 07 '25 21:09

IanH