I'm trying to return a vector of strings in fortran 90 but it's not working.
This is my main program and i want to fill in solutions with readFromCSV function.
program write_csv
character(LEN=30) :: fileName;
character(LEN=200) :: head1,head2,head3,head4,head5
character(len=50), dimension(10), external :: readFromCSV
character(len=50), dimension(10) :: solutions
fileName = "solutions.csv";
solutions = readFromCSV(fileName)
end program
ReadFromCSC function code:
function readFromCSV(fileName) result (solutions)
integer :: res
character(len=50), dimension(10) :: solutions
character(LEN=10) :: aux, aux2
character(LEN=30) :: fileName
open(10, file=fileName,access='sequential',form="formatted",iostat=res)
i = 1;
DO WHILE (i < 11)
read(10,fmt='(A)', iostat=res) solutions(i)
if(i < 10) THEN
solutions(i) = TRIM(solutions(i))
solutions(i) = solutions(i)(19:(LEN(solutions(i))))
ELSE
solutions(i) = TRIM(solutions(i))
solutions(i) = solutions(i)(20:(LEN(solutions(i))))
END IF
aux = solutions(i)(1:7)
aux2 = solutions(i)(9:LEN(solutions(i)))
solutions(i) = TRIM(aux)//TRIM(aux2)
i = i+1
end do
i = 1;
DO WHILE (i < 11)
write(*,'(a)') (solutions(i))
i = i+1
end do
readFromCSV = solutions
end function readFromCSV