source: sasview/sansmodels/igor_wrapper/headerGenerator.py @ 12e2b2b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 12e2b2b was 25a60dc1, checked in by Jae Cho <jhjcho@…>, 13 years ago

moving a folder

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[ae3ce4e]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
15import os
16
17def 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   
62def 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   
77if __name__ == '__main__':
78    write_header()
Note: See TracBrowser for help on using the repository browser.