Changeset 1753 in lmdz_wrf
- Timestamp:
- Dec 21, 2017, 3:57:15 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r1752 r1753 27 27 fillValueD = 1.e20 28 28 fillValueC = '-' 29 fillValueS = '-' 30 fillValueB = 'None' 29 31 fillValueI = -99999 30 32 fillValueI16 = -99999 … … 82 84 # get_configuration: Function to get the configuration from an ASCII external file 83 85 # get_specdictionary_HMT: Function to get specific values from a dictionary by selcting that keys with H*M*T 86 # getting_fixedline: Function to get the values from a line of text with fixed lenght of different values 84 87 # grib_CFequiv: Function to provide the CF name of a GRIB variable code number 85 88 # ijlonlat: Function to provide the imin,jmin imax,jmax of a lon,lat box … … 4689 4692 fname='typemod' 4690 4693 4691 if typeval == 'int' :4694 if typeval == 'int' or typeval == 'I': 4692 4695 return int(value) 4693 4696 elif typeval == 'long': … … 4701 4704 elif typeval == 'bool': 4702 4705 return bool(value) 4706 elif typeval == 'B': 4707 return Str_Bool(value) 4703 4708 elif typeval == 'list': 4704 4709 newval = [] … … 4738 4743 elif typeval == 'float32': 4739 4744 return np.float32(value) 4740 elif typeval == 'np.float64' :4745 elif typeval == 'np.float64' or typeval == 'D': 4741 4746 return np.float64(value) 4742 4747 elif typeval == 'float64': … … 12546 12551 return narray 12547 12552 12553 def getting_fixedline(line, cuts, types): 12554 """ Function to get the values from a line of text with fixed lenght of different values 12555 line: line with values 12556 cuts: character number where a value ends 12557 types: consecutive type of values 12558 'I': integer 12559 'R': real 12560 'D': float64 12561 'S': string 12562 'B': boolean 12563 >>> Sline=' 87007 03012015 25.6 6.4 9.4 5 15' 12564 >>> getting_fixedline(Sline, [8, 17, 23, 29, 36, 40, 45, 50], ['I', 'R', 'R', 'R', 'I', 'R', 'R', 'R']) 12565 [87007, 3012015.0, 25.6, 6.4, -99999, -99999, 9.4, 5.0, 15.0] 12566 """ 12567 fname = 'getting_fixedline' 12568 12569 values = [] 12570 val = line[0:cuts[0]+1] 12571 if len(val.replace(' ','')) >= 1: 12572 values.append(typemod(val, types[0])) 12573 else: 12574 if types[0] == 'I': values.append(fillValueI) 12575 elif types[0] == 'R': values.append(fillValueF) 12576 elif types[0] == 'D': values.append(fillValueF) 12577 elif types[0] == 'S': values.append(fillValueS) 12578 elif types[0] == 'B': values.append(fillValueB) 12579 12580 Ncuts = len(cuts) 12581 for ic in range(1,Ncuts): 12582 val = line[cuts[ic-1]:cuts[ic]+1] 12583 print 'Lluis val:', val 12584 if len(val.replace(' ','')) >= 1: 12585 values.append(typemod(val, types[ic])) 12586 else: 12587 if types[0] == 'I': values.append(fillValueI) 12588 elif types[0] == 'R': values.append(fillValueF) 12589 elif types[0] == 'D': values.append(fillValueF) 12590 elif types[0] == 'S': values.append(fillValueS) 12591 elif types[0] == 'B': values.append(fillValueB) 12592 12593 # Last value 12594 Lline = len(line) 12595 val = line[cuts[Ncuts-1]:Lline] 12596 if len(val.replace(' ','')) >= 1: 12597 values.append(typemod(val, types[Ncuts-1])) 12598 else: 12599 if types[0] == 'I': values.append(fillValueI) 12600 elif types[0] == 'R': values.append(fillValueF) 12601 elif types[0] == 'D': values.append(fillValueF) 12602 elif types[0] == 'S': values.append(fillValueS) 12603 elif types[0] == 'B': values.append(fillValueB) 12604 12605 return values 12606 12548 12607 #quit() 12549 12608
Note: See TracChangeset
for help on using the changeset viewer.