I use gnuplot to visualize meterological data. This program can visualize data under Windows, Linux/Unix and on MAC. Before working with real metereological data (see case 2) I used the simple case described here (case 1) to play around with gnuplot 3-dimensional data.
gnuplot has no official API. This makes it impossible to link gnuplot to a C or FORTRAN program. It must be called as a separate program so that is is difficult to transfer parameters. I assume here that not all gnuplot commands are entered manually. There are some methods to transfer parameters like data file names to gnuplot:
Meterological data often require visualizations showing isolines, very often isobars (i.e. lines delimiting areas with the same bar/pressure values). In gnuplot terms isoline plots are called contour plots. Contour plots under gnuplot require 3-dimensional data (x,y,z coordinates). Note that for 3-dimensional data gnuplot requires an empty line if a row (y dimension!) is finished.
The simple C-program makeGnuplotData I have written produces 3-dimensional data on stdout. No external data are needed. The program produces some simple geometrical (roof like) objects.
The following steps are required to produce the image below. These instructions are also contained in the comments at the start of the source code:
This is the resulting image plotted by
Here is the gnuplot macro to be used in the gnuplot call:
Here is the source code for the rather simple C-program:
This scenario is a little bit more complex than the preceeding one:
it uses real metereological data from DWD (Deutscher Wetterdienst). You
may find the data used here and many similar data sets
under this link.
There are lots of other data provided by DWD - not all given in
the simple ASCII format that we use here.
The C program is needed as gnuplot expects 3-dimensional data
in a special form: after each row an empty line must be inserted.
If you look at the ASCII (non-binary) data provided by DWD you will
see that the file contains only precipitation sums for each cell
in a rectangular area.
A value of -999 indicates that no data are found
at this grid cell (which is the probably outside the region of interest).
The program reads the first 6 lines (header) from the data file.
These lines contain
meta information for the data, among them
set terminal wxt size 1000,700
set title "EH Iso at " . strftime("%Y-%m-%d %H:%M:%S",time(0)+3600)
#set view 0, 0, 1.4, 1
set contour
set isosamples 40
#unset surface
set surface
splot "iso.dat" with lines
// module makeGnuplotData
// Generates data for subsequent call of gnuplot
// E.Huckert 02-2022
// 03-2022: this version is OK (tested under Windows 7 and Linux)
// Compile (GNU gcc under Linux):
// gcc -o gmakeGuplotData makeGnuplotData.c -lm
// For isolines (contour) in gnuplot:
// Produce the data, put them in file iso.dat
// makeGnuplotData > iso.dat
// Write a very basic macro (name=iso.gnu)for gnuplot:
/*
set xrange [0:13]
set yrange [0:15]
set zrange [0:10]
set contour
unset surface // optional, use # to comment out
splot "iso.dat" with lines
*/
// Call then gnuplot as follows:
// gnuplot iso.gnu -p
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
// --------------------------------------------
void usage()
{
fprintf(stderr, "call: makeGnuplotData >outfile\n");
fprintf(stderr, "E.Huckert 03-2023\n");
}
// --------------------------------------------
void drawHLine(int x1, int x2, int y, int z)
{
printf("%d %d %d\n", x1, y, z);
printf("%d %d %d\n", x2, y, z);
} // end drawHLine()
// --------------------------------------------
void drawVLine(int x, int y1, int y2, int z)
{
printf("%d %d %d\n", x, y1, z);
printf("%d %d %d\n", x, y2, z);
} // end drawVLine()
// --------------------------------------------
int main(int argc, char *argv[])
{
int x = 1;
int y = 1;
int xOffs = 1;
int yOffs = 2;
int yLen = 10;
int xLen = 10;
int zv = 2;
int x1, x2, y1, y2;
// Generate GRID data for gnuplot (output should be catched via redirection)
// Draw some 3-dimensional (roof like) objects
x1 = x + xOffs;
x2 = x1 + xLen;
y1 = y + yOffs;
y2 = y1 + yLen;
//
for (int n=0; n < 3; n++)
{
drawHLine(x1, x2, y1, zv);
drawVLine(x2, y1, y2, zv);
drawHLine(x2, x1, y2, zv);
drawVLine(x1, y2, y1, zv);
printf("\n");
//
x1 = x1 + xOffs;
x2 = x2 - xOffs;
y1 = y1 + yOffs;
y2 = y2 - yOffs;
zv = zv + 2;
} // end for int ...
//
zurueck: // label not used
return 1;
} // end main()
Case 2: Contour Plots using real metereology data
The program rearranges these data taking into account the
number of rows and columns.
The resulting data are written to stdout and can be catched
via redirection in
a file called iso2.data which is later used in macro iso2.gnu.
The source code contains comments explaining how to use the program.
The gnuplot macro is very similar to the macro used in case 1. It produces however however a JPEG file instead of plotting into an interactive window.
All necessary components (source code, gnuplot macro, sample data
and resulting JPEG image)
are in this
ZIP file.
The resulting JPEG image for our real metereology data follows here:
Sometimes metereologists need sequencies of images (movies) to visualize their results. A typical example is the movement of a cloud across time.
JPEG (or more correctly: JFIF) is not suited to represent movies (sequences of single JPEGs). MP4 should be the right format - but this is a real complicated beast.
The only simple format I found is GIF, or better: "animated GIF". This "animated GIF" format can contain sequences of GIF images. Most WEB browsers (but not all!) render animated GIFS by showing one image, making a short pause (1 sec. so similar) and then going to the next image.
My procedure for preparing animated GIFs works as follows:As this procedure is a little bit too complicated to be programmed in a shell script I wrote a C++ program called preparedAnimatedGif that controls the production of the target animated GIF. The coordinate files for the single GIFs are produced in an earlier step via C/C++ or FORTRAN programs. Note that it is important that the data files can be ordered so that program preparedAnimatedGif finds the in the correct sequence. I produce this order by naming the files with increasing numbers, i.e. "C001.dat", "C002.dat" ...
The program prepareAnimatedGif works as follows:The link for the C++ program surce code is here. The program is documented and has a usage text (coupled to option -v). It can also be started with option -v to show logging output. Option -skip nnn can be used to produce faster movies that skip some intermediate data files.
A sample animated GIF file is here. This movie like animated GIF shows an advection cloud moving from left to right. I is based on the data produced by a FORTRAN program written by Juergen Steppeler.
Copyright for all images, texts and software on this page: Dr. E. Huckert