示例#1
0
 def setCommandKey(self,comm_key,star,key_type,star_key=None,\
                   alternative=None,make_int=0,exp_not=0):
     
     '''
     Try setting a key in the command_list from a star instance. 
     
     If the key is unknown, it is left open and will be filled in from the 
     standard gastronoom inputfile.
     
     @param comm_key: the name of the keyword in the command list
     @type comm_key: string
     @param star: The parameter set
     @type star: Star()
     @param key_type: the type of the keyword, either 'DUST' or 'GAS' 
     @type key_type: string
     
     @keyword star_key: the name of the keyword in the star instance 
                        (minus '_%s'%key_type, which is added as well in a 
                        second attempt if the first without the addition is 
                        not found), if None, it is equal to comm_key
                        
                        (default: None)
     @type star_key: string
     @keyword alternative: a default value passed from the standard 
                           inputfile that is used if the keyword or the 
                           keyword + '_%s'%key_type is not found in Star()
                            
                           (default: None)
     @type alternative: string
     @keyword make_int: make an integer before converting to string for this
                        keyword.
                        
                        (default: 0)
     @type make_int: boolean
     @keyword exp_not: Convert to exponential notation in a string
                       
                       (default: 0)
     @type exp_not: bool
     
     @return: True if successful, otherwise False.
     @rtype: bool
     
     ''' 
     
     if star_key is None: star_key = comm_key
     try:
         self.command_list[comm_key] = \
                     DataIO.inputToString(star[star_key],make_int,exp_not)
         return True
     except KeyError: 
         try:
             self.command_list[comm_key] = \
                     DataIO.inputToString(star[star_key+ '_%s'%key_type],\
                                          make_int,exp_not)
             return True
         except KeyError:
             if alternative <> None:
                 self.command_list[comm_key] = \
                     DataIO.inputToString(alternative,make_int,exp_not)
                 return True
             else:
                 return False
示例#2
0
    def setCommandKey(self,comm_key,star,key_type,star_key=None,\
                      alternative=None,make_int=0,exp_not=0):
        '''
        Try setting a key in the command_list from a star instance. 
        
        If the key is unknown, it is left open and will be filled in from the 
        standard gastronoom inputfile.
        
        @param comm_key: the name of the keyword in the command list
        @type comm_key: string
        @param star: The parameter set
        @type star: Star()
        @param key_type: the type of the keyword, either 'DUST' or 'GAS' 
        @type key_type: string
        
        @keyword star_key: the name of the keyword in the star instance 
                           (minus '_%s'%key_type, which is added as well in a 
                           second attempt if the first without the addition is 
                           not found), if None, it is equal to comm_key
                           
                           (default: None)
        @type star_key: string
        @keyword alternative: a default value passed from the standard 
                              inputfile that is used if the keyword or the 
                              keyword + '_%s'%key_type is not found in Star()
                               
                              (default: None)
        @type alternative: string
        @keyword make_int: make an integer before converting to string for this
                           keyword.
                           
                           (default: 0)
        @type make_int: boolean
        @keyword exp_not: Convert to exponential notation in a string
                          
                          (default: 0)
        @type exp_not: bool
        
        @return: True if successful, otherwise False.
        @rtype: bool
        
        '''

        if star_key is None: star_key = comm_key
        try:
            self.command_list[comm_key] = \
                        DataIO.inputToString(star[star_key],make_int,exp_not)
            return True
        except KeyError:
            try:
                self.command_list[comm_key] = \
                        DataIO.inputToString(star[star_key+ '_%s'%key_type],\
                                             make_int,exp_not)
                return True
            except KeyError:
                if alternative <> None:
                    self.command_list[comm_key] = \
                        DataIO.inputToString(alternative,make_int,exp_not)
                    return True
                else:
                    return False