Webnucleo.org

Mail Lists | Developers
small logo

This tutorial demonstrates how to use Webnucleo's Perl script for converting an ascii file of sparse matrix input data into an XML file appropriate for use in Webnucleo's Sparse Matrix Tool. It assumes you are in a Linux or Unix environment. If you are using a different operating system, please adjust the following instructions as appropriate.

Download Perl Code

To begin, download the Sparse Matrix Tool distribution available in the downloads page.

Unpack the distribution. For example, the following commands below should work.

gunzip  sparse_matrix_x.tar.gz

tar  xvf  sparse_matrix_x.tar.gz

where x is the version number. For example, if you downloaded version 0.1, you would type

gunzip  sparse_matrix_0.1.tar.gz

tar  xvf  sparse_matrix_0.1.tar.gz

The perl script, input_matrix_ascii_to_xml.pl, is located in the pl/ directory and the example input file, input_matrix.txt, is in the data_pub directory.

In input_matrix.txt, each element of matrix data is given as a space-delimited triplet of row, column, and value. Thus, the first column in the file contains all the rows, the second column all the columns, and the third column all the matrix element values.

Make the Perl script executable by typing:

chmod  +x  input_matrix_ascii_to_xml.pl

You are now ready to create the XML file.

-top-

Create the XML

You can now run the Perl script to convert the ascii data in input_matrix.txt into XML. To do this, type the following:

perl  input_matrix_ascii_to_xml.pl  ../data_pub/input_matrix.txt  my_input_matrix.xml

The resulting XML file my_input_matrix.xml is ready to be uploaded to the Sparse Matrix Tool.

-top-

Challenges

Can you edit the input_matrix.txt file and run the Perl script to get a different XML file? Can you locate Perl on your system by typing:

which  perl

and then editing the shebang (# !) line in the input_matrix_ascii_to_xml.pl appropriately so you can simply type

input_matrix_ascii_to_xml.pl  input_matrix.txt  my_input_matrix.xml

to convert ascii to XML? This will save you time if you plan to use the Perl script to convert ascii input matrix data to XML in the future.

-top-



Valid XHTML 1.1        Copyright © 2001-2012, Clemson University. All rights reserved.        Valid CSS!
Page last modified on 2008/05/26 12:12