1 /* This file is part of libDAI - http://www.libdai.org/
3 * libDAI is licensed under the terms of the GNU General Public License version
4 * 2, or (at your option) any later version. libDAI is distributed without any
5 * warranty. See the file COPYING for more details.
7 * Copyright (C) 2006-2009 Joris Mooij [joris dot mooij at libdai dot org]
8 * Copyright (C) 2006-2007 Radboud University Nijmegen, The Netherlands
14 #include <dai/matlab/matlab.h>
15 #include <dai/factorgraph.h>
24 #define PSI_IN prhs[0]
25 #define FILENAME_IN prhs[1]
29 /* Output Arguments */
34 void mexFunction( int nlhs
, mxArray
* /*plhs*/[], int nrhs
, const mxArray
*prhs
[] ) {
37 // Check for proper number of arguments
38 if ((nrhs
!= NR_IN
) || (nlhs
!= NR_OUT
)) {
39 mexErrMsgTxt("Usage: dai_writefg(psi,filename);\n\n"
41 "INPUT: psi = linear cell array containing the factors\n"
42 " (psi{i} should be a structure with a Member field\n"
43 " and a P field, like a CPTAB).\n"
44 " filename = filename of a .fg file\n");
47 // Get input parameters
48 vector
<Factor
> factors
= mx2Factors(PSI_IN
,0);
51 buflen
= mxGetN( FILENAME_IN
) + 1;
52 filename
= (char *)mxCalloc( buflen
, sizeof(char) );
53 mxGetString( FILENAME_IN
, filename
, buflen
);
55 // Construct factorgraph
56 FactorGraph
fg(factors
);
59 fg
.WriteToFile( filename
);
60 } catch( std::exception
&e
) {
61 mexErrMsgTxt( e
.what() );