From e4eb7e97fec0ba9b0c5281b6f9819c617f4f5fdf Mon Sep 17 00:00:00 2001
From: sgeard <sgeard@users.noreply.github.com>
Date: Sat, 10 Jun 2023 12:02:37 +0100
Subject: [PATCH] Added size to amap and minor changes

---
 src/amap.f90         | 16 ++++++++++++++++
 src/rpn_stack_sm.f90 | 14 +++++++++-----
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/src/amap.f90 b/src/amap.f90
index d9e47ca..b83b291 100644
--- a/src/amap.f90
+++ b/src/amap.f90
@@ -24,6 +24,8 @@ module amap
         generic, public    :: write(formatted) => write_value_t
         procedure, private :: set_to_value_t
         generic, public    :: assignment(=) => set_to_value_t
+        procedure, private :: equals_value_t
+        generic, public    :: operator(==) => equals_value_t
     end type value_t
     
     ! Map elements are (key,value) pairs
@@ -45,6 +47,7 @@ module amap
         procedure, public  :: find => find_amap_t
         procedure, public  :: print => print_amap_t
         procedure, public  :: clear => clear_amap_t
+        procedure, public  :: size => size_amap_t
         procedure, private :: is_key_kt
         procedure, private :: is_key_kvt
         generic, public    :: contains => is_key_kt, is_key_kvt
@@ -52,6 +55,12 @@ module amap
 
 contains
 
+    function size_amap_t(this) result(r)
+        class(amap_t), intent(in) :: this
+        integer :: r
+        r = this%high_water
+    end function size_amap_t
+    
     subroutine clear_amap_t(this)
         class(amap_t), intent(inout)  :: this
         if (allocated(this%pairs)) then
@@ -169,6 +178,13 @@ contains
         r = trim(adjustl(this%k)) == trim(adjustl(k%k))
     end function equals_key_t
     
+    function equals_value_t(this, v) result(r)
+        class(value_t), intent(in) :: this
+        real(8), intent(in) :: v
+        logical :: r
+        r = this%v == v
+    end function equals_value_t
+    
     subroutine write_key_t(key, unit, iotype, v_list, iostat, iomsg)
         class(key_t), intent(in)    :: key
         integer, intent(in)         :: unit
diff --git a/src/rpn_stack_sm.f90 b/src/rpn_stack_sm.f90
index 20772d5..7b9a4d4 100644
--- a/src/rpn_stack_sm.f90
+++ b/src/rpn_stack_sm.f90
@@ -1,5 +1,6 @@
 ! Implementation code for stack
 submodule (rpn_stack) stack_sm
+    use iso_fortran_env, only: output_unit
     implicit none
 
 contains
@@ -22,8 +23,8 @@ contains
         integer :: i, j
         if (ve_mode) then
             do i=stk%high_water,1,-1
-                write(6,fmt='(a)',advance='no') stk%legend(i)//' '
-                write(6,'(dt)') stk%sdata(i)
+                write(output_unit,fmt='(a)',advance='no') stk%legend(i)//' '
+                write(output_unit,'(dt)') stk%sdata(i)
             end do
         else
             write(6,fmt='(dt)') stk%sdata(1)
@@ -141,6 +142,9 @@ end submodule stack_sm
 
 ! Implementation code for rpn_t
 submodule (rpn_stack) rpn_sm
+    use iso_fortran_env, only: output_unit
+    implicit none
+
 contains
 
     module subroutine write_rpns(se, unit, iotype, v_list, iostat, iomsg)
@@ -159,13 +163,13 @@ contains
             call to_string(z%re,str_re)
             call to_string(z%im,str_im)
             if (se%is_cartesian()) then
-                write(6,'(a)') '('//str_re//','//str_im//')'
+                write(output_unit,'(a)') '('//str_re//','//str_im//')'
             else
-                write(6,'(a)') '('//str_re//','//str_im//') p'
+                write(output_unit,'(a)') '('//str_re//','//str_im//') p'
             end if
         else
             call to_string(z%re,str_re)
-            write(6,'(a)') str_re
+            write(output_unit,'(a)') str_re
         end if
 
     end subroutine write_rpns