Reading unformatted files 'bit a bit' 
Author Message
 Reading unformatted files 'bit a bit'

Hallo,
I am trying to reproduce a C routine using fortran.
The aim of this routine is to read from a file values of 1-2-4 or 8 bit
lenght.
How can I define arrays whose values are 1-or-2or-4-bit-lenght?
How can I define variables of BYTE Type (classical UNSIGNED INT or CHAR, 8
bits without sign)?
Data I am working with are related to images. Images themself have values
from 0 to 255. How can I use INTEGER*1 variables to store my data (from 0 to
255 and not from -128 to 127)?

Thank You

PhD. Massimo Miozzi
ANPA-Agenzia Nazionale per l'Ambiente
ROME - ITALY



Fri, 25 Jul 2003 23:05:02 GMT  
 Reading unformatted files 'bit a bit'

Quote:
>Hallo,
>I am trying to reproduce a C routine using FORTRAN.
>The aim of this routine is to read from a file values of 1-2-4 or 8 bit
>lenght.
>How can I define arrays whose values are 1-or-2or-4-bit-lenght?
>How can I define variables of BYTE Type (classical UNSIGNED INT or CHAR, 8
>bits without sign)?
>Data I am working with are related to images. Images themself have values
>from 0 to 255. How can I use INTEGER*1 variables to store my data (from 0 to
>255 and not from -128 to 127)?

>Thank You

>PhD. Massimo Miozzi
>ANPA-Agenzia Nazionale per l'Ambiente
>ROME - ITALY

    This depends on what kind of "endian_ness" your OS/Compiler
 uses; if the 1st byte in memory is least significant, then:

  integer*1 byte  
  integer*2 ii
  equivalence (ii,byte)
  ii=0
  .
  .
  .

  byte = something

     then ii is the unsigned version of byte

else (other endian):

  integer*1 il(2)
  integer*2 ii
  equivalence (ii,il(1))
  ii=0  !so high byte=0

  .
  .
  .
  .  
   il(2)=something

     then ii is the unsigned version of byte

 Or: you can also (try to) say

    integer*1 byte
    integer i

    i=byte  
    if(i.lt.0)i=i+256

Chris



Sat, 26 Jul 2003 02:03:01 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. (typep (make-array 10 :element-type 'bit) '(array bit (10)))

2. Reading fortran 'unformatted' binary files

3. Reading binary file generated from 32-bit machine using 64-bit machine

4. Unformatted read's and write's

5. Unformatted read's and write's

6. Can't read CD bit in CR0 from boot floppy

7. 64-bit unformatted files

8. Reading serial RxD bit by bit?

9. Tcl can't handle 8-bit file names

10. Division 32-Bit/32-Bit with 16-Bit Register

11. How to read a binary-file into a bit-array

12. File Reading in 'J'

 

 
Powered by phpBB® Forum Software