fortran - Read multiple hex values from single line -


i want read set of hex values arranged in line, number of spaces between each value not determined. how can read in fortran 90. instance:

2f4----33--6b5----------4db3

program readsomehex  implicit none   integer:: decval , decval2 , decval3 , decval4 ,  open(1,file='input.txt')  open(2,file='output.txt')   read(1,'(z4,z4,z4,z4)') decval , decval2 , decval3 , decval4  write(*,*)        decval , decval2 , decval3 , decval4  end program readsomehex 

with "unformatted" input (by mean formatted (i.e. text) fortran input doesn't follow specific fixed format; not confused actual unformatted input [nb]) best option read in hexa values strings, perform fixed-format (rather list-directed) read on strings:

program readsomehex  implicit none  character*4 :: hexval, hexval2, hexval3, hexval4 integer:: decval , decval2 , decval3 , decval4   open(1,file='input.txt') open(2,file='output.txt')  read(1,*) hexval, hexval2, hexval3, hexval4 read(hexval,'(z4)') decval read(hexval2,'(z4)') decval2 read(hexval3,'(z4)') decval3 read(hexval4,'(z4)') decval4  write(*,*)        decval , decval2 , decval3 , decval4  end program readsomehex 

note should make sure each of hexa numbers @ 4 characters long.

[nb] if don't specify otherwise during open, fortran assumes mean formatted input/output, i.e. text file.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -