fortran90 - Reading a text file as a input and then writing text files with the data in 2D matrices as output -
fortran90 - Reading a text file as a input and then writing text files with the data in 2D matrices as output -
i real novice in fortran90, of course of study in other programming language. however, need create programme work. asking comment anybody. in advance.
from on, explain problem. original info next as;
15 1r 2 1r 70 22r 2 2r 15 1r 2 1r 8 8r 15 1 3r
this written 1 time again in way below;
15 15 2 2 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 2 2 2 15 15 2 2 8 8 8 8 8 8 8 8 8 15 1 1 1 1
so total number of info elements in above illustration can counted 48. total number of original info 12,113,640
. , original info made of 220(z) slices of 322(x) x 171(y)
. each slices has 55,062 of elements.
if possible, way of count of element number, programme count 55,062 elements , create output file(txt) , totally 220 slices of info should 2d array.
so have extract 220 slices 1 whole info file. , info should 2d array in each slice.
it - assume know how read lines file
program main character(len=120):: compressed character ch integer value, rval, repeat, ix, complen ! pretend line read file compressed = '15 1r 2 1r 70 22r 2 2r 15 1r 2 1r 8 8r 15 1 3r' complen = len(trim(compressed)) ix = 1 while (ix .lt. complen) ! skip spaces ch = compressed(ix:ix) if (ch .ne. ' ') exit ix = ix + 1 end ! extract number value = 0 ch = compressed(ix:ix) if (ch .ge. '0' .and. ch .le. '9') value = value * 10 + ichar(ch) - ichar('0') else exit end if ix = ix + 1 if (ix .gt. complen) exit end ! repeater repeat = 1 if (ch .eq. 'r') ! cut down 1 since 1 has been printed repeat = value - 1 ix = ix + 1 else rval = value end if ! assume there won't more 100 repeats write(*, '(100i3)', advance='no') (rval, ii = 1, repeat) end stop end programme
fortran90 fortran77
Comments
Post a Comment