Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Add I/O module
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristopherson committed Jul 6, 2020
1 parent 5e4d4da commit c9cbd63
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

# ------------------------------------------------------------------------------
Expand Down
36 changes: 36 additions & 0 deletions src/file_io.f90
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions src/file_io_fm.f90
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c9cbd63

Please sign in to comment.