1
!% Contains a module which outputs the structure of entire merger trees.
3
module Merger_Tree_Output_Structure
4
!% Outputs the structure of entire merger trees.
6
public :: Merger_Tree_Structure_Output
8
! Flag indicating if module is initialized.
9
logical :: structureOutputModuleInitialized=.false.
11
! Flag indicating if output is required.
12
logical :: mergerTreeStructureOutput
15
integer :: structureGroupID
19
!# <mergerTreePreEvolveTask>
20
!# <unitName>Merger_Tree_Structure_Output</unitName>
21
!# </mergerTreePreEvolveTask>
22
subroutine Merger_Tree_Structure_Output(thisTree)
23
!% Output the structure of {\tt thisTree}.
29
use Galacticus_HDF5_Groups
31
use ISO_Varying_String
34
type(mergerTree), intent(in) :: thisTree
35
type(treeNode), pointer :: thisNode
36
integer, allocatable, dimension(:) :: nodeIndex
37
double precision, allocatable, dimension(:) :: nodeProperty
38
integer :: nodeCount,structureDataID,treeGroupID
39
type(varying_string) :: groupName,groupComment
41
! Check if module is initialized.
42
if (.not.structureOutputModuleInitialized) then
43
! Get parameter specifying if output is required.
45
!@ <name>mergerTreeStructureOutput</name>
46
!@ <defaultValue>false</defaultValue>
47
!@ <attachedTo>module</attachedTo>
49
!@ Specifies whether or not to output the structure of merger trees prior to evolution.
52
call Get_Input_Parameter('mergerTreeStructureOutput',mergerTreeStructureOutput,defaultValue=.false.)
53
! Create an output group if necessary.
54
if (mergerTreeStructureOutput) then
55
groupName ='mergerTreeStructures'
56
groupComment='Pre-evolution structures of merger trees.'
57
structureGroupID=Galacticus_Output_Make_Group(groupName,groupComment)
59
! Flag that module is initialized.
60
structureOutputModuleInitialized=.true.
63
! Output the tree structure history.
64
if (mergerTreeStructureOutput) then
65
! Count up number of nodes in the tree.
67
thisNode => thisTree%baseNode
68
do while (associated(thisNode))
70
call thisNode%walkTree()
72
! Allocate storage space.
73
call Alloc_Array(nodeIndex ,nodeCount,'nodeIndex' )
74
call Alloc_Array(nodeProperty,nodeCount,'nodeProperty')
75
! Create a group for this tree structure.
76
groupName ='mergerTree'
77
groupName =groupName//thisTree%index
78
groupComment='Pre-evolution structure of merger tree.'
79
treeGroupID =Galacticus_Output_Make_Group(groupName,groupComment,structureGroupID)
81
! Extract node indices and output to file.
83
thisNode => thisTree%baseNode
84
do while (associated(thisNode))
86
nodeIndex(nodeCount)=thisNode%index()
87
call thisNode%walkTree()
90
call Galacticus_Output_Dataset(treeGroupID,structureDataID,'nodeIndex','Index of the node.',nodeIndex)
92
! Extract child node indices and output to file.
94
thisNode => thisTree%baseNode
95
do while (associated(thisNode))
97
nodeIndex(nodeCount)=thisNode%childNode%index()
98
call thisNode%walkTree()
101
call Galacticus_Output_Dataset(treeGroupID,structureDataID,'childNodeIndex','Index of the child node.',nodeIndex)
103
! Extract parent node indices and output to file.
105
thisNode => thisTree%baseNode
106
do while (associated(thisNode))
107
nodeCount=nodeCount+1
108
nodeIndex(nodeCount)=thisNode%parentNode%index()
109
call thisNode%walkTree()
112
call Galacticus_Output_Dataset(treeGroupID,structureDataID,'parentNodeIndex','Index of the parent node.',nodeIndex)
114
! Extract sibling node indices and output to file.
116
thisNode => thisTree%baseNode
117
do while (associated(thisNode))
118
nodeCount=nodeCount+1
119
nodeIndex(nodeCount)=thisNode%siblingNode%index()
120
call thisNode%walkTree()
123
call Galacticus_Output_Dataset(treeGroupID,structureDataID,'siblingNodeIndex','Index of the sibling node.',nodeIndex)
125
! Extract node masses and output to file.
127
thisNode => thisTree%baseNode
128
do while (associated(thisNode))
129
nodeCount=nodeCount+1
130
nodeProperty(nodeCount)=Tree_Node_Mass(thisNode)
131
call thisNode%walkTree()
134
call Galacticus_Output_Dataset(treeGroupID,structureDataID,'nodeMass','Mass of node.',nodeProperty)
136
! Extract node times and output to file.
138
thisNode => thisTree%baseNode
139
do while (associated(thisNode))
140
nodeCount=nodeCount+1
141
nodeProperty(nodeCount)=Tree_Node_Time(thisNode)
142
call thisNode%walkTree()
145
call Galacticus_Output_Dataset(treeGroupID,structureDataID,'nodeTime','Time at node.',nodeProperty)
147
! Deallocate storage space.
148
call Dealloc_Array(nodeIndex )
149
call Dealloc_Array(nodeProperty)
153
end subroutine Merger_Tree_Structure_Output
155
end module Merger_Tree_Output_Structure