diff --git a/src/io/io_read_particle.f90 b/src/io/io_read_particle.f90 new file mode 100644 index 000000000..c0f0dbdf1 --- /dev/null +++ b/src/io/io_read_particle.f90 @@ -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 diff --git a/src/io/io_write_particle.f90 b/src/io/io_write_particle.f90 index 23ba897b1..b5f9bbadf 100644 --- a/src/io/io_write_particle.f90 +++ b/src/io/io_write_particle.f90 @@ -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 @@ -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 diff --git a/src/modules/io.f90 b/src/modules/io.f90 index 34ea85824..469d37cda 100644 --- a/src/modules/io.f90 +++ b/src/modules/io.f90 @@ -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