The nvfortran trim function not trim newline, but the Gfortran and ifort dose.
It makes me have lot works to do. when I migrating a old fortran program to cuda fortran.
Is this behavior a bug OR expect?
for example:
write(*,*) 'should be 9 but get 10:',len(trim('nvfortran\n'))
write(*,*) 'should be 9 and get 9:',len(trim('nvfortran '))
“TRIM” only removes trailing blank spaces, I don’t believe it’s expected to remove special characters like newlines.
In running your example, both gfortran an ifort don’t treat “\n” as a newline character, but even when using a string with a newline appended, they still don’t remove it.
Is the string you’re using coming from C? Can you provide an example which illustrates the issue in your full program?
Example:
$ cat test.f90
write(*,*) 'should be 9 but get 10:',len(trim('nvfortran\n')), trim('nvfortran\n')
write(*,*) 'should be 9 and get 9:',len(trim('nvfortran ')), trim('nvfortran ')
end
$ gfortran test.f90; a.out
should be 9 but get 10: 11 nvfortran\n
should be 9 and get 9: 9 nvfortran
$ ifort test.f90; a.out
should be 9 but get 10: 11 nvfortran\n
should be 9 and get 9: 9 nvfortran
$ nvfortran test.f90; a.out
should be 9 but get 10: 10 nvfortran
should be 9 and get 9: 9 nvfortran
$ cat test2.f90
character(80) :: str1 = "nvfortran"//char(10)
character(80) :: str2 = "nvfortran "
write(*,*) 'should be 9 but get 10:',len(trim(str1)), trim(str1)
write(*,*) 'should be 9 and get 9:',len(trim(str2)), trim(str2)
end
$ gfortran test2.f90; a.out
should be 9 but get 10: 10 nvfortran
should be 9 and get 9: 9 nvfortran
$ ifort test2.f90; a.out
should be 9 but get 10: 10 nvfortran
should be 9 and get 9: 9 nvfortran
$ nvfortran test2.f90; a.out
should be 9 but get 10: 10 nvfortran
should be 9 and get 9: 9 nvfortran
I should mention, if you want nvfortran to match the behavior of gfortran/ifort in the first example, i.e. treat “\n” as two characters instead of a newline, add the flag “-Mbackslash”.
$ nvfortran -Mbackslash test.f90; a.out
should be 9 but get 10: 11 nvfortran\n
should be 9 and get 9: 9 nvfortran
Thanks for quick responding. Yes I test again. THEN realize those newline char comes from read() function.
I first think the issue related with “trim” because the error messages say that line have error during passing the string into a dynamic library (mylib.so) function.
thanks for help.
call someting_c_fuction(filename//C_NULL_CHAR)
by the way if I find newline issue in read function do you want me replay in this chain or open other post?