From: Richard Maine on
glen herrmannsfeldt <gah(a)ugcs.caltech.edu> wrote:

> It seems to me that the complaint is that intrinsic elemental
> functions are allowed to do things that user written ones
> are not. Especially print error messages.

There is a long history of intrinsic procedures being able to do things
that user procedures couldn't. Some of these things have later turned
into capabilities of user procedures. Others haven't.

Of the top of my head

1. Generic procedures started as intrinsic only.

2. Likewise for elemental.

3. Likewise for use in specification expressions.

I'd say that a current one of significance is the way that the return
kind of an intrinsic can depend on the value of an argument (the kind
argument). Still can't do that with user code.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: James Van Buskirk on
"ralf.schaa" <ralf.schaa(a)gmail.com> wrote in message
news:0882ce9b-f4c6-449b-add2-6a8efb4d83d1(a)22g2000yqr.googlegroups.com...

>I am struggling with implementation of a suitable error-catching
> mechanism for elemental procedures - the only thing that seems to work
> is to provide an error result-value, so that the error has to be
> handled in the calling-program, which is not always convenient. Are
> there other ways? What do you use?

Cheat. C binding should let you do it:

module elem_err
implicit none
integer, parameter :: dp = selected_real_kind(15,300)
contains
elemental function my_sqrt(x)
real(dp), intent(in) :: x
real(dp) my_sqrt
interface
pure subroutine sub1(x) bind(C,name='sub2')
use ISO_C_BINDING, only: C_DOUBLE
implicit none
real(C_DOUBLE), intent(in) :: x
end subroutine sub1
end interface
procedure(sub1), pointer :: sub4
if(x < 0) then
sub4 => sub1
call sub4(x)
my_sqrt = 0
else
my_sqrt = sqrt(x)
end if
end function my_sqrt
subroutine sub3(x) bind(C,name='sub2')
use ISO_C_BINDING, only: C_DOUBLE
real(C_DOUBLE), intent(in) :: x
write(*,*) 'Argument out of bounds for my_sqrt:',x
stop
end subroutine sub3
end module elem_err

program test
use elem_err
implicit none
real(dp) x, y

x = -0.707
y = my_sqrt(x)
write(*,*) 'my_sqrt(',x,') =',y
end program test

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end