# Dealing with piecewise arrays

**URL:** <https://www.ruby-forum.com/t/dealing-with-piecewise-arrays/163122>\
**Category:** Ruby\
**Created:** [March 17, 2009, 1:40pm UTC](https://www.ruby-forum.com/t/dealing-with-piecewise-arrays/163122 "2009-03-17T13:40:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaj\_Bhattacharya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/9de053/32.png) [@Yaj\_Bhattacharya](https://www.ruby-forum.com/u/Yaj_Bhattacharya)\
**Post date:** [March 17, 2009, 1:40pm UTC](https://www.ruby-forum.com/t/dealing-with-piecewise-arrays/163122/1 "2009-03-17T13:40:33Z")

</div>

I want to perform the following in Ruby, could someone please help  
translate this pseudocode?

1. Read in a time series in a columnar format from an external file  
(covered elsewhere in this forum, including for completeness)  
given data triplets: time, value, error

2. Check for discontinuities in data:  
if [time(i+1) - time(i)] \> some\_value, then  
store this piece of triplet array and give  
it a address (say piece\_1)  
continue reading until another discontinuity is  
encountered  
store the new piece of triplet array with  
new address (piece\_2)  
until end of file

3. Write out each piece as a separate file with meaningful filenames  
based on the time of the array above, so the file written for piece\_1  
would be called “time(i)\_time(i+n).dat” where the time array is a  
continuous array without gaps (no gaps greater than some\_value deduced  
in step 2).

Thanks in advance  
Yaj
