fortran - Reading 1D and 2D array from the file -
this code:
program reading_from_file implicit none integer::i,j integer,dimension(3)::type_sndm integer,dimension(2,3)::type_nndm real,dimension(3)::lenght_sndm real,dimension(2,3)::lenght_nndm character(350),parameter::fmta_1_5='(2x,3(f4.2,2x,i1,3x))' character(350),parameter::fmta_1_6='(/,/,/,2x,4(f5.3,2x,i1,3x))' open(unit=15,file='input.txt',status='unknown',action='readwrite') read(15,trim(adjustl(fmta_1_5)))(lenght_sndm(j),type_sndm(j),j=1,3) concurrent(i=1:2) read(15,trim(adjustl(fmta_1_6)))(lenght_nndm(i,j),type_nndm(i,j),j=1,3) end close(unit=15,status='keep') open(unit=15,file='output.txt',status='unknown',action='readwrite') write(15,trim(adjustl(fmta_1_5)))(lenght_sndm(j),type_sndm(j),j=1,3) concurrent(i=1:2) write(15,trim(adjustl(fmta_1_6)))(lenght_nndm(i,j),type_nndm(i,j),j=1,3) end close(unit=15,status='keep') end program reading_from_file
this content of input.txt
:
|2.50||2| |2.50||2| |2.50||2| |0.250||3| |0.250||3| |0.250||3| |0.250||3| |0.250||3| |0.250||3|
i tring read values input.txt
file. next intention write values in output.txt
file. afther program execution message is: fortan runtime error: end of file
. wrong code or formats of reading?
your format fmta_1_6
tries skip 3 lines /,/,/,
, (i guess) meant skip 2 blank lines between lines 1 , 4. second read in loop (i=2) attempts blank lines. lines don't exist, , eof error.
you should skip 2 blank lines before entering loop. also, should not using concurrent do
i/o operations.
after adding these changes, , fixing input.txt
file transcription error, code appears work. section within read now:
read(15,trim(adjustl(fmta_1_5)))(lenght_sndm(j),type_sndm(j),j=1,3) ! -- skip 2 lines read(15,*) read(15,*) i=1,2 read(15,trim(adjustl(fmta_1_6)))(lenght_nndm(i,j),type_nndm(i,j),j=1,3) end
with format:
character(350),parameter::fmta_1_6='(2x,4(f5.3,2x,i1,3x))'
presumably should write 2 blank lines in section.
Comments
Post a Comment