Skip to main content

Hi everyone,

 

I’ve recently started using OpticStudio. Currently, I’m trying to incrementally change the clear semi-diameter of a surface within my system. I know this can easily be achieved with a FOR loop.

However, for each iteration, I hope to save the resulting wavefront map. Unfortunately, using GETTEXTFILE within a loop does not appear to work as intended, as the FOR loop seems to run as normal, but does not create the required files. 

I’ve attached my code. If there’s any mistakes or changes that need to be made so that the solver iterates over the semi-diameter values and saves the wavefront map at each step, just let me know.

 

! Setting the desired format.

FORMAT 1 INT

FOR i, 0, 6, 1

    ! Reducing the clear semi-diameter by 5 lens units per iteration.

    CLR_SEMI_DIAM = 52 - i*5

    ! Returning the new clear semi-diameter to the editor.

    SOLVERETURN CLR_SEMI_DIAM

    ! Setting the output filename.

    FLNM$ = "F:\LGS_104_Wavefront_Map_" + $STR(i) + ".txt"

    ! Writing the wavefront map for each iteration to a text file.

    GETTEXTFILE FLNM$, Wfm

NEXT

 

Thanks in advance!

Ben

Hi Ben,

The SOLVERETURN, when used as a ZPL Solve, acts like a return in any other programming language, namely it should be used at the end of a function and no other commands should follow.  OpticStudio knows if you’re running a ZPL manually from the Programming tab or automatically via a ZPL Solve, which means the SOLVERETURN will be ignored when you run the code manually but will act as a stop point when running automatically.

Rather than using a ZPL Solve, you could simply use SURP to change the Clear Semi-Diameter of the desired surface:

FORMAT 1 INT

surfNum = 1

FOR i, 0, 6, 1

    SURP surfNum, 6, 52 - i * 5

    FLNM$ = "F:\LGS_104_Wavefront_Map_" + $STR(i) + ".txt"

    GETTEXTFILE FLNM$, Wfm

NEXT

I would also ensure that the F:\ drive is a local drive (rather than a network drive) and maybe use a PAUSE THREADS and UPDATE EDITORS before the GETTEXTFILE to ensure all updates are complete to the system before saving the Wavefront Map.


Reply