Dear all,
A quick question, for an extremely simplified example,
subroutine A(n)
integer :: n
if (n>100) then
write (6,*) 'Rich!', n
return
else
write (6,*) 'Poor!', n
return
endif
write (6,*) 'This is line shall not be displayed.'
end subroutine A
Now, for some reason I want the above subroutine A to be written as subroutine A_mod.
A_mod and A should behave exactly the same. That is, the text "This is line will not be displayed.‘’ really should not be displayed in both A_mod and A . I define sub subroutine show inside A_mod to simplify the write and return statements. In real case these write and return statements are actually some long and similar code. That is why I want to use sub subroutine show, so that I do not need to repeat some similar code blocks explicitly again and again.
So I make Amod as below,
subroutine A_mod(n)
integer :: n
if (n>100) then
call show('Rich!',*100)
else
call show('Poor',*100)
endif
write (6,*) 'This is line shall not be displayed.'
100 return ! sub subroutine show should just to here.
contains
subroutine show(ch,*)
character(*) :: ch
write (6,*) ch, n
return 1
end subroutine show
end subroutine A_mod
So that the sub subroutine show is really return to the proper place in the subroutine A_mod, which is
100 return
Here I used alternative return,
https://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vnb3/index.html
I know it looks like using alternative return, I can let sub subroutine show to jump to any place in subroutine A_mod as I want to.
However it seems alternative return may be an obsolete feature (however it seems very useful in this case). So anyway, I just wonder, is there any other modern way to let sub subroutine (such as show) jump to certain places in the main subroutine (such as A_mod)?
Thanks much in advance!