Changeset 2508
- Timestamp:
- Mar 9, 2006, 12:25:31 PM (19 years ago)
- Location:
- inundation
- Files:
-
- 3 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/util.py
r2314 r2508 48 48 49 49 from utilities.polygon import Polygon_function #No warning 50 from utilities.numerical_tools import gradient, gradient2, gradient_python #No warning 51 50 52 51 53 … … 547 549 548 550 549 #################################################################### 550 #Python versions of function that are also implemented in util_gateway.c 551 # 552 553 def gradient_python(x0, y0, x1, y1, x2, y2, q0, q1, q2): 554 """ 555 """ 556 557 det = (y2-y0)*(x1-x0) - (y1-y0)*(x2-x0) 558 a = (y2-y0)*(q1-q0) - (y1-y0)*(q2-q0) 559 a /= det 560 561 b = (x1-x0)*(q2-q0) - (x2-x0)*(q1-q0) 562 b /= det 563 564 return a, b 565 566 567 def gradient2_python(x0, y0, x1, y1, q0, q1): 568 """Compute radient based on two points and enforce zero gradient 569 in the direction orthogonal to (x1-x0), (y1-y0) 570 """ 571 572 #Old code 573 #det = x0*y1 - x1*y0 574 #if det != 0.0: 575 # a = (y1*q0 - y0*q1)/det 576 # b = (x0*q1 - x1*q0)/det 577 578 #Correct code (ON) 579 det = (x1-x0)**2 + (y1-y0)**2 580 if det != 0.0: 581 a = (x1-x0)*(q1-q0)/det 582 b = (y1-y0)*(q1-q0)/det 583 584 return a, b 585 586 587 ############################################## 588 #Initialise module 589 590 from utilities import compile 591 if compile.can_use_C_extension('util_ext.c'): 592 from util_ext import gradient, gradient2#, point_on_line 593 #separate_points_by_polygon = separate_points_by_polygon_c 594 else: 595 gradient = gradient_python 596 gradient2 = gradient2_python 597 598 599 if __name__ == "__main__": 600 pass 601 602 603 604 551 552 553 -
inundation/utilities/compile.py
r1980 r2508 156 156 # 157 157 if sys.platform == 'win32': #Windows 158 include = os.path.join(sys.exec_prefix, 'include')158 python_include = os.path.join(sys.exec_prefix, 'include') 159 159 else: 160 include = os.path.join(os.path.join(sys.exec_prefix, 'include'), 161 'python' + version) 162 163 #FIXME: Add path to includelist (see ticket:31) 164 160 python_include = os.path.join(os.path.join(sys.exec_prefix, 'include'), 161 'python' + version) 162 165 163 # Check existence of Python.h 166 164 # 167 headerfile = include + os.sep + 'Python.h'165 headerfile = python_include + os.sep + 'Python.h' 168 166 try: 169 167 open(headerfile, 'r') … … 173 171 In debian linux, for example, you need to install a 174 172 package called something like python2.3-dev""" %headerfile 173 174 175 176 #Add Python path + utilities to includelist (see ticket:31) 177 #Assume there is only one utilities dir under path dirs 178 179 utilities_include_dir = None 180 for pathdir in sys.path: 181 utilities_include_dir = pathdir + os.sep + 'utilities' 182 183 try: 184 os.stat(utilities_include_dir) 185 except OSError: 186 pass 187 else: 188 #print 'Found %s to be used as include dir' %utilities_include_dir 189 break 190 191 192 193 194 175 195 176 196 … … 186 206 187 207 try: 188 open(FN,'r') 189 except: 208 open(FN, 'r') 209 except: 210 #print 'CWD:', os.getcwd() 190 211 raise Exception, "Could not open: " + FN 191 212 … … 196 217 # Compile 197 218 # 198 s = "%s -c %s -I%s -o %s.o -Wall -O3" %(compiler, FN, include, root) 219 if utilities_include_dir is None: 220 s = '%s -c %s -I%s -o %s.o -Wall -O3'\ 221 %(compiler, FN, python_include, root) 222 else: 223 s = '%s -c %s -I%s -I%s -o %s.o -Wall -O3'\ 224 %(compiler, FN, python_include, utilities_include_dir, root) 199 225 200 226 if os.name == 'posix' and os.uname()[4] == 'x86_64': … … 262 288 else: 263 289 print '------- Trying to compile c-extension %s' %filename 264 290 291 #compile(filename) 265 292 try: 266 293 compile(filename) … … 320 347 pass 321 348 322 print '--------------- Trying to compile c-extension %s' %filename 349 print '--------------------------------------' 350 print 'Trying to compile c-extension %s in %s'\ 351 %(filename, os.getcwd()) 352 323 353 try: 324 354 compile(filename) 325 except :326 print 'Could not compile C extension %s' %filename 355 except Exception, e: 356 print 'Could not compile C extension %s' %filename 327 357 else: 328 358 print 'C extension %s OK' %filename -
inundation/utilities/numerical_tools.py
r2040 r2508 124 124 125 125 126 #################################################################### 127 #Python versions of function that are also implemented in numerical_tools_ext.c 128 # 129 130 def gradient_python(x0, y0, x1, y1, x2, y2, q0, q1, q2): 131 """ 132 """ 133 134 det = (y2-y0)*(x1-x0) - (y1-y0)*(x2-x0) 135 a = (y2-y0)*(q1-q0) - (y1-y0)*(q2-q0) 136 a /= det 137 138 b = (x1-x0)*(q2-q0) - (x2-x0)*(q1-q0) 139 b /= det 140 141 return a, b 142 143 144 def gradient2_python(x0, y0, x1, y1, q0, q1): 145 """Compute radient based on two points and enforce zero gradient 146 in the direction orthogonal to (x1-x0), (y1-y0) 147 """ 148 149 #Old code 150 #det = x0*y1 - x1*y0 151 #if det != 0.0: 152 # a = (y1*q0 - y0*q1)/det 153 # b = (x0*q1 - x1*q0)/det 154 155 #Correct code (ON) 156 det = (x1-x0)**2 + (y1-y0)**2 157 if det != 0.0: 158 a = (x1-x0)*(q1-q0)/det 159 b = (y1-y0)*(q1-q0)/det 160 161 return a, b 162 163 164 ############################################## 165 #Initialise module 166 167 from utilities import compile 168 if compile.can_use_C_extension('util_ext.c'): 169 from util_ext import gradient, gradient2#, point_on_line 170 else: 171 gradient = gradient_python 172 gradient2 = gradient2_python 173 174 175 if __name__ == "__main__": 176 pass 177
Note: See TracChangeset
for help on using the changeset viewer.