# Path: topoflow/components/d8_base.py
# class d8_component( BMI_base.BMI_component ):
#     def get_input_var_names(self):
#     def get_output_var_names(self):
#     def get_var_name(self, long_var_name):
#     def get_var_units(self, long_var_name):
#     def set_constants(self):
#     def set_default_config_vars(self):
#     def initialize(self, cfg_file=None, mode='nondriver',
#                    SILENT=False, REPORT=True):
#     def update(self, time=None, DEM=None,
#                SILENT=True, REPORT=False):
#     def update_most(self, time=None, DEM=None,
#                SILENT=True, REPORT=False):
#     def set_computed_input_vars(self):
#     def initialize_computed_vars(self, DOUBLE=False,
#                                  SILENT=True, REPORT=False):
#     def get_pixel_dimensions(self, DOUBLE=False,
#                              SILENT=True, REPORT=False):
#     def get_flow_code_list(self, ARC=False):
#     def get_flow_code_list_opps(self, ARC=False):
#     def get_valid_code_map(self, SILENT=True):
#     def get_ID_grid(self, SILENT=True):
#     def get_parent_inc_map(self):
#     def get_edge_IDs(self, SILENT=True):
#     def get_not_edge_grid(self, SILENT=True):
#     def resolve_array_cycle(self, w, t):
#     def get_resolve_array(self, SILENT=True, REPORT=False):
#     def update_parent_ID_grid(self, SILENT=True):
#     def update_parent_IDs(self):
#     def update_flow_from_IDs(self):
#     def update_flow_to_IDs(self):
#     def update_noflow_IDs(self):
#     def read_flow_grid(self, SILENT=True):
#     def update_flow_grid(self, DEM=None, SILENT=True, REPORT=False):
#     def start_new_d8_codes(self, DEM=None,
#                            z=None, IDs=None,
#                            SILENT=True, REPORT=False):
#     def break_flow_grid_ties(self, SILENT=True):
#     def link_flats(self, SILENT=True):
#     def update_flow_width_grid(self, DOUBLE=False, METHOD2=False,
#                                SILENT=True, REPORT=False):
#     def update_flow_length_grid(self, DOUBLE=False,
#                                 SILENT=True, REPORT=False):
#     def update_area_grid(self, SILENT=True, REPORT=False):
#     def change_extension_to_rtg(self, filename):
#     def open_input_files(self):
#     def read_input_files(self):
#     def close_input_files(self):
#     def update_outfile_names(self):
#     def open_output_files(self):
#     def write_output_files(self, time_seconds=None):
#     def close_output_files(self):
#     def save_grids(self, SILENT=True, REPORT=False):
#     def save_pixel_values(self):
#         DEM = rtg_files.read_grid( self.DEM_file, self.rti, SILENT=False )
#         MAP = np.zeros([129], dtype='Int32')
#         RTS_FILES = True
# 
# Path: topoflow/utils/rtg_files.py
# def unit_test(nx=4, ny=5, VERBOSE=False,
#               file_name="TEST_FILE.rtg"):
#     def __init__(self):
#     def open_file(self, file_name=None, UPDATE=False):
#     def check_and_store_info(self, file_name, info=None,
#                              var_name='UNKNOWN',
#                              dtype='float32',
#                              MAKE_RTI=True, MAKE_BOV=False):
#     def add_index_to_file_name(self, file_name): 
#     def open_new_file(self, file_name, info=None,
#                       var_name='UNKNOWN', dtype='float32',
#                       VERBOSE=False, ADD_INDEX=False,
#                       MAKE_RTI=True, MAKE_BOV=False):
#     def write_grid(self, grid, VERBOSE=False):
#     def add_grid(self, grid):
#     def read_grid(self, dtype='float32', rtg_type=None,
#                   REPORT=False, VERBOSE=False):
#     def get_grid(self, grid):
#     def close_file(self):
#     def close(self):
#     def byte_swap_needed(self):
# def read_grid( RTG_file, rti, RTG_type='FLOAT',
#                REPORT=False, SILENT=True ):
# def write_grid( grid, RTG_file, rti, RTG_type='FLOAT',
#                 REPORT=False, SILENT=True ):
# def read_xyz_as_grid(XYZ_file, RTG_file):
#     OK   = rtg.open_new_file( file_name, info, ADD_INDEX=True )
#     OK = rtg.open_file()
#     OK = rtg.open_new_file( file_name, info, ADD_INDEX=True)
#         NEW_INFO = True
#                 NEW_INFO = False
#         SWAP =  (machine_byte_order != self.info.byte_order)
#     SWAP_ENDIAN = tf_utils.Not_Same_Byte_Order(byte_order)
# class rtg_file():


import numpy as np
import os        # (for os.chdir(), in unit_test().)
import os.path
import time
from topoflow.components import d8_base
from topoflow.utils      import rtg_files
                grid.byteswap(True)
                grid.tofile(file_unit)
            else:
                self.A.tofile( file_unit )
            file_unit.close()
        
        #------------------
        # Optional report
        #------------------
        if (REPORT):
            if ('km' in self.A_units.lower()):
                unit_str = ' [km^2]'
            else:
                unit_str = ' [m^2]'
            A_str = str(self.A.min()) + ', ' + str(self.A.max())
            print '    min(A), max(A) = ' + A_str + unit_str
            print '    Number of iterations = ' + str(n_reps)

        #-------------------------------------------------
        # Compare saved area grid to one just computed
        #-------------------------------------------------
        # Note that unless self.LR_PERIODIC = False and
        # self.TB_PERIODIC = False, the area grids won't
        # agree on the edges.  This is because we don't
        # set them to zero when using periodic boundary
        # conditions.
        #-------------------------------------------------
        if (self.RT3_TEST):
            area_file = (self.in_directory +
                         self.site_prefix + '_area.rtg')

# Path: topoflow/components/d8_base.py
# class d8_component( BMI_base.BMI_component ):
#     def get_input_var_names(self):
#     def get_output_var_names(self):
#     def get_var_name(self, long_var_name):
#     def get_var_units(self, long_var_name):
#     def set_constants(self):
#     def set_default_config_vars(self):
#     def initialize(self, cfg_file=None, mode='nondriver',
#                    SILENT=False, REPORT=True):
#     def update(self, time=None, DEM=None,
#                SILENT=True, REPORT=False):
#     def update_most(self, time=None, DEM=None,
#                SILENT=True, REPORT=False):
#     def set_computed_input_vars(self):
#     def initialize_computed_vars(self, DOUBLE=False,
#                                  SILENT=True, REPORT=False):
#     def get_pixel_dimensions(self, DOUBLE=False,
#                              SILENT=True, REPORT=False):
#     def get_flow_code_list(self, ARC=False):
#     def get_flow_code_list_opps(self, ARC=False):
#     def get_valid_code_map(self, SILENT=True):
#     def get_ID_grid(self, SILENT=True):
#     def get_parent_inc_map(self):
#     def get_edge_IDs(self, SILENT=True):
#     def get_not_edge_grid(self, SILENT=True):
#     def resolve_array_cycle(self, w, t):
#     def get_resolve_array(self, SILENT=True, REPORT=False):
#     def update_parent_ID_grid(self, SILENT=True):
#     def update_parent_IDs(self):
#     def update_flow_from_IDs(self):
#     def update_flow_to_IDs(self):
#     def update_noflow_IDs(self):
#     def read_flow_grid(self, SILENT=True):
#     def update_flow_grid(self, DEM=None, SILENT=True, REPORT=False):
#     def start_new_d8_codes(self, DEM=None,
#                            z=None, IDs=None,
#                            SILENT=True, REPORT=False):
#     def break_flow_grid_ties(self, SILENT=True):
#     def link_flats(self, SILENT=True):
#     def update_flow_width_grid(self, DOUBLE=False, METHOD2=False,
#                                SILENT=True, REPORT=False):
#     def update_flow_length_grid(self, DOUBLE=False,
#                                 SILENT=True, REPORT=False):
#     def update_area_grid(self, SILENT=True, REPORT=False):
#     def change_extension_to_rtg(self, filename):
#     def open_input_files(self):
#     def read_input_files(self):
#     def close_input_files(self):
#     def update_outfile_names(self):
#     def open_output_files(self):
#     def write_output_files(self, time_seconds=None):
#     def close_output_files(self):
#     def save_grids(self, SILENT=True, REPORT=False):
#     def save_pixel_values(self):
#         DEM = rtg_files.read_grid( self.DEM_file, self.rti, SILENT=False )
#         MAP = np.zeros([129], dtype='Int32')
#         RTS_FILES = True
# 
# Path: topoflow/utils/rtg_files.py
# def unit_test(nx=4, ny=5, VERBOSE=False,
#               file_name="TEST_FILE.rtg"):
#     def __init__(self):
#     def open_file(self, file_name=None, UPDATE=False):
#     def check_and_store_info(self, file_name, info=None,
#                              var_name='UNKNOWN',
#                              dtype='float32',
#                              MAKE_RTI=True, MAKE_BOV=False):
#     def add_index_to_file_name(self, file_name): 
#     def open_new_file(self, file_name, info=None,
#                       var_name='UNKNOWN', dtype='float32',
#                       VERBOSE=False, ADD_INDEX=False,
#                       MAKE_RTI=True, MAKE_BOV=False):
#     def write_grid(self, grid, VERBOSE=False):
#     def add_grid(self, grid):
#     def read_grid(self, dtype='float32', rtg_type=None,
#                   REPORT=False, VERBOSE=False):
#     def get_grid(self, grid):
#     def close_file(self):
#     def close(self):
#     def byte_swap_needed(self):
# def read_grid( RTG_file, rti, RTG_type='FLOAT',
#                REPORT=False, SILENT=True ):
# def write_grid( grid, RTG_file, rti, RTG_type='FLOAT',
#                 REPORT=False, SILENT=True ):
# def read_xyz_as_grid(XYZ_file, RTG_file):
#     OK   = rtg.open_new_file( file_name, info, ADD_INDEX=True )
#     OK = rtg.open_file()
#     OK = rtg.open_new_file( file_name, info, ADD_INDEX=True)
#         NEW_INFO = True
#                 NEW_INFO = False
#         SWAP =  (machine_byte_order != self.info.byte_order)
#     SWAP_ENDIAN = tf_utils.Not_Same_Byte_Order(byte_order)
# class rtg_file():


# Path: topoflow/components/d8_global.py
import numpy as np
import os        # (for os.chdir(), in unit_test().)
import os.path
import time
from topoflow.components import d8_base
from topoflow.utils      import rtg_files

                grid.byteswap(True)
                grid.tofile(file_unit)
            else:
                self.A.tofile( file_unit )
            file_unit.close()
        
        #------------------
        # Optional report
        #------------------
        if (REPORT):
            if ('km' in self.A_units.lower()):
                unit_str = ' [km^2]'
            else:
                unit_str = ' [m^2]'
            A_str = str(self.A.min()) + ', ' + str(self.A.max())
            print '    min(A), max(A) = ' + A_str + unit_str
            print '    Number of iterations = ' + str(n_reps)

        #-------------------------------------------------
        # Compare saved area grid to one just computed
        #-------------------------------------------------
        # Note that unless self.LR_PERIODIC = False and
        # self.TB_PERIODIC = False, the area grids won't
        # agree on the edges.  This is because we don't
        # set them to zero when using periodic boundary
        # conditions.
        #-------------------------------------------------
        if (self.RT3_TEST):
            area_file = (self.in_directory +
                         self.site_prefix + '_area.rtg')

            saved_area_grid = rtg_files.read_grid(area_file, self.rti,