From c3ea9f219dd08b30ddd89b6ea76c3ca1f576ff41 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Wed, 2 Aug 2023 17:32:37 -0400 Subject: [PATCH] Improved the version control of version number. Added function to CMakeLists.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 --- .gitignore | 1 + CMakeLists.txt | 41 ++++++++++++++++++++++++---- python/swiftest/setup.py | 4 +-- src/base/base_module.f90 | 28 ++++++++++++------- src/collision/collision_generate.f90 | 2 +- src/collision/collision_io.f90 | 2 +- src/collision/collision_resolve.f90 | 2 +- src/encounter/encounter_io.f90 | 2 +- src/fraggle/fraggle_generate.f90 | 2 +- src/globals/globals_module.f90 | 2 +- src/rmvs/rmvs_step.f90 | 4 +-- src/swiftest/swiftest_driver.f90 | 2 +- src/swiftest/swiftest_io.f90 | 18 ++++++------ src/swiftest/swiftest_util.f90 | 4 +-- src/symba/symba_step.f90 | 2 +- src/whm/whm_drift.f90 | 2 +- version.txt | 1 + 17 files changed, 80 insertions(+), 39 deletions(-) create mode 100644 version.txt diff --git a/.gitignore b/.gitignore index 5c64de306..34cf5f6c2 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ dump* *ipynb_checkpoints **/.DS_Store !python/swiftest/tests/test_suite.py +!version.txt #Documentation !docs/* diff --git a/CMakeLists.txt b/CMakeLists.txt index b165d0d7d..558c93fab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}) diff --git a/python/swiftest/setup.py b/python/swiftest/setup.py index 917ad64e4..3a3c2a674 100644 --- a/python/swiftest/setup.py +++ b/python/swiftest/setup.py @@ -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()) \ No newline at end of file + packages=find_packages()) diff --git a/src/base/base_module.f90 b/src/base/base_module.f90 index 51266238f..f47bb9f7a 100644 --- a/src/base/base_module.f90 +++ b/src/base/base_module.f90 @@ -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 @@ -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 ' // & '[{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 diff --git a/src/collision/collision_generate.f90 b/src/collision/collision_generate.f90 index 7f529ba02..fc3b7ed99 100644 --- a/src/collision/collision_generate.f90 +++ b/src/collision/collision_generate.f90 @@ -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 diff --git a/src/collision/collision_io.f90 b/src/collision/collision_io.f90 index cb4a544a0..c1b5015de 100644 --- a/src/collision/collision_io.f90 +++ b/src/collision/collision_io.f90 @@ -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 diff --git a/src/collision/collision_resolve.f90 b/src/collision/collision_resolve.f90 index 0166711ab..72e6ad445 100644 --- a/src/collision/collision_resolve.f90 +++ b/src/collision/collision_resolve.f90 @@ -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 diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index fb5de048f..171191b39 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -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 diff --git a/src/fraggle/fraggle_generate.f90 b/src/fraggle/fraggle_generate.f90 index cd1df7033..aeeae27d9 100644 --- a/src/fraggle/fraggle_generate.f90 +++ b/src/fraggle/fraggle_generate.f90 @@ -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))) diff --git a/src/globals/globals_module.f90 b/src/globals/globals_module.f90 index dd58d6dae..a708b080d 100644 --- a/src/globals/globals_module.f90 +++ b/src/globals/globals_module.f90 @@ -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" diff --git a/src/rmvs/rmvs_step.f90 b/src/rmvs/rmvs_step.f90 index 4a5dcf3af..098622037 100644 --- a/src/rmvs/rmvs_step.f90 +++ b/src/rmvs/rmvs_step.f90 @@ -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 @@ -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 diff --git a/src/swiftest/swiftest_driver.f90 b/src/swiftest/swiftest_driver.f90 index 6cec24feb..3aea4aab7 100644 --- a/src/swiftest/swiftest_driver.f90 +++ b/src/swiftest/swiftest_driver.f90 @@ -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 diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 70ddac5f7..64731a7eb 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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)) @@ -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 @@ -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 @@ -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 diff --git a/src/swiftest/swiftest_util.f90 b/src/swiftest/swiftest_util.f90 index 19a0e6e98..c390be826 100644 --- a/src/swiftest/swiftest_util.f90 +++ b/src/swiftest/swiftest_util.f90 @@ -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) @@ -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:", //, & diff --git a/src/symba/symba_step.f90 b/src/symba/symba_step.f90 index 22cdddeb6..9da52440a 100644 --- a/src/symba/symba_step.f90 +++ b/src/symba/symba_step.f90 @@ -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 diff --git a/src/whm/whm_drift.f90 b/src/whm/whm_drift.f90 index 1161919f2..fa0dcdd8f 100644 --- a/src/whm/whm_drift.f90 +++ b/src/whm/whm_drift.f90 @@ -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 diff --git a/version.txt b/version.txt new file mode 100644 index 000000000..f2bfdb11a --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +2023.08.00 \ No newline at end of file