Added size to amap and minor changes

This commit is contained in:
sgeard 2023-06-10 12:02:37 +01:00 committed by GitHub
parent 00a0721f04
commit e4eb7e97fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View file

@ -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

View file

@ -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