Alex Rivera | Logout

Fortran query and print out function or subroutine name

Asked 2011-08-11T21:56:26.827
11

Is it possible in Fortran to query the name of the function or subroutine that I am in? I.e., what do I put in place of '???' to get it to print 'my_subroutine' on the screen?

subroutine my_subroutine()
   write(*,*) ???
end subroutine my_subroutine

I am trying to find a way to implement a custom debugger/profiler using nothing but a text editor's search and replace mechanism. Programmatically querying my position in the code would be helpful.

Edit
Report

1 Answer

2

Why don't you just hard write the name of the subroutine you're in, in the WRITE statement?

You cannot programmatically (dynamically) give or change the name of the subroutine, therefore I see no reason to try to access it either that way (about that: while I'm not sure that it is impossible to access it somehow, I'm quite sure that it is the wrong way to go ... you will cause yourself more trouble going that way, than just hard coding it).

Btw, why are you trying to print it out anyway? Wouldn't a well phrased diagnostic message be more informative?

answered 2011-08-11T22:09:44.773

Your Answer