New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 4137 – NEMO

Changeset 4137


Ignore:
Timestamp:
2013-10-25T16:06:26+02:00 (11 years ago)
Author:
andrewryan
Message:

added a verbose option to quick script which shows the updates the script has made to the namelist

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2013/dev_r3987_UKMO4_OBS/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/ooo.py

    r4136 r4137  
    2525    parser.add_argument("--dry-run", action="store_true", 
    2626                        help="Flag to test namelist building without submitting.") 
     27    parser.add_argument("-v", "--verbose", action="store_true", 
     28                        help="Prints difference between before and after namelists.") 
    2729    parser.add_argument("namelist", metavar="NAMELIST",  
    2830                        help="NEMO namelist to edit.") 
     
    3234    args.lead_times = map(int, args.lead_times.split(',')) 
    3335    return args 
     36 
     37def printdiff(text1, text2): 
     38    # Provides nice text difference summary of namelists 
     39    import difflib 
     40    lines1 = text1.splitlines() 
     41    lines2 = text2.splitlines() 
     42    d = difflib.Differ() 
     43    result = list(d.compare(lines1, lines2)) 
     44    text = '\n'.join(result) 
     45    print text 
    3446 
    3547def main(): 
     
    5365    text = nml.reader(args.namelist) 
    5466    sublists = nml.namelists(text) 
     67 
     68    # Verbose save original text 
     69    if args.verbose: 
     70        original_text = text 
    5571 
    5672    # namooo 
     
    87103    text = nml.update("namobs", text, data=namobs) 
    88104 
     105    # Verbose print namelist differences 
     106    if args.verbose: 
     107        printdiff(original_text, text) 
     108 
    89109    # pipe text to file 
    90110    tmp = args.namelist+".tmp" 
Note: See TracChangeset for help on using the changeset viewer.