Saturday, April 4, 2009

Visualize results with Gnuplot

This article is briefly showing a hands-on guide to turn the output data of SUIKOU-2D into professional-looking graphs with Gnuplot, a freely distributed plotting tool.

According to FAQ 1.7, Gnuplot is freeware in the sense that you don't have to pay for it. However, it is not freeware in the sense that you would be allowed to distribute a modified version of your gnuplot freely.

The program could be downloaded here. Please read and accept the Copyrights to use it. Basically, Gnuplot is a command line driven plotting tool with extensive supports for many types of plots in either 2D and 3D with capabilities to draw using lines, points, boxes, contours, vector fields, surfaces, and various associated text, but it would be very nice to be able to have the FORTRAN codes to continue execution without fires it up in the command-line mode.

By inserting the below fortran code in SUIKOU-2D.for, it automatically displays interactive plots at the end of running program. Control plots could be managed by user in a separate text file of gnuport.txt, a compilation of selected shell scripts. It only requires "wgnuplot.exe" (1,906KB) that must be copied into folder where SUIKOU-2D.for is otherwise the plots won't be displayed.

Here is the Fortran code with an example of main program to call.
$freeform
program gnuport
call porting_gnuplot ( 'gnuport.txt' )
stop ''
end

subroutine porting_gnuplot(console)
character (len=100) command
character (len=*) console
integer status

integer system
write (command, *) 'wgnuplot ' // trim (console)
status=system(trim(command))
if (status.eq.0) then
write (*,*)

write ( *, '(a)' ) ' Normally end.'
else
write(*,*)
write ( *, '(a)' ) ' Fatal error!'

stop ''
end if

return
end

and a simple example of gnuport.txt
unset key
set title "Visualization with Gnuplot" font "Times-Roman,14"
set size ratio 0.35
set ticslevel 0
set ztics 5

set noxtics
set noytics
set zrange [0:10]
set xlabel "x-grid"
set ylabel "y-grid"

set cbtics 5
set cblabel "water depth (m)" offset character -2,0
set cbrange [0:10]
set palette rgbformulae 3,0,13
splot "y0004.gnu" matrix with pm3d

pause -1

set size ratio 1.35
set view map

splot "y0004.gnu" matrix with pm3d
pause -1
set view map
set contour base

set palette rgbformulae 3,0,13
set cbtics 5

set cbrange [0:10]
unset surface
splot "y0004.gnu" matrix with lines palette
pause -1
a=0.01
plot "u0004.gnu" using 1:2:(a*$3):(a*$4) with vector
pause -1


Screenshots:





It's a simple work to make fruitful life, isn't? :)

Link:
http://gnuplot.sourceforge.net/demo/

No comments: