From: Michael on
I wish I could post the Zemax files with this message but oh well. Here goes.

I have a few simple NSC system with 2 sources a null object (3), a paraxial lense and two detectors. I can push the update to the zemax file but the merit function does not seem to update.
Furthermore, the pause statement seems like trouble if the raytrace time varies more than allowed and wasteful if it take less time to run the raytrace. How can I make it wait until the update is done? Does anyone have experience using the mzdde toolbox to speak? How can I update the merit function and get the new values?

The merit function essentially
NSDD 1 0 0 0 0 0 0 0 0
NSTR 1 1 0 0 0 0 0 0 0 0 0
NSDD 1 6 -6 0 0 0 0 0 0 0 0
NSDD 1 6 -7 0 0 0 0 0 0 0 0
BLNK
NSDD 1 0 0 0 0 0 0 0 0
NSTR 1 1 0 0 0 0 0 0 0 0 0
NSDD 1 6 -6 0 0 0 0 0 0 0 0
NSDD 1 6 -7 0 0 0 0 0 0 0 0

----Matlab script-------
zddeinit

minangle = 0;
maxangle = 360;
stepsize = 90;
zSetNSCPosition(1, 3, 6, 0)
numstep = ((maxangle-minangle)/stepsize + 1);
index=0;
[PositionData, Material] = zGetNSCPosition(1,3);
Spot_Pos_Field_1(numstep,2)=0;
Spot_Pos_Field_2(numstep,2)=0;

for m=1:numstep
Spot_Pos_Field_1(m,1)=zGetOperand (3,10);
Spot_Pos_Field_1(m,2)=zGetOperand (4,10);

Spot_Pos_Field_2(m,1)=zGetOperand (8,10);
Spot_Pos_Field_2(m,2)=zGetOperand (9,10);
minangle = minangle + stepsize;

if minangle<=maxangle
zSetNSCPosition(1, 3, 6, minangle);
Status = zPushLens(5);
zGetUpdate;
pause(25);
end
end
--------------------------
From: Michael on
Hello everyone,

ignore part of my first message I added the line zGetRefresh and it worked.
> if minangle<=maxangle
> zSetNSCPosition(1, 3, 6, minangle);
> Status = zPushLens(5);
> zGetUpdate;
> pause(25);
zGetRefresh;
> end
> end
> --------------------------
However, the pasue statement still seem clunky. If any one knows of a more elegant way to do this please let me know?
> Furthermore, the pause statement seems like trouble if the raytrace time varies more than allowed and wasteful if it take less time to run the raytrace. How can I make it wait until the update is done?
>
From: Walter Roberson on
Michael wrote:

>> if minangle<=maxangle
>> zSetNSCPosition(1, 3, 6, minangle);
>> Status = zPushLens(5);
>> zGetUpdate;
>> pause(25);
> zGetRefresh;
>> end
>> end
>> --------------------------
> However, the pasue statement still seem clunky. If any one knows of a
> more elegant way to do this please let me know?
>> Furthermore, the pause statement seems like trouble if the raytrace
>> time varies more than allowed and wasteful if it take less time to run
>> the raytrace. How can I make it wait until the update is done?

I'm really not sure what you are trying to do; I've never heard of the MZDDE
toolbox before. It appears to be a FEX contribution,
http://www.mathworks.com/matlabcentral/fx_files/7507/1/content/MZDDE/Documents/MZDDE%20Function%20Reference.html

Looking at the function reference, it appears to be that both zGetUpdate and
zGetRefresh invoke raytracing, and it appears that both of them execute until
they either finish or time out (with the timeout settable via zSetTimeout ). I
seem to be missing what it is that you want to wait until the update is done ?
You are not checking the return value of zGetUpdate or zGetRefresh and are
thus not detecting possible timeouts as imposed by zSetTimeout, so it would
seem to me that at least one of the two of us is not understanding the
documentation.

What it sounds like to me is if you believe that zGetUpdate is not waiting for
the ray tracing to finish, but the way I read the documentation for zGetUpdate
and zGetRefresh is that either they _both_ wait for ray tracing to finish or
else neither even _start_ ray tracing (and merely leave the system in a state
where ray tracing would be legal.) Thus it appears to me that either you have
duplicate ray tracing going on, or else no ray tracing (I don't know which.)
From: Michael on
Walter

Thanks for the help. Yeah the documentation of the zGetUpdate and zGetRefresh sounded very similar to me as well. But without the ZGetRefresh call I did not get any results. I am not sure as to why could be timing out I do not know. I will try to eliminate one of the commands and check the return value of the remaining command and see if this solves my issue.

Basically, I only want the system to wait as long as it takes to finsih the raytrace before sending the next command.