format - Read and write tab-delimited text data -
i have excel output in tab-delimited format:
temperature h2o co2 n2 nh3 10 2.71539e+12 44374931376 7410673406 2570.560804 20 2.34216e+12 38494172272 6429230649 3148.699673 30 2.04242e+12 33759520581 5639029060 3856.866413 40 1.75491e+12 29172949817 4882467457 4724.305292 . . .
i need convert these numbers format(1x,f7.0,2x,1p4e11.3)
readable code. i've come with:
program fixformat real temp, neuts(4) integer i,j character header open(11,file='./unformatted.txt',status='old') open(12,file='./formatted.txt',status='unknown') read(11,*) header write(12,*) header = 1, 200 read(11,*) temp, (neuts(j),j=1,4) write(12,23) temp, (neuts(j),j=1,4) end 23 format(1x,f7.0,2x,1p4e11.3) close(11) close(12) return end
i keep getting error:
fortran runtime error: bad real number in item 1 of list input
is there other way convert data format?
you need character string, not single character
header
character(80) header
other program works me. make sure have right number of lines in loop
do i=1,200
adjust 200
real number of data lines.
if reason still cannot read single line, can use format:
read(11,'(f2.0,4(1x,f11.0))') temp, (neuts(j),j=1,4)
because tab character can skip.
notes:
unformatted , formatted means different in fortran. unformatted may know "binary".
use indentation , blank lines programs make them readable.
there no reason explicitly use status=unknown
. don't put there. in case status=replace
may more appropriate.
the format
statement quite obsolete, in modern fortran use format strings:
write(12,'(1x,f7.0,2x,1p4e11.3)') temp, (neuts(j),j=1,4)
there absolutely no reason return
before end. returns return procedure. put stop
before end program
, superfluous.
Comments
Post a Comment