Sender: on the Sand of the Sahara Desert, the letter area: matlab
Title: Analysis: Solving the compilation problem of m procedures into CPP programs [Wavelet work workers?
Sending station: Harbin Institute of Technology (SAT NOV 29 21:32:06 2003), station letter
Background: There is a friend wants to use wavelet transform to image processing, using the ready-made MATLAB wavelet toolbox
program. But his mentor requires all MATLAB programs into C language programs and compiles in the VC environment.
In fact, there is a large limit to the CPP file with MATLAB procedures and independently compile. First of all
Many compiled MEX programs, although it can be compiled, but usually get this warning:
"The" xxx "Function is Only Available In Mex Mode. A Run-Time Error
Will Occur if this code is executed in standard-alone mode. "This will cause a
Runtime error, carefully check that this MEX file is existing in the form of a DLL, the corresponding M file
It's just a scorpion, the presence of M file is just to provide instructions; even if you use it
All functions exist in m files, sometimes there is a problem, please see the following procedure:
%%%%%%%%%%%%%
Function Simon ()
[X, map] = IMREAD ('Simon.bmp');
x = x;
ColorMap (MAP);
x = double (x);
H = WaveDecnd (x, 2, 'Haar')
Image (h {1});
%%%%%%%%%%%%%
This program is a 'Haar' wavelet transform for simon.bmp and displaying the first block.
Compile it: MCC -B SGLCPP SIMON
SIMON.EXE generated automatically after compiling, an error occurred:
"Exception! File: Handler.cpp, Line: 73
Variables Are Not Supported by Eval In Compiled Code.
During this, the function "EVAL" does not support CPP compilation, but we don't have explicitly call this function.
Ah, then it is definitely called this function in the other function we call. So on
WaveDecnd function A function of checking all its direct or indirect calls, finally
I found three calls to EVAL in Wavemngr.m:
"EVAL (['load' bin_file '-mat'], 'err = 1;');"
How to solve this problem? MathWorks gives the answer, see:
Http://www.mathworks.com/support/tech-notes/1100/1103.shtml
I chose to replace the indirect call for EVAL with the "Try Catch" structure:
%%%%%%%%%%%%%%%%%%%%%%% EVAL (['load' bin_file '-mat'], 'err = 1; ');
Try
LOAD (bin_file, '-mat');
Catch
Err = 1;
end
IF ERR
Err = 0;
% EVAL (['load' bin_ini_file '-mat'], 'err = 1;');
Try
LOAD (bin_ini_file, '-mat');
Catch
Err = 1;
end
.......................................
% EVAL (['Save'], 'Err = 1;');
Try
Save (bin_file, 'wavelets_info');
Catch
Err = 1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
After completing, compile: MCC -B SGLCPP SIMON
Run the program and error:
"Exception! File: Handler.cpp, Line: 73
Reference to unknown Function 'DBWAVF' from FEVAL in Stand-Alone Mode. "
It means that the unknown function "dbwavf" is called in the FEVAL, so I find this in WFILTERS.M.
One call:
"F = fEVAL (FNAME, WNAME);"
And FNAME comes from this file:
"[WTYPE, FNAME] = Wavemngr ('Fields', WNAME, 'Type', 'File');"
Tracing! Open WAVEMNGR.M to see this statement:
Files = ...
{...
'dbwavf';
'dbwavf';
'Symwavf';
'coifwavf';
'biorwavf';
'rbiowavf';
'meyer';
'Dmey.mat';
'Gauswavf';
'mexihat';
'morlet'
'cgauwavf';
'shanwavf';
'FBSPWAVF';
'cmorwavf'
}
"
So the solution is there, and the reason for analyzing the error is in the file indirect calls in FEVAL.
The function "DBWAVF", FEVAL just processes it as a string instead of the file name, before the previous code
There is no explicit declaration of this function in the middle, so the compiler does not know the CPP generation that needs to be generated.
Plus the declaration of this function, no additional dbwavf.m into CPP files, solve
There are two ways:
1. Use "F = DBWAME" to replace "F = FEVAL (FNAME, WNAME);"
Compile, run, no problem :)
2. The reader must find the problem in the first method, if it is called Symwavf, or morlet
Or any other function? Then this method reduces the flexibility of the original procedure, the method of solving
(Oh, thinking of this method is really inductive!) Is in WFILTERS.M
"F = fEVAL (FNAME, WNAME);" to do a function that may be called before
Pseudo-state (whose fake statement is because there seems to be no statement in Matlab, but doing this
The substance is equivalent to the statement in the C language), that is, before "f = fEVAL (FNAME, WNAME);"
Plus: "DBWAVF ('Haar');"
It is now:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DBWAVF ('Haar');
IF WTYPE == 1% Orth. Wavelet
IF ~ ISEMPTY (MAT_F)
F = evAl (WNAME);
Else
F = fEVAL (FNAME, WNAME);
% F = DBWAVF (WNAME);
end
................................
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Note, I only added: "DBWAVF ('Haar');" because I know it only calls
This function, if it wants to call multiple functions, just draw a gourd.
Compile, run, ok :)
The rest is to add the generated CPP file and HPP file to the project in the VC, modify the corresponding
Compile and connect parameters, compile a separate EXE program.