如何在fortran 90中返回一个字符向量?

时间:2018-01-25 19:06:56

标签: fortran gfortran fortran90

我正在尝试在fortran 90中返回一个字符串向量,但它不起作用。

这是我的主程序,我想用readFromCSV函数填写解决方案。

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 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

0 个答案:

没有答案