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

Commit

Permalink
Improved the version control of version number. Added function to CMa…
Browse files Browse the repository at this point in the history
…keLists.txt that will update the version number for both the Fortran and Python source files based on the contents of version.txt. Also improved how base_util_exit output is handled by allowing output to be directed to the proper display unit set by param%display_unit
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 2, 2023
1 parent f9baf87 commit c3ea9f2
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dump*
*ipynb_checkpoints
**/.DS_Store
!python/swiftest/tests/test_suite.py
!version.txt

#Documentation
!docs/*
Expand Down
41 changes: 36 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
# Define the project and the depencies that it has
##################################################

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5...3.20.1)
PROJECT(Swiftest Fortran)

# Set the Swiftest version
SET(VERSION 1.0.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.20.1)
# Get version stored in text file
FILE(READ "version.txt" VERSION)
PROJECT(Swiftest VERSION ${VERSION} LANGUAGES Fortran)

INCLUDE(CTest)

Expand Down Expand Up @@ -68,6 +67,38 @@ SET(LIB ${CMAKE_SOURCE_DIR}/lib)
SET(BIN ${CMAKE_SOURCE_DIR}/bin)
SET(MOD ${CMAKE_SOURCE_DIR}/include)
SET(TEST ${CMAKE_SOURCE_DIR}/test)
SET(PY ${CMAKE_SOURCE_DIR}/python/swiftest)

FUNCTION(REPLACE_VERSION IN_FILE LANGUAGE)
# Make list of strings from file
FILE(STRINGS ${IN_FILE} LINES)

# Replace file with new one
FILE(WRITE ${IN_FILE} "")

# Look for the word "VERSION" and replace the line with the updated one
FOREACH(LINE IN LISTS LINES)
IF (LANGUAGE STREQUAL "Fortran") # This is the version found in the swiftest driver program
STRING(FIND "${LINE}" " VERSION =" LINE_HAS_VER)
IF (LINE_HAS_VER GREATER_EQUAL 0) # This is the version line
FILE(APPEND ${IN_FILE} " character(*), parameter :: VERSION = \"${CMAKE_PROJECT_VERSION}\" !! Swiftest version\n")
ELSE ()
FILE(APPEND ${IN_FILE} "${LINE}\n") # No match. Put this line back like we found it
ENDIF ()
ELSEIF (LANGUAGE STREQUAL "Python") # This is the version found in the Python package
STRING(FIND "${LINE}" "version=" LINE_HAS_VER)
IF (LINE_HAS_VER GREATER_EQUAL 0) # This is the version line
FILE(APPEND ${IN_FILE} " version='${CMAKE_PROJECT_VERSION}',\n")
ELSE ()
FILE(APPEND ${IN_FILE} "${LINE}\n") # No match. Put this line back like we found it
ENDIF ()
ENDIF ()
ENDFOREACH ()
ENDFUNCTION ()

REPLACE_VERSION(${SRC}/globals/globals_module.f90 "Fortran" )
REPLACE_VERSION(${PY}/setup.py "Python")


# Have the .mod files placed in the lib folder
SET(CMAKE_Fortran_MODULE_DIRECTORY ${MOD})
Expand Down
4 changes: 2 additions & 2 deletions python/swiftest/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
from setuptools import setup, find_packages

setup(name='swiftest',
version='0.2',
version='2023.08.00',
author='David A. Minton',
packages=find_packages())
packages=find_packages())
28 changes: 18 additions & 10 deletions src/base/base_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ subroutine base_util_dealloc_storage(self)
end subroutine base_util_dealloc_storage


subroutine base_util_exit(code)
subroutine base_util_exit(code,unit)
!! author: David A. Minton
!!
!! Print termination message and exit program
Expand All @@ -596,25 +596,33 @@ subroutine base_util_exit(code)
implicit none
! Arguments
integer(I4B), intent(in) :: code
integer(I4B), intent(in), optional :: unit
! Internals
character(*), parameter :: BAR = '("------------------------------------------------")'
character(*), parameter :: SUCCESS_MSG = '(/, "Normal termination of Swiftest (version ", f3.1, ")")'
character(*), parameter :: FAIL_MSG = '(/, "Terminating Swiftest (version ", f3.1, ") due to error!!")'
character(*), parameter :: BAR = '("---------------------------------------------------")'
character(*), parameter :: SUCCESS_MSG = '(/, "Normal termination of Swiftest (version ", A, ")")'
character(*), parameter :: FAIL_MSG = '(/, "Terminating Swiftest (version ", A, ") due to error!!")'
character(*), parameter :: USAGE_MSG = '("Usage: swiftest <whm|helio|rmvs|symba> <paramfile> ' // &
'[{standard}|compact|progress]")'
character(*), parameter :: HELP_MSG = USAGE_MSG
integer(I4B) :: iu

if (present(unit)) then
iu = unit
else
iu = OUTPUT_UNIT
end if

select case(code)
case(SUCCESS)
write(*, SUCCESS_MSG) VERSION_NUMBER
write(*, BAR)
write(iu, SUCCESS_MSG) VERSION
write(iu, BAR)
case(USAGE)
write(*, USAGE_MSG)
write(iu, USAGE_MSG)
case(HELP)
write(*, HELP_MSG)
write(iu, HELP_MSG)
case default
write(*, FAIL_MSG) VERSION_NUMBER
write(*, BAR)
write(iu, FAIL_MSG) VERSION
write(iu, BAR)
error stop
end select

Expand Down
2 changes: 1 addition & 1 deletion src/collision/collision_generate.f90
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module subroutine collision_generate_bounce(self, nbody_system, param, t)
call self%merge(nbody_system, param, t) ! Use the default collision model, which is merge
case default
call swiftest_io_log_one_message(COLLISION_LOG_OUT,"Error in swiftest_collision, unrecognized collision regime")
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,unit=param%display_unit)
end select
end associate
end select
Expand Down
2 changes: 1 addition & 1 deletion src/collision/collision_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ module subroutine collision_io_netcdf_initialize_output(self, param)

667 continue
write(*,*) "Error creating fragmentation output file. " // trim(adjustl(errmsg))
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,unit=param%display_unit)
end subroutine collision_io_netcdf_initialize_output


Expand Down
2 changes: 1 addition & 1 deletion src/collision/collision_resolve.f90
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ module subroutine collision_resolve_plpl(self, nbody_system, param, t, dt, irec)
if (loop == MAXCASCADE) then
call swiftest_io_log_one_message(COLLISION_LOG_OUT,"A runaway collisional cascade has been detected in collision_resolve_plpl.")
call swiftest_io_log_one_message(COLLISION_LOG_OUT,"Consider reducing the step size or changing the parameters in the collisional model to reduce the number of fragments.")
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,unit=param%display_unit)
end if
end associate
end do
Expand Down
2 changes: 1 addition & 1 deletion src/encounter/encounter_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ module subroutine encounter_io_netcdf_initialize_output(self, param)

667 continue
write(*,*) "Error creating encounter output file. " // trim(adjustl(errmsg))
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,param%display_unit)
end subroutine encounter_io_netcdf_initialize_output


Expand Down
2 changes: 1 addition & 1 deletion src/fraggle/fraggle_generate.f90
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module subroutine fraggle_generate(self, nbody_system, param, t)
message = "Supercatastrophic disruption between"
case default
write(*,*) "Error in swiftest_collision, unrecognized collision regime"
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,param%display_unit)
end select
call collision_io_collider_message(pl, impactors%id, message)
call swiftest_io_log_one_message(COLLISION_LOG_OUT, trim(adjustl(message)))
Expand Down
2 changes: 1 addition & 1 deletion src/globals/globals_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module globals
integer(I4B), parameter :: UPPERCASE_OFFSET = iachar('A') - iachar('a') !! ASCII character set parameter for lower to upper
!! conversion - offset between upper and lower

real(SP), parameter :: VERSION_NUMBER = 1.0_SP !! Swiftest version
character(*), parameter :: VERSION = "2023.08.00" !! Swiftest version

!> Symbolic name for integrator types
character(*), parameter :: UNKNOWN_INTEGRATOR = "UKNOWN INTEGRATOR"
Expand Down
4 changes: 2 additions & 2 deletions src/rmvs/rmvs_step.f90
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ subroutine rmvs_interp_in(cb, pl, nbody_system, param, dt, outer_index)
vtmp(:,i), new_line('a'), &
" STOPPING "
call swiftest_io_log_one_message(COLLISION_LOG_OUT, message)
call base_util_exit(failure)
call base_util_exit(FAILURE,param%display_unit)
end if
end do
end if
Expand All @@ -317,7 +317,7 @@ subroutine rmvs_interp_in(cb, pl, nbody_system, param, dt, outer_index)
write(*, *) xtmp(:,i)
write(*, *) vtmp(:,i)
write(*, *) " STOPPING "
call base_util_exit(failure)
call base_util_exit(FAILURE,param%display_unit)
end if
end do
end if
Expand Down
2 changes: 1 addition & 1 deletion src/swiftest/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ program swiftest_driver
#ifdef COARRAY
if (this_image() == 1) then
#endif
call base_util_exit(SUCCESS)
call base_util_exit(SUCCESS,unit=param%display_unit)
#ifdef COARRAY
end if ! (this_image() == 1)
#endif
Expand Down
18 changes: 9 additions & 9 deletions src/swiftest/swiftest_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ module subroutine swiftest_io_conservation_report(self, param, lterminal)
if (abs(nbody_system%Mtot_error) > 100 * epsilon(nbody_system%Mtot_error)) then
write(*,*) "Severe error! Mass not conserved! Halting!"
! Save the frame of data to the bin file in the slot just after the present one for diagnostics
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,param%display_unit)
end if
end if
end associate
Expand Down Expand Up @@ -344,7 +344,7 @@ module subroutine swiftest_io_dump_param(self, param_file_name)

667 continue
write(*,*) "Error opening parameter dump file " // trim(adjustl(errmsg))
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,self%display_unit)
end subroutine swiftest_io_dump_param


Expand Down Expand Up @@ -896,7 +896,7 @@ module subroutine swiftest_io_netcdf_initialize_output(self, param)

667 continue
write(*,*) "Error creating NetCDF output file. " // trim(adjustl(errmsg))
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,param%display_unit)
end subroutine swiftest_io_netcdf_initialize_output


Expand Down Expand Up @@ -1161,7 +1161,7 @@ module function swiftest_io_netcdf_read_frame_system(self, nc, param) result(ier
write(*,*) "Error reading in NetCDF file: The recorded value of ntp does not match the number of active test particles"
write(*,*) "Recorded: ",ntp
write(*,*) "Active : ",ntp_check
call base_util_exit(failure)
call base_util_exit(FAILURE,param%display_unit)
end if

! Now read in each variable and split the outputs by body type
Expand Down Expand Up @@ -2879,7 +2879,7 @@ module subroutine swiftest_io_read_in_cb(self, param)

667 continue
write(*,*) "Error reading central body file: " // trim(adjustl(errmsg))
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,param%display_unit)
end subroutine swiftest_io_read_in_cb


Expand Down Expand Up @@ -2922,7 +2922,7 @@ module subroutine swiftest_io_read_in_system(self, nc, param)
end if
ierr = self%read_frame(nc, tmp_param)
deallocate(tmp_param)
if (ierr /=0) call base_util_exit(FAILURE)
if (ierr /=0) call base_util_exit(FAILURE,param%display_unit)
end if

param%loblatecb = ((abs(self%cb%j2rp2) > 0.0_DP) .or. (abs(self%cb%j4rp4) > 0.0_DP))
Expand Down Expand Up @@ -3044,7 +3044,7 @@ module function swiftest_io_read_frame_body(self, iu, param) result(ierr)
class default
write(*,*) "Error reading body file: " // trim(adjustl(errmsg))
end select
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,param%display_unit)
end function swiftest_io_read_frame_body


Expand Down Expand Up @@ -3122,7 +3122,7 @@ module subroutine swiftest_io_set_display_param(self, display_style)

667 continue
write(*,*) "Error opening swiftest log file: " // trim(adjustl(errmsg))
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,self%display_unit)
end subroutine swiftest_io_set_display_param


Expand Down Expand Up @@ -3203,7 +3203,7 @@ module subroutine swiftest_io_initialize_output_file_system(self, nc, param)

667 continue
write(*,*) "Error writing nbody_system frame: " // trim(adjustl(errmsg))
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,param%display_unit)
end subroutine swiftest_io_initialize_output_file_system

end submodule s_swiftest_io
4 changes: 2 additions & 2 deletions src/swiftest/swiftest_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2367,7 +2367,7 @@ module subroutine swiftest_util_setup_construct_system(nbody_system, param)
write(*,*) 'RINGMOONS-SyMBA integrator not yet enabled'
case default
write(*,*) 'Unkown integrator',param%integrator
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,param%display_unit)
end select

allocate(swiftest_particle_info :: nbody_system%cb%info)
Expand Down Expand Up @@ -3329,7 +3329,7 @@ module subroutine swiftest_util_version()
!!
!! Adapted from David E. Kaufmann's Swifter routine: util_version.f90
implicit none
write(*, 200) VERSION_NUMBER
write(*, 200) VERSION
200 format(/, "************* Swiftest: Version ", f3.1, " *************", //, &
"Based off of Swifter:", //, &
"Authors:", //, &
Expand Down
2 changes: 1 addition & 1 deletion src/symba/symba_step.f90
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ recursive module subroutine symba_step_recur_system(self, param, t, ireci)
write(*, *) "SWIFTEST Warning:"
write(*, *) " In symba_step_recur_system, local time step is too small"
write(*, *) " Roundoff error will be important!"
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,param%display_unit)
END IF
irecp = ireci + 1
if (ireci == 0) then
Expand Down
2 changes: 1 addition & 1 deletion src/whm/whm_drift.f90
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module subroutine whm_drift_pl(self, nbody_system, param, dt)
call swiftest_io_log_one_message(COLLISION_LOG_OUT, message)
end if
end do
call base_util_exit(FAILURE)
call base_util_exit(FAILURE,param%display_unit)
end if
end associate

Expand Down
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023.08.00

0 comments on commit c3ea9f2

Please sign in to comment.