Archive for June, 2011

Publish MATLAB output as a document(html, doc, LaTex, Powerpoint etc.,)

Here I wanted to share how did I convert the matlab output to the specific document using the publish command of matlab. We can also run the matlab code from outside matlab window.

The following steps are to be followed to run the matlab code from command prompt.
step1: First edit PATH system variable and set the matlab path as [MATLABINSTALLEDFOLDER/bin/]
step2: Now from the command prompt we can run any file using the following code
matlab -r scriptname (without the .m extension but first we have to change directory to the source existing folder)
ex: c:\Users\MyWindows7\MATLAB > matlab -r example
[example.m is the actual script to be run]
Now let us actually see how we can publish an output of script as a document

function [ret]= publishToFormat(filename, format)
    options_doc_nocode.format= format;
    options_doc_nocode.outputDir = 'd:/matlabNDVIOutput';
    options_doc_nocode.showCode = false;

In the above code we are providing the name of the function and format to which the script output has to be stored. The above code is simple and straight forward it says the format of the output file and where that output file has to be stored. whether the source code of the script file has to be written to the output or not.

The following links are the ways of using java code in matlab and convert the matlab file into the java file and java web services.

Open-ssh Server installation in ubuntu

If you want to remotely login to any system which is running linux you can do so by using ssh command which is very famous for its security awareness. In ssh all the communication via port 22 is encrypted unlike other communication protocols such as TELNET, ftp, rlogin etc., where all the data and passwords can be hacked.

In all the flavors of linux there is no guarantee that ssh is pre installed. Particularly I’m running ubuntu LT 10.04 in which it is not pre-installed. We have install it manually. Openssh is a free open source version of ssh protocol implementation.

We can install openssh client and server using the below command

# sudo apt-get install openssh-server openssh-client

then we can test it by using

ssh localhost
# ssh user@your-server-ip-address
Ex: #ssh sshVasnath@vasanth

if you want to get the sudo privileges to sshVasanth user running on the machine IP address, you should
use the run the following command in the server( with sudo

# sudo adduser <ACCOUNTNAME> admin

Ex: sudo adduser sshVasanth admin

SOAP message to run the service in server

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

 * @author Chittampally Vasanth Raja
public class SOAPMessage1 {

         //First create the connection
    public static void main(String[] args) throws IOException, TransformerConfigurationException, TransformerException {
        try {
            SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
            SOAPConnection connection = soapConnFactory.createConnection();
            MessageFactory messageFactory = MessageFactory.newInstance();
            SOAPMessage message = messageFactory.createMessage();
            //Create objects for the message parts
            SOAPPart soapPart = message.getSOAPPart();
            SOAPEnvelope envelope = soapPart.getEnvelope();
            SOAPBody body = envelope.getBody();
            //Populate the body
            //Create the main element and namespace
            SOAPElement bodyElement = body.addChildElement(envelope.createName("add", "ns2", ""));
            //Add content
            // bodyElement.setEncodingStyle("text/xml");
            //Save the message
            //Check the input
            //Populate the Message
            //        StreamSource preppedMsgSrc = new StreamSource(
            //                 new FileInputStream("./prepped.msg"));
            //        soapPart.setContent(preppedMsgSrc);
            //String destination = "http://localhost:8084/TestAT/HelloWorld";
            String destination="http://localhost:8080/GlassWS/HelloWorldService";
            //Send the message
            SOAPMessage reply =, destination);
            System.out.println("" + reply);
            //Create the transformer
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
            //Extract the content of the reply
            Source sourceContent = reply.getSOAPPart().getContent();
            //Set the output for the transformation
            StreamResult result = new StreamResult(System.out);
            transformer.transform(sourceContent, result);
            //Close the connection
        } catch (SOAPException ex) {
            Logger.getLogger(SOAPMessage1.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedOperationException ex) {
            Logger.getLogger(SOAPMessage1.class.getName()).log(Level.SEVERE, null, ex);


Parallel OpenMP Search algorithm

Here is the parallel version of the linear search algorithm using OpenMP

//Author: Chittampally Vasanth Raja
//The following program is parallized version of search algorithm
#define MAXTHREADS 10
#define ARRAYSIZE 44
int main(void)
	int a[]={3,5,1,2,34,67,90,43,53,3,4,26,34,35,54,67,87,21,34,56,33,45,12,34,5,6,7,8,123,45,32,455,666,444,333,222,11,22,44,55,333,222},i,j,found=0,key=222;
	double start_time,run_time;
start_time = omp_get_wtime();
		#pragma omp parallel private(i)

			int start,noofsteps;
			#pragma omp single
				printf("num of threads in action: %d\n",j);


if(key==a[i]) {
						printf("Key has been found in %d thread at %d position\n",omp_get_thread_num(),i+1);

		run_time = omp_get_wtime() - start_time;
	  printf("\n %f seconds %d threds \n ",run_time,j);

return 0;

My First OpenMP program

This is my first OpenMP program

//Author: Chittampally Vasanth Raja
//First Hello World simple OpneMP program

using namespace std;
#include <iostream>
#include <omp.h>

int main(void)
	#pragma omp parallel
	cout<<"Hello World !! It has "<<omp_get_num_threads()<<" threads.. This line is printed by Thread: "<<omp_get_thread_num()<<"\n";
	return 0;

compile the above program using
g++ -o hello -fopenmp First.cpp