~abenson/galacticus/v0.9.0

« back to all changes in this revision

Viewing changes to source/merger_trees.output_structure.F90

  • Committer: Andrew Benson
  • Date: 2010-05-27 14:18:28 UTC
  • Revision ID: abesnson@its.caltech.edu-20100527141828-dzvnjovtiq02impa
* Importing full Galacticus code as developed to date.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
!% Contains a module which outputs the structure of entire merger trees.
 
2
 
 
3
module Merger_Tree_Output_Structure
 
4
  !% Outputs the structure of entire merger trees.
 
5
  private
 
6
  public :: Merger_Tree_Structure_Output
 
7
  
 
8
  ! Flag indicating if module is initialized.
 
9
  logical :: structureOutputModuleInitialized=.false.
 
10
  
 
11
  ! Flag indicating if output is required.
 
12
  logical :: mergerTreeStructureOutput
 
13
 
 
14
  ! HDF5 group index.
 
15
  integer :: structureGroupID
 
16
  
 
17
contains
 
18
 
 
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}.
 
24
    use Merger_Trees
 
25
    use Tree_Nodes
 
26
    use Tree_Node_Methods
 
27
    use Input_Parameters
 
28
    use Memory_Management
 
29
    use Galacticus_HDF5_Groups
 
30
    use HDF5
 
31
    use ISO_Varying_String
 
32
    use String_Handling
 
33
    implicit none
 
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
 
40
 
 
41
    ! Check if module is initialized.
 
42
    if (.not.structureOutputModuleInitialized) then
 
43
       ! Get parameter specifying if output is required.
 
44
       !@ <inputParameter>
 
45
       !@   <name>mergerTreeStructureOutput</name>
 
46
       !@   <defaultValue>false</defaultValue>
 
47
       !@   <attachedTo>module</attachedTo>
 
48
       !@   <description>
 
49
       !@     Specifies whether or not to output the structure of merger trees prior to evolution.
 
50
       !@   </description>
 
51
       !@ </inputParameter>
 
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)
 
58
       end if
 
59
       ! Flag that module is initialized.
 
60
       structureOutputModuleInitialized=.true.
 
61
    end if
 
62
 
 
63
    ! Output the tree structure history.
 
64
    if (mergerTreeStructureOutput) then
 
65
       ! Count up number of nodes in the tree.
 
66
       nodeCount=0
 
67
       thisNode => thisTree%baseNode
 
68
       do while (associated(thisNode))
 
69
          nodeCount=nodeCount+1
 
70
          call thisNode%walkTree()
 
71
       end do
 
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)
 
80
 
 
81
       ! Extract node indices and output to file.
 
82
       nodeCount=0
 
83
       thisNode => thisTree%baseNode
 
84
       do while (associated(thisNode))
 
85
          nodeCount=nodeCount+1
 
86
          nodeIndex(nodeCount)=thisNode%index()        
 
87
          call thisNode%walkTree()
 
88
       end do
 
89
       structureDataID=0
 
90
       call Galacticus_Output_Dataset(treeGroupID,structureDataID,'nodeIndex','Index of the node.',nodeIndex)
 
91
    
 
92
       ! Extract child node indices and output to file.
 
93
       nodeCount=0
 
94
       thisNode => thisTree%baseNode
 
95
       do while (associated(thisNode))
 
96
          nodeCount=nodeCount+1
 
97
          nodeIndex(nodeCount)=thisNode%childNode%index()        
 
98
          call thisNode%walkTree()
 
99
       end do
 
100
       structureDataID=0
 
101
       call Galacticus_Output_Dataset(treeGroupID,structureDataID,'childNodeIndex','Index of the child node.',nodeIndex)
 
102
    
 
103
       ! Extract parent node indices and output to file.
 
104
       nodeCount=0
 
105
       thisNode => thisTree%baseNode
 
106
       do while (associated(thisNode))
 
107
          nodeCount=nodeCount+1
 
108
          nodeIndex(nodeCount)=thisNode%parentNode%index()        
 
109
          call thisNode%walkTree()
 
110
       end do
 
111
       structureDataID=0
 
112
       call Galacticus_Output_Dataset(treeGroupID,structureDataID,'parentNodeIndex','Index of the parent node.',nodeIndex)
 
113
    
 
114
       ! Extract sibling node indices and output to file.
 
115
       nodeCount=0
 
116
       thisNode => thisTree%baseNode
 
117
       do while (associated(thisNode))
 
118
          nodeCount=nodeCount+1
 
119
          nodeIndex(nodeCount)=thisNode%siblingNode%index()        
 
120
          call thisNode%walkTree()
 
121
       end do
 
122
       structureDataID=0
 
123
       call Galacticus_Output_Dataset(treeGroupID,structureDataID,'siblingNodeIndex','Index of the sibling node.',nodeIndex)
 
124
    
 
125
       ! Extract node masses and output to file.
 
126
       nodeCount=0
 
127
       thisNode => thisTree%baseNode
 
128
       do while (associated(thisNode))
 
129
          nodeCount=nodeCount+1
 
130
          nodeProperty(nodeCount)=Tree_Node_Mass(thisNode)
 
131
          call thisNode%walkTree()
 
132
       end do
 
133
       structureDataID=0
 
134
       call Galacticus_Output_Dataset(treeGroupID,structureDataID,'nodeMass','Mass of node.',nodeProperty)
 
135
    
 
136
       ! Extract node times and output to file.
 
137
       nodeCount=0
 
138
       thisNode => thisTree%baseNode
 
139
       do while (associated(thisNode))
 
140
          nodeCount=nodeCount+1
 
141
          nodeProperty(nodeCount)=Tree_Node_Time(thisNode)
 
142
          call thisNode%walkTree()
 
143
       end do
 
144
       structureDataID=0
 
145
       call Galacticus_Output_Dataset(treeGroupID,structureDataID,'nodeTime','Time at node.',nodeProperty)
 
146
    
 
147
       ! Deallocate storage space.
 
148
       call Dealloc_Array(nodeIndex   )
 
149
       call Dealloc_Array(nodeProperty)
 
150
    end if
 
151
 
 
152
    return
 
153
  end subroutine Merger_Tree_Structure_Output
 
154
  
 
155
end module Merger_Tree_Output_Structure