Conrec6 demo
The routine Conrec6.cin is an implementation of the Conrec algorithm, adapted for efficient generation of contour maps in EPS format. It was developed by Dmitrii Kouznetsov in collaboration with ChatGPT (OpenAI), based on the original algorithm of Paul Bourke [1].
The main novelty of Conrec6 is:
- merging of contour segments into continuous polylines,
- reduced EPS file size,
- optional discrimination parameter DMAX to suppress spurious lines near branch cuts.
This article is under construction
Motivation
Contour plotting is widely available (e.g. in gnuplot, matplotlib), but standard tools often generate verbose EPS with each line segment written separately. This leads to very large files and inefficient rendering.
Conrec6 addresses this by:
- grouping successive contour segments into a single polyline ('M…L…L…S'),
- allowing direct embedding of compact EPS in articles and books,
- enabling robust visualization of branch cuts in complex functions.
Algorithm
The code follows the marching–squares logic of Paul Bourke’s original Conrec subroutine, but extended with:
- EPS output (instead of device-specific plotting),
- discrimination parameter DMAX,
- simplified calling convention for use in C++ drivers.
Code
The main routine is distributed as Conrec6.cin. It is called from a driver as
Conrec6(o, F, X, Y, NX, NY, level, DMAX);
where:
- o – file pointer for EPS output,
- F – array of scalar field values (flattened 1D array of size NX*NY),
- X, Y – coordinate arrays,
- NX, NY – grid sizes,
- level – contour level,
- DMAX – discrimination parameter.
Examples
The 3 examples of maps generated with Conrec6.cin are shown in figures at right.
The first picture just reproduces the bottom part of Fig.18.2 of book Superfunctions.
The second map shows lines of constant real part of the function.
The third map shows lines of constant imaginary part of the function.
Combination of the two last maps and the labels gives an equivalent of the Fig.18.2.
More complex maps generated with Conrec6.cin are loaded in article MapConrec6demo.
Usage
Compile and run a demo driver with:
c++ demo.cc -O2 -o demo ./demo_double
It is expected produces an EPS file with demo contour maps.
Remarks
- Conrec6 is not strictly portable to C++98,
since 2D array handling is fragile in older compilers. Flattened arrays are recommended for robustness.
- The routine is particularly suited for holomorphic function mapping,
where long continuous contours are common.
Credits
- Original algorithm: Paul Bourke (1987).
- Adaptation to EPS and discrimination parameter: Dmitrii Kouznetsov.
- Polyline merging and code refinement: ChatGPT (OpenAI).
References
- ↑ https://paulbourke.net/papers/conrec/ Bourke, P., "Conrec: A Contouring Subroutine", 1987.
https://en.citizendium.org/wiki/Contour_plot/Code/conto.cin // Copyleft 2008 by Dmitrii Kouznetsov This page was last modified 01:05, 2 February 2009.
See also (Keywords)
«Ado.cin», «C++», «Conrec», «Conrec6.cin», «Conto.cin», «EPS», «Contour map», «Complex map», «Complex mapping», «ChatGPT», «Holomorphic function», «MapConrec6demo»,