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

Fortran tips

I am relearning Fortran, including the features which have been added since I last used it some twenty years ago.

Here is a method for compling a sample Fortran program NAME.F.  This method checks for memory leaks.

gfortran -fbounds-check -o NAME NAME.F

Tom’s Fortran programs & related posts:  FORTRAN

– Tom Irvine

Autocorrelation & Cross-correlation

Cross-correlation is a measure of similarity of two waveforms as a function of a time-lag applied to one of them.

Autocorrelation is the cross-correlation of a signal with itself. It is a time domain analysis useful for determining the periodicity or repeating patterns of a signal.

Here are two Matlab scripts which perform correlation analysis.  They do not require the Matlab Signal toolbox.


Here is a paper:  autocorrelation.pdf

See also:  Python Autocorrelation & Cross-correlation

* * *

Here is a set of Fortran programs:



– Tom Irvine

Time History Synthesis for Shaker Shock Testing

Consider a component which is to be subjected to a shock test using a shaker table.

The test specification for this example is a Shock Response Spectrum (SRS).

The control computer must synthesize a time history for the test.  The typical method is via a series of wavelets.

The Matlab scripts in demonstrate this process.

The main script is:  wavelet_synth.m

The remaining scripts are supporting functions.

* * *

Here is a Fortran version:  wavelet_synth.f

* * *

Here is a script that uses a series of sinusoids:

* * *

See also:   SRS Synthesis (mainly for pyrotechnic shock simulation)

* * *

Tom Irvine

Rainflow Fatigue Cycle Counting

Endo & Matsuishi (1968) developed the Rainflow Counting method by relating stress reversal cycles to streams of rainwater flowing down a Pagoda.  This method is very useful for fatigue analysis.

The rainflow method allows the application of Miner’s rule in order to assess the fatigue life of a structure subject to complex loading.

The resulting tabular data is sometimes referred to as a spectra.

rainflow bins.m is a Matlab script that performs rainflow cycle counting on a time history per ASTM E 1049-85 (2005). Its supporting function is: progressbar.m

Rainflow counting is also included in the following GUI package.

Matlab script: Vibrationdata Signal Analysis Package

The specific method is ASTM E 1049-85, section 5.4.4, Rainflow Counting. The results of this method for an example are shown in Figure 6 of the ASTM document.

A Fortran version is:  RAINFLOW.F

A C/C++ version is:

* * *

Here is a version which outputs the results in a NASGRO long block format:


* * *

These scripts calculate the response of a single-degree-of-freedom system to an arbitrary base input time history.

The scripts also have an option for rainflow cycle counting.

arbit_rainflow.m is the main script.

The remaining scripts are supporting functions.

* * *

Here is a script for calculating a damage index from the rainflow results. It is meant for relative comparisons only. fatigue_damage_sum.m

* * *

See also:

Basic Rainflow Cycle Counting & Fatigue Damage Spectrum: basic_rainflow_FDS_revA.pptx 

Fatigue Analysis Webinars

A Comparison of the Consecutive Peak and Rainflow Cycle Counting Methods for Cumulative Damage Calculation: Rayleigh_rainflow_study.pdf

Fatigue Damage for a Stress Response PSD

Miner’s Cumulative Fatigue via Rainflow Cycle Counting

Rainflow Counting Tutorial & Alternate Link

Fatigue Damage Spectrum

Dirlik Method for PSDs

Python Rainflow Page

Matlab Mex Example

Enveloping Nonstationary Random Vibration Data

Sine Vibration Rainflow & Fatigue Damage

* * *

– Tom Irvine
Join me at:  LinkedIn

Contact Form:

Fourier transform

The following Matlab scripts calculate the Fourier transform of a time history:

The main script is: fourier.m

The remaining scripts are supporting functions.

* * *

A Matlab GUI version is included in:  Vibrationdata Matlab Signal Analysis Package

* * *

See also:

Shock and Vibration Signal Analysis

Python Fourier Transform

Waterfall FFT

* * *

A Fortran version is given at: FOURIER.F

A Fast Fourier version is: FFT.F

* * *

Please let me know if you have any questions.

Tom Irvine

Power Spectral Density of a Time History

The Matlab scripts in calculate the power spectral density function for a time history.

The main script is:  PSD.m

The remaining scripts are supporting functions.

* * *

A Fortran power spectral density program is given at:  PSD.F

* * *

See also:

Matlab Random Vibration Page

Random Vibration & Power Spectral Density Page

Python Power Spectral Density

* * *

Please let me know if you have any questions.

Thank you,
Tom Irvine

Shock Response Spectrum

 The most widely used algorithm for the Shock Response Spectrum (SRS) calculation for base excitation is the ramp invariant digital recursive filtering relationship given in:

David O. Smallwood, An Improved Recursive Formula for Calculating Shock Response Spectra, Shock and Vibration Bulletin, No. 51, May 1981.  The link is:  DS_SRS1.pdf

Smallwood duly gave the resulting filtering coefficients in his paper, but he omitted the derivation details for brevity.

This omission is typical for papers published in journals and conference proceedings, given that derivations may require dozens of steps.

The SRS derivation requires impulse response functions, Laplace transforms and Z-transforms.

The following paper fills in the details:  ramp_invariant_base.pdf

See also:

An Introduction to the Shock Response Spectrum:  srs_intr.pdf

Hypersphere SRS

Additional papers are given at: Vibrationdata SRS

* * *

Here is a Matlab script for the SRS calculation of an arbitrary base input pulse: srs.m

Supporting functions:


* * *

A Matlab GUI version is included in:  Vibrationdata Matlab Signal Analysis Package

* * *

Here is a Matlab SRS function which call be called by main scripts:  srs_function.m

* * *

Here is a Matlab script for the time history response of a specific SDOF system to an arbitrary pulse:

* * *

Here is a Matlab script for the SRS of a half-sine pulse & its supporting function:  halfsine.m  & time_calc.m

* * *

A Fortran SRS program is given at:  QSRS.F

* * *

See also:

SRS Educational Animation

Shock Webinar

Python SRS

Synthesize an Acceleration Time History to Satisfy a Shock Response Spectrum

SRS Tripartite

Pyrotechnic Shock Characterization Testing

Pyrotechnic Shock Joint Attenuation

* * *

– Tom Irvine
Join me at:  LinkedIn

Solve a System of Linear Equations, Ax=B

Here is a Fortran program which solves a system of linear equations: LIN_EQ.F

It is compiled via:

gfortran -o LIN_EQ LIN_EQ.F -llapack

The program uses the LAPACK subroutine: DGESV

* * *

A version written in C/C++ is given at:  linear_eq.cpp 

It is compiled via:

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

* * *

Tom Irvine



Message Passing Interface (MPI) is a portable library of subprograms which can be used to facilitate parallel computing.

The MPI subprograms can be called from C and Fortran programs.

Parallel Computing

Parallel computing enables large scale numerical problems to be solved in a timely manner.  It can be performed on a multi-core PC, or using several networked PCs on a cluster or grid.

The key is to separate large problems into smaller ones.  The calculations are then carried out simultaneously.

The MPI subprograms regulate the communication and synchronization between the various CPUs and memory locations.


MPI can be downloaded from:

The best installation method is to build the source code using the directions in:

This can be done under Cygwin or Linux.

Sample Program

Then go to:

Download the greetings.c program to the same folder which contains mpicc.

Also find and copy libmpich.a into this same folder.

Compile the program via:

mpicc -o greetings greetings.c libmpich.a

Then run the program via:

./mpirun-n 4 ./greetings

Grant persmission to run under firewalls if so prompted by pop-up windows.

The program can also be run as:

./mpiexec -n 4 ./greetings

In the above example, four processors were used.

More later . . .

* * *

Another source…     Argonne National Labs MPICH2

Tom Irvine