Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved io handling for restarting runs from dump files
  • Loading branch information
daminton committed May 24, 2021
1 parent 378feef commit 31d195d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
43 changes: 43 additions & 0 deletions src/io/io_read_particle.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
submodule (io) s_io_read_particle

contains
module subroutine io_read_particle_pl(swiftest_plA, param)
!! author: David A. Minton
!!
!! Writes particle information to a file.
!!
use swiftest, except_this_one => io_read_particle_pl
implicit none
! Arguments
class(swiftest_pl), intent(inout) :: swiftest_plA !! Swiftest massive body structure
type(user_input_parameters), intent(in) :: param !! Input colleciton of user-defined parameters
! Internals
integer(I4B), parameter :: lun = 22
integer(I4B) :: i, ierr, id, idx
integer(I4B), save :: iu = lun

associate(out_form => param%out_form, out_type => param%out_type, particle_file => param%particle_file)
open(unit = iu, file = particle_file, status = 'OLD', form = 'UNFORMATTED', iostat = ierr)
if (ierr /= 0) then
write(*, *) "Swiftest error:"
write(*, *) " unable to open binary particle file for reading"
call util_exit(FAILURE)
end if

do
read(LUN, iostat=ierr) id
if (ierr /=0) exit
idx = findloc(swiftest_plA%id(:), id, dim=1)
read(LUN) swiftest_plA%info(idx)
end do
close(unit = iu, iostat = ierr)
if (ierr /= 0) then
write(*, *) "Swiftest error:"
write(*, *) " unable to close particle output file"
call util_exit(FAILURE)
end if
end associate
return

end subroutine io_read_particle_pl
end submodule s_io_read_particle
14 changes: 6 additions & 8 deletions src/io/io_write_particle.f90
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
submodule (io) s_io_write_particle

contains
module procedure io_write_particle_pl !(swiftest_plA, idx, param)
module subroutine io_write_particle_pl(swiftest_plA, idx, param)
!! author: David A. Minton
!!
!! Writes particle information to a file.
!!
use module_interfaces
use module_symba
use swiftest
use swiftest, except_this_one => io_write_particle_pl
implicit none
! Arguments
!class(swiftest_pl), intent(in) :: swiftest_plA !! Swiftest massive body structure
!integer(I4B), dimension(:), intent(in) :: idx !! Array of particle indices to append to the particle file
!type(user_input_parameters), intent(in) :: param !! Input colleciton of user-defined parameters
class(swiftest_pl), intent(in) :: swiftest_plA !! Swiftest massive body structure
integer(I4B), dimension(:), intent(in) :: idx !! Array of particle indices to append to the particle file
type(user_input_parameters), intent(in) :: param !! Input colleciton of user-defined parameters
! Internals
logical, save :: lfirst = .true.
integer(I4B), parameter :: lun = 22
Expand Down Expand Up @@ -62,5 +60,5 @@
end associate
return

end procedure io_write_particle_pl
end subroutine io_write_particle_pl
end submodule s_io_write_particle
7 changes: 7 additions & 0 deletions src/modules/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ module subroutine io_write_particle_pl(swiftest_plA, idx, param)
integer(I4B), dimension(:), intent(in) :: idx !! Array of particle indices to append to the particle file
type(user_input_parameters), intent(in) :: param !! Input colleciton of user-defined parameters
end subroutine io_write_particle_pl

module subroutine io_read_particle_pl(swiftest_plA, param)
implicit none
class(swiftest_pl), intent(inout) :: swiftest_plA !! Swiftest massive body structure
type(user_input_parameters), intent(in) :: param !! Input colleciton of user-defined parameters
end subroutine io_read_particle_pl



end interface
Expand Down

0 comments on commit 31d195d

Please sign in to comment.