diff --git a/src/io/io.f90 b/src/io/io.f90 index f2cd4d2f5..df9fd6f50 100644 --- a/src/io/io.f90 +++ b/src/io/io.f90 @@ -157,8 +157,12 @@ module subroutine io_dump_swiftest(self, param) dump_file_name = trim(adjustl(param%intpfile)) end select open(unit = iu, file = dump_file_name, form = "UNFORMATTED", status = 'replace', err = 667, iomsg = errmsg) + select type(self) + class is (swiftest_body) + write(iu, err = 667, iomsg = errmsg) self%nbody + end select call self%write_frame(iu, param) - close(LUN, err = 667, iomsg = errmsg) + close(iu, err = 667, iomsg = errmsg) return @@ -205,6 +209,7 @@ module subroutine io_dump_system(self, param) dump_param%intpfile = trim(adjustl(DUMP_TP_FILE(idx))) dump_param%out_form = XV dump_param%out_stat = 'APPEND' + dump_param%in_type = REAL8_TYPE dump_param%T0 = param%t call dump_param%dump(param_file_name) @@ -1006,9 +1011,9 @@ module subroutine io_read_frame_body(self, iu, param, form) if (.not.allocated(self%capom)) allocate(self%capom(n)) if (.not.allocated(self%omega)) allocate(self%omega(n)) if (.not.allocated(self%capm)) allocate(self%capm(n)) - read(iu, err = 667, iomsg = errmsg) self%a(:) - read(iu, err = 667, iomsg = errmsg) self%e(:) - read(iu, err = 667, iomsg = errmsg) self%inc(:) + read(iu, err = 667, iomsg = errmsg) self%a(:) + read(iu, err = 667, iomsg = errmsg) self%e(:) + read(iu, err = 667, iomsg = errmsg) self%inc(:) read(iu, err = 667, iomsg = errmsg) self%capom(:) read(iu, err = 667, iomsg = errmsg) self%omega(:) read(iu, err = 667, iomsg = errmsg) self%capm(:) @@ -1044,7 +1049,14 @@ module subroutine io_read_frame_body(self, iu, param, form) return 667 continue - write(*,*) "Error reading central body file: " // trim(adjustl(errmsg)) + select type (self) + class is (swiftest_pl) + write(*,*) "Error reading massive body file: " // trim(adjustl(errmsg)) + class is (swiftest_tp) + write(*,*) "Error reading test particle file: " // trim(adjustl(errmsg)) + class default + write(*,*) "Error reading body file: " // trim(adjustl(errmsg)) + end select call util_exit(FAILURE) end subroutine io_read_frame_body @@ -1065,16 +1077,20 @@ module subroutine io_read_frame_cb(self, iu, param, form) ! Internals character(len=STRMAX) :: errmsg - read(iu, err = 667, iomsg = errmsg) self%id !read(iu, err = 667, iomsg = errmsg) self%name + read(iu, err = 667, iomsg = errmsg) self%id read(iu, err = 667, iomsg = errmsg) self%Gmass self%mass = self%Gmass / param%GU read(iu, err = 667, iomsg = errmsg) self%radius read(iu, err = 667, iomsg = errmsg) self%j2rp2 read(iu, err = 667, iomsg = errmsg) self%j4rp4 if (param%lrotation) then - read(iu, err = 667, iomsg = errmsg) self%Ip(:) - read(iu, err = 667, iomsg = errmsg) self%rot(:) + read(iu, err = 667, iomsg = errmsg) self%Ip(1) + read(iu, err = 667, iomsg = errmsg) self%Ip(2) + read(iu, err = 667, iomsg = errmsg) self%Ip(3) + read(iu, err = 667, iomsg = errmsg) self%rot(1) + read(iu, err = 667, iomsg = errmsg) self%rot(2) + read(iu, err = 667, iomsg = errmsg) self%rot(3) end if if (param%ltides) then read(iu, err = 667, iomsg = errmsg) self%k2 @@ -1094,29 +1110,22 @@ module subroutine io_read_frame_system(self, iu, param, form) !! Read a frame (header plus records for each massive body and active test particle) from a output binary file implicit none ! Arguments - class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object - integer(I4B), intent(inout) :: iu !! Unit number for the output file to write frame to + class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object + integer(I4B), intent(inout) :: iu !! Unit number for the output file to write frame to class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - character(*), intent(in) :: form !! Input format code ("XV" or "EL") + character(*), intent(in) :: form !! Input format code ("XV" or "EL") ! Internals - logical, save :: lfirst = .true. character(len=STRMAX) :: errmsg integer(I4B) :: ierr - iu = BINUNIT - if (lfirst) then - open(unit = iu, file = param%outfile, status = 'OLD', form = 'UNFORMATTED', err = 667, iomsg = errmsg) - lfirst = .false. - end if ierr = io_read_hdr(iu, param%t, self%pl%nbody, self%tp%nbody, param%out_form, param%out_type) if (ierr /= 0) then - write(*, *) "Swiftest error:" - write(*, *) " Binary output file already exists or cannot be accessed" - return + write(errmsg, *) "Cannot read header." + goto 667 end if - call self%cb%read_frame(iu, param, form) - call self%pl%read_frame(iu, param, form) - call self%tp%read_frame(iu, param, form) + call self%cb%read_frame(iu, param, param%out_form) + call self%pl%read_frame(iu, param, param%out_form) + call self%tp%read_frame(iu, param, param%out_form) return @@ -1137,7 +1146,7 @@ function io_read_hdr(iu, t, npl, ntp, out_form, out_type) result(ierr) ! Arguments integer(I4B), intent(in) :: iu integer(I4B), intent(out) :: npl, ntp - character(*), intent(out) :: out_form + character(*), intent(out) :: out_form real(DP), intent(out) :: t character(*), intent(in) :: out_type ! Result @@ -1147,19 +1156,18 @@ function io_read_hdr(iu, t, npl, ntp, out_form, out_type) result(ierr) character(len=STRMAX) :: errmsg select case (out_type) - case (REAL4_TYPE, SWIFTER_REAL4_TYPE) - read(iu, iostat = ierr, err = 667, iomsg = errmsg) ttmp, npl, ntp, out_form - if (ierr /= 0) return + case (REAL4_TYPE) + read(iu, iostat = ierr, err = 667, iomsg = errmsg) ttmp t = ttmp - case (REAL8_TYPE, SWIFTER_REAL8_TYPE) + case (REAL8_TYPE) read(iu, iostat = ierr, err = 667, iomsg = errmsg) t - read(iu, iostat = ierr, err = 667, iomsg = errmsg) npl - read(iu, iostat = ierr, err = 667, iomsg = errmsg) ntp - read(iu, iostat = ierr, err = 667, iomsg = errmsg) out_form case default write(errmsg,*) trim(adjustl(out_type)) // ' is an unrecognized file type' ierr = -1 end select + read(iu, iostat = ierr, err = 667, iomsg = errmsg) npl + read(iu, iostat = ierr, err = 667, iomsg = errmsg) ntp + read(iu, iostat = ierr, err = 667, iomsg = errmsg) out_form return diff --git a/src/main/swiftest_driver.f90 b/src/main/swiftest_driver.f90 index 5e28452e0..a97ba46b0 100644 --- a/src/main/swiftest_driver.f90 +++ b/src/main/swiftest_driver.f90 @@ -35,7 +35,7 @@ program swiftest_driver param%integrator = integrator call setup_construct_system(nbody_system, param) - call param%read_from_file(param_file_name) + call param%read_in(param_file_name) associate(t => param%t, & t0 => param%t0, & diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 0c11e4895..8d447158f 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -78,10 +78,10 @@ module swiftest_classes logical :: lyarkovsky = .false. !! Turn on Yarkovsky effect logical :: lyorp = .false. !! Turn on YORP effect contains - procedure :: reader => io_param_reader - procedure :: writer => io_param_writer - procedure :: dump => io_dump_param - procedure :: read_from_file => io_read_in_param + procedure :: reader => io_param_reader + procedure :: writer => io_param_writer + procedure :: dump => io_dump_param + procedure :: read_in => io_read_in_param end type swiftest_parameters !******************************************************************************************************************************** @@ -93,7 +93,6 @@ module swiftest_classes contains !! The minimal methods that all systems must have procedure :: dump => io_dump_swiftest - procedure(abstract_initialize), deferred :: initialize procedure(abstract_read_frame), deferred :: read_frame procedure(abstract_write_frame), deferred :: write_frame end type swiftest_base @@ -128,7 +127,7 @@ module swiftest_classes real(DP), dimension(NDIM) :: L0 = 0.0_DP !! Initial angular momentum of the central body real(DP), dimension(NDIM) :: dL = 0.0_DP !! Change in angular momentum of the central body contains - procedure :: initialize => io_read_in_cb !! I/O routine for reading in central body data + procedure :: read_in => io_read_in_cb !! I/O routine for reading in central body data procedure :: read_frame => io_read_frame_cb !! I/O routine for reading out a single frame of time-series data for the central body procedure :: write_frame => io_write_frame_cb !! I/O routine for writing out a single frame of time-series data for the central body end type swiftest_cb @@ -174,7 +173,7 @@ module swiftest_classes procedure :: drift => drift_body !! Loop through bodies and call Danby drift routine on heliocentric variables procedure :: v2pv => gr_vh2pv_body !! Converts from velocity to psudeovelocity for GR calculations using symplectic integrators procedure :: pv2v => gr_pv2vh_body !! Converts from psudeovelocity to velocity for GR calculations using symplectic integrators - procedure :: initialize => io_read_in_body !! Read in body initial conditions from a file + procedure :: read_in => io_read_in_body !! Read in body initial conditions from a file procedure :: read_frame => io_read_frame_body !! I/O routine for writing out a single frame of time-series data for the central body procedure :: write_frame => io_write_frame_body !! I/O routine for writing out a single frame of time-series data for the central body procedure :: accel_obl => obl_acc_body !! Compute the barycentric accelerations of bodies due to the oblateness of the central body @@ -356,12 +355,6 @@ subroutine abstract_accel(self, system, param, t, lbeg) logical, intent(in) :: lbeg !! Optional argument that determines whether or not this is the beginning or end of the step end subroutine abstract_accel - subroutine abstract_initialize(self, param) - import swiftest_base, swiftest_parameters - class(swiftest_base), intent(inout) :: self !! Swiftest base object - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - end subroutine abstract_initialize - subroutine abstract_kick_body(self, system, param, t, dt, lbeg) import swiftest_body, swiftest_nbody_system, swiftest_parameters, DP implicit none diff --git a/src/modules/swiftest_globals.f90 b/src/modules/swiftest_globals.f90 index 454f454f5..17c5d9b19 100644 --- a/src/modules/swiftest_globals.f90 +++ b/src/modules/swiftest_globals.f90 @@ -107,7 +107,7 @@ module swiftest_globals character(*), dimension(2), parameter :: DUMP_CB_FILE = ['dump_cb1.bin', 'dump_cb2.bin' ] character(*), dimension(2), parameter :: DUMP_PL_FILE = ['dump_pl1.bin', 'dump_pl2.bin' ] character(*), dimension(2), parameter :: DUMP_TP_FILE = ['dump_tp1.bin', 'dump_tp2.bin' ] - character(*), dimension(2), parameter :: DUMP_PARAM_FILE = ['dump_param1.dat', 'dump_param2.dat'] + character(*), dimension(2), parameter :: DUMP_PARAM_FILE = ['dump_param1.in', 'dump_param2.in'] !> Default file names that can be changed by the user in the parameters file character(*), parameter :: CB_INFILE = 'cb.in' diff --git a/src/setup/setup.f90 b/src/setup/setup.f90 index ea15bf1fe..d56f2becb 100644 --- a/src/setup/setup.f90 +++ b/src/setup/setup.f90 @@ -133,10 +133,10 @@ module subroutine setup_initialize_system(self, param) ! Arguments class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - - call self%cb%initialize(param) - call self%pl%initialize(param) - call self%tp%initialize(param) + + call self%cb%read_in(param) + call self%pl%read_in(param) + call self%tp%read_in(param) call self%validate_ids(param) call self%set_msys() call self%pl%set_mu(self%cb)