Changeset 0bd0877 in sasmodels for sasmodels/py2c.py
- Timestamp:
- Jan 8, 2018 11:07:32 AM (7 years ago)
- Children:
- ff431ca
- Parents:
- 4339764
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/py2c.py
r4339764 r0bd0877 123 123 generator = SourceGenerator(constants=constants, fname=fname, lineno=lineno) 124 124 generator.visit(tree) 125 c_code = "\n".join(generator.c_proc)125 # c_code = "\n".join(generator.c_proc) 126 126 c_code = "".join(generator.c_proc) 127 127 return (c_code, generator.warnings) … … 1280 1280 return valid_params, fname_in,fname_out 1281 1281 1282 C_HEADER = """ 1283 #include <stdio.h> 1284 #include <stdbool.h> 1285 #include <math.h> 1286 #define constant const 1287 double square(double x) { return x*x; } 1288 double cube(double x) { return x*x*x; } 1289 double polyval(constant double *coef, double x, int N) 1290 { 1291 int i = 0; 1292 double ans = coef[0]; 1293 1294 while (i < N) { 1295 ans = ans * x + coef[i++]; 1296 } 1297 1298 return ans; 1299 } 1300 """ 1282 1301 def main(): 1283 1302 print("Parsing...using Python" + sys.version) … … 1293 1312 .replace(name+'.n', 'GAUSS_N') 1294 1313 .replace(name+'.z', 'GAUSS_Z') 1295 .replace(name+'.w', 'GAUSS_W')) 1296 1314 .replace(name+'.w', 'GAUSS_W') 1315 .replace('if __name__ == "__main__"', "def main()") 1316 ) 1297 1317 translation,warnings = translate([(code, fname_in, 1)]) 1318 translation = translation.replace("double main()", "int main(int argc, char *argv[])") 1298 1319 1299 1320 with open(fname_out, "w") as file_out: 1321 file_out.write(C_HEADER) 1300 1322 file_out.write(str(translation)) 1301 1323 if warnings:
Note: See TracChangeset
for help on using the changeset viewer.