io_functions.f90 Source File


This file depends on

sourcefile~~io_functions.f90~~EfferentGraph sourcefile~io_functions.f90 io_functions.f90 sourcefile~uemep_definitions.f90 uEMEP_definitions.f90 sourcefile~io_functions.f90->sourcefile~uemep_definitions.f90

Files dependent on this one

sourcefile~~io_functions.f90~~AfferentGraph sourcefile~io_functions.f90 io_functions.f90 sourcefile~uemep_read_config.f90 uEMEP_read_config.f90 sourcefile~uemep_read_config.f90->sourcefile~io_functions.f90 sourcefile~uemep_save_emission_netcdf.f90 uEMEP_save_emission_netcdf.f90 sourcefile~uemep_save_emission_netcdf.f90->sourcefile~io_functions.f90 sourcefile~uemep_read_meteo_nc.f90 uEMEP_read_meteo_nc.f90 sourcefile~uemep_save_emission_netcdf.f90->sourcefile~uemep_read_meteo_nc.f90 sourcefile~uemep_main.f90 uEMEP_main.f90 sourcefile~uemep_main.f90->sourcefile~uemep_read_config.f90 sourcefile~uemep_main.f90->sourcefile~uemep_save_emission_netcdf.f90 sourcefile~uemep_main.f90->sourcefile~uemep_read_meteo_nc.f90 sourcefile~uemep_read_meteo_nc.f90->sourcefile~uemep_read_config.f90

Source Code

module io_functions
    !! This module contains procedures that support IO operations

    use uEMEP_definitions, only: unit_logfile

    implicit none
    private

    public :: check_dir_exist

contains

    function check_dir_exist(path) result(exists)
        !! Checks if a directory exists and/or if we have write permission
        !! in that directory.
        !!
        !! Returns .true. if directory exists and is accessible
        character(len=*), intent(in) :: path !! Directory path
        logical:: exists 

        ! Local variables
        integer :: u, ios, len_trimmed

        ! Get length of directory path
        len_trimmed = len_trim(path)

        ! Attempt to open a temporary file in the specified directory
        if (path(len_trimmed:len_trimmed) == "/") then
            open(newunit=u, file=trim(path)//"tmp", status="new", iostat=ios)
        else
            open(newunit=u, file=trim(path)//"/tmp", status="new", iostat=ios)
        end if
        if (ios /= 0) then
            exists = .false.
        else
            ! If succesfull, delete the temporary file
            close(unit=u, status="delete")
            exists = .true.
        end if
    end function check_dir_exist

end module io_functions