préparer le champ vectoriel

To plot a vector field, we need to get that field into vfplot. The basic field representation in the program is on a grid of vector samples (which is sparse, i.e., permitting absent values). The program reads several formats of such data, probably the most useful is CSV, that is the (i, j) location in the grid and the (u, v) components of the vector at that location. That's easiest to write.

If you're in a position to generate these files from your own code, then ideally generate a grid at least 256 pixels on the smaller side, preferably 512. The rows of the file do not need to be in any particular order You should also keep in mind the extent of the (x, y) region of the grid. Note that the input CSV is zero offset: the smallest (i, j) pair is (0, 0).

This CSV file can be processed by vfplot directly, but one must pass some extra command-line options to the program specifying the size and range (extent) of the grid in the file (see the --grid-size, --grid-range options), this is simply because CSV can't carry metadata.

So it makes sense to convert those CSV files for something which does contain that metadata, and the GMT grd file (which is just a NetCDF file which follows some layout coventions) is well-suited. It is a compact binary format, so are file are small and load faster. They can also be further processed with various tools from the GMT suite: cutting, sampling, smoothing and so on.

The program csv-grd make a conversion of CSV to GMT grd: it reads a single CSV file and writes two GMT grd files with the u and v components of velocity. Typical usage:

csv-grd \
    --verbose \
    --input uv.csv \
    --grid-size 128/128 \
    --grid-range 0/1/0/1 \
    --pixel \
    u.grd v.grd

Some of these options (shared with the vfplot program) are:

--grid-size
One cannot tell from the CSV input what the size of the grid we are passing in actually is; we can (and do) read the entire file to work out the minimal size. It's a but faster if we don't do this pre-read scan, hence the option.
--grid-range
This specifies the location of the grid in the (x, y) coordinates of the vector field, that is the coordinate space of the code generating the CSV. The same coordinate system will be used in dealing with domains, so this information allows correct alignment of these components.
--pixel
Specified that the grid is pixel-aligned, data points are in the centre of the pixels -- this is commonly the case with fluid dynamics models. The default, gridline, instead takes the data points to be at the corners of the pixels, so the vertical and horizontal lines joining them make the edges of the pixels.