1 /* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
2 Radboud University Nijmegen, The Netherlands /
3 Max Planck Institute for Biological Cybernetics, Germany
5 This file is part of libDAI.
7 libDAI is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 libDAI is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with libDAI; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 /*=================================================================*
25 * This is a MEX-file for MATLAB. *
27 * dai_writefg(psi, filename); *
29 *=================================================================*/
34 #include <dai/matlab/matlab.h>
35 #include <dai/factorgraph.h>
44 #define PSI_IN prhs[0]
45 #define FILENAME_IN prhs[1]
49 /* Output Arguments */
54 void mexFunction( int nlhs
, mxArray
* /*plhs*/[], int nrhs
, const mxArray
*prhs
[] )
59 // Check for proper number of arguments
60 if ((nrhs
!= NR_IN
) || (nlhs
!= NR_OUT
)) {
61 mexErrMsgTxt("Usage: dai_writefg(psi,filename);\n\n"
63 "INPUT: psi = linear cell array containing the factors\n"
64 " (psi{i} should be a structure with a Member field\n"
65 " and a P field, like a CPTAB).\n"
66 " filename = filename of a .fg file\n");
69 // Get input parameters
70 vector
<Factor
> factors
= mx2Factors(PSI_IN
,0);
73 buflen
= mxGetN( FILENAME_IN
) + 1;
74 filename
= (char *)mxCalloc( buflen
, sizeof(char) );
75 mxGetString( FILENAME_IN
, filename
, buflen
);
77 // Construct factorgraph
78 FactorGraph
fg(factors
);
81 fg
.WriteToFile( filename
);
82 } catch( std::exception
&e
) {
83 mexErrMsgTxt( e
.what() );