You are a guest. Restricted access. Read more.
SCaVis manual

Using Groovy

You can program in Groovy language as well. Groovy gets its attention because is designed to work seamlessly with the JVM, unlike Jython. One important advantage of Groovy scripting is that programs (especially loops) implemented in this language are 3-4 times faster than those in Jython, and much faster than in BeanShell. Look at some benchmarking results here.

Here are a few Groovy tutorials:

You can use either Groovy Console (from the Run menu) or editor. In case of the editor, do not forget to use the extension “.groovy” “.gvy” or “.gy”.

First, let us show how to make a standard Java JFrame:

import javax.swing.JFrame
frame = new JFrame("Hello Swing")

Groovy and SCaVis

Let us show how to work with scientific libraries using Groovy.

Let us rewrite Jython/Python example of how to create a histogram and shown it using Groovy language. Our goal will be to rewrite this script showing H1D histogram.

First of all, one can use interactive Groovy shell of the IDE for (in the menu [Run]) or jut typing a code in the editor and saving it with the extension .gy or .groovy. But our goal will be to write a script using the editor.

import jhplot.HPlot
import jhplot.H1D
 
c1=new HPlot()
c1.setGTitle("Global labels: F_{2},  x_{γ}  #bar{p}p F_{2}^{c#bar{c}}");
c1.visible()
c1.setAutoRange()
 
h1 = new H1D("Simple1",100, -2, 2.0)
rand =new java.util.Random()
 
print "Use of for loop in Groovy \n"
for (int i=0; i<100; i++) {
   h1.fill(rand.nextGaussian())
   }
 
c1.draw(h1)

Create a file “example.gy” with this code (the extension “.gy” is very important!) and run this script as usual. To run this script, use the Run button [] on the toolbar of SCaVis. One can also use the [F8] key for fast execution of a script. In case of an error, the SCaVis outputs error to the Output console.

Java class imports

You are not full member and have a limited access to this section. One can unlock this part after becoming a full member.

Converting Jython example to Groovy examples

Since most of SCaVis example are written in Jython/Python, here are a few suggestions how to convert Jython code to Groovy scripts:

You are not full member and have a limited access to this section. One can unlock this part after becoming a full member.

Groovy and ScaVis libraries

Groovy scripts, if the run inside SCaVis, access to all numerical and scientific libraries of SCaVis. Here is one example:

You are not full member and have a limited access to this section. One can unlock this part after becoming a full member.

man/program/groovy.txt · Last modified: 2013/07/28 08:43 by admin
CC Attribution-Share Alike 3.0 Unported
Powered by PHP Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 Valid HTML5