Register to reply

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

by roy437
Tags: character, file
Share this thread:
Dec14-12, 12:09 PM
P: 6

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"

Phys.Org News Partner Science news on
New type of solar concentrator desn't block the view
Researchers demonstrate ultra low-field nuclear magnetic resonance using Earth's magnetic field
Asian inventions dominate energy storage systems
Dec14-12, 12:20 PM
P: 2,938
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.
Dec14-12, 12:21 PM
P: 166
What fortran interpreter?

Dec14-12, 12:45 PM
P: 6
I can not read character 0A in a bmp file with Compaq Visual Fortran 6.6C

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

Crashes when reading header !
Dec14-12, 12:54 PM
P: 2,938
you're reading a binary file with as if it were a text file. You need to modify your read to open the file as binary.

Notice the open statement with the form=binary

open (55,file=xxx,access='DIRECT',form='BINARY',recl=1)
Dec14-12, 12:57 PM
P: 166
Where is your open() statement for nfile? That is what needs changed. You need FORM='BINARY' in the compaq fortran interpreter.
Dec14-12, 01:16 PM
P: 6
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)
Dec14-12, 01:46 PM
P: 166
You need to pass in UNFORMATTED or BINARY for the open mode as discussed. This should help you:
Dec14-12, 01:50 PM
Borek's Avatar
P: 23,533
Quote Quote by justsomeguy View Post
What fortran interpreter?
FORTRAN is interpreted?
Dec14-12, 02:50 PM
PF Gold
phinds's Avatar
P: 6,274
Quote Quote by Borek View Post
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.
Dec14-12, 03:15 PM
P: 166
Using it in the "vmware is melting my brain in another window" sense. Apologies.
Dec15-12, 08:48 AM
P: 6
Thank you very much to jedishrfu and justsomeguy !

Register to reply

Related Discussions
In binary can we have a value with deci centi mili or more lower valued prefix? Computers 14
Could a Black Hole be the cycle of Dark Matter powered by Dar Energy:? General Physics 3
Difference between Identical , Equal , Equivalent Calculus & Beyond Homework 9
Deleting a file that can not read from the source file or disk Computers 13