Hi,
I have a set of output subroutines in a F90 program.
At the moment they are called like this:
call Output_Str( "My name is Reynold" )
call Output_StrInt( "My age is", 21 )
call Output_StrReal( "My shoe size is",9.5 )
They cry out for a common interface such as:
interface Output
module procedure Output_Str
module procedure Output_StrInt
module procedure Output_StrReal
end interface
but this can't be done because the length of the string arguments to my
output subroutines are known only at run-time
e.g.
subroutine Output_Str(txt)
character(len=*) :: txt !<-known only at run-time
integer :: ios
write(out,'(a)',iostat=ios) txt
if ( ios.ne.0) call error_handler()
end subroutine Output_Str
Petros Dafniotis posted nearly the same problem (20 Jan 2000: "Question on
character valued functions") which was resolved by Richard Maine. Great, but
I'm still stuck!
The suggested F95 solution was using PURE functions.
I am limited to F90, so I can't use PURE. (I think I couldn't use PURE
anyway - something about doing i/o within a pure function??)
The suggested (untested) F90 solution was essentially:
function output_str(string)
character*(*) :: string
end function output_str
and this didn't work for me.
Is this a brick wall?
All replies, including confirmation that it is bricks+mortar, gratefully
received.
Happy coding,
Reynold :-)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|