mavscript - with BeanShell

Copyright (c) A.Vontobel, 2004 - 2016

With Mavscript you can do calculations in a text document.

The following file formats are supported:

Mavscript with BeanShell

Instead of a computer-algebra-system one may use BeanShell. BeanShell is a scripting language for the programming language Java.
The basic mathematical operations are easily to use, but algebraic functions are not available. BeanShell therefore is not a replacement for a computer-algebra-program.
The power of BeanShell is that you can access external java programs, that algorithms can be written in (simplified or normal) Java and that the hole functionality of Java is available. If you are a little bit familiar with the programming language Java, you have got a very powerful tool.

How it works

Mavscript reads the calculation commands. These commands start with the control characters §m and end with one of the following control characters: §i, §o, §io and §n. Their meaning will be explained later. The commands are forwarded to BeanShell. BeanShell evaluates them and then returns an answer to Mavscript, i.e. the result of the calculation command. Mavscript now can insert this answer in the text, where the command was. When all calculations are done Mavscript saves the text document in a new file out-originalname. The original file remains unchanged.

You do not always want to replace the calculation command by the answer from BeanShell. When you assign a value to a variable you usually want that the command remains in the text. Therefore there are the following possibilities.

Input in the template file     Output                 Notes
--------------------------     ------                 -----
§m l = 5.0 §i                  l = 5.0                The command remains unchanged. §i stands for input.
§m b = 4.0 §i                  b = 3.0                The control characters are removed.
§m h = 2.0 §i m                h = 2.0 m
§m V = l*b*h §io V = l*b*h --> 40. Both the input and the output are shown. §m 2. + 3. * 4. §io 2. + 3. * 4. --> 14. §io stands for input/output.
§m doubleVol = 2*V §n Sometimes you do not want to show the command or its result. §m static import Math.*; §n §n stands for nothing.
§m doubleVol §o 80. Only the return value (answer) is shown. §o stands for output. §m sin(PI/4.) §o 0.7071067811865475 This is useful if you want to separate the calculation and the results.

Some rules:



Installation

see How to install

Usage

STANDARD

If Mavscript has been installed as described and the included BeanShell is used:
  1. Create a template (input) file: template.txt or template.odt
  2. Drag the template file with the mouse on the Mavscript-bsh-icon on the desktop.
  3. A window opens and the calculation is executed. When finished, check if there is an error message and close the window.
  4. Open the output file (out-template.txt or out-template.odt) .

ALTERNATE (in order to use advanced functions or if the standard procedure does not work)

Mavscript alternately can be called out of the shell (command prompt, konsole, terminal).
cd path-to-mavscript and then:

ENHANCED FUNCTIONS

Tips

  1. Mavscript expects commands to be on a single line. But BeanShell is powerful because you can easily write methods (algorithms, functions). If you have to write them on a single line they are hardly readable.
    This problem can be avoided if you save multi line commands in a separate file (e.g. algorithm.bsh). The file then can be called using one of the following ways:
    The first way is useful for methods that are commonly used. Have a look at the file lib/init.bsh, the methods min(), max(), nf() are defined there.
  2. The method nf() (which is defined in the file lib/init.bsh) is useful for formatting numbers.
    mavscript --beanshell --init lib/init.bsh ./template.txt
    Usage: §m nf(2.33333333, 2) §o returns 2.33

Disclaimer