Gnuplot – Plotting Program


is a portable command-line driven graphing utility for Linux, OS/2, MS Windows, OSX, VMS, and many other platforms. The source code is copyrighted but freely distributed (i.e., you don’t have to pay for it). It was originally created to allow scientists and students to visualize mathematical functions and data interactively, but has grown to support many non-interactive uses such as web scripting

Gnuplot can be downloaded from previous link or from: softpedia gnuplot

* * *

Here is an example for plotting the time history shown above using the following files:

Gnuplot command file:  plot_drop.plt

Time history:  drop.txt

* * *

Here is an example for generating a graph with two subplots using the multiplot command.

Gnuplot command file:  plot_drop_multiplot.plt

Time histories:  drop.txt  &  drop_velox.txt

Here is an alternate example that plots the two curves in separate windows:  plot_drop_2.plt

* * *

The follow command is then entered into the gnuplot window:

gnuplot>load “plot_drop.plt”

* * *

The drop_plot.plt file also generates a corresponding png file as shown at the beginning of this post.

The  above plot was made using Gnuplot Version 4.6 patchlevel 3.

The png file can be accessed by other applications but may require the following command first depending on the application, operating system, etc.


* * *

Here is an example for plotting a power spectral density in log-log format, with some manually added tics.

Data file: plate.psd

Gnuplot file: plot_psd.plt

gnuplot>load “plot_psd.plt”

* * *

Here is an example for plotting a shock response spectrum with two curves and a legend.

Data file:  half_sine_srs.txt

Gnuplot file:  plot_srs.plt

gnuplot> load “plot_srs.plt”

* * *

Here is an example for calling gnuplot from within a Fortran program running in Ubuntu:  fortran_gnuplot_demo.f

The key code line is:

CALL SYSTEM(‘gnuplot gnuplot_demo.plt -persist’)

* * *

See also:  Python & Gnuplot

* * *

– Tom Irvine

Bombardier Q400 Turboprop Acoustics


I recently flew from Spokane to Seattle, Washington on an Alaska/Horizon Air Bombardier Q400 aircraft, similar to the one in the above image.

This model aircraft has two Pratt & Whitney Canada PW150A turboprop engines.

I captured the following video during cruise using a Motorola/Android phone (when it was safe for passengers to turn on their portable electronic devices): Audio/Video File

* * *

Data Analysis


(Click on image for a better view)

The PW150A engine/propeller rotation rate during takeoff and climb is 1020 RPM, but is throttled back at cruise altitude to 850 RPM, or 14.17 Hz. There are six blades on each engine, so the blade passing frequency is 85 Hz. This frequency and its integer harmonics are clearly visible in the spectral analysis of the audio track.

Here is the time history: Q400.txt – time(sec) & unscaled sound pressure

* * *

See also: Bombardier

– Tom Irvine

* * *

Notes to self so I can remember the processing steps:

Audio track processing

Extract audio: avconv -i input.3gp output.wav
Matlab script: audio_txt.m

Video processing

Convert video format:

The following steps were done in Ubuntu:

Rotate 90 degrees: avidemux

Trim video footage:

avconv -i input.avi -vcodec copy -acodec copy -ss 00:00:09 -t 00:00:21 output.avi

Matrix Inversion in LAPACK

Here is a Fortran program which performs matrix inversion using the LU decomposition method:  INVERSE_MATRIX.F

It is compiled via:


It compiles & runs under both Ubuntu & Cygwin.

See also:

* * *

The INVERSE_MATRIX.F program uses the subroutines: DGETRF & DGETRI

DGETRF computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges.

DGETRI computes the inverse of a matrix using the LU factorization computed by DGETRF.

This method inverts U and then computes inv(A) by solving the system inv(A)*L = inv(U) for inv(A).

* * *

Here is a similar C++ program:  matrix_inverse.cpp 

It is compiled as:

gcc -o matrix_inverse matrix_inverse.cpp -llapack -lstdc++

* * *

See also:  Python Matrix Inversion

* * *

Tom Irvine

Mixed C++ Fortran Programming

This is another matrix multiplication project using the BLAS function dgemm. It is complied and run in an Ubuntu system.

The set consists of two programs:  (right mouse click.  save target or link as)


The set calculates: C = A*B

The C++ program matrix_mult_cf reads in two matrices, A & B.

The input matrices may each have an arbitrary number of rows and columns up to a certain cell limit. Furthermore, the number of A columns must be equal to the number of B rows.

The matrix_mult_cf program then calls a subroutine from fort_matmul_main to do the matrix multiplication.

The fort_matmul_main subroutine uses dgemm to perform the actual multiplication.

An important feature of this program set is that the C++ and Fortran codes pass the matrices back and forth using 1D arrays. This approach requires some extra steps, but it avoids the complexity of passing 2D arrays, especially if any of the matrices is non-square.

The set is compiled using:

gfortran matrix_mult_cf.cpp fort_matmul_main.f -o mmult_cf -lstdc++ -lblas

The resulting executable code is run as


* * *

Tom Irvine

Ubuntu Plotting Programs

I am evaluating plotting programs for Ubuntu.  I already have plotting capability via Matlab and Python/matplotlib running under Ubuntu.

The Matlab export plot quality is ok but not great.

So far my Python knowledge only extends to making static plots.  Identifying interactive, dynamic plotting methods in Python is still on my “to do” list.

In the mean time, I am looking for an alternate plotting program that will import ASCII text data which may be comma, space, or tab delimited.  The data will then be plotted in a 2D line graph.

The program should have options for grid, labels, scaling, changing plot limits, log format, multiple curves, legend, makers, etc. The program should be user-friendly and preferably free.  It should be useful for both quick visualization and publication quality plots.

* *

Here are the results so far in alphabetical order.  This post will be updated as further evaluations are made.
DataScene – commercial package. Evaluation pending.

Gnumeric – nice spreadsheet capabilities.  Need more control over plotting parameters.

gnuplot – command line program.  Currently evaluating at Gnuplot Post.

Grace –  still trying to work through input file browser.  Further effort is needed to learn.

PlotDrop – on the right track, but needs more features.  Good for quick visualization.

QtiPlot –  nice spreadsheet capabilities.  Need more control over plotting parameters.

Rlplot – was unable to properly read input file.  Further effort is needed to learn.

SciDAVis – reasonably good at both quick visualization and export image quality.

Scilab –  review pending.

Tecplot – commercial package. Evaluation pending.

Veusz – reasonably good results.  Takes some getting use to.  May be better for preparing publication plots than for quick visualization.

ygraph – on the right track, but needs more features.

* * *

Hopefully,  these programs will be revised with feature enhancements, etc.

SciDAVis is the program which best meets my criteria for the time being.

* * *

Tom Irvine


Linux Ubuntu Tips

The make install command is necessary to build certain software package.

This may result in an error such as:

/usr/local/lib: Permission denied

The problem can be fixed by typing:

su -c “make install”

Then enter root password when prompted

* * *

The Update Manager may hang.

An alternate method is to use the following commands in the terminal:

sudo apt-get update
sudo apt-get upgrade

* * *
Tom Irvine

Install CBLAS in Ubuntu & Cygwin

CBLAS is C interface to the BLAS library.

* * *

Ubuntu Installation instructions:

BLAS must be installed first.

The instructions for BLAS are given at:
Generalized Eigenvalue Problem & BLAS



tar zxf cblas.tgz

Go to CBLAS folder.

Open in a text editor.

Modify this line in

BLLIB = (specify path)/BLAS/blas_LINUX.a

make all

* * *

The Cygwin installation is similar except that the following is needed in

BLLIB = C:/cygwin/lib/libblas.a

* * *

Tom Irvine

Matrix Multiplication in BLAS & CBLAS

Here is a program that uses dgemm to multiply two matrices:  matrix_mult.cpp

The dgemm function is implemented using gsl blas.

It can be compiled under Cygwin as:

gcc -o matrix_mult_alt matrix_mult_alt.cpp -lgsl -lstdc++

And under Ubuntu as:

gcc -o matrix_mult_alt matrix_mult_alt.cpp -lgsl -lgslcblas -lstdc++

* * *

For benchmark comparison, here is a matrix multiplication program which uses pure pointer access without BLAS.    matrix_11.cpp

* * *

A Fortran program which uses the intrinsic function MATMUL is given at:  MATRIX_MULT.F

A Fortran program which uses DGEMM is:  MATRIX_MULT_D.F

The program was compiled using:

gfortran -o MATRIX_MULT_D MATRIX_MULT_D.F -lblas -llapack

As an aside, the following was used to determine memory leaks during the debugging process:

gfortran -g -o MATRIX_MULT_D MATRIX_MULT_D.F -lblas -llapack -Wall -fbounds-check -fmax-errors=1 -Werror

* * *

Here is a program  matrix_mult_cblas.cpp  which uses cblas_dgemm.

It is compiled in Cygwin via:

gcc -o matrix_mult_cblas matrix_mult_cblas.cpp c:/cygwin/lib/libblas.a c:/cygwin/lib/libcygwin.a c:/cygwin/home/tirvine/CBLAS/lib/cblas_LINUX.a -lstdc++

The paths should be modified according to your library installation.

Note that CBLAS can be installed in Cygwin using the instructions at:

* * *

Tom Irvine

Lapack in Ubunutu

Blas and Lapack may be installed on an Ubuntu system using the instructions at:

Generalized Eigenvalue Problem

* * *

C++ programs that use Lapack can be compiled in Terminal or Bash shell mode via:

g++ file_in -o file_out -lgfortran -llapack -lm


file_in is the source code

file_out is the output executable file

In addition, linker option -lblas may be needed by the source code.

Verify that the output file exists:

ls -lt

Then run the program:


* * *

The source code can also be built in the Code::Blocks IDE.

The following lines must be added to the linker options:

-lblas     (if needed by source code)


1. Suggest running Ubuntu with Gnome shell rather than Unity in order to avoid Code::Blocks missing menu bar problem.

2. Failure to include the linker options will result in errors such as:

ilaenv.f   undefined reference to ‘_gfortran_compare_string’

* * *
Tom Irvine

Generalized Eigenvalue Problem

The goal of this project is to solve a “very large” generalized eigenvalue problem in a “reasonable” amount of time using library functions. The mass and stiffness matrices may be either dense or sparse. Optimum routines are desired for each case.

Here is description of the libraries and packages

gcc – GNU Compiler Collection for C/C++

BLAS – Basic Linear Algebra Subprograms

CBLAS – C interface to the BLAS

LAPACK – Linear Algebra PACKage. LAPACK is a software library for numerical linear algebra including the generalized eigenvalue problem. It uses BLAS.

PETSc – Portable, Extensible Toolkit for Scientific Computation. PETSc is a suite of data structures and routines for the scalable (parallel) solution of scientific applications modeled by partial differential equations. It includes a large suite of parallel linear and nonlinear equation solvers that are easily used in application codes written in C, C++, Fortran and now Python.

SLEPc – a software library for the parallel computation of eigenvalues and eigenvectors of large, sparse matrices. It can be seen as a module of PETSc that provides solvers for different types of eigenproblems, including linear (standard and generalized) and quadratic, as well as the SVD.

Note that PETSc/SLEPc requires BLAS/LAPACK.

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

Installation Steps:

I have a PC with Ubuntu 11.10 running with the gnome-classic shell.

I have installed the following:

Code::Blocks with the gcc compiler from the Ubuntu Software Center

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *


Step 1: download

$ wget

Step 2: extraction

$ tar zxf blas.tgz    this will create a directory BLAS

Step 3: compilation

$ cd BLAS

$ make all

If everything was correct in the previous step, your library is in the BLAS directory, called blas_LINUX.a

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *


Installation instructions:

BLAS must be installed first.



tar zxf cblas.tgz

Go to CBLAS folder.

Open in a text editor.

Modify this line in

BLLIB = (specify path)/BLAS/blas_LINUX.a

make all

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *


Step 1: download

$ wget

Step 2: extraction

$ tar zxf lapack.tgz        this will create a directory lapack.

Step 3: compilation

$ cd lapack-3.3.1

The configuration can be done in the file:

modify:  BLASLIB      = /directory/where/to/find/BLAS/blas$(PLAT).a

The LaPack library uses the BLAS library, so you need to tell where to find it. The result is a library lapack_LINUX.a: this can be copied in a place of your choice.

Save file as:

$ sudo apt-get install cmake      (if not installed already)

$ cmake

$ make

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


The following step may also be needed:
$ sudo apt-get install libblas-dev liblapack-dev

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

The C++ source code for the generalized eigenvalue program is given at:
gen_eigen.cpp    (right mouse click & save target or link)

The header files are:   dsygv.h     dsyev.h     cblas.h

The source code uses BLAS, CBLAS & LAPACK.

The following linker options are required:


* * * * * * * * *

Here is another C++ version: gen_eig.cpp

The program can be compiled via:

gcc -o gen_eig gen_eig.cpp -lblas -llapack -lstdc++

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

Here is a pure Fortran program for the generalized eigenvalue problem:  geigen.f

The program can be compiled via:

$ gfortran -o geigen geigen.f -lblas -llapack

* * *

Matlab scripts are given at:

Matlab Linear Algebra Page

* * *

A future generalized eigenvalue problem code will use PETSC & SLEPc.  These packages can be downloaded via:

sudo apt-get install petsc-dev

sudo apt-get install slepc3.1-dev

* * *

Python is well-suited for the generalized eigenvalue problem.  It has functions derived from LAPACK.  It also has functions for sparse systems using ARPACK.  Sample scripts are posted at:

Vibrationdata Python  Generalized Eigenvalue

* * *

Tom Irvine