Does Lumerical script adopt function/sub-function and sub-script?


#1

Hello, I have a question about Lumerical scripts.
Does Lumerical script adopt function/sub-function and sub-script? How to define and use sub-script?
Thank you.


#2

Hi @ahan

Lumerical script does not support functions and sub-functions by now. But some of the features of functions and sub-functions can be achieved by using sub-scripts. You could directly call a sub-script in another script by using the name of the sub-script file without file extension if they are in the same location. The name of the sub-script cannot be started by numbers and there is no restrictions for naming the main script.

Please check out the two example files 56331-main.lsf (54 Bytes) and fun.lsf (54 Bytes). In the main script 56331-main.lsf, the fun.lsf is called in the for loop.

I hope this could help :slightly_smiling:


#3

You can define sub-functions in Lumerical’s script in a limited capacity. Any script that you create can be called from another script file as long as the former stays in the working directory. So you can write a script to behave like the required sub-function. This page on KB has detailed information as to how a script file can be called from another one.

The one shortcoming you will see is if you want to create a sub-function that takes in some variables as input and provides some output variable. This is because all variables in Lumerical’s script workspace are global variables and any script file you run shares the same workspace. This means that when you call a sub-function, you do not need to define input variables (and output variables) for it separately as it will have full access to the workspace used by the parent script. The downside is that since the sub-function will use the same workspace, it might overwrite some variables used by the parent script if not careful.


#4

For the sake of completeness, you can also use a matlab session and exploit matlab functionalities. In this KB page you can find some more info.

Hope this helps.