Changeset 4699 for nappy


Ignore:
Timestamp:
22/12/08 22:37:11 (11 years ago)
Author:
astephen
Message:

Various nappy updates to improve comments and combining them with inserted comments.

Location:
nappy/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/nappy.ini

    r4693 r4699  
    44default_delimiter = __space____space____space____space__ 
    55default_float_format = %g 
    6 comment_override_rule = extend 
     6comment_override_rule = insert  
    77add_column_headers = True 
    88annotations_file = annotations.ini 
     
    1010 
    1111[header_partitions] 
    12 sc_start = "=== Special Comments follow ===" 
    13 sc_end = "=== Special Comments end ===" 
    14 nc_start = "=== Normal Comments follow ===" 
    15 nc_end = "=== Normal Comments end ===" 
     12sc_start = "==== Special Comments follow ====" 
     13sc_end = "==== Special Comments end ====" 
     14nc_start = "==== Normal Comments follow ====" 
     15nc_end = "==== Normal Comments end ====" 
    1616data_next = "=== Data Section begins on the next line ===" 
    17 sing_start = "=== Singleton Variables defined in the source file follow ===" 
    18 sing_end = "=== Singleton Variables defined in the source file end ===" 
    19 ncatts_start = "=== Variable attributes from source (NetCDF) file follow ===" 
    20 ncatts_end = "=== Variable attributes from source (NetCDF) file end ===" 
    21 addl_globals = "Additional Global Attributes defined in the source file and not translated elsewhere:" 
    22 addl_vatts = "Additional Variable Attributes defined in the source file and not translated elsewhere:" 
     17sing_start = "== Singleton Variables defined in the source file follow ==" 
     18sing_end = "== Singleton Variables defined in the source file end ==" 
     19ncatts_start = "== Variable attributes from source (NetCDF) file follow ==" 
     20ncatts_end = "== Variable attributes from source (NetCDF) file end ==" 
     21addl_globals = "=== Additional Global Attributes defined in the source file ===" 
     22addl_vatts = "=== Additional Variable Attributes defined in the source file ===" 
    2323 
    2424[na_to_nc_map] 
  • nappy/trunk/nappy/nc_interface/na_content_collector.py

    r4698 r4699  
    731731                print msg 
    732732                self.output_message.append(msg) 
    733                 self.na_dict["DATE"] = [-999] * 3  
     733                self.na_dict["DATE"] = [999] * 3  
    734734        else:  
    735735            if not self.na_dict.has_key("DATE"): 
     
    737737                print msg 
    738738                self.output_message.append(msg) 
    739                 self.na_dict["DATE"] = [-999] * 3  
     739                self.na_dict["DATE"] = [999] * 3  
    740740            else: 
    741741                pass # i.e. use existing DATE 
  • nappy/trunk/nappy/nc_interface/nc_to_na.py

    r4693 r4699  
    4444add_column_headers = bool(nappy.utils.getDefault("add_column_headers")) 
    4545 
     46config_dict = nappy.utils.getConfigDict() 
     47header_partitions = config_dict["header_partitions"] 
     48hp = header_partitions 
     49 
    4650# Define global variables 
    4751permitted_overwrite_metadata = ("DATE",  "RDATE", "ANAME", "MNAME", 
     
    188192                        if comment_override_rule == "replace": 
    189193                            comments_list = new_item[:] 
    190                         elif comment_override_rule == "insert": 
    191                             comments_list = new_item[:] + this_na_dict.get(key, []) 
     194                        elif comment_override_rule in ("insert", "extend"): 
     195                            comments_list = self._cleanWrapComments(existing_comments, new_comments, key, comment_override_rule) 
     196                        else: 
     197                            raise Exception("Did not recognise comment_override_rule: " + str(comment_override_rule)) 
     198 
     199                        """elif comment_override_rule == "insert": 
     200                            new_comments = new_items[:] 
     201                            existing_comments = this_na_dict.get(key, []) 
     202                            comments_list = self._cleanWrapComments(existing_comments, new_comments, key, comment_override_rule) 
     203                            #comments_list = new_item[:] + this_na_dict.get(key, []) 
    192204                        elif comment_override_rule == "extend":  
    193                             comments_list = this_na_dict.get(key, []) + new_item[:] 
     205                            comments_list = this_na_dict.get(key, []) + new_item[:]  """ 
    194206 
    195207                        this_na_dict[key] = comments_list 
     
    225237 
    226238            # Report on what has been written 
    227             msg = "\nWrote the following variables:" + "\n\t" + ("\n\t".join(vars_to_write[0])) 
     239            msg = "\nWrote the following variables:" + "\n  " + ("\n  ".join(vars_to_write[0])) 
    228240            if DEBUG: print msg 
    229241            self.output_message.append(msg) 
     
    232244            aux_var_count = vars_to_write[1] 
    233245            if len(aux_var_count) > 0: 
    234                 msg = "\nWrote the following auxiliary variables:" + "\n\t" + ("\n\t".join(aux_var_count))       
     246                msg = "\nWrote the following auxiliary variables:" + "\n  " + ("\n  ".join(aux_var_count))       
    235247             
    236248            singleton_var_count = vars_to_write[2] 
    237249            if len(singleton_var_count) > 0: 
    238                 msg = "\nWrote the following Singleton variables:" + "\n\t" + ("\n\t".join(singleton_var_count)) 
     250                msg = "\nWrote the following Singleton variables:" + "\n  " + ("\n  ".join(singleton_var_count)) 
    239251 
    240252            if len(file_list) > 0: 
     
    348360        na_dict["NNCOML"] = len(na_dict["NCOM"]) 
    349361        return   
     362 
     363 
     364    def _cleanWrapComments(self, existing_comments, new_comments, key, comment_override_rule): 
     365        """ 
     366        Combines new_comments with existing_comments where comments are 
     367        either Special or Normal. 'key' defines this being defined as either 
     368        "SCOM" or "NCOM". 'comment_override_rule' is either "insert" (new_comments first) 
     369        or "extend" (existing_comments first). 
     370        Returns a new list of combined_comments. 
     371        """ 
     372        # Strip start header if used 
     373        c1 = key[0].lower() 
     374        start_line = hp[c1 + "c_start"] 
     375        start_used = False 
     376 
     377        if existing_comments[0] == start_line: 
     378            existing_comments = existing_comments[1:] 
     379            start_used = start_line 
     380         
     381        # Now check last line 
     382        end_line = hp[c1 + "c_end"] 
     383        end_used = False 
     384 
     385        if existing_comments[-1] == end_line: 
     386            existing_comments = existing_comments[:-1] 
     387            end_used = end_line 
     388 
     389        # Check for alternative last line in NCOM 
     390        if end_used == False and key == "NCOM": 
     391            end_line2 = hp["data_next"] 
     392            if existing_comments[-1] == end_line2: 
     393                existing_comments = existing_comments[:-1] 
     394                end_used = end_line2  
     395        
     396        # Now put back together 
     397        ordered_comments = [existing_comments, new_comments] 
     398        if comment_override_rule == "insert": 
     399            ordered_comments.reverse()  
     400 
     401        combined_comments = ordered_comments[0] + ordered_comments[1] 
     402        if start_used: 
     403            combined_comments.insert(0, start_used) 
     404        if end_used: 
     405            combined_comments.append(end_used) 
     406     
     407        return combined_comments 
     408 
Note: See TracChangeset for help on using the changeset viewer.