#!/bin/sh #! -*-perl-*- eval 'exec perl -x -wS $0 ${1+"$@"}' if 0; =begin copyright Tridens density plot program Copyright 2003, 2011 John Lapeyre, All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. =end copyright =cut package Tridens; our $VERSION = '0.19'; # use POSIX module for log10 and floor functions use POSIX; use Pod::Simple::Text; # for processing the docs use Term::ReadLine; use Text::ParseWords; use Text::Wrap; use Data::Dumper; use Carp; sub deb; # use this to avoid failure of the entire program if a function is missing #use autouse MODULENAME; # Tue Oct 20 17:45:24 CEST 2009 # Fixed pod interpreter complaints # Added -square -tri -sidelength options. # changed documentation # changed a "die" to just an exit at line 641 # Fixed several other bugs. Eg, in is_power_2 # Fixed pdf output # Added a bunch of things that would take too much work to list # and is not worth the trouble # Nov 15 2009, version 0.15. More refined calculation of height for superscript. # 0.16 Feb 25 2010 # * set ColorMapLo default to 0.2. # * add viewerscale feature # 0.17 # * added -nosameunits feature # * fixed some small bugs # * improved docs # * added tab completion # * fixed portrait to landscape and back bug # * set some fonts # * strip some trailing zeros in postscript # * changed dot to x in sci notation # * correctly detect if gv processs is killed # TODO # * add ability to write tick labels with numbers multiplied by powers # of ten, so that the power of ten can be put into the label # * also ability to to sci notation on the tick labels. # * lots of code cleaning: eg uses routines to check values (not 'xpdf' everywhere, etc.) # * saving and restoring not complete # * number of labels on key should be selected, not the skip value # * completion with show, set, etc. needs improvment (remove useless completions # etc. # * optionally doing the /pd postscript routine in perl might make rendering to pdf faster # * send commands to xpdf, such as 'raise' upon plotting =begin comment tridens -- Programmers' notes. An identifier begins with a capital letter if and only if it is global (declared with 'our'). Sections of this file and related groups of routines are separated by a bar like this '#==== ...'. A block that serves only to implement scoping of variables to be shared by some routines is enclosed with bars like this '#*=*=*=* ...' . This file is organized (!) as follows from top to bottom: * Pod documentation. This is the source for man page, html, etc. as is usual with pod. It also has to local directives that are used to extract short interactive help messages. So the format (not documented) should be followed. * The interactive mode code. It is in the Shell package. * Hmm the rest has been put into comment boxes marked with the string 'SECTION'. =end comment =cut #=====================================================================================# # SECTION # # # # User documentation that is extracted from this file and formatted in various ways. # # # # # #=====================================================================================# =head1 NAME B -- create density plots on a triangular or square lattice in postscript or pdf format. =head1 SYNOPSIS usage: tridens [options] [F, F ...] =head1 DESCRIPTION tridens reads data from the input files specified on command line and, for each one, writes color or grayscale density plots. The input data is on a triangular lattice (or, optionally, a square lattice.) For the triangular(square) lattice, each coordinate pair in the input file is covered with a hexagon(square). The output file format is PostScript or PDF. tridens also operates in an interactive mode. =head2 Quick start C -- write a density plot data.dat.pdf of a regular square (or rectangular) array of data points from a file with lines of the form 'x y val'. C -- write a density plot and display the result in the pdf viewer and enter interactive mode. C -- write a density plot data.dat.pdf of data on a triangular lattice from a file with lines of the form 'x y val', where at least one of the nearest neighbors to the first point is present. (There can be 'holes' or missing points in the remainder of the data set.) =head2 Why another plotting program? =over 1 =item 1 I could not find a program that can make a density plot of hexagonal tiles on a triangular lattice. =item 2 The method of producing plots is different from most other methods. For instance, gnuplot's pm3d can be applied in more cases, but produces an essentially different plot. =item 3 To produce PostScript plots, tridens requires only a standard perl installation, which is present on all Linux and nearly all Unix machines. (But you probably want to generate eps or pdf, in which case ghostscript is required, but this is also standard on Unix/Linux; see below.) The tridens program is a single file that needs no compilation or installation and generates its own documentation and parameter files. I wrote it after trying downloading/compiling/getting licenses/libraries for a bunch of programs that couldn't do a density plot on a triangular lattice anyway. (This was in 2003, perhaps there are more programs available now that are easier to install.) See REQUIREMENTS AND DEPENDENCIES below for other features and requirements. =back =head2 Plotting options Most plotting options, (axes, labels, etc.) are controlled through command line options or interactively, more are available by setting parameters in a parameter file. Command line options override settings in the parameter file. If you need to set more options than are available on the command line (or prefer to use a configuration file) type C to generate the file F<.tridens> with the default parameters in the current directory. Then edit this file to suit your needs. It will be read each time tridens is run. This parameter file is moderately well commented. Any parameters that are deleted from or 'commented out' of F<.tridens> will be determined by the built-in defaults. If you copy F<.tridens> to F and edit the result, then, only when processing data file F, the file F will be read after F<.tridens> and any parameters present will override previously set values. There is a copy of F<.tridens> inside the F executable program, which is a plain text file. If you edit these internal parameters, then they become the default parameters. In summary parameters are set in this order: 1) internal (default) parameters, 2) parameters in F<.tridens>, 3) parameters in F, 4) parameters given on the command line. 5) parameters set interactively. In this list, settings with higher numbers override settings with lower numbers. =head2 Interactive mode Interactive mode is entered by either omitting a data filename on the command line or giving the option B<-i>. Here is an example: myshellprompt > tridens -i -o sq.pdf sq1.dat tridens> plot tridens> set -title 'This is the title' tridens> plot tridens> plot 'other.dat' In the example, the plot is drawn twice, adding a title the second time. Then, data from a second data file is plotted. If Term::Readline is installed on your system (It is available as a package in all linux distributions.) the you can use command history and tab completion. Try tab completion in various contexts. (In particular, this document may be out of date, and tab completion can show available commands or arguments.) The following lists commands recognized in the interactive mode. =head3 Commands in interactive mode =over 1 =item B Print command line options =item B I Print brief help on a topic. Hit TAB twice to see list of topics (if perl-gnu readline is installed). The content of brief help is taken from the man and html pages. =item B View long documentation as unix man page. =item B Print documentation to tridens.html and try to open it in a browser (firefox by default) =for trihelp commands start =item B I write (or rewrites) the output plot file. If FILENAME is given as an argument (in single quotes) then the data is read (or reread) from the file. If there is no argument, then the most recently read data is used. If you have set the option B<-dis> then tridens will try to display the plot immediately in a viewer (which can be configured to be xpdf or ghostview.) =item B Reread the data from the most recently read input data file and replot the data. If an argument is given, data is instead read from the file named in the argument. This is equivalent to using 'read' and then 'plot'. =item B I