From cdb7d7d379928a2659e56b2a722e5e7fc608b2e0 Mon Sep 17 00:00:00 2001
From: Jacob Williams <jacobwilliams@users.noreply.github.com>
Date: Fri, 16 Aug 2024 21:53:42 -0500
Subject: [PATCH 1/2] always enclose filename in quotes in execute function if
 it isn't already

also added an extra error check if the filename is blank
---
 src/pyplot_module.F90 | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/pyplot_module.F90 b/src/pyplot_module.F90
index fa5a767..68d05a7 100644
--- a/src/pyplot_module.F90
+++ b/src/pyplot_module.F90
@@ -1397,6 +1397,12 @@ subroutine execute(me, pyfile, istat, python)
             file = trim(pyfile)    !use the user-specified name
         end if
 
+        if (file == '') then
+            if (present(istat)) istat = -1
+            write(error_unit,'(A)') 'Error: filename is blank.'
+            return
+        end if
+
         !open the file:
         open(newunit=iunit, file=file, status='REPLACE', iostat=iostat)
         if (iostat/=0) then
@@ -1423,8 +1429,8 @@ subroutine execute(me, pyfile, istat, python)
             end if
 
             !run the file using python:
-            if (index(file,' ')>0) then
-                ! space in path, probably should enclose in quotes
+            if (file(1:1)/='"') then
+                ! if not already in quotes, should enclose in quotes
                 call execute_command_line(python_//' "'//file//'"')
             else
                 call execute_command_line(python_//' '//file)

From da34d279402ed3b7ef1ed22fb2b168c0e75e4212 Mon Sep 17 00:00:00 2001
From: Jacob Williams <jacobwilliams@users.noreply.github.com>
Date: Sat, 17 Aug 2024 08:54:19 -0500
Subject: [PATCH 2/2] test update

---
 test/test.f90 | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/test/test.f90 b/test/test.f90
index 7f48b1d..1898554 100644
--- a/test/test.f90
+++ b/test/test.f90
@@ -201,5 +201,11 @@ program test
                      dpi='200', &
                      transparent=.true.,istat=istat, python='python')
 
+    ! also test one with spaces and () in the filename
+    call plt%savefig(testdir//'error bar (1).png', &
+                     pyfile=testdir//'error bar (1).py', &
+                     dpi='200', &
+                     transparent=.true.,istat=istat, python='python')
+
     end program test
 !*****************************************************************************************