def open_new_cs_file(self,
                     file_name,
                     info=None,
                     var_name='X',
                     long_name='Unknown',
                     units_name='None',
                     dtype='float32',
                     time_units='minutes',
                     nx=None,
                     ny=None,
                     dx=None,
                     dy=None):

    #---------------------------
    # Was grid info provided ?
    #---------------------------
    if (info is not None):
        info.file_name = file_name
        info.data_type = rti_files.get_rti_data_type(dtype)
        if (nx is not None): info.ncols = nx
        if (ny is not None): info.nrows = ny
        if (dx is not None): info.xres = dx
        if (dy is not None): info.yres = dy
    else:
        if (nx is not None) and (ny is not None) and \
           (dx is not None) and (dy is not None):
            info = rti_files.make_info(file_name, nx, ny, dx, dy)
        else:
            print 'ERROR during open_new_cs_file().'
            print '      Grid info not provided.'
            print ' '
            ## return -1

    #--------------------------------------------
    # Open new netCDF file to write curbe stacks
    # using var_name to build variable names
    #--------------------------------------------
    try:
        nccs_unit_str = "self." + var_name + "_nccs_unit"
        nccs_file_str = "self." + var_name + "_nccs_file"
        cs_file_str = "self." + var_name + "_cs_file"

        exec(nccs_file_str + "= file_utils.replace_extension(" + cs_file_str +
             ", '.nc')")
        exec(nccs_unit_str + "=" + "nccs_files.nccs_file()")
        exec(nccs_unit_str + ".open_new_file(" + nccs_file_str +
             ", self.rti, var_name, long_name, units_name, " +
             "dtype=dtype, " +  ## (11/5/13)
             "time_units=time_units)")
        MAKE_RT3 = False
    except:
        print 'ERROR: Unable to open new netCDF file:'
        exec("print '      ', self." + var_name + "_nccs_file")
        print ' '
        print 'Will write cube stack in generic RT3 format.'
        print ' '
        MAKE_RT3 = True
Exemplo n.º 2
0
def open_new_cs_file(self, file_name, info=None,
                     var_name='X',
                     long_name='Unknown',
                     units_name='None',
                     dtype='float32',
                     time_units='minutes',
                     nx=None, ny=None, dx=None, dy=None):

    #---------------------------
    # Was grid info provided ?
    #---------------------------
    if (info != None):
        info.file_name = file_name
        info.data_type = rti_files.get_rti_data_type( dtype )
        if (nx != None): info.ncols = nx
        if (ny != None): info.nrows = ny
        if (dx != None): info.xres  = dx
        if (dy != None): info.yres  = dy
    else:
        if (nx != None) and (ny != None) and \
           (dx != None) and (dy != None):
            info = rti_files.make_info( file_name, nx, ny, dx, dy )
        else:
            print 'ERROR during open_new_cs_file().'
            print '      Grid info not provided.'
            print ' '
            ## return -1
        
    #--------------------------------------------
    # Open new netCDF file to write curbe stacks
    # using var_name to build variable names
    #--------------------------------------------
    try:
        nccs_unit_str = "self." + var_name + "_nccs_unit"
        nccs_file_str = "self." + var_name + "_nccs_file"
        cs_file_str   = "self." + var_name + "_cs_file"
            
        exec( nccs_file_str + "= file_utils.replace_extension(" +
              cs_file_str + ", '.nc')" )
        exec( nccs_unit_str + "=" + "nccs_files.nccs_file()" )
        exec( nccs_unit_str + ".open_new_file(" + nccs_file_str +
              ", self.rti, var_name, long_name, units_name, " +
              "dtype=dtype, " +  ## (11/5/13)
              "time_units=time_units)" )
        MAKE_RT3 = False
    except:
        print 'ERROR: Unable to open new netCDF file:'
        exec( "print '      ', self." + var_name + "_nccs_file" )
        print ' '
        print 'Will write cube stack in generic RT3 format.'
        print ' '
        MAKE_RT3 = True
Exemplo n.º 3
0
def open_new_gs_file(self, file_name, info=None,
                     var_name='X',
                     long_name='Unknown',
                     units_name='None',
                     dtype='float32',
                     time_units='minutes',
                     nx=None, ny=None, dx=None, dy=None):

    #---------------------------
    # Was grid info provided ?
    #---------------------------
    if (info != None):
        info.file_name = file_name
        info.data_type = rti_files.get_rti_data_type( dtype )
        if (nx != None): info.ncols = nx
        if (ny != None): info.nrows = ny
        if (dx != None): info.xres  = dx
        if (dy != None): info.yres  = dy
    else:
        if (nx != None) and (ny != None) and \
           (dx != None) and (dy != None):
            info = rti_files.make_info( file_name, nx, ny, dx, dy )
        else:
            print 'ERROR during open_new_gs_file().'
            print '      Grid info not provided.'
            print ' '
            ## return -1

    #---------------------------------------------
    # Get long_name and units_name from var_name
    #---------------------------------------------
#     long_name  = self.get_var_long_name( var_name )
#     units_name = self.get_var_units( var_name )
#     dtype      = self.get_var_type( var_name )  
           
    #---------------------------------
    # Build strings to be used below 
    #---------------------------------
    ncgs_unit_str = "self." + var_name + "_ncgs_unit"
    ncgs_file_str = "self." + var_name + "_ncgs_file"
    gs_file_str   = "self." + var_name + "_gs_file"
    #-------------------
    # For testing only
    #-------------------
    # print 'ncgs_unit_str =', ncgs_unit_str
    # print 'ncgs_file_str =', ncgs_file_str
    # print 'gs_file_str   =', gs_file_str
    # print 'var_name      =', var_name
    # print 'long_name     =', long_name
    # print 'units_name    =', units_name
    # print 'time_units    =', time_units
    # print ' '

    #--------------------------------------------
    # Open new netCDF file to write grid stacks
    # using var_name to build variable names
    #--------------------------------------------
    # Note that "dtype" was not included in the
    # last TopoFlow version (always float32),
    # but Erode needs other types.
    #--------------------------------------------
    try:
        exec( ncgs_file_str + "= file_utils.replace_extension(" +
              gs_file_str + ", '.nc')" )
        exec( ncgs_unit_str + "=" + "ncgs_files.ncgs_file()" )
        exec( ncgs_unit_str + ".open_new_file(" + ncgs_file_str +
              ", self.rti, var_name, long_name, units_name, " +
              "dtype=dtype, " +
              "time_units=time_units)" )
        MAKE_RTS = False
    except:
        print 'ERROR: Unable to open new netCDF file:'
        exec( "print '      '," + ncgs_file_str )
        print ' '
        print 'Will write grid stack in generic RTS format.'
        print ' '
        MAKE_RTS = True

    #-------------------------------------------
    # Always save grid stacks in an RTS file ?
    #--------------------------------------------------
    # Note that if PyNIO is missing, we don't get
    # an exception above and MAKE_RTS is still False.
    #--------------------------------------------------
    MAKE_RTS = True   #####
##    print '#################################'
##    print 'MAKE_RTS =', MAKE_RTS
##    print '#################################'
    
    #---------------------------------
    # Build strings to be used below 
    #---------------------------------
    rts_unit_str = "self." + var_name + "_rts_unit"
    rts_file_str = "self." + var_name + "_rts_file"
    gs_file_str  = "self." + var_name + "_gs_file"

    #------------------------------------------
    # Open new RTS files to write grid stacks
    #------------------------------------------
    if (MAKE_RTS):
        try:
            exec( rts_file_str + "= file_utils.replace_extension(" +
                  gs_file_str + ", '.rts')" )
            exec( rts_unit_str + " = rts_files.rts_file()" )
            exec( rts_unit_str + ".open_new_file(" + rts_file_str +
                  ", self.rti, var_name, " +
                  "dtype=dtype, " +
                  "MAKE_BOV=True)" )
        except:
            print 'ERROR: Unable to open new RTS file:'
            exec( "print '      '," + rts_file_str )
            # exec( "print '      ', self." + var_name + "_rts_file" )
            print ' '
Exemplo n.º 4
0
    def check_and_store_info(self, file_name, info=None,
                             var_name='UNKNOWN',
                             dtype='float32',
                             MAKE_RTI=True, MAKE_BOV=False):

        #-----------------------------------------------------
        # Note: This object (self) may be new or it may have
        #       been used previously.  In the latter case,
        #       "info" should still be available in "self".
        #       We only need info if MAKE_RTI or MAKE_BOV.
        #-----------------------------------------------------
        self.format = 'RTG'
        self.file_name = file_name
        if not(MAKE_RTI or MAKE_BOV): return

        #---------------------------------
        # Was "info" argument provided ?
        #---------------------------------
        NEW_INFO = True
        if (info == None):
            try:
                info = self.info
                NEW_INFO = False
                ## print 'Found info in state.'
            except:
                #------------------------------------------
                # Try to find RTI file to copy info from.
                # Don't create a new RTI file.
                #------------------------------------------
                RTI_file = rti_files.try_to_find_rti_file( file_name )
                if (RTI_file != 'none'):
                    info = rti_files.read_info( RTI_file )
                    ## print 'Reading info from: ' + RTI_file
                else:
                    print 'ERROR during open_new_file():'
                    print '   Could not find RTI file and "info"'
                    print '   argument was not provided.'
                    print ' '
                    return

        #-----------------------------
        # Update "info" as necessary
        #-----------------------------
        info.grid_file   = file_name
        info.data_type   = rti_files.get_rti_data_type( dtype )
        info.data_source = 'TopoFlow 3.0'
        info.gmin        = -9999.0
        info.gmax        = -9999.0
        
        #---------------------------------------
        # If new "info" was provided, store it
        #---------------------------------------
        if (NEW_INFO):
            self.info = info
            self.nx   = info.ncols
            self.ny   = info.nrows           
            ## print 'Stored new info in state.'
            
##        if (info != None):
##            #------------------------------
##            # Save info to a new RTI file
##            #------------------------------
##            prefix   = rti_files.get_file_prefix( file_name )
##            RTI_file = (prefix + '.rti')
##            rti_files.write_info( RTI_file, info )          
##
##        else:
##            #------------------------------------------
##            # Try to find RTI file to copy info from.
##            # Don't create a new RTI file.
##            #------------------------------------------
##            RTI_file = rti_files.try_to_find_rti_file( file_name )
##            if (RTI_file != 'none'):
##                info = rti_files.read_info( RTI_file )
##                info.file_name = file_name
##                info.data_type = rti_files.get_rti_data_type( dtype )
##            else:
##                print 'ERROR during open_new_file():'
##                print '   Could not find RTI file and "info"'
##                print '   argument was not provided.'
##                print ' '
##                return

        #-------------------
        # Write RTI file ?
        #-------------------
        if (MAKE_RTI):
            prefix   = rti_files.get_file_prefix( file_name )
            RTI_file = (prefix + '.rti')
            rti_files.write_info( RTI_file, info )
            # print 'Wrote grid info to: ' + RTI_file   ######
            
        #-------------------
        # Write BOV file ?
        #-------------------
        if (MAKE_BOV):
            bov_files.write_info_as_bov( file_name, info, var_name)
def open_new_gs_file(self,
                     file_name,
                     info=None,
                     var_name='X',
                     long_name='Unknown',
                     units_name='None',
                     dtype='float32',
                     time_units='minutes',
                     nx=None,
                     ny=None,
                     dx=None,
                     dy=None):

    #---------------------------
    # Was grid info provided ?
    #---------------------------
    if (info is not None):
        info.file_name = file_name
        info.data_type = rti_files.get_rti_data_type(dtype)
        if (nx is not None): info.ncols = nx
        if (ny is not None): info.nrows = ny
        if (dx is not None): info.xres = dx
        if (dy is not None): info.yres = dy
    else:
        if (nx is not None) and (ny is not None) and \
           (dx is not None) and (dy is not None):
            info = rti_files.make_info(file_name, nx, ny, dx, dy)
        else:
            print 'ERROR during open_new_gs_file().'
            print '      Grid info not provided.'
            print ' '
            ## return -1

    #---------------------------------------------
    # Get long_name and units_name from var_name
    #---------------------------------------------
#     long_name  = self.get_var_long_name( var_name )
#     units_name = self.get_var_units( var_name )
#     dtype      = self.get_var_type( var_name )

#---------------------------------
# Build strings to be used below
#---------------------------------
    ncgs_unit_str = "self." + var_name + "_ncgs_unit"
    ncgs_file_str = "self." + var_name + "_ncgs_file"
    gs_file_str = "self." + var_name + "_gs_file"
    #-------------------
    # For testing only
    #-------------------
    # print 'ncgs_unit_str =', ncgs_unit_str
    # print 'ncgs_file_str =', ncgs_file_str
    # print 'gs_file_str   =', gs_file_str
    # print 'var_name      =', var_name
    # print 'long_name     =', long_name
    # print 'units_name    =', units_name
    # print 'time_units    =', time_units
    # print ' '

    #--------------------------------------------
    # Open new netCDF file to write grid stacks
    # using var_name to build variable names
    #--------------------------------------------
    # Note that "dtype" was not included in the
    # last TopoFlow version (always float32),
    # but Erode needs other types.
    #--------------------------------------------
    try:
        #         gs_filename = getattr( self, (var_name + '_gs_file') )
        #         setattr( self, (var_name + '_ncgs_file'),
        #                  file_utils.replace_extension( gs_filename, '.nc') )
        #         setattr( self, (var_name + '_ncgs_unit'), ncgs_files.ncgs_file() )
        #         setattr( self, (var_name + '_ncgs_unit'),
        #
        #         exec( ncgs_unit_str + ".open_new_file(" + ncgs_file_str +
        #               ", self.rti, var_name, long_name, units_name, " +
        #               "dtype=dtype, " +
        #               "time_units=time_units)" )
        #--------------------------------------------------------------
        exec(ncgs_file_str + "= file_utils.replace_extension(" + gs_file_str +
             ", '.nc')")
        exec(ncgs_unit_str + "=" + "ncgs_files.ncgs_file()")
        exec(ncgs_unit_str + ".open_new_file(" + ncgs_file_str +
             ", self.rti, var_name, long_name, units_name, " +
             "dtype=dtype, " + "time_units=time_units)")
        MAKE_RTS = False
    except:
        print 'ERROR: Unable to open new netCDF file:'
        exec("print '      '," + ncgs_file_str)
        print ' '
        print 'Will write grid stack in generic RTS format.'
        print ' '
        MAKE_RTS = True

    #-------------------------------------------
    # Always save grid stacks in an RTS file ?
    #--------------------------------------------------
    # Note that if PyNIO is missing, we don't get
    # an exception above and MAKE_RTS is still False.
    #--------------------------------------------------
    MAKE_RTS = True  #####
    ##    print '#################################'
    ##    print 'MAKE_RTS =', MAKE_RTS
    ##    print '#################################'

    #---------------------------------
    # Build strings to be used below
    #---------------------------------
    rts_unit_str = "self." + var_name + "_rts_unit"
    rts_file_str = "self." + var_name + "_rts_file"
    gs_file_str = "self." + var_name + "_gs_file"

    #------------------------------------------
    # Open new RTS files to write grid stacks
    #------------------------------------------
    if (MAKE_RTS):
        try:
            exec(rts_file_str + "= file_utils.replace_extension(" +
                 gs_file_str + ", '.rts')")
            exec(rts_unit_str + " = rts_files.rts_file()")
            exec(rts_unit_str + ".open_new_file(" + rts_file_str +
                 ", self.rti, var_name, " + "dtype=dtype, " + "MAKE_BOV=True)")
        except:
            print 'ERROR: Unable to open new RTS file:'
            exec("print '      '," + rts_file_str)
            # exec( "print '      ', self." + var_name + "_rts_file" )
            print ' '
    def check_and_store_info(self,
                             file_name,
                             info=None,
                             grid_name='UNKNOWN',
                             dtype='float32',
                             MAKE_RTI=True,
                             MAKE_BOV=False):

        #-----------------------------------------------------
        # Note: This object (self) may be new or it may have
        #       been used previously.  In the latter case,
        #       "info" should still be available in "self".
        #       We only need info if MAKE_RTI or MAKE_BOV.
        #-----------------------------------------------------
        self.format = 'NCGS'
        self.file_name = file_name
        self.time_index = 0
        self.grid_name = grid_name

        #-----------------------------------------------------
        # This was used by rts_files.check_and_store_info()
        # but is not appropriate here because we need to
        # know nx, ny, dx and dy for the netCDF file.
        #-----------------------------------------------------
        ### if not(MAKE_RTI or MAKE_BOV): return

        #---------------------------------
        # Was "info" argument provided ?
        #---------------------------------
        NEW_INFO = True
        if (info is None):
            try:
                info = self.info
                self.nx = info.ncols  ###
                self.ny = info.nrows
                NEW_INFO = False
                ## print 'Found info in state.'
            except:
                #------------------------------------------
                # Try to find RTI file to copy info from.
                # Don't create a new RTI file.
                #------------------------------------------
                RTI_file = rti_files.try_to_find_rti_file(file_name)
                if (RTI_file != 'none'):
                    print 'Reading info from: ' + RTI_file
                    info = rti_files.read_info(RTI_file)
                else:
                    print 'ERROR during open_new_file():'
                    print '   Could not find RTI file and "info"'
                    print '   argument was not provided.'
                    print ' '
                    return

        #-----------------------------
        # Update "info" as necessary
        #-----------------------------
        info.grid_file = file_name
        info.data_type = rti_files.get_rti_data_type(dtype)
        info.data_source = 'TopoFlow 3.0'
        info.gmin = -9999.0
        info.gmax = -9999.0

        #---------------------------------------
        # If new "info" was provided, store it
        #---------------------------------------
        if (NEW_INFO):
            self.info = info
            self.nx = info.ncols
            self.ny = info.nrows
            ## print 'Stored new info in state.'

        #-------------------
        # Write RTI file ?
        #-------------------
        if (MAKE_RTI):
            prefix = rti_files.get_file_prefix(file_name)
            RTI_file = (prefix + '.rti')
            rti_files.write_info(RTI_file, info)
            # print 'Wrote grid info to: ' + RTI_file   ######

        #-------------------
        # Write BOV file ?
        #-------------------
        if (MAKE_BOV):
            bov_files.write_info_as_bov(file_name, info, grid_name)
Exemplo n.º 7
0
    def check_and_store_info(
        self, file_name, info=None, grid_name="UNKNOWN", dtype="float32", MAKE_RTI=True, MAKE_BOV=False
    ):

        # -----------------------------------------------------
        # Note: This object (self) may be new or it may have
        #       been used previously.  In the latter case,
        #       "info" should still be available in "self".
        #       We only need info if MAKE_RTI or MAKE_BOV.
        # -----------------------------------------------------
        self.format = "NCGS"
        self.file_name = file_name
        self.time_index = 0
        self.grid_name = grid_name

        # -----------------------------------------------------
        # This was used by rts_files.check_and_store_info()
        # but is not appropriate here because we need to
        # know nx, ny, dx and dy for the netCDF file.
        # -----------------------------------------------------
        ### if not(MAKE_RTI or MAKE_BOV): return

        # ---------------------------------
        # Was "info" argument provided ?
        # ---------------------------------
        NEW_INFO = True
        if info == None:
            try:
                info = self.info
                self.nx = info.ncols  ###
                self.ny = info.nrows
                NEW_INFO = False
                ## print 'Found info in state.'
            except:
                # ------------------------------------------
                # Try to find RTI file to copy info from.
                # Don't create a new RTI file.
                # ------------------------------------------
                RTI_file = rti_files.try_to_find_rti_file(file_name)
                if RTI_file != "none":
                    print "Reading info from: " + RTI_file
                    info = rti_files.read_info(RTI_file)
                else:
                    print "ERROR during open_new_file():"
                    print '   Could not find RTI file and "info"'
                    print "   argument was not provided."
                    print " "
                    return

        # -----------------------------
        # Update "info" as necessary
        # -----------------------------
        info.grid_file = file_name
        info.data_type = rti_files.get_rti_data_type(dtype)
        info.data_source = "TopoFlow 3.0"
        info.gmin = -9999.0
        info.gmax = -9999.0

        # ---------------------------------------
        # If new "info" was provided, store it
        # ---------------------------------------
        if NEW_INFO:
            self.info = info
            self.nx = info.ncols
            self.ny = info.nrows
            ## print 'Stored new info in state.'

        # -------------------
        # Write RTI file ?
        # -------------------
        if MAKE_RTI:
            prefix = rti_files.get_file_prefix(file_name)
            RTI_file = prefix + ".rti"
            rti_files.write_info(RTI_file, info)
            # print 'Wrote grid info to: ' + RTI_file   ######

        # -------------------
        # Write BOV file ?
        # -------------------
        if MAKE_BOV:
            bov_files.write_info_as_bov(file_name, info, grid_name)
Exemplo n.º 8
0
def open_new_gs_file(self,
                     file_name,
                     info=None,
                     var_name='X',
                     long_name='Unknown',
                     units_name='None',
                     dtype='float32',
                     time_units='minutes',
                     nx=None,
                     ny=None,
                     dx=None,
                     dy=None):

    #---------------------------
    # Was grid info provided ?
    #---------------------------
    if (info != None):
        info.file_name = file_name
        info.data_type = rti_files.get_rti_data_type(dtype)
        if (nx != None): info.ncols = nx
        if (ny != None): info.nrows = ny
        if (dx != None): info.xres = dx
        if (dy != None): info.yres = dy
    else:
        if (nx != None) and (ny != None) and \
           (dx != None) and (dy != None):
            info = rti_files.make_info(file_name, nx, ny, dx, dy)
        else:
            print 'ERROR during open_new_gs_file().'
            print '      Grid info not provided.'
            print ' '
            ## return -1

    #--------------------------------------------
    # Open new netCDF file to write grid stacks
    # using var_name to build variable names
    #--------------------------------------------
    try:
        ncgs_unit_str = "self." + var_name + "_ncgs_unit"
        ncgs_file_str = "self." + var_name + "_ncgs_file"
        gs_file_str = "self." + var_name + "_gs_file"

        exec(ncgs_file_str + "= file_utils.replace_extension(" + gs_file_str +
             ", '.nc')")
        exec(ncgs_unit_str + "=" + "ncgs_files.ncgs_file()")
        exec(ncgs_unit_str + ".open_new_file(" + ncgs_file_str +
             ", self.rti, var_name, long_name, units_name, " +
             "time_units=time_units)")
        MAKE_RTS = False
    except:
        print 'ERROR: Unable to open new netCDF file:'
        exec("print '      ', self." + var_name + "_ncgs_file")
        print ' '
        print 'Will write grid stack in generic RTS format.'
        print ' '
        MAKE_RTS = True

    #-------------------------------------------
    # Always save grid stacks in an RTS file ?
    #-------------------------------------------
    MAKE_RTS = True  #####

    #------------------------------------------
    # Open new RTS files to write grid stacks
    #------------------------------------------
    if (MAKE_RTS):
        try:
            rts_unit_str = "self." + var_name + "_rts_unit"
            rts_file_str = "self." + var_name + "_rts_file"
            gs_file_str = "self." + var_name + "_gs_file"

            exec(rts_file_str + "= file_utils.replace_extension(" +
                 gs_file_str + ", '.rts')")
            exec(rts_unit_str + " = rts_files.rts_file()")
            exec(rts_unit_str + ".open_new_file(" + rts_file_str +
                 ", self.rti, var_name, MAKE_BOV=True)")
        except:
            print 'ERROR: Unable to open new RTS file:'
            exec("print '      ', self." + var_name + "_rts_file")
            print ' '
Exemplo n.º 9
0
def open_new_gs_file(self, file_name, info=None,
                     var_name='X',
                     long_name='Unknown',
                     units_name='None',
                     dtype='float32',
                     time_units='minutes',
                     nx=None, ny=None, dx=None, dy=None):

    #---------------------------
    # Was grid info provided ?
    #---------------------------
    if (info is not None):
        info.file_name = file_name
        info.data_type = rti_files.get_rti_data_type( dtype )
        if (nx is not None): info.ncols = nx
        if (ny is not None): info.nrows = ny
        if (dx is not None): info.xres  = dx
        if (dy is not None): info.yres  = dy
    else:
        if (nx is not None) and (ny is not None) and \
           (dx is not None) and (dy is not None):
            info = rti_files.make_info( file_name, nx, ny, dx, dy )
        else:
            print 'ERROR during open_new_gs_file().'
            print '      Grid info not provided.'
            print ' '
            ## return -1
        
    #--------------------------------------------
    # Open new netCDF file to write grid stacks
    # using var_name to build variable names
    #--------------------------------------------
    try:
        ncgs_unit_str = "self." + var_name + "_ncgs_unit"
        ncgs_file_str = "self." + var_name + "_ncgs_file"
        gs_file_str   = "self." + var_name + "_gs_file"
            
        exec( ncgs_file_str + "= file_utils.replace_extension(" +
              gs_file_str + ", '.nc')" )
        exec( ncgs_unit_str + "=" + "ncgs_files.ncgs_file()" )
        exec( ncgs_unit_str + ".open_new_file(" + ncgs_file_str +
              ", self.rti, var_name, long_name, units_name, " +
              "time_units=time_units)" )
        MAKE_RTS = False
    except:
        print 'ERROR: Unable to open new netCDF file:'
        exec( "print '      ', self." + var_name + "_ncgs_file" )
        print ' '
        print 'Will write grid stack in generic RTS format.'
        print ' '
        MAKE_RTS = True

    #-------------------------------------------
    # Always save grid stacks in an RTS file ?
    #-------------------------------------------
    MAKE_RTS = True   #####
    
    #------------------------------------------
    # Open new RTS files to write grid stacks
    #------------------------------------------
    if (MAKE_RTS):
        try:
            rts_unit_str = "self." + var_name + "_rts_unit"
            rts_file_str = "self." + var_name + "_rts_file"
            gs_file_str  = "self." + var_name + "_gs_file"
            
            exec( rts_file_str + "= file_utils.replace_extension(" +
                  gs_file_str + ", '.rts')" )
            exec( rts_unit_str + " = rts_files.rts_file()" )
            exec( rts_unit_str + ".open_new_file(" + rts_file_str +
                  ", self.rti, var_name, MAKE_BOV=True)" )
        except:
            print 'ERROR: Unable to open new RTS file:'
            exec( "print '      ', self." + var_name + "_rts_file" )
            print ' '