I use a simple user type
type vector
integer :: size
real(real64), allocatable :: data(:)
contains
procedure :: write_vector
generic :: write(formatted) => write_vector
end type vector
and a custom formatted write procedure
subroutine write_vector(v, unit, iotype, v_list, iostat, iomsg)
class(vector), intent(in) :: v
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
!** write formatted array v%data
if( iotype(1:2)=='DT' ) then
!** Use specific formatting
else
!** Use default formatting
end if
end subroutine
I want to be able to pass a format specifier to the write sub such that
type(vector) :: v
v = vector(3, [1d0,1/2d0,1/3d0])
write (*, '(a,DT(g0.5))') "v=", v
But the above does not work because iotype
is only 'DT'
and the remaining format spec is stripped, Additionally, v_list
is an undefined pointer array always, even if I specify DT(1,2)
as the format specifier for example.
In summary, how do I write a user defined type write subroutine that I can pass a format specifier to?