[ Prev | Index | Next ]  # Step 3 - How to Execute Scripts

The RINPn can execute a script file written in the "Vnano", to perform procedural, algorithmic, or other complicated calculations. ## What is the Vnano?

The vnano is a compact script engine & language for embedded use in applications. The vnano has simple C-like syntax. For details of syntax of the Vnano, see: "Features of the Vnano as a Language" in the Vnano Official Website. To create a script of the Vnano, no development environments (e.g.: compiler) is required. Simply create a text file of which name ends with the extention ".vnano", and write code in there.

## Example Script

There is an example script file "Example.vnano" in the folder of the RINPn. This example script calculates the numerical integration value of cos(x) from 0 to 1:

(The content of "Example.vnano")

// Integration parameters
double A = 0.0;
double B = 1.0;
int N = 100000;

// Integrant function
double f(double x) {
return cos(x);
}

// Perform integration
double delta = (B - A) / N;
double value = 0.0;
for(int i=0; i<N; ++i) {
double x = A + i * delta;
value += ( f(x) + f(x+delta) + 4.0 * f(x+delta/2.0) ) * delta / 6.0;
}

// Output result
output(value);

For detailed explanations about the above code, see: https://www.vcssl.org/en-us/code/archive/0001/7800-vnano-integral-output/

## How to Execute a Script in GUI mode

To execute this script in the GUI mode, input the script file name (or path) into "INPUT" text-field as follows, and press Enter key. Then the script will be executed and its output value will be displayed on "OUTPUT" text-field:

For example, input the name of the above example script "Example.vnano" and press Enter key: As the above, the output value of the script will be displayed on the "OUTPUT" text-field. The output value "0.8414709848" is matched well with the value of sin(1) which is the theoretical integration value of cos(x) from 0 to 1, so it indicates that the above example script has run correctly.

By the way, if you want to execute a script file in the different folder with the folder at which you has launched the RINPn, it is necessary to input the absolute file path ("C:\...\Example.vnano", "/home/.../Example.vnano", etc.) of the script to execute it. (If you are using Microsoft® Windows®, right-click the script file with pressing Shift key, and then you can copy the file path from the right-click menu.)

## How to Execute a Script in CUI mode

As same as the GUI mode, you can execute a script on CUI mode, by inputting the name or the path of the script file.

Here we assume that the path of "bin" folder of the RINPn is registered in the environment variable "PATH"/"Path" of your PC (» More details), and "rinpn" command is available.

For executing a script file in the current directory, pass only name of the script file to the "rinpn" command:

cd (The directory in which the script file is)

rinpn Example.vnano
(Result) 0.8414709848

When a script file is in a different directory with the current directory, you can specify the relative file path of it, instead of the file name:

rinpn ../Example.vnano     (Execute a script in the parent directory)
rinpn ./example/Example.vnano     (Execute a script in "example" directory)

Also, if necessary, you can specify the absolute file path as follows,

rinpn "C:\...\Example.vnano"     (For Microsoft® Windows®)
rinpn "/home/.../Example.vnano"     (For Linux®, etc.)

## About Optimization Levels:When Processing of a Script Is Heavy ...

By the way, when processing of a script is heavy, it might be helpful to raise the optimization level specified in "Settings.txt" as "acceleratorOptimizationLevel", to make the processing faster.

Even when the value of the optimization level is 0, probably the processing speed is enough to use the RINPn in the standard way of a calculator software, so the default value of the optimization level is set to 0. However, if you execute numerical calculation programs frequently on the RINPn, the processing speed might not be sufficient with the default optimization level.

## Get New Scripts from the Code Archive

You can write new scripts from scratch, but sometimes the code archive in the official website of the VCSSL/Vnano may be helpful:

Code Archive » Vnano
https://www.vcssl.org/en-us/code/#vnano

Useful scripts are being distributed on the code archive, with commentary articles explaining algorithms, background knowledge, and so on.

- Examples of Scripts Distributed in the Code Archive -
 Solve The Lorenz Equations Numerically Solve the Lorenz equations, and output data to plot the solution curve (well-known as the "Lorenz Attractor") on a 3D graph. Output Data of Numerical Integration For Plotting Graph Example code computing integrated values numerically, and output data for plotting the integrated functions into graphs. Compute Integral Value Numerically Example code computing integral values numerically by using rectangular method, trapezoidal method, and Simpson's rule.

Sponsored Link  [ Prev | Index | Next ]
Index of this category
[ Prev | Index | Next ]
Announcement（ Twitter ）