Changeset d9341fa in sasmodels


Ignore:
Timestamp:
Dec 18, 2017 11:01:30 AM (7 years ago)
Author:
Omer Eisenberg <omereis@…>
Children:
5c2a0f2
Parents:
98a4f14
Message:

writing constants to sniplets in 'add_constants'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/py2c.py

    r98a4f14 rd9341fa  
    11001100        print(tree_source) 
    11011101 
     1102def add_constants (sniplets, c_constants): 
     1103    sniplets.append("#include <math.h>") 
     1104    sniplets.append("") 
     1105    vars = c_constants.keys() 
     1106    for c_var in vars: 
     1107        declare_values = str(c_constants[c_var]) 
     1108        if (hasattr(declare_values,'__len__')): 
     1109            declare_values = declare_values.replace ('  ',' ') 
     1110            declare_values = declare_values.replace ('[ ','[') 
     1111            declare_values = declare_values.replace (' ]',']') 
     1112            declare_values = declare_values.replace (' ',',') 
     1113        str_dcl = "double " + c_var 
     1114        str_dcl += " = " + declare_values + ";" 
     1115        sniplets.append (str_dcl) 
     1116        sniplets.append("") 
     1117 
    11021118def translate(functions, constants=0): 
    11031119    sniplets = [] 
    1104     sniplets.append("#include <math.h>") 
    1105     sniplets.append("static double pi = 3.14159265359;") 
     1120#    sniplets.append("#include <math.h>") 
     1121#    sniplets.append("static double pi = 3.14159265359;") 
     1122    add_constants (sniplets, constants) 
    11061123    for source,fname,line_no in functions: 
    11071124        line_directive = '#line %d "%s"' %(line_no,fname) 
Note: See TracChangeset for help on using the changeset viewer.