Changeset 2800 in lmdz_wrf for trunk/tools
- Timestamp:
- Feb 11, 2020, 7:22:25 PM (5 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/create_OBSnetcdf.py
r2798 r2800 150 150 return finalist 151 151 152 def stringS_dictvar(stringv, Dc=',', DVs=':'): 153 """ Function to provide a dictionary from a String which list of DVs separated 154 [key] [value] couples 155 stringv: String with a dictionary content as [key1][DVs][val1][Dc][key2][DVs][Val2][Dc]... 156 Sc: character to separate key values 157 DVs: character to separate key-value couples 158 >>> stringS_dictvar('i:1,iv:4,vii:7',',',':') 159 {'i': '1', 'vii': '7', 'iv': '4'} 160 """ 161 fname = 'stringS_dictvar' 162 163 if stringv.count(Dc) != 0: 164 strvv = stringv.split(Dc) 165 else: 166 strvv = [stringv] 167 168 dictv = {} 169 for Svals in strvv: 170 keyn = Svals.split(DVs)[0] 171 valn = Svals.split(DVs)[1] 172 dictv[keyn] = valn 173 174 return dictv 152 175 153 176 def set_attribute(ncvar, attrname, attrvalue): … … 311 334 divc, divide by [val] 312 335 rmchar,[val],[pos], remove [val] characters from [pos]='B', beginning, 'E', end 336 repl,[char1]:[val1];...;[charM]:[valM], replace a given character [chari] 337 by a value [vali] 313 338 NAMElon=name of the variable with the longitude (x position) 314 339 NAMElat=name of the variable with the latitude (y position) … … 389 414 fname = 'value_fmt' 390 415 391 aopers = ['sumc','subc','mulc','divc', 'rmchar' ]416 aopers = ['sumc','subc','mulc','divc', 'rmchar', 'repl'] 392 417 393 418 fmts = ['D', 'F', 'I', 'I64', 'S'] … … 434 459 " work with '" + op.split(',')[2] + "' !!" 435 460 quit(-1) 461 436 462 elif fmt == 'F': 437 463 opv = np.float(operv) … … 454 480 455 481 elif fmt == 'I': 456 opv = int(operv) 457 if opern == 'sumc': newval = int(val) + opv 458 elif opern == 'subc': newval = int(val) - opv 459 elif opern == 'mulc': newval = int(val) * opv 460 elif opern == 'divc': newval = int(val) / opv 482 if opern == 'sumc': newval = int(val) + int(operv) 483 elif opern == 'subc': newval = int(val) - int(operv) 484 elif opern == 'mulc': newval = int(val) * int(operv) 485 elif opern == 'divc': newval = int(val) / int(operv) 461 486 elif opern == 'rmchar': 462 487 opv = int(operv) … … 471 496 " work with '" + op.split(',')[2] + "' !!" 472 497 quit(-1) 498 elif opern == 'repl': 499 replvals = stringS_dictvar(operv, Dc=';', DVs=':') 500 print replvals 501 replaced = False 502 for repls in replvals.keys(): 503 print operv, repls, operv == repls 504 if operv == repls: 505 newval = int(replvals[operv]) 506 replaced = True 507 break 508 print operv, 'replaced', replaced 509 if not replaced: newval = int(operv) 510 473 511 elif fmt == 'I64': 474 512 opv = np.int64(operv) -
trunk/tools/generic_tools.py
r2788 r2800 10593 10593 """ 10594 10594 fname = 'stringS_dictvar' 10595 10596 if stringv.count(Dc) != 0: 10597 strvv = stringv.split(Dc) 10598 else: 10599 strvv = [stringv] 10600 10595 10601 dictv = {} 10602 for Svals in strvv: 10596 10603 for Svals in stringv.split(Dc): 10597 10604 keyn = Svals.split(DVs)[0]
Note: See TracChangeset
for help on using the changeset viewer.