Skip to content

Commit 8793741

Browse files
author
Damian Rouson
committed
feat(assert): add "object" class type guard
This facilitates the output of diagnostic data.
1 parent 1e36371 commit 8793741

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

src/assertions_implementation.F90

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
module procedure assert
1313
use iso_fortran_env, only : error_unit
1414
use string_functions_interface, only : string
15+
use object_interface, only : object
1516

1617
character(len=:), allocatable :: header, trailer
1718
integer, parameter :: max_this_image_digits=9
@@ -32,21 +33,25 @@
3233
else
3334

3435
block
35-
character(len=*), parameter :: lede = "with diagnostic data"
36+
character(len=*), parameter :: prefix = "with diagnostic data"
37+
integer, parameter :: max_data_length = 1024
3638

3739
select type(diagnostic_data)
3840
type is(character(len=*))
39-
trailer = lede // diagnostic_data
41+
trailer = prefix // diagnostic_data
4042
type is(integer)
41-
trailer = lede // string(diagnostic_data)
43+
trailer = prefix // string(diagnostic_data)
44+
class is(object)
45+
trailer = repeat(" ", ncopies = max_data_length)
46+
write(trailer,*) diagnostic_data
4247
class default
43-
trailer = lede // 'of unsupported type'
48+
trailer = prefix // 'of unsupported type'
4449
end select
4550
end block
4651

4752
end if
4853

49-
error stop header // trailer
54+
error stop header // trim(trailer)
5055

5156
end if
5257

src/object_interface.f90

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
!! author: Damian Rouson, GSE LLC
2-
!! category: Morfeus-FD
3-
!! summary: Abstract base type, `object`
4-
!!
5-
!! ### Copyright notice
6-
!!
7-
!! ```
8-
!! (c) 2019-2020 Guide Star Engineering, LLC
9-
!! This Software was developed for the US Nuclear Regulatory Commission (US NRC) under contract
10-
!! "Multi-Dimensional Physics Implementation into Fuel Analysis under Steady-state and Transients (FAST)",
11-
!! contract # NRC-HQ-60-17-C-0007
12-
!! ```
13-
1+
! ### Copyright notice
2+
!
3+
! ```
4+
! (c) 2019-2020 Guide Star Engineering, LLC
5+
! This Software was developed for the US Nuclear Regulatory Commission (US NRC) under contract
6+
! "Multi-Dimensional Physics Implementation into Fuel Analysis under Steady-state and Transients (FAST)",
7+
! contract # NRC-HQ-60-17-C-0007
8+
! ```
149
module object_interface
1510
implicit none
1611

@@ -31,6 +26,8 @@ module object_interface
3126
contains
3227
procedure :: mark_as_defined
3328
procedure :: user_defined
29+
procedure(write_interface), deferred :: write_formatted
30+
generic :: write(formatted) => write_formatted
3431
end type
3532

3633
interface
@@ -50,4 +47,16 @@ pure module function user_defined(this) result(is_defined)
5047

5148
end interface
5249

50+
abstract interface
51+
subroutine write_interface(self, unit, iotype, v_list, iostat, iomsg)
52+
import object
53+
class(object), intent(in) :: self
54+
integer, intent(in) :: unit
55+
character(*), intent(in) :: iotype
56+
integer, intent(in) :: v_list(:)
57+
integer, intent(out) :: iostat
58+
character(*), intent(inout) :: iomsg
59+
end subroutine
60+
end interface
61+
5362
end module object_interface

0 commit comments

Comments
 (0)