|
Helllo Everyone,
I still have the of how to verify the contents of MySettings file.
But the main reason for my post is the code below. It appears to be functional (I am still verifing the output is the same as what . However, I would appreciate any feed back on how this could be streamlined or if there are any errors that would cause errors.
%% Intro
% Created M. Lisowksi
% June 22, 2011
% File Designed to Calculate the Frequency (cy/mm) at which
% a minimun desired contrast level is reached as the source position is moved
% polychromatic and 3 field point
%
%
%% Establish Link
link = zDDEInit;
if link~=0
warndlg('Link not established','!! Warning !!')
end
zGetRefresh
%% Verify Correct File
Time=8;
zSetTimeout(Time);
%zGetFile
%zGetRefresh
%% Set Inital Parameters
StartPosition =5000;
zSetSurfaceData(0,3,StartPosition);
Status=zPushLens(3);
if Status ~=0
errordlg('Lens not updated','File Error');
end
zGetRefresh;
if Status ~=0
errordlg('Lens not refreshed','File Error');
end
EndPosition = 10000;
Interval =1000;
NumStep= abs((StartPosition-EndPosition)/Interval);
ContrastLevel=0.5;
%% Inital MTF Data
Reply=zGetTextFile('C:\Documents and Settings\mlisowski\My Documents\MATLAB\MyDataFile', 'Mtf', ...
'C:\Documents and Settings\mlisowski\My Documents\MATLAB\MySettingsFile', 0);
if Reply ==0
errordlg('MTF not Calculated','File Error')
end
zmxOTF = ReadZemaxOTF('C:\Documents and Settings\mlisowski\My Documents\MATLAB\MyDataFile');
AvezmxOTF=zeros(length(zmxOTF.data),3);
[m,n] = size(AvezmxOTF);
FreqContrastLevel=zeros(NumStep,n+1);%need #step
counter=1;
PlotZemaxOTF(zmxOTF)
%% Evaluate
for position= StartPosition:Interval:EndPosition
%% Processing
disp('Processing....Please wait')
%% Average Tangnetial and Sagital for all filed points
for i=1:length(zmxOTF.data)
AvezmxOTF(i,1)= (zmxOTF.data(i,1)+ zmxOTF.data(i,2))/2;
AvezmxOTF(i,2)= (zmxOTF.data(i,3)+ zmxOTF.data(i,4))/2;
AvezmxOTF(i,3)= (zmxOTF.data(i,5)+ zmxOTF.data(i,6))/2;
end
overContrast_level = AvezmxOTF > ContrastLevel;
index_level=zeros(1,n);
%% Find Contrast Frequency
for temp=1:1:n
index_level(1,temp)= nnz(overContrast_level(1:end,temp));
if index_level(1,temp)<= 1 %test closest value
warndlg('Contrast never greater than Specified Limit','!! Warning !!')
index_level(1,temp)=1;
elseif index_level(1,temp)<= (m-1)
diff1= AvezmxOTF(index_level(1,temp),temp)-0.5;
diff2= 0.5 - AvezmxOTF(index_level(1,temp)+1,temp);
if diff2<diff1
index_level(1,temp)=index_level(1,temp)+1;
end
else
warndlg('Contrast never less than Specified Limit','!! Warning !!')
end
end
%% Output Matrix
FreqContrastLevel(counter,1)=position;
for temp=1:1:n
FreqContrastLevel(counter,temp+1)=zmxOTF.abscis(index_level(1,temp));
end
%% Plot Data
% PlotZemaxOTF(zmxOTF)
%% Setup Next Loop
counter=counter+1;
if position < EndPosition
zSetSurfaceData(0,3,(position+Interval));
Status=zPushLens(10);
if Status ~=0
errordlg('Lens not updated','File Error');
end
zGetRefresh;
if Status ~=0
errordlg('Lens not refreshed','File Error');
end
Reply=zGetTextFile('C:\Documents and Settings\mlisowski\My Documents\MATLAB\MyDataFile', 'Mtf', ...
'C:\Documents and Settings\mlisowski\My Documents\MATLAB\MySettingsFile', 0);
if Reply ==0
errordlg('MTF not Calculated','File Error')
end
%zPushLens(10);
%zGetRefresh;
zmxOTF = ReadZemaxOTF('C:\Documents and Settings\mlisowski\My Documents\MATLAB\MyDataFile');
AvezmxOTF=zeros(length(zmxOTF.data),3);
[m,n] = size(AvezmxOTF);
end
end
%% Plot Results
PlotZemaxOTF (zmxOTF)
PlotZemaxOTFContrast (FreqContrastLevel, zmxOTF)
|