I am trying to create an overloaded function num2str(x)
which will take integer or real values as input and return a string value. My purpose of doing this is to use it when writing log file.
Based on suggestions given in my previous post (creating log file)
I have created a subroutine message(msglevel, string)
which I am using to write my log file. Now I can only send a string to this function and I am trying to make it easy to create a string using num2str(x)
.
Could someone explain me where should I place this code (In a subroutine, in a module) so I can access it from everywhere. I saw an example of this, but it uses it in the main program, which I can't do.
Please let me know if this approach is correct.I would also like to know if I can modify num2str(x)
to return string for array variables.
!GLOBAL FUNCTIONS
interface num2str
function num2str_int(number)
integer,intent(in)::number
character(len=*)::num2str_int
end function
character function num2str_real(number)
real::number
character(len=*)::num2str_real
end function
end interface
function num2str_int(number)
implicit none
integer,intent(in)::number
character(len=*)::num2str_int
write(num2str_int,'(I)')number
return
end function
character function num2str_real(number)
implicit none
real,intent(in)::number
character(len=*)::num2str_real
write(num2str_real,'(F6.4)')number
return
end function