95 {
96
97
98 if (segments.size() == 1) {
99 dt_constant = true;
100 has_dead_components = false;
101 is_sorted = true;
102 has_overlaps = false;
103 has_gaps = false;
104 if (segments[0].live()) {
105 number_live = 1;
106 first_live = 0;
107 t0 = segments[0].t0();
108 endtime = segments[0].endtime();
109 dt = segments[0].dt();
110 this->spliced_nsamp = segments[0].npts();
111 } else {
112 number_live = 0;
113 first_live = -1;
114 t0 = 0.0;
115 dt = 0.0;
116 endtime = 0.0;
117 this->spliced_nsamp = 0;
118 }
119 } else if (segments.size() == 0) {
120 dt_constant = true;
121 has_dead_components = false;
122 is_sorted = true;
123 has_overlaps = false;
124 has_gaps = false;
125 number_live = 0;
126 first_live = -1;
127 t0 = 0.0;
128 dt = 0.0;
129 endtime = 0.0;
130 this->spliced_nsamp = 0;
131 } else {
132 double test_dt, dtfrac;
133 double first_t0, previous_t0, previous_endtime;
134
135
136 bool this_is_first(true);
137 has_overlaps = false;
138 is_sorted = true;
139 has_dead_components = false;
140
141
142 const double dt_fraction_mismatch(0.001);
143 for (size_t i = 0; i < segments.size(); ++i) {
144 if (segments[i].dead()) {
145 has_dead_components = true;
146 continue;
147 }
148 if (this_is_first) {
149 this->dt_constant = true;
150 this->first_live = i;
151 first_t0 = segments[i].t0();
152 previous_t0 = first_t0;
153 test_dt = segments[i].dt();
154 previous_endtime = segments[i].endtime();
155 this_is_first = false;
156 this->dt = test_dt;
157 this->t0 = first_t0;
158 this->number_live = 1;
159 } else {
160
161
162
163 if (segments[i].t0() < previous_t0)
164 is_sorted = false;
165
166 if ((previous_endtime + test_dt * TIME_TEAR_TOLERANCE) >
167 segments[i].t0())
168 has_overlaps = true;
169
170 if ((segments[i].t0() - previous_endtime - test_dt) / test_dt >
171 TIME_TEAR_TOLERANCE)
172 has_gaps = true;
173
174 dtfrac = fabs(segments[i].dt() - test_dt) / test_dt;
175 if (dtfrac > dt_fraction_mismatch)
176 dt_constant = false;
177 previous_endtime = segments[i].endtime();
178 previous_t0 = segments[i].t0();
179 ++this->number_live;
180 }
181 }
182 this->endtime = previous_endtime;
183 this->spliced_nsamp = lround((previous_endtime - this->t0) / this->dt);
184 ++this->spliced_nsamp;
185 }
186}