I am working on converting an exe to a dll. I am passing strings from c# to the dll, and the strings that are coming from c# are specified as follows:
character(len=1), dimension(*), intent(in) :: fileName
I am also passing an integer that gives the length of each string. This seems to work as expected, and I can easily iterate through the characters in the string using the passed length.
As I see it, the character declaration says essentially this: "this is a deferred length character array where each character is 1 byte in length, and the array itself can be any length."
The problem is that some of the code that I am interfacing with was written by another programmer. Though I consider my Fortran skills perhaps intermediate to advanced, I am having trouble grasping how to handle this situation.
The character variable that I need to copy the string to is defined as a deferred type variable as follows:
CHARACTER(:), ALLOCATABLE :: string_data
So this declaration, as far as I can tell, says something completely different, and it says this is a single character where the character itself can be any number of bytes in length.
NOTE: The array is subsequently allocated to the length of the string that it is expected to hold.
If I try to do a simple copy from the string that is coming from c# such as
string_data = fileName(1:fileNameLength)
The compiler gives me an error that says that the shapes of the arrays do not match. This, to me anyway, seems to make sense if I am correct about the meanings of the declaration statements. However, if I set that string to a string constant such as
string_data = '1234567890xyz'
it compiles fine, and works as expected.
If I change
CHARACTER(:), ALLOCATABLE :: string_data
to something that would match like the following:
CHARACTER(len=1), ALLOCATABLE :: string_data(:)
Not only does it give me hundreds of errors when I compile, there is also a chance that this will break a number of different programs since the code where this is declared is used for several other projects. So, I would prefer, if possible, not to change that code.
The closest I have come to getting this to work is with the following code:
read(string_data, *) fileName(1:fileNameLength)
However, this only reads the first character from "fileName", and I have am having difficulty determining a format specifier that will correctly convert the data types between the two.
Anyone have any suggestions as to how to handle this?
Thanks in advance!