Generate a Graphviz digraph structure for the DAG.
dot: dot -Tpdf -o test.pdf test.dot,
where test.dot is str written to a file.| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(dag), | intent(in) | :: | me | |||
| character(len=*), | intent(in), | optional | :: | rankdir |
right to left orientation (e.g. 'RL') |
|
| integer, | intent(in), | optional | :: | dpi |
resolution (e.g. 300) |
function dag_generate_digraph(me,rankdir,dpi) result(str) implicit none class(dag),intent(in) :: me character(len=:),allocatable :: str character(len=*),intent(in),optional :: rankdir !! right to left orientation (e.g. 'RL') integer,intent(in),optional :: dpi !! resolution (e.g. 300) integer :: i,j !! counter integer :: n_edges !! number of edges character(len=:),allocatable :: attributes,label logical :: has_label, has_attributes character(len=*),parameter :: tab = ' ' !! for indenting character(len=*),parameter :: newline = new_line(' ') !! line break character if (me%n == 0) return str = 'digraph G {'//newline//newline if (present(rankdir)) & str = str//tab//'rankdir='//rankdir//newline//newline if (present(dpi)) & str = str//tab//'graph [ dpi = '//integer_to_string(dpi)//' ]'//newline//newline ! define the vertices: do i=1,me%n has_label = allocated(me%vertices(i)%label) has_attributes = allocated(me%vertices(i)%attributes) if (has_label) label = 'label="'//trim(adjustl(me%vertices(i)%label))//'"' if (has_label .and. has_attributes) then attributes = '['//trim(adjustl(me%vertices(i)%attributes))//','//label//']' elseif (has_label .and. .not. has_attributes) then attributes = '['//label//']' elseif (.not. has_label .and. has_attributes) then attributes = '['//trim(adjustl(me%vertices(i)%attributes))//']' else ! neither attributes = '' end if str = str//tab//integer_to_string(i)//' '//attributes//newline if (i==me%n) str = str//newline end do ! define the dependencies: do i=1,me%n if (allocated(me%vertices(i)%edges)) then n_edges = size(me%vertices(i)%edges) str = str//tab//integer_to_string(i)// merge(' -> ',' ',n_edges/=0) do j=1,n_edges ! comma-separated list: str = str//integer_to_string(me%vertices(i)%edges(j)) if (n_edges>1 .and. j<n_edges) str = str//',' end do str = str//';'//newline end if end do str = str//newline//'}' end function dag_generate_digraph