module globals implicit none save integer, parameter:: dble = kind(1d0) end module globals program SimpleFileIO use globals implicit none !variable declarations integer, parameter:: T=5 real(dble) xvect(T), yvect(T) real(dble) xmat(T,T), y1mat(T,T), y2mat(T,T) real(dble) xvar integer i,j !variable initializations xvar = 1.0d0 xvect = (/(sqrt(xvar + i),i=0,T-1)/) xmat = reshape((/((xvar+i)**(1/3.0d0), i=0,T*T)/), (/T,T/)) !Writing a 1-dimensional array to a file open(11,file = "data.txt") do i =1,T write(11,'(f8.4)') xvect(i) end do close(11) !Reading data from a file into a 1-dimensional array open(11,file = "data.txt") read(11,*) yvect close(11) !Writing 2 2-dimensional arrays to a file open(12,file = "data2.txt") write(12,'(f8.4)') ((xmat(i,j),i=1,T),j=1,T) write(12,'(f8.4)') ((xmat(i,j),j=1,T),i=1,T) close(12) !Reading data from a file into 2 2-dimensional arrays open(12,file = "data2.txt") read(12,*) y1mat, y2mat close(12) !Printing to screen print '(a,100f8.4,:)', "xvect=", (xvect(i), i=1,T) print '(a,100f8.4,:)', "yvect=", (yvect(i), i=1,T) print *, "xmat" do i=1,T print '(100f8.4,:)', (xmat(i,j),j=1,T) end do print *, "y1mat" do i=1,T print '(100f8.4,:)', (y1mat(i,j),j=1,T) end do print *, "y2mat" do i=1,T print '(100f8.4,:)', (y2mat(i,j),j=1,T) end do close(12) end program SimpleFileIO