Monday 27 July 2009

Write Matlab files without Matlab via Java and JMatIO

I had to interface a shiny new analytical suite built on KNIME with some legacy applications in Matlab we are unfortunately still using. This demanded exporting tables into Matlab's proprietary data format from Java.

I used the JMatIO library and everything worked like a charm. The following code snippet (taken from here) best illustrates the use of the library:

//1. First create example arrays
double[] src = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
MLDouble mlDouble = new MLDouble( "double_arr", src, 3 );
MLChar mlChar = new MLChar( "char_arr", "I am dummy" );

//2. write arrays to file
ArrayList list = new ArrayList();
list.add( mlDouble );
list.add( mlChar );

new MatFileWriter( "mat_file.mat", list );

This is equivalent to the following Matlab code:

double_arr = [ 1 2; 3 4; 5 6];
char_arr = 'I am dummy';
save('mat_file.mat', 'double_arr', 'char_arr');

Neat, isn't it?

Friday 24 July 2009

Adding external Java libraries to new KNIME plugins

Sorry, it is a blunt copy-paste plagiarism, but I needed to keep it written somewhere. Here it goes:

In order to add external jars to new KNIME plugins you need to: 

  1. Create a lib directory in your KNIME plugin.
  2. Copy the file(s) into the lib directory. (Java libraries are packed either as a zip or jar archive.)
  3. Edit the META-INF/MANIFEST.MF file with the "Plug-in Manifest Editor".
  4. Go to the "Runtime" tab and add all necessary libraries to the "Classpath" list on the bottom-right corner using the "Add..." button.
  5. Go the to "Build" tab and add the files to the list contained in the section "Extra classpath entries".
  6. Make sure that the lib directory is selected in both the "Binary Build" and "Source Build" list (in the same tab).

Finally note that adding jar files to the plugins build path, i.e. project context menu -> "Java Build Path" ->"Libraries" is not necessary.

Saturday 18 July 2009

Dealing with filenames with spaces in bash scripts

My war against spaces in filenames is lost. Even if I would never dare type one, my hardrive keeps receiving them from computer illiterate colleagues.

Admittedly, they are not a big pain until I want to make backups. My backup script contained a 

for file in `find . -type f`
do
...
done

kind of script. But whenever the found filename contained an space, my variable $file contained part of the filename and a huge mess unleashed.

Here is, however,  a neat solution to my troubles:

find . -type f -name '*' | while read file
do
...   
done

Friday 17 July 2009

Problems with Alfresco Share running on non-standard ports

There is almost no web application which does not want to listen on port 8080. Alfresco is one of them. But, sorry, on my machine the port is already taken!

So I had to move it to an anagram (I am running short of them!) and edited the file

$ALFRESCO_HOME/tomcat/conf/server.xml

replacing the string 8080 by 8800.

However, Alfresco Share refused to start. After trying to log in, I got a "Failed to Login" error followed by "The remote server may be unavailable or your authentication details have not been recognized". But my user/password was correct...

There was another obscure quirk to update in order that the port migration were effective: replacing every occurrence of the old port number in file

$ALFRESCO_HOME/tomcat/webapps/share/WEB-INF/classes/alfresco/webscript-framework-config.xml

After that, Alfresco Share was fully functional.