Skip to content

Instantly share code, notes, and snippets.

@rsnemmen
Last active April 4, 2016 22:57
Show Gist options
  • Select an option

  • Save rsnemmen/97430966421b8b96fac8506f47c8f3ee to your computer and use it in GitHub Desktop.

Select an option

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.
! 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