Beruflich Dokumente
Kultur Dokumente
function h = StartZemax(ZemaxFile)
%USAGE: h = StartZemax(ZemaxFile);
%Sets up a DDE connection to Zemax and loads
% the specified file.
%Note: With recent (2004) Zemax versions, an instance of Zemax
%
must already be running to use DDE from Matlab, although
%
a particular file need not be loaded.
%INPUTS:
% ZemaxFile: Zemax file name (and path) to be loaded
%
If not entered, no file is loaded, but
%
the channel handle, h, is still returned
%OUTPUT:
%
h: The DDE channel to zemax
%
%START ZEMAX
h = ddeinit('zemax','notopic');
if h == 0
error('Zemax not started')
end
%
if nargin > 0
%LOAD ZEMAX FILE:
loadstr = ['LoadFile,' ZemaxFile];
rc = ddereq(h,loadstr);
if rc == -999
error('Zemax file load failed')
elseif rc ~= 0
error('Zemax update failed')
end
end
D = pwd;
F = [D '\PSFText.txt'];
%
%
%Read text file into Matlab array:
[A,Hdr] = readZMX(F);
%Delete temp file to ensure against false data:
%delete(F);
%USAGE: X = GetParameter(channel,Surf,P);
%Gets values, X, from Zemax LDE parameter columns, P
%INPUTS:
% channel: Open DDE channel to Zemax (with file loaded)
%
P: A vector indicating which parameters to get.
%OUTPUT:
%
X: A cell array with the requested data
%
%Set up the base DDE request string:
L = 'GetSurfaceParameter,';
S = [num2str(Surf) ','];
fmt = [1 0]; %Return numeric data
%
for ii = 1:length(P)
Pstr = num2str(P(ii));
%Set up the DDE request string:
reqstr = [L S Pstr];
%
%Get the parameter:
rc = ddereq(channel, reqstr, fmt);
X{ii} = rc;
end %(over size(P))
%
return