I've got a simple Fortran function that converts a comma delimited string into an array of character(len=255). I can't figure out how to create a variable that can receive the output of this function.
Here's my comma delimited string to array function:
function CommaDelimitedStringToArray(commastr) result (slist)
character(*), intent(in) :: commastr
! Local vars
character(255), dimension (:), allocatable :: slist
integer :: scount
! Lots of code removed - I set scount to be the number
! of elements in the comma delimited string, with a
! minimum value of 1
! Create the slist and populate it...
allocate (slist(scount))
! Lots more code removed. At the end of this function I know I have
! slist defined with the correct size and correct contents
end function CommaDelimitedStringToArray
Now I want to actually use this function. I've tried this:
character(255) :: commastr
character(255), dimension (:), allocatable :: mylist
commastr = "this,that,theother,etc"
mylist = CommaDelimitedStringToArray(trim(commastr))
But mylist
does not receive the array from the function call.
In my testing if I allocate mylist to the correct size before calling the function it does receive the array correctly. But, obviously, in the real world I don't know the size before I call the function.
How do I declare/use mylist so it will correctly receive the array?
EDIT - My compiler reports itself as "Intel® Parallel Studio XE 2016 Update 3 Composer Edition for Fortran Windows Integration for Microsoft Visual Studio 2015, Version 16.0.0062.14" running on Win 10.
Compiler flags are:
/nologo /debug:full /Od /warn:interfaces /module:"Debug\" /object:"Debug\" /Fd"Debug\vc140.pdb" /traceback /check:bounds /check:stack /libs:static /threads /dbglibs /c