From be976a38f1d95258f19d94f4cf5dc4c677041ed9 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Mon, 29 Mar 2021 16:38:00 -0400 Subject: Changed how temp files work on UNIX-y stuff. Fixed templates, which were quite broken. --- common/utilities.F90 | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'common') 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) -- cgit v1.2.3