text: #!/usr/bin/env python
  
  # Copyright (c) 2017-2020, The Bifrost Authors. All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions
  # are met:
  # * Redistributions of source code must retain the above copyright
  #   notice, this list of conditions and the following disclaimer.
  # * Redistributions in binary form must reproduce the above copyright
  #   notice, this list of conditions and the following disclaimer in the
  #   documentation and/or other materials provided with the distribution.
  # * Neither the name of The Bifrost Authors nor the names of its
  #   contributors may be used to endorse or promote products derived
  #   from this software without specific prior written permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  """
  # your_first_block.py
  
  This testbench initializes a simple bifrost pipeline that reads from a binary file,
  and then writes the data to an output file. 
  """
  
  # Python2 compatibility
  from __future__ import print_function
  
  import os
  import numpy as np
  import bifrost.pipeline as bfp
  from bifrost.blocks import BinaryFileReadBlock, BinaryFileWriteBlock
  import glob
  from datetime import datetime
  from copy import deepcopy
  from pprint import pprint
  
  class UselessAddBlock(bfp.TransformBlock):
      def __init__(self, iring, n_to_add, *args, **kwargs):
          super(UselessAddBlock, self).__init__(iring, *args, **kwargs)
          self.n_to_add = n_to_add
  
      def on_sequence(self, iseq):
          ohdr = deepcopy(iseq.header)
          ohdr["name"] += "_with_added_value"
          return ohdr
  
      def on_data(self, ispan, ospan):
          in_nframe  = ispan.nframe
          out_nframe = in_nframe
  
          idata = ispan.data + self.n_to_add
          odata = ospan.data
  
          odata[...] = idata
          return out_nframe
  
  class PrintStuffBlock(bfp.SinkBlock):
      def __init__(self, iring, *args, **kwargs):
          super(PrintStuffBlock, self).__init__(iring, *args, **kwargs)
          self.n_iter = 0
  
      def on_sequence(self, iseq):
          print("[%s]" % datetime.now())
          print(iseq.name)
          pprint(iseq.header)
          self.n_iter = 0
  
      def on_data(self, ispan):
          now = datetime.now()
          if self.n_iter % 100 == 0:
              print("[%s] %s" % (now, ispan.data))
          self.n_iter += 1
  
  
  if __name__ == "__main__":
      # Setup pipeline
      filenames   = sorted(glob.glob('testdata/sin_data*.bin'))
  
      b_read      = BinaryFileReadBlock(filenames, 32768, 1, 'f32')
      b_add       = UselessAddBlock(b_read, n_to_add=100)
      b_print     = PrintStuffBlock(b_read)
      b_print2    = PrintStuffBlock(b_add)
  
      # Run pipeline
      pipeline = bfp.get_default_pipeline()
      print(pipeline.dot_graph())
      pipeline.run()
      
  