Last active
April 4, 2016 22:57
-
-
Save rsnemmen/97430966421b8b96fac8506f47c8f3ee to your computer and use it in GitHub Desktop.
Opens a datafile and reads the columns as arrays. Illustrates the use of dynamically allocated arrays.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ! Opens a datafile and reads the columns as arrays. | |
| ! Illustrates the use of dynamic allocated arrays. | |
| program test | |
| implicit none | |
| real, dimension(:), allocatable :: x, y | |
| integer :: i,n | |
| character(len=50) :: in | |
| write(unit=*,fmt='(A,$)') 'Filename: ' | |
| read *, in | |
| write(unit=*,fmt='(A,$)') 'Number of points: ' | |
| read *, n | |
| open(unit=1,file=in,status='old') | |
| allocate(x(n),y(n)) | |
| do i=1,n | |
| read(unit=1,fmt=*) x(i), y(i) | |
| print *, x(i),y(i) | |
| end do | |
| deallocate(a) | |
| close(unit=1) ! closes file | |
| end program | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment