Conrec6 demo

From TORI
Revision as of 10:43, 6 September 2025 by T (talk | contribs) (Created page with "{{top}} {{fig|Fig1802.jpg|400|-64|0|4|Use of output of Conrec6: reproducing fig.18.2 from book Superfunctions}} The routine '''Conrec6.cin''' is an implementation of...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Fig1802.jpg
Use of output of Conrec6: reproducing fig.18.2 from book Superfunctions

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

Sorry, the pictures below are not yet loaded (and not even generated)
{{pic|Conrec6_Re.png|Contours of Re(f(z))}}
{{pic|Conrec6_Im.png|Contours of Im(f(z))}}

File sizes:

  • naive EPS output: 54 KB,
  • Conrec6 EPS output: 36 KB,

with no visible loss of quality.

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.
 where long continuous contours are common.

Credits

References

  1. 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», «Conrec», «Conrec6.cin», «Conto.cin», «EPS», «Contour map», «Complex map», «Complex mapping», «ChatGPT», «Holomorphic function», «MapConrec6demo»,