-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathids_allocate.xsl
More file actions
167 lines (145 loc) · 5.64 KB
/
ids_allocate.xsl
File metadata and controls
167 lines (145 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?xml version="1.0" encoding="UTF-8"?>
<?modxslt-stylesheet type="text/xsl" media="fuffa, screen and $GET[stylesheet]" href="./%24GET%5Bstylesheet%5D" alternate="no" title="Translation using provided stylesheet" charset="ISO-8859-1" ?>
<?modxslt-stylesheet type="text/xsl" media="screen" alternate="no" title="Show raw source of the XML file" charset="ISO-8859-1" ?>
<!-- Generating MEX access layer code from Data Dictionary IDSDef.xml -->
<!-- -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
xmlns:my="dummy"
version="2.0">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>
<!--================================================-->
<!-- Include section -->
<!--================================================-->
<xsl:include href="mex_tools.xsl"/>
<xsl:include href="allocate.xsl"/>
<!--================================================-->
<!-- Template for the whole document -->
<!--================================================-->
<xsl:template match = "/IDSs">
<xsl:result-document href="src/ids/ids_allocate.c" standalone="yes" method="text">
/** \addtogroup extra MEX-interface-extra
* @{
*/
/**
\file ids_allocate.c
Initialise array of structure in MATLAB External Interfaces
This is a MEX file for MATLAB.
Usage:
\code{.m}
ids = ids = ids_allocate(IDSname, pathInIDS, n)
\endcode
MATLAB help:
\include matlab/ids_allocate.m
*/
/** @}*/
#include "ids_allocate.h"
#include "imas_mex_utils.h"
/**
Entry point to C/C++ MEX function built with C Matrix API
*/
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
/* Check for three input arguments */
if(nrhs != 3) {
mexErrMsgIdAndTxt("IMAS:ids_allocate:nargin",
"Three inputs required.");
}
/* make sure IDSname is a string */
if( !mxIsChar(prhs[0]) ) {
mexErrMsgIdAndTxt("IMAS:ids_allocate:notChar",
"Input IDSname must be a string.");
}
/* Get the value of IDSname */
char *IDSname = mxArrayToString(prhs[0]);
if (params.verbosity >= 4)
mexPrintf("The input IDSname is: %s\n", IDSname);
/* make sure pathInIDS is a string */
if( !mxIsChar(prhs[1]) ) {
mexErrMsgIdAndTxt("IMAS:ids_allocate:notChar",
"Input pathInIDS must be a string.");
}
/* Get the value of pathInIDS */
char *pathInIDS = mxArrayToString(prhs[1]);
if (params.verbosity >= 4)
mexPrintf("The input pathInIDS is: %s\n", pathInIDS);
/* make sure n is scalar */
if( !mxIsNumeric(prhs[2]) ||
!mxIsScalar(prhs[2]) ) {
mexErrMsgIdAndTxt("IMAS:ids_allocate:notScalar",
"Input n must be a scalar.");
}
/* Get the value of n */
int n = (int) mxGetScalar(prhs[2]);
if (params.verbosity >= 4)
mexPrintf("The input n is: %d\n", n);
/* Check for one output argument */
if(nlhs > 1) {
mexErrMsgIdAndTxt("IMAS:ids_allocate:nargout",
"One output maximum required.");
}
/* Extract IDS name */
char* name = IDSname;
/* Declare Function Pointer */
al_status_t(*ids_allocate)(char *, int, mxArray**) = NULL;
/* Assign pointer based on IDS name */
<xsl:apply-templates select = "IDS" mode="SWITCH">
<xsl:with-param name="function_name">ids_allocate</xsl:with-param>
</xsl:apply-templates>
/* Error if there was no match */
mexErrMsgIdAndTxt("IMAS:ids_allocate:unknown_ids",
"Unknown IDS name: %s", IDSname);
/* Clean-up previous errors */
resetErrMsgIdAndTxt();
/* Call function */
al_status_t err = ids_allocate(pathInIDS, n, &plhs[0]);
if (err.code < 0 )
my_mexErrMsgIdAndTxt(err, "IMAS:ids_allocate:");
return;
}
</xsl:result-document>
<xsl:result-document href="src/ids/ids_allocate.h" standalone="yes" method="text">
#include "mex.h"
#include "imas_mex_utils.h"
<xsl:apply-templates select = "IDS" mode="LIST">
<xsl:with-param name="prefix" select="'al_status_t ids_allocate_'"/>
<xsl:with-param name="suffix" select="'(char* pathInIDS, int n, mxArray** ids);'"/>
</xsl:apply-templates>
</xsl:result-document>
<xsl:result-document href="src/ids/allocate_ids.c" standalone="yes" method="text">
#include "imas_mex_utils.h"
<xsl:for-each select="IDS">
al_status_t ids_allocate_<xsl:value-of select="@name"/>(char* pathInIDS, int n, mxArray** ids)
{
al_status_t status;
void *array;
mxArray* data;
int i;
size_t pathLength = strlen(pathInIDS);
status = init_dataTree_array_read(1);
if (status.code >= 0) status = iterate_dataTree_array(0);
if (status.code >= 0) {
<xsl:for-each select=".//field[@data_type='struct_array']">
if (pathLength == <xsl:value-of select="string-length(@path)"/> && !strcmp(pathInIDS, <xsl:value-of select="concat('"',@path,'"')"/>)) {
<xsl:apply-templates select="field" mode="ALLOCATE"/>
} else
</xsl:for-each>
mexErrMsgIdAndTxt("IMAS:ids_allocate:unknown_path",
"Path '%s' did not match any known AoS in <xsl:value-of select="@name"/>", pathInIDS);
}
if (status.code >= 0) status = end_dataTree_array_action();
if (status.code >= 0) status = replicate_dataTree_array(NULL, n);
if (status.code >= 0) status = get_data_from_dataTree(NULL, ids);
/* Error handling */
if (status.code < 0) {
addIdsPathInfoToErrMsg("\n ... in IDS <xsl:value-of select="@name"/>",1);
}
return status;
}
</xsl:for-each>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>