1 | #!/usr/bin/env python |
---|
2 | ## \mainpage DANSE wrapper code for IGOR |
---|
3 | # |
---|
4 | # \section intro_sec Introduction |
---|
5 | # This module provides automatically generated code to help |
---|
6 | # use DANSE code in third party software like IGOR. |
---|
7 | # |
---|
8 | # Look under the Files tab of the Doxygen information |
---|
9 | # for details about the models. |
---|
10 | # |
---|
11 | """ |
---|
12 | @copyright 2007: University of Tennessee, for the DANSE project |
---|
13 | """ |
---|
14 | |
---|
15 | import os |
---|
16 | |
---|
17 | def write_header(path = 'src'): |
---|
18 | """ |
---|
19 | Write a header file that imports all the header files in a directory |
---|
20 | @param path: include path to analyze |
---|
21 | """ |
---|
22 | |
---|
23 | # Write a line for each file |
---|
24 | # "double oriented_[C_FILENAME]_2D(double pars[], double q, double phi)" |
---|
25 | #double disperse_cylinder_analytical_2D(double dp[], double q, double phi) { |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | headerfile = open('include/danse.h', 'w') |
---|
30 | template = open("templates/function_header_template.h", 'r') |
---|
31 | |
---|
32 | tmp_buf = template.read() |
---|
33 | tmp_lines = tmp_buf.split('\n') |
---|
34 | |
---|
35 | # Get header file list |
---|
36 | file_list = os.listdir(path) |
---|
37 | func_list = '' |
---|
38 | for file in file_list: |
---|
39 | # Look for 'disp' |
---|
40 | if file[:5]=='disp_': |
---|
41 | toks = file[5:].split('.') |
---|
42 | func_list += "double oriented_%s_2D(double pars[], double q, double phi);\n" % toks[0] |
---|
43 | func_list += "double disperse_%s_analytical_2D(double dp[], double q, double phi);\n" % toks[0] |
---|
44 | |
---|
45 | func_list += "double %s_Weights(double dp[], double *phi_values, double *phi_weights, int n_phi,\n" % toks[0] |
---|
46 | func_list += " double *theta_values, double *theta_weights, int n_theta, " |
---|
47 | func_list += "double q, double phi_q);\n\n" |
---|
48 | |
---|
49 | print "Found %s" % file |
---|
50 | |
---|
51 | for tmp_line in tmp_lines: |
---|
52 | |
---|
53 | # Include file |
---|
54 | newline = replaceToken(tmp_line, |
---|
55 | "[FUNCTION_LIST]", func_list) |
---|
56 | |
---|
57 | # Write new line to the wrapper .c file |
---|
58 | headerfile.write(newline+'\n') |
---|
59 | |
---|
60 | headerfile.close() |
---|
61 | |
---|
62 | def replaceToken(line, key, value): #pylint: disable-msg=R0201 |
---|
63 | """ Replace a token in the template file |
---|
64 | @param line: line of text to inspect |
---|
65 | @param key: token to look for |
---|
66 | @param value: string value to replace the token with |
---|
67 | @return: new string value |
---|
68 | """ |
---|
69 | lenkey = len(key) |
---|
70 | newline = line |
---|
71 | while newline.count(key)>0: |
---|
72 | index = newline.index(key) |
---|
73 | newline = newline[:index]+value+newline[index+lenkey:] |
---|
74 | return newline |
---|
75 | |
---|
76 | |
---|
77 | if __name__ == '__main__': |
---|
78 | write_header() |
---|