Changeset 2342 in lmdz_wrf
- Timestamp:
- Feb 15, 2019, 8:06:14 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2337 r2342 5046 5046 fname='typemod' 5047 5047 5048 if typeval == 'int' or typeval == 'I': 5049 return int(value) 5050 elif typeval == 'long': 5051 return long(value) 5052 elif typeval == 'float' or typeval == 'F' or typeval == 'R': 5053 return float(value) 5054 elif typeval == 'complex': 5055 return complex(value) 5056 elif typeval == 'str' or typeval == 'S': 5057 return str(value) 5058 elif typeval == 'bool': 5059 return bool(value) 5060 elif typeval == 'B': 5061 return Str_Bool(value) 5062 elif typeval == 'list': 5063 newval = [] 5064 newval.append(value) 5065 return newval 5066 elif typeval == 'dic': 5067 newval = {} 5068 newval[value] = value 5069 return newval 5070 elif typeval == 'tuple': 5071 newv = [] 5072 newv.append(value) 5073 newval = tuple(newv) 5074 return newval 5075 elif typeval == 'np.int8': 5076 return np.int8(value) 5077 elif typeval == 'np.int16': 5078 return np.int16(value) 5079 elif typeval == 'np.int32': 5080 return np.int32(value) 5081 elif typeval == 'np.int64': 5082 return np.int64(value) 5083 elif typeval == 'np.uint8': 5084 return np.uint8(value) 5085 elif typeval == 'np.uint16': 5086 return np.uint16(value) 5087 elif typeval == 'np.np.uint32': 5088 return np.uint32(value) 5089 elif typeval == 'np.uint64': 5090 return np.uint64(value) 5091 elif typeval == 'np.float' or typeval == 'R': 5092 return np.float(value) 5093 elif typeval == 'np.float16': 5094 return np.float16(value) 5095 elif typeval == 'np.float32': 5096 return np.float32(value) 5097 elif typeval == 'float32': 5098 return np.float32(value) 5099 elif typeval == 'np.float64' or typeval == 'D': 5100 return np.float64(value) 5101 elif typeval == 'float64': 5102 return np.float64(value) 5103 elif typeval == 'np.complex': 5104 return np.complex(value) 5105 elif typeval == 'np.complex64': 5106 return np.complex64(value) 5107 elif typeval == 'np.complex128': 5108 return np.complex128(value) 5048 if type(typeval) == type('S'): 5049 if typeval == 'int' or typeval == 'I': 5050 return int(value) 5051 elif typeval == 'long': 5052 return long(value) 5053 elif typeval == 'float' or typeval == 'F' or typeval == 'R': 5054 return float(value) 5055 elif typeval == 'complex': 5056 return complex(value) 5057 elif typeval == 'str' or typeval == 'S': 5058 return str(value) 5059 elif typeval == 'bool': 5060 return bool(value) 5061 elif typeval == 'B': 5062 return Str_Bool(value) 5063 elif typeval == 'list': 5064 newval = [] 5065 newval.append(value) 5066 return newval 5067 elif typeval == 'dic': 5068 newval = {} 5069 newval[value] = value 5070 return newval 5071 elif typeval == 'tuple': 5072 newv = [] 5073 newv.append(value) 5074 newval = tuple(newv) 5075 return newval 5076 elif typeval == 'np.int8': 5077 return np.int8(value) 5078 elif typeval == 'np.int16': 5079 return np.int16(value) 5080 elif typeval == 'np.int32': 5081 return np.int32(value) 5082 elif typeval == 'np.int64': 5083 return np.int64(value) 5084 elif typeval == 'np.uint8': 5085 return np.uint8(value) 5086 elif typeval == 'np.uint16': 5087 return np.uint16(value) 5088 elif typeval == 'np.uint32': 5089 return np.uint32(value) 5090 elif typeval == 'np.uint64': 5091 return np.uint64(value) 5092 elif typeval == 'np.float' or typeval == 'R': 5093 return np.float(value) 5094 elif typeval == 'np.float16': 5095 return np.float16(value) 5096 elif typeval == 'np.float32': 5097 return np.float32(value) 5098 elif typeval == 'float32': 5099 return np.float32(value) 5100 elif typeval == 'np.float64' or typeval == 'D': 5101 return np.float64(value) 5102 elif typeval == 'np.complex': 5103 return np.complex(value) 5104 elif typeval == 'np.complex64': 5105 return np.complex64(value) 5106 elif typeval == 'np.complex128': 5107 return np.complex128(value) 5108 else: 5109 print errormsg 5110 print fname + ': data type "' + typeval + '" is not ready !' 5111 print errormsg 5112 quit(-1) 5109 5113 else: 5110 print errormsg 5111 print fname + ': data type "' + typeval + '" is not ready !' 5112 print errormsg 5113 quit(-1) 5114 5114 if typeval == type(int(1)): 5115 return int(value) 5116 elif typeval == type(long(1)): 5117 return long(value) 5118 elif typeval == type(float(1.)): 5119 return float(value) 5120 elif typeval == type(complex(1)): 5121 return complex(value) 5122 elif typeval == type('s'): 5123 return str(value) 5124 elif typeval == type(False): 5125 return bool(value) 5126 elif typeval == type(list([1])): 5127 newval = [] 5128 newval.append(value) 5129 return newval 5130 elif typeval == type({1: 'dic'}): 5131 newval = {} 5132 newval[value] = value 5133 return newval 5134 elif typeval == type(tuple([1, 2])): 5135 newv = [] 5136 newv.append(value) 5137 newval = tuple(newv) 5138 return newval 5139 elif typeval == type(np.int8(1)): 5140 return np.int8(value) 5141 elif typeval == type(np.int16(1)): 5142 return np.int16(value) 5143 elif typeval == type(np.int32(1)): 5144 return np.int32(value) 5145 elif typeval == type(np.int64(1)): 5146 return np.int64(value) 5147 elif typeval == type(np.uint8(1)): 5148 return np.uint8(value) 5149 elif typeval == type(np.uint16(1)): 5150 return np.uint16(value) 5151 elif typeval == type(np.uint32(1)): 5152 return np.uint32(value) 5153 elif typeval == type(np.uint64(1)): 5154 return np.uint64(value) 5155 elif typeval == type(np.float(1.)): 5156 return np.float(value) 5157 elif typeval == type(np.float16(1.)): 5158 return np.float16(value) 5159 elif typeval == type(np.float32(1.)): 5160 return np.float32(value) 5161 elif typeval == type(float32(1.)): 5162 return np.float32(value) 5163 elif typeval == type(np.float64(1.)): 5164 return np.float64(value) 5165 elif typeval == type(np.complex(1.)): 5166 return np.complex(value) 5167 elif typeval == type(np.complex64(1.)): 5168 return np.complex64(value) 5169 elif typeval == type(np.complex128(1.)): 5170 return np.complex128(value) 5171 else: 5172 print errormsg 5173 print fname + ': data type "' + typeval + '" is not ready !' 5174 print errormsg 5175 quit(-1) 5176 5115 5177 return 5116 5178
Note: See TracChangeset
for help on using the changeset viewer.