- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks ! I could do that, but i was hoping that fortran has a way of doing it in a simpler way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks ! Works perfectly !

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page