Hi,
Is there a way to read an entire file (only text, example kernel for opencl ) to a character(len=10000) in one read command ?
I can't seem to have more than the first line for formatted file, and i missed the first column but that's obviously because it is not in unformatted format !
Thanks.
链接已复制
4 回复数
If you are more comfortable with C/C++ you can call a C/C++ function to perform the open, allocate buffer, read and return pointer to buffer and file size.
You can then use the interoperability features to convert the C pointer to FORTRAN pointer. Add a C/C++ function to delete the buffer (if buffer was allocated). I think you are not intending on parsing this file, just reference the buffer when launching the OpenCL portion of your applicaiton.
Jim Dempsey
You can do it in Fortran with POSIX extensions. Here's an example:
[fortran]
use ifposix
character(10000) contents
character(*), parameter :: filename = 'path_to_file'
integer bytes_read, filedes, ierr
call PXFOPEN (filename,len(filename),IPXFCONST('O_RDONLY'),0,filedes,ierr)
if (ierr /= 0) then
print *, "Open failed with POSIX error", ierr
stop
end if
call PXFREAD (filedes,contents,len(contents),bytes_read,ierr)
if (ierr /= 0) then
print *, "Read failed with POSIX error", ierr
stop
end if
print *,contents(1:400)
call PXFCLOSE (filedes,ier)
end
[/fortran]
