check_dir_exist Function

public 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

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: path

Directory path

Return Value logical


Called by

proc~~check_dir_exist~~CalledByGraph proc~check_dir_exist check_dir_exist proc~uemep_read_config uEMEP_read_config proc~uemep_read_config->proc~check_dir_exist proc~uemep_save_emission_netcdf uEMEP_save_emission_netcdf proc~uemep_save_emission_netcdf->proc~check_dir_exist proc~uemep_calculate_emissions_for_emep uEMEP_calculate_emissions_for_EMEP proc~uemep_calculate_emissions_for_emep->proc~uemep_save_emission_netcdf program~uemep uEMEP program~uemep->proc~uemep_read_config program~uemep->proc~uemep_calculate_emissions_for_emep

Source Code

    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