# 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.path
import time
import d8_global   ### (9/19/14.  Attempt to fix issue.)
import erode_base
from topoflow.utils import rtg_files

        # n=1.0, K=1.0. Making K smaller allows dt_too_small
        # to be bigger. Now K is smaller.
        #-----------------------------------------------------
        # Fixed units issue in Qs_Grid so should be able to
        # reduce dt_too_small.
        #-----------------------------------------------------
        ## if (self.dt_min <= 0):
        if (self.dt_min < self.dt_too_small):
            print '### WARNING: dt < ' + str(self.dt_too_small)
            print '        dt = ' + str(self.dt_min)
            print ' '
            if (self.dt_min <= 0):
                sys.exit()

        #------------------
        # Optional report
        #------------------
        if (REPORT):
            print 'min(del_z), max(del_z) =', del_z.min(), del_z.max()
            print 'min(Qs), max(Qs) =', self.Qs.min(), self.Qs.max()
            print 'min(dt), max(dt) =', self.dt_grid.min(), self.dt_grid.max()
            wm = np.where( self.dt_grid != self.dt_grid.max() )
            print 'max(dt_used)     =', self.dt_grid[wm].max()
            print ' '

        #-----------------------------
        # Save grid as an RTG file ?
        #-----------------------------
        if (SAVE_RTG):
            RTG_file = (self.case_prefix + '_dt.rtg')

# 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/erode_d8_global.py
import numpy as np
import os.path
import time
import d8_global   ### (9/19/14.  Attempt to fix issue.)
import erode_base
from topoflow.utils import rtg_files

        # n=1.0, K=1.0. Making K smaller allows dt_too_small
        # to be bigger. Now K is smaller.
        #-----------------------------------------------------
        # Fixed units issue in Qs_Grid so should be able to
        # reduce dt_too_small.
        #-----------------------------------------------------
        ## if (self.dt_min <= 0):
        if (self.dt_min < self.dt_too_small):
            print '### WARNING: dt < ' + str(self.dt_too_small)
            print '        dt = ' + str(self.dt_min)
            print ' '
            if (self.dt_min <= 0):
                sys.exit()

        #------------------
        # Optional report
        #------------------
        if (REPORT):
            print 'min(del_z), max(del_z) =', del_z.min(), del_z.max()
            print 'min(Qs), max(Qs) =', self.Qs.min(), self.Qs.max()
            print 'min(dt), max(dt) =', self.dt_grid.min(), self.dt_grid.max()
            wm = np.where( self.dt_grid != self.dt_grid.max() )
            print 'max(dt_used)     =', self.dt_grid[wm].max()
            print ' '

        #-----------------------------
        # Save grid as an RTG file ?
        #-----------------------------
        if (SAVE_RTG):
            RTG_file = (self.case_prefix + '_dt.rtg')

            rtg_files.write_grid( self.dt_grid, RTG_file, self.rti )
