Weather and climate modeling codes from Fortran to C++

This is the most intelligent conclusion. Trying to make fortran close to Matlab than Python will get more users.

2 Likes

I have never understood the point of unary operators as opposed to functions:
I think inv(A) is nicer than .inv.A. Is there any benefit from user defined unary operators? The point of binary operators is more understandable.

1 Like

.div. is nice, but I have too strong connotation to “divergence” (\nabla\cdot) that it would bother me.

1 Like

I think you can create an INTERFACE for which some module procedures are PURE and others are IMPURE. This would require some repetitive code compared to a procedure with optional arguments but avoids run-time overhead of handling the optional argument (which admittedly is probably very small). The following module compiles with gfortran, ifort, and g95.

module m
implicit none
interface mysqrt
   module procedure mysqrt_pure, mysqrt_impure
end interface mysqrt
contains
function mysqrt_impure(x, err) result(y)
real, intent(in) :: x
integer, intent(out) :: err
real :: y
if (x >= 0.0) then
   y = sqrt(x)
   err = 0
else
   err = 1
end if
end function mysqrt_impure
!
function mysqrt_pure(x) result(y)
real, intent(in) :: x
real :: y
if (x >= 0.0) then
   y = sqrt(x)
else
   y = -huge(x)
end if
end function mysqrt_pure
end module
1 Like

@Beliavsky great idea. I was going to suggest to have pure versions of most functions.