diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c90c04..1823b75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,12 +76,12 @@ elseif (Fortran_COMPILER_NAME MATCHES "ifort.*") set (CMAKE_Fortran_FLAGS_RELEASE "-f77rtl -O3") set (CMAKE_Fortran_FLAGS_DEBUG "-f77rtl -O0 -g") else (Fortran_COMPILER_NAME MATCHES "gfortran.*") - message ("CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER}) - message ("Fortran compiler: " ${Fortran_COMPILER_NAME}) message ("No optimized Fortran compiler flags are known, we just try -O2...") set (CMAKE_Fortran_FLAGS_RELEASE "-O2 -Wl,--allow-multiple-definition") set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -Wall -Wl,--allow-multiple-definition") endif () +message(STATUS "CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER}) +message(STATUS "Fortran compiler: " ${Fortran_COMPILER_NAME}) # Locate Dependencies find_package(ferror 1.3.0) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ff70c8e..3ebed62 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,12 +8,15 @@ set(fcore_sources fcore_constants.f90 collections.f90 collections_list.f90 + file_io.f90 + file_io_fm.f90 ) # Build the library add_library(fcore ${fcore_sources}) target_link_libraries(fcore ${ferror_LIBRARIES} + # ${linalg_LIBRARIES} ) # ------------------------------------------------------------------------------ diff --git a/src/file_io.f90 b/src/file_io.f90 new file mode 100644 index 0000000..bd7400c --- /dev/null +++ b/src/file_io.f90 @@ -0,0 +1,36 @@ +! file_io.f90 + +!> @brief This module contains routines to support file I/O operations. +module file_io + use iso_fortran_env + use ferror + implicit none + private + public :: file_manager + +! ****************************************************************************** +! TYPES +! ------------------------------------------------------------------------------ + !> @brief Defines a base type for managint file I/O. + type file_manager + private + !> @brief The unit value. + integer(int32) :: m_unit = -1 + !> @brief Delete file upon closing? + logical :: m_deleteOnClose = .false. + contains + procedure, public :: get_unit => fm_get_unit + end type + +! ****************************************************************************** +! INTERFACES +! ------------------------------------------------------------------------------ + interface + module function fm_get_unit(this) result(rst) + class(file_manager), intent(inout) :: this + integer(int32) :: rst + end function + end interface + +! ------------------------------------------------------------------------------ +end module diff --git a/src/file_io_fm.f90 b/src/file_io_fm.f90 new file mode 100644 index 0000000..fed5461 --- /dev/null +++ b/src/file_io_fm.f90 @@ -0,0 +1,48 @@ +! file_io_fm.f90 + +submodule (file_io) file_io_tfm +contains +! ------------------------------------------------------------------------------ + !> @brief Returns the unit value. + !! + !! @param[in,out] this The file_manager object. + !! + !! @return The Fortran unit value for this stream. + module function fm_get_unit(this) result(rst) + ! Arguments + class(file_manager), intent(inout) :: this + integer(int32) :: rst + + ! Parameters + integer(int32), parameter :: min_unit = 10 + integer(int32), parameter :: max_unit = 1000 + + ! Local Variables + logical :: opened + integer(int32) :: i + + ! Process + if (this%m_unit == -1) then + do i = min_unit, max_unit + inquire(unit = i, opened = opened) + if (.not.opened) then + this%m_unit = i + exit + end if + end do + end if + rst = this%m_unit + end function + +! ------------------------------------------------------------------------------ + +! ------------------------------------------------------------------------------ + +! ------------------------------------------------------------------------------ + +! ------------------------------------------------------------------------------ + +! ------------------------------------------------------------------------------ + +! ------------------------------------------------------------------------------ +end submodule