Running groovy scripts with matlab - matlab

I wrote a groovy script that I need to execute on matlab. I added the groovy-all.jar file to matlab's JavaClassPath, and I'm able to run a few commands, such as adding jars to groovy ClassPath by creating a groovy console object.
javaaddpath('C:\Users\rx49\Desktop\DoseWatch\QC_Project\Script_QA_images\groovy-all-2.4.7.jar');
javaaddpath('C:\Program Files\Java\jre1.8.0_91\lib\rt.jar');
console=groovy.ui.Console();
pth='C:\Users\rx49\Desktop\DoseWatch\QC_Project\Script_QA_images\file.groovy';
script = javaObject('java.io.File', pth)
console.loadScriptFile(script);
THe console.loadScriptFile function only take as argument a java.io.File object. So I created one through the matlab javaObject function. When I execute the code below, matlab sends me the following error :
??? Java exception occurred:
java.lang.NullPointerException: Cannot invoke method edt() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:57)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at groovy.ui.Console.loadScriptFile(Console.groovy:649)
Error in ==> run_script at 7
console.loadScriptFile(script);

I have no idea if this will work, I don't have Matlab, or your script, but it feels like you should be able to do:
javaaddpath('C:\Users\rx49\Desktop\DoseWatch\QC_Project\Script_QA_images\groovy-all-2.4.7.jar');
pth='C:\Users\rx49\Desktop\DoseWatch\QC_Project\Script_QA_images\file.groovy';
shell = groovy.lang.GroovyShell();
matrix = shell.run(javaObject('java.io.File', pth));

Related

Importing Python sympy module into Julia

I have a Julia module in which I would like to import the Python function sympy.physics.wigner.wigner_9j. My minimal example module is as follows:
module my_module
using PyCall
using SymPy
export test
test()=sympy.physics.wigner.wigner_9j(1,1,1,1,1,1,1,1,1)
end
Then in my Julia notebook running:
using my_module
test()
gives
KeyError: key :physics not found
However adding to the notebook
#pyimport sympy.physics.wigner as sympy_wigner
sympy_wigner.wigner_9j(1,1,1,1,1,1,1,1,1)
gives the correct output. For some reason using #pyimport inside modules gives errors, which I typically avoid by using an __init__ inside my module, e.g adding to my_module.jl
const camb=PyNULL()
function __init__() # this should probably go in SFBBispectrum.jl
copy!(camb, pyimport_conda("camb", "camb", "conda-forge"))
pars=camb.CAMBparams()
end
which allows me to access camb.CAMBparams. Unfortunately I am failing to do something similar for sympy.physics.wigner.wigner_9j.
It has been awhile, but does this help https://github.com/JuliaPy/SymPy.jl/blob/master/src/physics.jl

"Undefined function or variable" loadAudioPlugin

I am trying to run this simple command on Matlab to load a VST:
hostedPlugin = loadAudioPlugin(pluginpath)
However, I am getting the following error: Undefined function or variable 'loadAudioPlugin'.
What's wrong? I can't seem to figure it out... This is the output I get when I type the "ver" command:
...
Audio System Toolbox Version 1.2 (R2017a)
...
The Audio system toolbox seems to be installed correctly. And the path is set correctly apparently, I can see the "loadAudioPlugin.p" file in the compiled folder.
Any ideas why Matlab says the loadAudioPlugin is not a function??

MATLAB: error when importing matlab.io.fits

I am trying to create .fits files using the matlab.io.fits functions, following the example given here: matlab.io.fits.createFile.
However, this gives me the following error:
>> import matlab.io.*
>> fptr = fits.createFile('myfile.fits');
??? Undefined variable "fits" or class "fits.createFile".
Importing the fits class directly also gives an error:
>> import matlab.io.fits
??? Import argument 'matlab.io.fits' cannot be found or cannot be imported
I get the same result in Matlab2009 and 2015.
What am I doing wrong? Do I need to install a specific class? I am new to Matlab, so it might be a very easy mistake, but some of my more Matlab proficient colleagues has not been able to solve the problem.
This error indicate that the function cannot be found. This is usually caused by the MATLAB path being corrupted. You can restore it with:
>> restoredefaultpath
>> rehash toolboxcache
You can figure out if the file is found by executing:
>> which -all matlab.io.fits.createFile
The file should be in <matlabroot>/toolbox/matlab/imagesci/+matlab/+io/+fits/createFile.m. If it is not there, you probably need to reinstall MATLAB.

Calling Jmeter Functions from BeanShell Assertion Script

I am trying to run the jmeter test-suites in eclipse.
In my test-suite I am using a BeanShellAssertion to count the number of rows in a csv file.
I have a custom jmeter function to do so.
The script of the BeanShellAssertion is :
String str = "${__CustomFunction("Path to the CSV file")}";
int i = Integer.parseInt(str);
if(i ==0)
{
Failure = true;
FailureMessage = "Failed!";
}
return i;
This test-suite works fine when I run it using the jmeter on my local machine.
Only when I try to run it with eclipse, (using the jmeter maven plugin) I see the following error:
jmeter.util.BeanShellInterpreter: Error invoking bsh method:
eval Sourced file: inline evaluation of: `` String str =
"${__CustomFunction("FilePath")}"; int i = Integ . . . '' : Typed
variable declaration : Method Invocation Integer.parseInt
I am wondering if there's some other way to invoke the jmeter functions when executing it using eclipse cause I am sure that the function is correct as I mentioned before that it works fine when the test suite is run using the jmeter on my local machine.
Any help would be appreciated.
Thanks.
Are you sure your custom function jar is visible for the Maven Plugin ?
As when you run it from JMeter, it works , I suppose you have a jar in lib/ext.
So you need to make this jar available to the jmeter maven plugin.

Scala on Mac - Cannot figure out how to run target?

I'm attempting to run a Scala script that imports scala.IO.Source, which throws an exception every time I try to run it as follows:
Exception in thread "main" java.lang.RuntimeException: Cannot figure out how to run target: countchars1.scala
at scala.sys.package$.error(package.scala:27)
at scala.tools.nsc.GenericRunnerCommand.scala$tools$nsc$GenericRunnerCommand$$guessHowToRun(GenericRunnerCommand.scala:38)
at scala.tools.nsc.GenericRunnerCommand$$anonfun$2.apply(GenericRunnerCommand.scala:48)
at scala.tools.nsc.GenericRunnerCommand$$anonfun$2.apply(GenericRunnerCommand.scala:48)
at scala.Option.getOrElse(Option.scala:108)
at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:48)
at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:17)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:33)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
I believe it is due to my Path or Classpath settings but I'm unsure what these need to be or where they need to be set. I have tried amending .bash_profile to no avail and have tried adding .profile with what I believe to be the required PATH settings but there doesn't appear to be a straight answer to this that I can find
I'm currently running Scala 2.9.1 on a Mac OSX 10.6. The script I'm trying to run from 'Programming in Scala' is as follows:
import scala.io.Source
if (args.length > 0) {
for (line <- Source.fromFile(args(0)).getLines)
print(line.length +" "+ line)
}
else
Console.err.println("Please enter filename")
I encounter the exception when I type the following in the terminal window:
$ scala countchars1.scala countchars1.scala
Any help with this would be much appreciated.
Managed to solve the issue by setting the JAVA_HOME variable using the following instructions:
http://decoding.wordpress.com/2010/02/26/how-to-set-the-java_home-variable-in-mac-os-x-snow-leopard/