297 class(dag),
intent(in) :: me
298 character(len=:),
allocatable :: str
299 character(len=*),
intent(in),
optional :: rankdir
300 integer,
intent(in),
optional :: dpi
301 character(len=*),
intent(in),
optional :: edge
305 character(len=:),
allocatable :: attributes,label
306 logical :: has_label, has_attributes
308 character(len=*),
parameter :: tab =
' '
309 character(len=*),
parameter :: newline = new_line(
' ')
311 if (me%n == 0)
return
313 str =
'digraph G {'//newline//newline
314 if (
present(rankdir)) &
315 str = str//tab//
'rankdir='//rankdir//newline//newline
317 str = str//tab//
'graph [ dpi = '//integer_to_string(dpi)//
' ]'//newline//newline
319 str = str//tab//
'edge [ dir = "'//trim(adjustl(edge))//
'" ]'//newline//newline
323 has_label =
allocated(me%vertices(i)%label)
324 has_attributes =
allocated(me%vertices(i)%attributes)
325 if (has_label) label =
'label="'//trim(adjustl(me%vertices(i)%label))//
'"'
326 if (has_label .and. has_attributes)
then
327 attributes =
'['//trim(adjustl(me%vertices(i)%attributes))//
','//label//
']'
328 elseif (has_label .and. .not. has_attributes)
then
329 attributes =
'['//label//
']'
330 elseif (.not. has_label .and. has_attributes)
then
331 attributes =
'['//trim(adjustl(me%vertices(i)%attributes))//
']'
335 str = str//tab//integer_to_string(i)//
' '//attributes//newline
336 if (i==me%n) str = str//newline
341 if (
allocated(me%vertices(i)%edges))
then
342 n_edges =
size(me%vertices(i)%edges)
343 str = str//tab//integer_to_string(i)//
' -> '
346 str = str//integer_to_string(me%vertices(i)%edges(j))
347 if (n_edges>1 .and. j<n_edges) str = str//
','
349 str = str//
';'//newline
353 str = str//newline//
'}'