I can not read character 0A in a bmp file with Compaq Visual Fortran 6.6C

  • Context: Fortran 
  • Thread starter Thread starter roy437
  • Start date Start date
  • Tags Tags
    File Fortran Visual
Click For Summary

Discussion Overview

The discussion revolves around the issue of reading a specific character ("0A") in a BMP file using Compaq Visual Fortran 6.6C. Participants explore the technical aspects of reading binary files, the appropriate methods for file handling in Fortran, and the implications of using incorrect file modes.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports an error when attempting to read character "0A" from a BMP file, indicating a problem with file reading.
  • Another participant suggests that the issue may stem from using an ASCII read function on a binary file, emphasizing the need to open the file in binary mode.
  • A participant provides a subroutine for reading the BMP header, noting that it crashes when reading the header.
  • Several participants recommend modifying the open statement to include FORM='BINARY' to correctly read the file.
  • There is a discussion about the terminology used regarding the Fortran interpreter, with some participants questioning the use of "interpreted" in this context.

Areas of Agreement / Disagreement

Participants generally agree that the file should be opened in binary mode to avoid reading errors, but there is some confusion regarding the terminology used to describe the Fortran environment.

Contextual Notes

Some participants note the importance of using the correct file mode when opening binary files, but the specifics of the implementation and potential variations in Fortran interpreters are not fully resolved.

roy437
Messages
6
Reaction score
0
I can not read character "0A" in a bmp file with "Compaq Visual Fortran 6.6C"

Hi,

How to read character "0A" in a bmp file with "Compaq Visual Fortran 6.6C"
Here's an excerpt from bmp file:
42 4D 16 02 00 00 00 00 00 00 36 00 00 00 28 00
00 00 10 00 00 00 0A 00 00 00 01 00 18 00 00 00
Because the meeting this character appears error: "forrtl: severe (268): end of record during read, unit 1, file 16x10.bmp"

Thanks
 
Technology news on Phys.org


it seems you are trying to read a binary file with an ascii read function or you've not opened the file as binary.

The 0A you mention is a linefeed character, commonly used to terminate lines of text in ascii files and stripped off when you read a line of text.

BMP files are images files (screen shots...) created on windows machines or by image editors that support that file type.
 


What fortran interpreter?
 


Here are some of the source code:

subroutine read_bmp_header(nfile, file_size, hpix, vpix)

! file_size - in bits
! hpix - numbers horizontal pixels
! vpix - numbers vertical pixels
! reading remains the first pixel

implicit none

character *54 header
character *8 fs, hm, vm
character *4 h

integer (2) i, j, nfile
integer (4) file_size, hpix, vpix

read(nfile, '(a)', advance = 'no') header
do i = 1, 4
j = 7 - i
h(i:i) = header(j:j)
j = 2 * i
write(fs(j-1:j), '(z2.2)') ichar(h(i:i))
j = 23 - i
h(i:i) = header(j:j)
j = 2 * i
write(hm(j-1:j), '(z2.2)') ichar(h(i:i))
j = 27 - i
h(i:i) = header(j:j)
j = 2 * i
write(vm(j-1:j), '(z2.2)') ichar(h(i:i))
end do

read(fs, '(z8)') file_size
read(hm, '(z8)') hpix
read(vm, '(z8)') vpix
return
end

Crashes when reading header !
 


Where is your open() statement for nfile? That is what needs changed. You need FORM='BINARY' in the compaq fortran interpreter.
 


Here is the calling unit:

implicit none

integer (4) file_size, hpix, vpix
integer (2) k, l, m

character *100 fisi
character *54 header
character *1, allocatable :: r(:), g(:), b(:)

open(1, file = fisi)

call read_bmp_header(int2(1), file_size, hpix, vpix)
 


justsomeguy said:
What fortran interpreter?

FORTRAN is interpreted?
 
  • #10


Borek said:
FORTRAN is interpreted?

Yeah, I had the same question. I think he must be using the word in the English language sense, not the computer science sense.
 
  • #11


Using it in the "vmware is melting my brain in another window" sense. Apologies.
 
  • #12


Thank you very much to jedishrfu and justsomeguy !
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 58 ·
2
Replies
58
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 20 ·
Replies
20
Views
6K
  • · Replies 1 ·
Replies
1
Views
17K
Replies
6
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K