How do I pass a file path/ string in main.c?
Ältere Kommentare anzeigen
Hello all,
I have created a shared library with MATLAB Coder. With the programme I want to read data from a path, process it and then output the result again. The input for the MATLAB function is therefore a string (char) of the file path and a few more number arguments (double).
To create the .sh, I have compiled the code accordingly in C and would now like to adapt my main.c. To run it in the Linux terminal, I have to create a new main.c.
In order to be able to execute the .sh in the Linux terminal, I adapt my main function as follows:
int main(int argc, char **argv)
{
char * path =argv[1];
double rpd;
double noc;
rpd = strtol(argv[2],&pEnd_1,10);
noc = strtol(argv[3],&pEnd_2,10);
c_main_test_f(path, rpd, noc);
test_f_terminate();
return 0;
}
In test_f I then pass the values of the function generated by MATLAB Coder. I have defined two return variables for this:
static void c_main_test_f(char path[], double rtg, double az)
{
/* This is autogenerated by MATLAB Coder*/
emxArray_real_T *result_normal;
emxArray_real_T *result_query;
emxInitArray_real_T(&result_query, 2);
emxInitArray_real_T(&result_normal, 2);
printf("Path: %s RTG-value: %f az-value: %f \n", path, rtg, az);
test_f(path, rtg, az, result_query, result_normal);
emxDestroyArray_real_T(result_query);
emxDestroyArray_real_T(result_normal);
}
When I compile this now I get the following error:
/home/user/Desktop/lin_file/test_f.h:26:57: note: expected sconst rtString *e {aka rconst struct > *e} but argument is of type schar *t
In the original function (without input parameters) MATLAB Coder suggests me the following for the string/path:
static emxArray_char_T *argInit_1xUnbounded_char_T(void);
static rtString argInit_rtString(void);
static char argInit_char_T(void);
static char argInit_char_T(void)
{
return '?';
}
static rtString argInit_rtString(void)
{
rtString result;
/* Set the value of each structure field.
Change this value to the value that the application requires. */
result.Value = argInit_1xUnbounded_char_T(pfad_1);
return result;
}
static emxArray_char_T *argInit_1xUnbounded_char_T(void)
{
emxArray_char_T *result;
int idx0;
int idx1;
char *result_data;
/* Set the size of the array.
Change this size to the value that the application requires. */
result = emxCreate_char_T(1, 2);
result_data = result->data;
/* Loop over the array to initialize each element. */
for (idx0 = 0; idx0 < 1; idx0++) {
for (idx1 = 0; idx1 < result->size[1U]; idx1++) {
/* Set the value of the array element.
Change this value to the value that the application requires. */
result_data[idx1] = argInit_char_T();
}
}
return result;
}
And in c_main_test_f:
/* Befor function call*/
rtString path_name;
path_name = argInit_rtString();
/* After function call*/
emxDestroy_rtString(path_name);
Unfortunately, as I am absolutely no C specialist and also new to MATLAB coders, I have no idea how to pass the file path so that my function can use it.
Can anyone help me here?
Many thanks and best regards
Antworten (1)
Tom Engels
am 22 Feb. 2022
Bearbeitet: Tom Engels
am 22 Feb. 2022
2 Kommentare
Tom Engels
am 22 Feb. 2022
Bearbeitet: Tom Engels
am 22 Feb. 2022
Tom Engels
am 22 Feb. 2022
Kategorien
Mehr zu MATLAB Coder finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!