module double
! number precision control
integer, parameter :: dp = selected_real_kind(12)
end module double
module dynamic
use double
real(kind=dp), dimension(:,:), allocatable :: array
integer :: nx = 11! x-nodes
integer :: ny = 11! y-nodes
integer :: nz = 11 ! z-nodes
end module dynamic
module field_in_mod
interface field_in_inter
subroutine field_in(i,field)
use dynamic
implicit none
integer :: i, k
character(7) :: field
end subroutine field_in
end interface field_in_inter
end module field_in_mod
program test
use field_in_mod
use double
use dynamic
implicit none
allocate(array(6,nx*ny*nz))
call field_in(nx*ny*nz,"in01.bi") ! in01.bi - binary, in01.in - ascii
write(*,*) array(:,1)
write(*,*) array(:,2)
deallocate(array)
end program test
subroutine field_in(i, field)
use dynamic
implicit none
! i - number of steps/element in e-field file
! k - do-loop var
integer :: i, k
character(7) :: field
! open file with e-field data
! file layout is assumed
! x y z Ex Ey Ez
if (field=='in01.bi') then
open(unit=10, file=field, recl=nx*ny*nz, &
access='direct', form='unformatted')
! filling array
do k=1,i,1
read(10, rec=1) array(1,k), & ! x
array(2,k), & ! y
array(3,k), & ! z
array(4,k), & ! Ex
array(5,k), & ! Ey
array(6,k) ! Ez
end do
! close file
close(10)
else
open(unit=10, file=field, form='formatted')
! filling array
do k=1,i,1
read(10, fmt=*) array(1,k), & ! x
array(2,k), & ! y
array(3,k), & ! z
array(4,k), & ! Ex
array(5,k), & ! Ey
array(6,k) ! Ez
end do
! close file
close(10)
end if
end subroutine field_in