aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/utilities.F9032
1 files changed, 17 insertions, 15 deletions
diff --git a/common/utilities.F90 b/common/utilities.F90
index 2e19031..3ce3363 100644
--- a/common/utilities.F90
+++ b/common/utilities.F90
@@ -122,6 +122,7 @@ contains
function generate_temporary_filename() result(fullpath)
use iso_c_binding
+ use logging
implicit none
character(len=:), pointer::fullpath
@@ -177,24 +178,13 @@ contains
res = GetTempFileName(tmp_path, c_null_ptr, 0, tmp_name)
call c_free(tmp_path)
-#else
- interface
- function tmpnam(p) bind(c, name='tmpnam')
- use iso_c_binding
- type(c_ptr), value::p
- type(c_ptr)::tmpnam
- end function tmpnam
- end interface
- type(c_ptr)::ignored
-
- tmp_name = c_malloc(int(1024, kind=c_size_t))
-
- ignored = tmpnam(tmp_name)
-#endif
-
! Convert the C Ptr to a Fortran object
clength = c_strlen(tmp_name)
+ if(clength == 0) then
+ call write_log("temp name is zero length")
+ stop
+ end if
call c_f_pointer(tmp_name, cfullpath, (/ clength /))
allocate(character(len=clength)::fullpath)
do i = 1, clength
@@ -204,6 +194,18 @@ contains
cfullpath => null()
call c_free(tmp_name)
+#else
+ character(32)::num_text
+ real::rnum
+
+ allocate(character(len=1024) :: fullpath)
+
+ call random_number(rnum)
+ write(num_text, *) abs(rnum)
+ fullpath = "/tmp/lv."//trim(adjustl(num_text))//".tmp"
+
+#endif
+
end function generate_temporary_filename
subroutine delete_file(filename)