Please enable JavaScript to view this site.

Knowledge Base

Navigation: Scripting Language

User defined functions

Scroll Prev Top Next More

User defined functions give the users the ability to define their own script functions with arbitrary inputs and output.

 

FDTD STACK MODE DGTD CHARGE HEAT FEEM INTERCONNECT

 

Syntax

Description

Function definition:

function function_name(input1, input2, ...){

....

return output;

}

 

Function call:

out=function_name(input1, input2, ...);

The function keyword is used to define a function which can have arbitrary number of inputs and one output. The return statement is used to specify the output. The function body will be located in between the brackets.

The name of the function is used to call the function and the inputs should be in the same format as the definition.    

 

Examples

Defining a function that rounds down the input number to the nearest even number

function even_floor(a) {

    return floor(a) - mod(floor(a),2);

}

 

This function will change the current working directory to the currently opened file directory

 function change_to_project_directory() {

    if(currentfilename != "") {

        cd(filedirectory(currentfilename ));

    }

}

Functions can also be nested into other functions definition. The following example shows using an add function to create another add function with 4 input arguments:

function add(a, b){

    return a+b;

}

function add4(i, j, k, l){

    return add(add(i, j), add(k, l));

}

 

 

See Also

Functions,

Copyright Lumerical Inc. | Privacy | Site Map