Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Jun 17, 2024
2 parents ca90ef2 + c20e5f3 commit 300b882
Show file tree
Hide file tree
Showing 8 changed files with 502 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
!src/
!src/*/
!*.f90
!src/globals/module_globals.f90.in
!.gitignore
!CMakeLists.txt
!distclean.cmake
Expand Down
69 changes: 58 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
# This file is part of Swiftest.
# Copyright 2024 - The Minton Group at Purdue University
# This file is part of CTEM
# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
Expand All @@ -17,6 +17,34 @@ SET(SKBUILD_PROJECT_NAME "ctem" CACHE STRING "Name of project set by scikit-buil
# Get version stored in text file
FILE(READ "version.txt" VERSION)
PROJECT(${SKBUILD_PROJECT_NAME} LANGUAGES C Fortran VERSION ${VERSION})
SET(SKBUILD_SCRIPTS_DIR "${CMAKE_SOURCE_DIR}/bin" CACHE STRING "Install location of binary executable")

IF (SKBUILD)
set(ENV_PREFIX "$ENV{PREFIX}")
string(REPLACE "<ENV_PREFIX>" "${ENV_PREFIX}" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
ENDIF ()

IF(DEFINED ENV{CIBUILDWHEEL})
SET(CIBUILDWHEEL ON)
ENDIF()

# Check for a Fortran compiler
IF(DEFINED ENV{FC})
SET(CMAKE_Fortran_COMPILER $ENV{FC} CACHE STRING "Fortran compiler")
ELSE()
# If FC is not set, search for the Fortran compilers in the specified order.
FIND_PROGRAM(Fortran_COMPILER
NAMES gfortran-14 gfortran-13 gfortran-12 gfortran ifort mpiifort
DOC "Fortran compiler")

# If a compiler is found, set it as the Fortran compiler.
IF(Fortran_COMPILER)
SET(CMAKE_Fortran_COMPILER ${Fortran_COMPILER} CACHE STRING "Fortran compiler")
ELSE()
MESSAGE(FATAL_ERROR "No suitable Fortran compiler was found.")
ENDIF()
ENDIF()
MESSAGE(STATUS "Using Fortran compiler: ${CMAKE_Fortran_COMPILER}")

IF (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
SET(COMPILER_OPTIONS "Intel" CACHE STRING "Compiler identified as Intel")
Expand Down Expand Up @@ -49,22 +77,28 @@ FILE(TO_CMAKE_PATH ${PY} PY)

INCLUDE(GNUInstallDirs)
IF (SKBUILD)
SET(INSTALL_BINDIR ${SKBUILD_SCRIPTS_DIR})
SET(INSTALL_LIBDIR ${SKBUILD_DATA_DIR}/lib)
SET(INSTALL_INCLUDEDIR ${SKBUILD_HEADERS_DIR})
SET(INSTALL_PYPROJ ${SKBUILD_PLATLIB_DIR}/${SKBUILD_PROJECT_NAME})
IF (APPLE)
SET(CMAKE_INSTALL_RPATH "@loader_path;${CMAKE_BINARY_DIR}/bin")
ELSEIF (LINUX)
SET(CMAKE_INSTALL_RPATH "@ORIGIN;${CMAKE_BINARY_DIR}/bin")
ENDIF ()
SET(INSTALL_BINDIR ${INSTALL_PYPROJ})
IF (CIBUILDWHEEL)
SET(INSTALL_LIBDIR ${CMAKE_BINARY_DIR}/lib)
SET(CMAKE_INSTALL_RPATH "${CMAKE_BINARY_DIR}/bin")
ELSE()
SET(INSTALL_LIBDIR ${INSTALL_BINDIR})
SET(CMAKE_INSTALL_RPATH "${INSTALL_LIBDIR}")
ENDIF()
SET(INSTALL_INCLUDEDIR ${SKBUILD_HEADERS_DIR})
ELSE ()
SET(INSTALL_PYPROJ ${PY})
SET(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
SET(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
SET(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
ENDIF ()

MESSAGE(STATUS "INSTALL_BINDIR: ${INSTALL_BINDIR}")
MESSAGE(STATUS "INSTALL_LIBDIR: ${INSTALL_LIBDIR}")
MESSAGE(STATUS "INSTALL_INCLUDEDIR: ${INSTALL_INCLUDEDIR}")
MESSAGE(STATUS "INSTALL_PYPROJ: ${INSTALL_PYPROJ}")
MESSAGE(STATUS "CMAKE_INSTALL_RPATH: ${CMAKE_INSTALL_RPATH}")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Have the .mod files placed in the lib folder
Expand All @@ -74,8 +108,21 @@ SET(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
FILE(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" LOCAL_MODULE_PATH)
LIST(APPEND CMAKE_MODULE_PATH ${LOCAL_MODULE_PATH})

MESSAGE(STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
#####################################
# Tell how to install this executable
#####################################
IF(CMAKE_SYSTEM_NAME STREQUAL "Windows")
SET(CMAKE_INSTALL_PREFIX "C:\\Program Files\\swiftest")
FILE(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX} CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Path for install")
ELSE()
SET(CMAKE_INSTALL_PREFIX /usr/local CACHE PATH "Path for install")
ENDIF()


# Set the name of the ctem library
SET(CTEM_LIBRARY ctem)
SET(CTEM_LIBRARY ${SKBUILD_PROJECT_NAME})

# The source for the CTEM binary and have it placed in the bin folder
ADD_SUBDIRECTORY(${SRC} ${BIN})
Expand Down
44 changes: 44 additions & 0 deletions ctem/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import pty
import subprocess
import sys


def main(binary_name="CTEM"):
"""Executes the binary located in the package root, passing along any command-line arguments, and streams the output to the terminal in real-time, handling progress bars correctly by using a pseudo-terminal."""

# Determine the path to the binary relative to this script
package_root = os.path.dirname(os.path.abspath(__file__))
binary_path = os.path.join(package_root, binary_name)

# sys.argv[1:] contains all the arguments passed to the script, excluding the script name itself
args = [binary_path] + sys.argv[1:]

# Use pty to spawn the process and create a pseudo-terminal
main_fd, subordinate_fd = pty.openpty()

# Spawn the subprocess
proc = subprocess.Popen(args, stdin=subordinate_fd, stdout=subordinate_fd, stderr=subordinate_fd, close_fds=True)

# Close the subordinate file descriptor in the parent process
os.close(subordinate_fd)

# Read the output from the main file descriptor
while True:
try:
output = os.read(main_fd, 1024).decode()
if output:
sys.stdout.write(output)
sys.stdout.flush()
else:
break
except OSError:
break

# Wait for the subprocess to finish
proc.wait()

return

if __name__ == "__main__":
main()
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ctem"
version = "2024.2.0"
version = "2024.6.0"
authors=[
{name = 'David A. Minton', email='daminton@purdue.edu'},
{name = 'James E. Richardson'},
Expand Down Expand Up @@ -28,12 +28,16 @@ dependencies = [
'scipy>=1.10.1',
'matplotlib>=3.7',
'cython>=3.0.0',
'mkdocs>=1.5.3'
'mkdocs>=1.5.3',
'pandas>=2.2'
]

[project.urls]
Repository = 'https://github.itap.purdue.edu/MintonGroup/ctem'

[project.scripts]
CTEM = "ctem.cli:main"

[build-system]
requires = [
"scikit-build-core",
Expand Down
10 changes: 5 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
# This file is part of Swiftest.
# Copyright 2024 - The Minton Group at Purdue University
# This file is part of CTEM
# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
Expand All @@ -8,9 +8,9 @@
# If not, see: https://www.gnu.org/licenses.

# Communicate version number and other CMake build variables to the source code
#set(GLOBAL_MODULE_IN ${SRC}/globals/globals_module.f90.in)
#set(GLOBAL_MODULE_OUT ${SRC}/globals/globals_module.f90)
#CONFIGURE_FILE(${GLOBAL_MODULE_IN} ${GLOBAL_MODULE_OUT})
set(GLOBAL_MODULE_IN ${SRC}/globals/module_globals.f90.in)
set(GLOBAL_MODULE_OUT ${SRC}/globals/module_globals.f90)
CONFIGURE_FILE(${GLOBAL_MODULE_IN} ${GLOBAL_MODULE_OUT})

IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
MESSAGE(FATAL_ERROR "Fortran compiler does not support F90")
Expand Down
2 changes: 1 addition & 1 deletion src/globals/module_globals.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module module_globals
implicit none
public

character(len=*),parameter :: CTEMVER = "1.5 DEVELOPMENT"
character(len=*),parameter :: CTEMVER = "2024.6.0"

! Symbolic names for kind types of 4-, 2-, and 1-byte integers:
integer, parameter :: I8B = selected_int_kind(17)
Expand Down
Loading

0 comments on commit 300b882

Please sign in to comment.