Solved

# How to SETSURFACEPROPERTY using a variable?

• 73 views

• Single Emitter
• 0 replies

I have defined an array variable with various surface parameters called L1(i,j)

for example:

L1(1,1) is the value of a curvature

L1(1,2) is the value of a thickness

I would like to use the numeric values of this array variable in a .ZPL so for instance I could say:

SETSURFACEPROPERTY  12, 2, L1(1,1)

but I see that I cannot use a variable that is a number for the value of the curvature., has to be converted to a STRING  Why the heck not, the curvature is not a string but IS a number?  Just another backward ancient programming ZEMAX thing.

Anyway, I guess that the value of the lens parameter to set has to be a STRING, a number, or a numerical expression, not a variable?  So how do I convert L1(1,1) to a STRING to set the curvature parameter in the lens which is actually not a string but a number?  Retarded.

I thank anyone for the time taken to help.  I tried to use the \$STR(val) and FORMAT but loe and behold can’t get that to work.

Like \$STR(L1(1,1)) gets rewarded an error message.

…………………………………………………………………………………………………..

As an aside, it’s like you can’t hardly do any lens-parameter-based math on the fly in a .ZPL.

If I want to set a variable to be the ratio of (thickness 2)/(thickness 1),  I have to define operands in a Merit Function that calculate to thickness 1 and thickness 2 and then do the ratio there and then call in the .ZPL the proper Merit Function row and column that has that ratio.

I have to know the row,column.   So when I or anybody else comes back and looks at that macro, they have to figure out what is in Merit Function Row 2 Column 7.  Unless you add comments to every maco line.

in CodeV in the macro I write:

^ratio == (thi s2)/(thi s1)

what’s worng with that?  It;s like an English sentence.

icon

Best answer by MichaelH 27 November 2023, 00:13

View original

Userlevel 6
+2

Hi Harvey,

First, the 2D array structure is primarily designed to be populated with values and then to either be plotted with PLOT2D or to be used with PRINT to save the data to disk; this structure was not primarily designed to be used inside the ZPL itself with other FUNCTIONS or KEYWORDS.

The ZPL has a pre-processor to try to convert each line in the ZPL to properly formatted commands to execute.  With KEYWORDS such as SETSURFACEPROPERTY or SURP, the pre-processor counts the number of commas for the keyword and if the commas don’t match, then an error is thrown.  In this case, the multi-dimensional array `L1(1,1)` has an “extra” comma in it so the SETSURFACEPROPERTY throws an error.  To get around this, you can either assign the value of L1(1,1) to a variable and use this variable in the SETSURFACEPROPERTY command or you can switch to a 1D array:

``! set the curvature from a 2D array by using a variablec = L1(1,1)SURP 12, 2, c! est the curvature directly from a 1D arrayDECLARE L2, DOUBLE, 1, nSURP 12, 2, L2(1)``

As for getting the thickness ratios, you can simply use the following line:

``ratio = THIC(1) / THIC(2)``

This is slightly different than CV but I think it’s as easy to read.  You can use RADI, THIC, GIND, SDIA, CHZN, MCSD, CONI, SPRO (s, 7) and PARM to get all the numeric values in the Lens Data Editor (radius, thickness, d-light refractive index, clear semi-diameter, chip zone, mechanical semi-diameter, TCE, and all parameters.

P.S.

Yes, using FORMAT and \$STR() is the correct way of converting from double to string.