forked from MaxvandenBoom/matmef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_mef_struct.c
72 lines (51 loc) · 2.95 KB
/
init_mef_struct.c
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
/**
* @file
* MEF 3.0 Library Matlab Wrapper
* Create and initialize a new universal-header or metadata structure-array with default values
*
* Copyright 2022, Max van den Boom (Multimodal Neuroimaging Lab, Mayo Clinic, Rochester MN)
* Adapted from PyMef (by Jan Cimbalnik, Matt Stead, Ben Brinkmann, and Dan Crepeau)
*
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <ctype.h>
#include "mex.h"
#include "matmef_mapping.h"
/**
* Main entry point for 'init_mef_struct'
*
* @param type The type of struct to generate [either 'uh', 'ts_section2', 'tmd2', 'v_section2', 'vmd2', 'section3' or 'md3']
* @return A new and initialized matlab structure-array
*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
// check the type input argument
if (nrhs < 1) mexErrMsgIdAndTxt("MATLAB:init_mef_struct:noTypeArg", "'type' input argument not set");
if (mxIsEmpty(prhs[0])) mexErrMsgIdAndTxt("MATLAB:init_mef_struct:invalidTypeArg", "'type' input argument invalid, argument is empty");
if (!mxIsChar(prhs[0])) mexErrMsgIdAndTxt("MATLAB:init_mef_struct:invalidTypeArg", "'type' input argument invalid, should be a string (array of characters)");
// retrieve the type input string and make lower case
char *mat_type = mxArrayToString(prhs[0]);
for(int i = 0; mat_type[i]; i++) mat_type[i] = tolower(mat_type[i]);
// check if the input type string matches any of the options
if (strcmp(mat_type, "uh") == 0) {
// create and initialize a universal-header matlab-struct
plhs[0] = create_init_matlab_uh();
} else if (strcmp(mat_type, "ts_section2") == 0 || strcmp(mat_type, "tmd2") == 0) {
// create and initialize a time-series section 2 metadata matlab-struct
plhs[0] = create_init_matlab_tmd2();
} else if (strcmp(mat_type, "v_section2") == 0 || strcmp(mat_type, "vmd2") == 0) {
// create and initialize a video section 2 metadata matlab-struct
plhs[0] = create_init_matlab_vmd2();
} else if (strcmp(mat_type, "section3") == 0 || strcmp(mat_type, "md3") == 0) {
// create and initialize a section 3 metadata matlab-struct
plhs[0] = create_init_matlab_md3();
} else {
// invalid type
mexErrMsgIdAndTxt("MATLAB:init_mef_struct:invalidTypeArg", "'type' input argument invalid. Valid arguments are: 'uh', 'ts_section2', 'tmd2', 'v_section2', 'vmd2', 'section3' or 'md3'");
}
return;
}