diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/utilities.F90 | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/common/utilities.F90 b/common/utilities.F90 index e8bceff..4c0c13f 100644 --- a/common/utilities.F90 +++ b/common/utilities.F90 @@ -35,8 +35,32 @@ module utilities module procedure replace_field_int end interface + character(len=:), pointer::temporary_directory + contains + subroutine set_temporary_directory(d) +#ifdef WINDOWS + use iso_c_binding, only: c_null_char +#endif + implicit none + + character(*), intent(in)::d + + if(len_trim(d) > 0) then + +#ifdef WINDOWS + allocate(character(len=(len_trim(d)+1)) :: temporary_directory) + temporary_directory = d//c_null_char +#else + allocate(character(len=(len_trim(d))) :: temporary_directory) + temporary_directory = d +#endif + + end if + + end subroutine set_temporary_directory + function is_absolute_path(path) implicit none @@ -200,12 +224,18 @@ contains integer::res tmp_path = c_malloc(int(1024, kind=c_size_t)) - res = GetTempPath(1023, tmp_path) + if(.not. associated(temporary_directory)) then + res = GetTempPath(1023, tmp_path) + else + tmp_path = c_loc(temporary_directory) + end if tmp_name = c_malloc(int(1024, kind=c_size_t)) res = GetTempFileName(tmp_path, c_null_ptr, 0, tmp_name) - call c_free(tmp_path) + if(.not.associated(temporary_directory)) then + call c_free(tmp_path) + end if ! Convert the C Ptr to a Fortran object clength = c_strlen(tmp_name) @@ -229,7 +259,15 @@ contains call random_number(rnum) write(num_text, *) abs(rnum) - fullpath = "/tmp/lv."//trim(adjustl(num_text))//".tmp" + if(associated(temporary_directory)) then + if(temporary_directory(len(temporary_directory):len(temporary_directory)) == "/") then + fullpath = temporary_directory//"lv."//trim(adjustl(num_text))//".tmp" + else + fullpath = temporary_directory//"/lv."//trim(adjustl(num_text))//".tmp" + end if + else + fullpath = "/tmp/lv."//trim(adjustl(num_text))//".tmp" + end if !call write_log("My temp filename is: '"//trim(fullpath)//"'") #endif @@ -501,7 +539,7 @@ contains close(unum) end if - call delete_file(tempfilename) + call unlink(tempfilename) deallocate(tempfilename) end subroutine get_one_line_output_shell_command |