Changeset 3832f27 in sasmodels
- Timestamp:
- May 4, 2016 8:04:45 PM (9 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 47e498b
- Parents:
- 5a91c6b
- Location:
- sasmodels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/generate.py
r81ec7c8 r3832f27 215 215 import warnings 216 216 from collections import namedtuple 217 import inspect 217 218 218 219 import numpy as np … … 460 461 461 462 # Load additional sources 462 source = [open(f).read() for f in model_sources(model_info)] 463 source = [p 464 for f in model_sources(model_info) 465 # Add #line directives at the start of each file 466 for p in ('#line 0 "%s"'%f, open(f).read()) 467 ] 468 source.append('#line 133 "%s"'%C_KERNEL_TEMPLATE_PATH) 463 469 464 470 # Prepare defines … … 498 504 double form_volume(VOLUME_PARAMETER_DECLARATIONS); 499 505 double form_volume(VOLUME_PARAMETER_DECLARATIONS) { 506 #line %(line)d "%(file)s" 500 507 %(body)s 501 508 } 502 """ % {'body':model_info['form_volume']} 509 """ % {'body':model_info['form_volume'], 510 'file':model_info['filename'], 511 'line':model_info['form_volume_line'], 512 } 503 513 source.append(fn) 504 514 … … 527 537 double Iq(double q, IQ_PARAMETER_DECLARATIONS); 528 538 double Iq(double q, IQ_PARAMETER_DECLARATIONS) { 539 #line %(line)d "%(file)s" 529 540 %(body)s 530 541 } 531 """ % {'body':model_info['Iq']} 542 """ % {'body':model_info['Iq'], 543 'file':model_info['filename'], 544 'line':model_info['Iq_line'], 545 } 532 546 source.append(fn) 533 547 … … 556 570 double Iqxy(double qx, double qy, IQXY_PARAMETER_DECLARATIONS); 557 571 double Iqxy(double qx, double qy, IQXY_PARAMETER_DECLARATIONS) { 572 #line %(line)d "%(file)s" 558 573 %(body)s 559 574 } 560 """ % {'body':model_info['Iqxy']} 575 """ % {'body':model_info['Iqxy'], 576 'file':model_info['filename'], 577 'line':model_info['Iqxy_line'], 578 } 561 579 source.append(fn) 562 580 … … 655 673 kernel_module = getattr(models, model_name, None) 656 674 return kernel_module 675 676 def find_source_lines(model_info, kernel_module): 677 """ 678 Identify the location of the C source inside the model definition file. 679 680 This code runs through the source of the kernel module looking for 681 lines that start with 'Iq', 'Iqxy' or 'form_volume'. Clearly there are 682 all sorts of reasons why this might not work (e.g., code commented out 683 in a triple-quoted line block, code built using string concatenation, 684 or code defined in the branch of an 'if' block), but it should work 685 properly in the 95% case, and getting the incorrect line number will 686 be harmless. 687 """ 688 # Check if we need line numbers at all 689 if callable(model_info['Iq']): 690 return None 691 692 if (model_info['Iq'] is None 693 and model_info['Iqxy'] is None 694 and model_info['form_volume'] is None): 695 return 696 697 # Make sure we have harmless default values 698 model_info['Iqxy_line'] = 0 699 model_info['Iq_line'] = 0 700 model_info['form_volume_line'] = 0 701 702 # find the defintion lines for the different code blocks 703 source = inspect.getsource(kernel_module) 704 for k, v in enumerate(source.split('\n')): 705 if v.startswith('Iqxy'): 706 model_info['Iqxy_line'] = k+1 707 elif v.startswith('Iq'): 708 model_info['Iq_line'] = k+1 709 elif v.startswith('form_volume'): 710 model_info['form_volume_line'] = k+1 657 711 658 712 … … 726 780 functions = "ER VR form_volume Iq Iqxy shape sesans".split() 727 781 model_info.update((k, getattr(kernel_module, k, None)) for k in functions) 782 find_source_lines(model_info, kernel_module) 728 783 return model_info 729 784 -
sasmodels/kernel_template.c
r2a55a6f r3832f27 1 #line 1 "kernel_template.c" 1 2 // GENERATED CODE --- DO NOT EDIT --- 2 3 // Code is produced by sasmodels.gen from sasmodels/models/MODEL.c
Note: See TracChangeset
for help on using the changeset viewer.