function get_system_temp_dir() result(temp_dir) character(len=:), allocatable :: temp_dir ! Use runtime OS detection instead of compile-time if (get_os_type() == OS_WINDOWS) then ! Windows system - try environment variables block character(len=256) :: temp_env integer :: env_status ! Try Windows environment variables first call get_environment_variable('TEMP', temp_env, status=env_status) if (env_status == 0 .and. len_trim(temp_env) > 0) then temp_dir = trim(temp_env) else call get_environment_variable('TMP', temp_env, status=env_status) if (env_status == 0 .and. len_trim(temp_env) > 0) then temp_dir = trim(temp_env) else ! Fallback to Windows default temp_dir = 'C:\Windows\Temp' end if end if end block else ! Unix/Linux system temp_dir = '/tmp' end if end function get_system_temp_dir