fortran - Fortran95 -- Reading from a formatted text file -
i need read values table. these first 5 rows, give idea of should like:
1 + 3 98 96 1 2 + 337 2799 2463 1 3 + 2801 3733 933 1 4 + 3734 5020 1287 1 5 + 5234 5530 297 1
my interest in first 4 columns of each row. need read these arrays. used following code:
program ---- implicit none integer, parameter :: totbases = 4639675, totgenes = 4395 integer :: codtot, ks integer, dimension(totgenes) :: ngene, lend, rend character :: genome*4639675, sign*4 open(1,file='e_coli_g_info') open(2,file='e_coli_g_str') ks = 1, totgenes read(1,100) ngene(ks),sign(ks:ks),lend(ks), rend(ks) end 100 format(1x,i4,8x,a1, 2(5x,i7), 22x) ks = 1, 100 write(*,*) ngene(ks), sign(ks:ks),lend(ks), rend(ks) end end program
the loop @ end of program print first hundred entries test being read correctly. problem getting garbage (the fourth row problem):
1 + 3 757934891 2 + 337 724249387 3 + 2801 757803819 4 + 3734 757803819 5 + 5234 757935405
clearly, fourth column way off. in fact, cannot find these values anywhere in file reading from. using gfortran compiler ubuntu 12.04. appreciate if point me in right direction. i'm sure it's i'm missing obvious because i'm new @ fortran.
fortran formats (traditionally, there's newer stuff won't go here) fixed format, is, best suited file formats fixed columns. i.e. column n starts @ character position m, no ifs or buts. if file format more "free format"-like, is, columns separated whitespace, it's easier , more robust read data using list formatting. is, try read loop as
ks = 1, totgenes read(1, *) ngene(ks), sign(ks:ks), lend(ks), rend(ks) end
also, general advice, when opening own files, start unit 10 , go upwards there. fortran implementations typically use of low-numbered units standard input, output, , error (a common choice units 1, 5, , 6). don't want redirect those.
ps 2: haven't tried code, seems have bounds overflow in sign variable. it's declared of length 4, assign index ks goes way totgenes. you're using gfortran on ubuntu 12.04 (that is, gfortran 4.6), when developing compile options "-o1 -wall -g -fcheck=all"
Comments
Post a Comment