- Timestamp:
- Jun 16, 2016, 4:47:47 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r832 r837 19 19 20 20 ####### Content 21 # CFvar_MODvar: Function to provide which model values can provide a CF-variable from ASCII file 21 22 # chainSnumHierarchy: Class to provide the structure of a `ChainStrNum' hierarchy 22 23 # chainSnum_levnext: Function to provide the next value for a given level from a chainStrnum hirerarchy of numbers … … 41 42 # vals_around: Function to provide the 3x3 values around a given j,i point 42 43 44 def searchInlist(listname, nameFind): 45 """ Function to search a value within a list 46 listname = list 47 nameFind = value to find 48 >>> searInlist(['1', '2', '3', '5'], '5') 49 True 50 """ 51 for x in listname: 52 if x == nameFind: 53 return True 54 return False 55 43 56 def values_line(line, splitv, chars): 44 57 """ Function to retrieve values from a line of ASCII text removing a series of characters … … 251 264 if idate == 'h': 252 265 print fname + '_____________________________________________________________' 253 print variables_values.__doc__266 print period_information.__doc__ 254 267 quit() 255 268 … … 552 565 553 566 return 567 568 def CFvar_MODvar(varn): 569 """ Function to provide which model values can provide a CF-variable from ASCII file 570 'variables_values.dat' 571 CFvar_MODvar(varName) 572 [varName]= name of the variable 573 >>> CFvar_MODvar('hfss') 574 ['hfss', 'LSENS', 'sens', 'HFX', 'hfx'] 575 >>> CFvar_MODvar('clm') 576 ['clm', 'cldm', 'LCLDM', 'Mid-level cloudiness'] 577 >>> CFvar_MODvar('pr') 578 ['pr', 'RAINTOT', 'precip', 'LPRECIP', 'Precip Totale liq+sol'] 579 """ 580 import subprocess as sub 581 582 fname='CFvar_MODvar' 583 584 if varn == 'h': 585 print fname + '_____________________________________________________________' 586 print CFvar_MODvar.__doc__ 587 quit() 588 589 folder = os.path.dirname(os.path.realpath(__file__)) 590 591 infile = folder + '/variables_values.dat' 592 593 if not os.path.isfile(infile): 594 print errormsg 595 print ' ' + fname + ": File '" + infile + "' does not exist !!" 596 quit(-1) 597 598 ncf = open(infile, 'r') 599 600 MODvars = [] 601 for line in ncf: 602 if line[0:1] != '#': 603 values = line.replace('\n','').split(',') 604 varvals = [values[1].replace(' ',''), values[2].replace(' ',''), \ 605 np.float(values[3]), np.float(values[4]),values[5].replace(' ',''), \ 606 values[6].replace(' ',''), values[7].replace(' ','')] 607 if varvals[0] == varn: MODvars.append(values[0]) 608 609 if len(MODvars) == 0: 610 print errormsg 611 print ' ' + fname + ": variable '" + varn + "' not defined !!!" 612 ncf.close() 613 return None 614 else: 615 return MODvars 616 617 print CFvar_MODvar('hfss') 618 print CFvar_MODvar('pr') 619 620 quit() 554 621 555 622 def variables_values_old(varName): … … 1419 1486 return end 1420 1487 1421 def searchInlist(listname, nameFind):1422 """ Function to search a value within a list1423 listname = list1424 nameFind = value to find1425 >>> searInlist(['1', '2', '3', '5'], '5')1426 True1427 """1428 for x in listname:1429 if x == nameFind:1430 return True1431 return False1432 1433 1488 def datetimeStr_datetime(StringDT): 1434 1489 """ Function to transform a string date ([YYYY]-[MM]-[DD]_[HH]:[MI]:[SS] format) to a date object
Note: See TracChangeset
for help on using the changeset viewer.