Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read entire file to buffer?

Status
Not open for further replies.

mojomother

Programmer
Apr 20, 2010
9
DE
Is there any way to read an entire file into an ALLOCATABLE buffer in Fortran? Say I have the code

Code:
CHARACTER, DIMENSION(:), ALLOCATABLE :: file_buffer
file_size = get_file_size(filename)
ALLOCATE(file_buffer(file_size))

What needs to happen afterwards to read the entire file "file_name" into file_buffer? The file might be big (~ 5 MB).

The way I'm trying to do it, I keep getting "input statement requires too much data" errors.

Thanks in advance!
Matt
 
You need to do something like
Code:
  open (30, &
      file='bigfile.bmp', &
      status='old', &
      recl=file_size, &
      form='unformatted', &
      access='direct')
   read (30, rec=1) file_buffer
   close (30)
Where bigfile.bmp is the name of the file

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top