diff -urNP gnuplot-datastrings/configure.in gnuplot-eam/configure.in
--- gnuplot-datastrings/configure.in	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/configure.in	2004-04-14 10:50:54.000000000 -0700
@@ -743,6 +743,14 @@
                [ Define to allow string-handling in datafiles. EXPERIMENTAL ])
    fi])
 
+dnl histograms
+AC_ARG_ENABLE(histograms,dnl
+[  --enable-histograms     enable histograms plot style (EXPERIMENTAL)],
+  [if test "$enableval" = yes; then
+     AC_DEFINE(EAM_HISTOGRAMS, 1,
+               [ Define to enable histograms plot style. EXPERIMENTAL ])
+   fi])
+
 dnl IRIS terminal on IRIS4D series computer
 AC_ARG_ENABLE(iris,dnl
 [  --enable-iris           enable IRIS terminal (IRIS4D only)],
@@ -969,6 +977,10 @@
   AC_MSG_RESULT([  Enable string-handling in datafiles (EXPERIMENTAL)])
 fi
 
+if test "$enable_histograms" = yes; then
+  AC_MSG_RESULT([  Enable plot style histograms (EXPERIMENTAL)])
+fi
+
 if test "$enable_iris" = yes; then
   AC_MSG_RESULT([  Enable IRIS terminal])
 fi
diff -urNP gnuplot-datastrings/demo/histograms.dem gnuplot-eam/demo/histograms.dem
--- gnuplot-datastrings/demo/histograms.dem	1969-12-31 16:00:00.000000000 -0800
+++ gnuplot-eam/demo/histograms.dem	2004-04-14 10:50:54.000000000 -0700
@@ -0,0 +1,167 @@
+#
+# Example of using histogram modes
+#
+reset
+set title "US immigration from Europe by decade"
+set missing "-"
+set xtics nomirror rotate by -45
+#
+# First plot using linespoints
+set style data linespoints
+plot 'immigration.dat' using 2:xtic(1) t 2, \
+'' u 3 t 3, '' u 4 t 4, '' u 5 t 5, '' u 6 t 6, \
+'' u 7 t 7, '' u 8 t 8, '' u 9 t 9, '' u 10 t 10, \
+'' u 11 t 11, '' u 12 t 12, '' u 13 t 13, '' u 14 t 14, \
+'' u 15 t 15, '' u 16 t 16, '' u 17 t 17, '' u 18 t 18, \
+'' u 19 t 19, '' u 20 t 20, '' u 21 t 21, '' u 22 t 22
+#
+pause -1 "<cr> to plot the same data as a histogram"
+#
+set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes"
+set auto x
+set yrange [0:300000]
+set style data histogram
+set style histogram cluster gap 1
+set style fill solid border -1
+set boxwidth 0.9
+set xtic rotate by -45
+set bmargin 6
+plot 'immigration.dat' using 6:xtic(1) ti col, '' u 12 ti col, '' u 13 ti col, '' u 14 ti col
+#
+pause -1 "<cr> to change the gap between clusters"
+#
+set title "US immigration from Northern Europe\n(same plot with larger gap between clusters)"
+set style histogram gap 5
+replot
+#
+pause -1 "<cr> to plot the same dataset as stacked histogram"
+#
+#
+# Stacked histograms
+#
+set title "US immigration from Europe by decade\nPlot as stacked histogram"
+set key invert reverse Left outside
+set key autotitle columnheader
+set yrange [0:5e6]
+set auto x
+unset xtics
+set xtics nomirror rotate by -45
+set style data histogram
+set style histogram rowstacked
+set style fill solid border -1
+set boxwidth 0.75
+#
+plot 'immigration.dat' using 2:xtic(1), \
+'' using 3, \
+'' using 4, \
+'' using 5, \
+'' using 6, \
+'' using 7, \
+'' using 8, \
+'' using 9, \
+'' using 10, \
+'' using 11, \
+'' using 12, \
+'' using 13, \
+'' using 14, \
+'' using 15, \
+'' using 16, \
+'' using 17, \
+'' using 18, \
+'' using 19, \
+'' using 20, \
+'' using 21, \
+'' using 22
+#
+pause -1 "<cr> to rescale each stack to % of total"
+#
+# Stacked histograms by percent
+#
+set title "US immigration from Europe by decade\nFraction of total plotted as stacked histogram"
+set key invert reverse Left outside
+set yrange [0:100]
+set ylabel "% of total"
+unset ytics
+set grid y
+set border 3
+set style data histograms
+set style histogram rowstacked
+set style fill solid border -1
+set boxwidth 0.75
+#
+plot 'immigration.dat' using (100.*$2/$24):xtic(1) t 2, \
+'' using (100.*$3/$24) t 3, \
+'' using (100.*$4/$24) t 4, \
+'' using (100.*$5/$24) t 5, \
+'' using (100.*$6/$24) t 6, \
+'' using (100.*$7/$24) t 7, \
+'' using (100.*$8/$24) t 8, \
+'' using (100.*$9/$24) t 9, \
+'' using (100.*$10/$24) t 10, \
+'' using (100.*$11/$24) t 11, \
+'' using (100.*$12/$24) t 12, \
+'' using (100.*$13/$24) t 13, \
+'' using (100.*$14/$24) t 14, \
+'' using (100.*$15/$24) t 15, \
+'' using (100.*$16/$24) t 16, \
+'' using (100.*$17/$24) t 17, \
+'' using (100.*$18/$24) t 18, \
+'' using (100.*$19/$24) t 19, \
+'' using (100.*$20/$24) t 20, \
+'' using (100.*$21/$24) t 21, \
+'' using (100.*$22/$24) t 22, \
+'' using (100.*$23/$24) t 23
+#
+pause -1 "Now try histograms stacked by columns"
+#
+# Columnstacks
+#	xtic labels should be picked up from column heads ('title column')
+#	key titles should be picked up from row heads ('key(1)')
+#
+set title "Immigration from Northern Europe\n(columstacked histogram)"
+set style histogram columnstacked
+set key noinvert box
+set yrange [0:*]
+set xrange [0:*]
+set ylabel "Immigration by decade"
+set xlabel "Country of Origin"
+set ticscale 0.0
+set ytics
+unset xtics
+set xtics norotate
+plot 'immigration.dat' using 6 ti col, '' using 12 ti col, \
+     '' using 13 ti col, '' using 14:key(1) ti col
+#
+pause -1 "Next we do several sets of parallel histograms"
+#
+# 'newhistogram' keyword to plot
+#
+set title "Immigration from different regions\n(give each histogram a separate title)"
+set key under
+set style histogram clustered gap 1 title 2,0.25
+set style fill solid noborder
+set boxwidth 0.95
+unset xtics
+set xtics rotate by -45
+set xlabel "(note: histogram titles have specified offset relative to X-axis label)" 0,-3
+set ytics
+set grid y
+set auto y
+plot \
+newhistogram "Northern Europe", \
+'immigration.dat' using 6:xtic(1) t 6, '' u 13 t 13, '' u 14 t 14, \
+newhistogram "Southern Europe", \
+'' u 9:xtic(1) t 9, '' u 17 t 17, '' u 22 t 22, \
+newhistogram "British Isles", \
+'' u 10:xtic(1) t 10, '' u 21 t 21
+#
+pause -1 "Same plot using rowstacked histogram"
+#
+set style histogram rows
+set boxwidth 0.8
+set yrange [0:900000]
+set xlabel "(Same plot using rowstacked rather than clustered histogram)"
+replot
+#
+pause -1
+
diff -urNP gnuplot-datastrings/demo/immigration.dat gnuplot-eam/demo/immigration.dat
--- gnuplot-datastrings/demo/immigration.dat	1969-12-31 16:00:00.000000000 -0800
+++ gnuplot-eam/demo/immigration.dat	2004-04-14 10:50:54.000000000 -0700
@@ -0,0 +1,11 @@
+# IMMIGRATION BY REGION AND SELECTED COUNTRY OF LAST RESIDENCE
+#
+Region	Austria	Hungary	Belgium	Czechoslovakia	Denmark	France	Germany	Greece	Ireland	Italy	Netherlands	Norway	Sweden	Poland	Portugal	Romania	Soviet_Union	Spain	Switzerland	United_Kingdom	Yugoslavia	Other_Europe	TOTAL	
+1891-1900	234081	181288	18167	-	50231	30770	505152	15979	388416	651893	26758	95015	226266	96720	27508	12750	505290	8731	31179	271538	-	282	3378014	
+1901-1910	668209	808511	41635	-	65285	73379	341498	167519	339065	2045877	48262	190505	249534	-	69149	53008	1597306	27935	34922	525950	-	39945	7387494	
+1911-1920	453649	442693	33746	3426	41983	61897	143945	184201	146181	1109524	43718	66395	95074	4813	89732	13311	921201	68611	23091	341408	1888	31400	4321887	
+1921-1930	32868	30680	15846	102194	32430	49610	412202	51084	211234	455315	26948	68531	97249	227734	29994	67646	61742	28958	29676	339570	49064	42619	2463194	
+1931-1940	3563	7861	4817	14393	2559	12623	144058	9119	10973	68028	7150	4740	3960	17026	3329	3871	1370	3258	5512	31572	5835	11949	377566	
+1941-1950	24860	3469	12189	8347	5393	38809	226578	8973	19789	57661	14860	10100	10665	7571	7423	1076	571	2898	10547	139306	1576	8486	621147	
+1951-1960	67106	36637	18575	918	10984	51121	477765	47608	43362	185491	52277	22935	21697	9985	19588	1039	671	7894	17675	202824	8225	16350	1325727	
+1961-1970	20621	5401	9192	3273	9201	45237	190796	85969	32966	214111	30606	15484	17116	53539	76065	3531	2465	44659	18453	213822	20381	11604	1124492	
diff -urNP gnuplot-datastrings/docs/gnuplot.doc gnuplot-eam/docs/gnuplot.doc
--- gnuplot-datastrings/docs/gnuplot.doc	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/docs/gnuplot.doc	2004-04-14 10:50:54.000000000 -0700
@@ -3300,7 +3299,7 @@
  where <style> is either `lines`, `points`, `linespoints`, `impulses`,
  `dots`, `steps`, `fsteps`, `histeps`, `errorbars`, `labels`, `xerrorbars`,
  `yerrorbars`, `xyerrorbars`, `errorlines`, `xerrorlines`, `yerrorlines`,
- `xyerrorlines`, `boxes`, `filledcurves`, `boxerrorbars`,
+ `xyerrorlines`, `boxes`, `histograms`, `filledcurves`, `boxerrorbars`,
  `boxxyerrorbars`, `financebars`, `candlesticks`, `vectors` or `pm3d`. Some
  of these styles require additional information. See `plotting styles` for
  details of each style.  `fill` is relevant only to certain 2D plots
@@ -4012,7 +4011,7 @@
 ?show boxwidth
 ?boxwidth
  The `set boxwidth` command is used to set the default width of boxes in the
- `boxes`, `boxerrorbars` and `candlesticks` styles.
+ `boxes`, `boxerrorbars`, `candlesticks` and `histogram` styles.
 
  Syntax:
        set boxwidth {<width>} {absolute|relative}
@@ -5193,6 +5192,7 @@
        set key {on|off} {default}
                {left | right | top | bottom | outside | below | <position>}
                {Left | Right} {{no}reverse}
+               {{no}invert}
                {samplen <sample_length>} {spacing <vertical_spacing>}
                {width <width_increment>}
                {height <height_increment>}
@@ -5218,6 +5218,12 @@
  and `linewidth`, or a user-defined `linestyle`. Note that not all
  terminal drivers support linewidth selection, though.
 
+ By default the first plot label is at the top of the key and successive labels
+ are entered below it. The `invert` option causes the first label to be placed
+ at the bottom of the key, with successive labels entered above it. This option
+ is useful to force the vertical ordering of labels in the key to match the
+ order of box types in a stacked histogram.
+
  The length of the sample line can be controlled by `samplen`.  The sample
  length is computed as the sum of the tic length and <sample_length> times the
  character width.  `samplen` also affects the positions of point samples in
@@ -5262,9 +5268,9 @@
  This default behavior can be switched off by the `noenhanced` option.
 
  The defaults for `set key` are `on`, `right`, `top`, `Right`, `noreverse`,
- `samplen 4`, `spacing 1.25`, `title ""`, and `nobox`.  The default <linetype>
- is the same as that used for the plot borders.  Entering `set key default` 
- returns the key to its default configuration.
+ `noinvert`, `samplen 4`, `spacing 1.25`, `title ""`, and `nobox`.  
+ The default <linetype> is the same as that used for the plot borders.
+ Entering `set key default` returns the key to its default configuration.
 
  The <position> can be a simple x,y,z as in previous versions, but these can
  be preceded by one of four keywords (`first`, `second`, `graph`, `screen`)
@@ -6785,6 +6791,7 @@
  Syntax:
        set style arrow <n> <arrowstyle>
        set style fill <fillstyle>
+       set style histogram <histogram style options>
        set style line <n> <linestyle>
 
 4 set style arrow
@@ -6885,8 +6894,8 @@
 ?set style fill
 ?show style fill
 ?fillstyle
- The `set style fill` command is used to set the style of boxes
- or candlesticks.
+ The `set style fill` command is used to set the style of boxes,
+ histograms or candlesticks.
 
  Syntax:
        set style fill {empty | solid {<density>} | pattern {<n>}}
@@ -7037,7 +7044,7 @@
  a column in the data file and an entry in the `using` list.)
 
  For three columns, only `xerrorbars`, `yerrorbars` (or `errorbars`),
- `xerrorlines`, `yerrorlines` (or `errorlines`), `boxes` 
+ `xerrorlines`, `yerrorlines` (or `errorlines`), `boxes`,
  and `boxerrorbars` are allowed. If another plot style is used, the style
  will be changed to `yerrorbars`. The `boxerrorbars` style will
  calculate the boxwidth automatically.
@@ -7141,6 +7148,115 @@
  x11, windows, pm, postscript, fig, pbm, png, gif, hpdj, hppj, hpljii, hp500c,
  jpeg, nec_cp6, epson_180dpi, epson_60dpi, epson_lx800, okidata, starc and
  tandy_60dpi. The BeOS driver (`be`) is untested.
+5 histograms
+?commands set style histograms
+?set style histograms
+?style histograms
+?histograms
+ The `histograms` style is only relevant to 2-d plotting.  It produces a bar
+ chart from a sequence of data columns in parallel. Each element of the 
+ `plot` command must specify a single input data source (e.g. one column of 
+ the input file), possibly with associated tic values or key titles.
+ Three styles of histogram layout are currently supported. 
+ 
+       set style histogram clustered {gap <gapsize>}
+       set style histogram rowstacked
+       set style histogram columnstacked
+ 
+ The default style corresponds to `set style histogram clustered gap 2`. 
+ Each set of parallel data values is collected into a group of boxes clustered
+ at the x-axis coordinate corresponding to their sequential position (row #)
+ in the selected datafile columns.  Thus if <n> datacolumns are selected, the
+ first cluster is centered about x=1, and contains <n> boxes whose heights are
+ taken from the first entry in the corresponding <n> data columns. This
+ is followed by a gap and then a second cluster of boxes centered about x=2
+ corresponding to the second entry in the respective data columns, and so on.
+ The default gap width of 2 indicates that the empty space between clusters is
+ equivalent to the width of 2 boxes.  All boxes derived from any one column
+ are given the same fill color and/or pattern (see `set style fill`).
+
+ Each cluster of boxes is derived from a single row of the input data file.
+ It is common in such input files that the first element of each row is a
+ label. Labels from this column may be placed along the x-axis underneath
+ the appropriate cluster of boxes with the `xticlabels` option to `using`.
+
+ Two styles of stacked histogram are supported, chosen by the command
+ `set style histogram {rowstacked|columnstacked}`.  In these styles the data
+ values from the selected columns are collected into stacks of boxes.
+ The default stacking mode is `rowstacked`.
+
+ The `rowstacked` style places a box resting on the x-axis for each
+ data value in the first selected column; the first data value results in 
+ a box a x=1, the second at x=2, and so on.  Boxes corresponding to the
+ second and subsequent data columns are layered on top of these, resulting
+ in a stack of boxes at x=1 representing the first data value from each
+ column, a stack of boxes at x=2 representing the second data value from
+ each column, and so on.  All boxes derived from any one column are given the 
+ same fill color and/or pattern (see `set style fill`).
+
+ The `columnstacked` style is similar, except that each stack of boxes is
+ built up from a single data column. Each data value from the first specified
+ column yields a box in the stack at x=1, each data value from the second
+ specified column yields a box in the stack at x=2, and so on.  In this style
+ the color of each box is taken from the row number, rather than the column
+ number, of the corresponding data field.
+
+ Box widths may be modified using the `set boxwidth` command.
+ Box fill styles may be set using the `set style fill` command.
+
+ Examples:
+
+ To plot a data file containing multiple columns of data as a histogram
+ of clustered boxes (the default style):
+
+       set boxwidth 0.9 relative
+       set style data histograms
+       set style fill solid 1.0 border -1
+       plot 'file.dat' using 2, '' using 4, '' using 3 
+
+ This will produce a plot with clusters of three boxes (vertical bars) centered
+ at each integral value on the x axis. If the first column of the input file
+ contains labels, they may be placed along the x-axis using the variant command
+
+       plot 'file.dat' using 2, '' using 4, '' using 3:xticlabels(1) 
+
+ To plot the same data as a rowstacked histogram:
+
+       set style histogram rows
+       plot 'file.dat' using 2, '' using 4, '' using 3:xtic(1) 
+
+ This will produce a plot in which each vertical bar contains a stack of three
+ segments, corresponding in height to the values found in columns 2, 4 and 3
+ of the datafile.
+
+ Finally, the commands
+
+       set style histogram columnstacked
+       plot 'file.dat' using 2, '' using 4, '' using 3 
+
+ will produce three vertical stacks. The stack at x=1 will contain a box for
+ each entry in column 2 of the datafile.  The stack at x=2 will contain a box
+ for each parallel entry in column 4 of the datafile, and the stack at x=3 a
+ box for each entry of column 3.  
+
+ More than one set of histograms can appear in a single plot. In this case you
+ can force a gap between them, and a separate label for each set, by using the
+ `newhistogram { "title" } { <linestyle> }` plot command.  For example
+       set style histogram  cluster
+       plot newhistogram "Set A", 'a' using 1, '' using 2, '' using 3, \
+            newhistogram "Set B", 'b' using 1, '' using 2, '' using 3
+
+ The labels "Set A" and "Set B" will appear beneath the respective sets of 
+ histograms, under the overall x axis label.
+
+ The newhistogram command can also be used to force histogram coloring to
+ begin with a specific color (linetype). By default colors will continue to
+ increment successively even across histogram boundaries. Here is an example
+ using the same coloring for multiple histograms
+       plot newhistogram "Set A" lt 4, 'a' using 1, '' using 2, '' using 3, \
+            newhistogram "Set B" lt 4, 'b' using 1, '' using 2, '' using 3
+ 
+
 5 filledcurves
 ?commands set style filledcurves
 ?set style filledcurves
diff -urNP gnuplot-datastrings/src/datafile.c gnuplot-eam/src/datafile.c
--- gnuplot-datastrings/src/datafile.c	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/datafile.c	2004-04-14 10:50:55.000000000 -0700
@@ -178,6 +178,9 @@
 static void plot_ticlabel_using __PROTO((int));
 static void df_parse_string_field __PROTO((char *, char *));
 #endif
+#ifdef EAM_HISTOGRAMS
+static void add_key_entry __PROTO((char *temp_string, int df_datum));
+#endif
 
 /*}}} */
 
@@ -191,7 +194,7 @@
 };
 
 #ifdef EAM_DATASTRINGS
-enum COLUMN_TYPE { CT_DEFAULT, CT_STRING, 
+enum COLUMN_TYPE { CT_DEFAULT, CT_STRING, CT_KEYLABEL,
 		CT_XTICLABEL, CT_X2TICLABEL, CT_YTICLABEL, CT_Y2TICLABEL,
 		CT_ZTICLABEL, CT_CBTICLABEL };
 #endif
@@ -202,6 +205,9 @@
 #ifdef EAM_DATASTRINGS
 int df_no_tic_specs;		/* except ticlabel columns are counted here */
 #endif
+#ifdef EAM_HISTOGRAMS
+struct curve_points *df_current_plot; /* set before calling df_readline() */
+#endif
 int df_line_number;
 int df_datum;			/* suggested x value if none given */
 TBOOLEAN df_matrix = FALSE;	/* is this a matrix splot */
@@ -1023,6 +1029,9 @@
 	    } else if (almost_equals(c_token, "cbtic$labels")) {
 		plot_ticlabel_using(CT_CBTICLABEL);
 #endif
+	    } else if (almost_equals(c_token, "key")) {
+		plot_ticlabel_using(CT_KEYLABEL);
+
 #endif
 	    } else {
 		int col = (int) real(const_express(&a));
@@ -1293,9 +1302,18 @@
 			xpos = (axcol == 0) ? df_datum : v[axcol-1];
 		    else
 			xpos = v[axcol];
+#ifdef EAM_HISTOGRAMS
+		    if (df_current_plot) xpos += df_current_plot->histogram->start;
+#endif
 
 		    df_parse_string_field(temp_string,df_tokens[output]);
 		    add_tic_user(axis,temp_string,xpos,0);
+#ifdef EAM_HISTOGRAMS
+		} else if (use_spec[output].expected_type == CT_KEYLABEL) {
+		    char temp_string[64];
+		    df_parse_string_field(temp_string,df_tokens[output]);
+		    add_key_entry(temp_string,df_datum);
+#endif
 		} else
 #endif
 		if (use_spec[output].at) {
@@ -1829,6 +1847,19 @@
 df_set_key_title( plot )
 struct curve_points *plot;
 {
+#ifdef EAM_HISTOGRAMS
+    if (plot->plot_style == HISTOGRAMS
+    &&  histogram_opts.type == HT_STACKED_IN_TOWERS) {
+	/* In this case it makes no sense to treat key titles in the usual */
+	/* way, so we assume that it is supposed to be an xtic label.      */
+	/* FIXME EAM - This style should default to notitle!               */
+	double xpos = plot->histogram_sequence + plot->histogram->start;
+	add_tic_user(FIRST_X_AXIS,df_key_title,xpos,0);
+	df_key_title[0] = '\0';
+	return;
+    }
+#endif
+
     /* What if there was already a title specified? */
     if (plot->title && !plot->title_is_filename)
 	return;
@@ -1861,4 +1892,29 @@
     parse_esc(temp_string);
     strcpy(string,temp_string);
 }
+
+#ifdef EAM_HISTOGRAMS
+static void
+add_key_entry(char *temp_string, int df_datum)
+{
+    text_label *new_entry = gp_alloc(sizeof(text_label), "key entry");
+
+    /* Associate this key list with the histogram it belongs to. */
+    if (!df_current_plot->labels) {
+	df_current_plot->labels = gp_alloc(sizeof(text_label), "key entry");
+	df_current_plot->labels->tag  = -1;
+	df_current_plot->labels->next = NULL;
+	df_current_plot->labels->text = NULL;
+	df_current_plot->labels->font = NULL;
+    }
+
+    new_entry->text = gp_strdup(temp_string);
+    new_entry->tag = df_datum;
+    new_entry->font = NULL;
+    new_entry->next = df_current_plot->labels->next;
+    df_current_plot->labels->next = new_entry;
+}
+#endif
+
 #endif /* EAM_DATASTRINGS */
+
diff -urNP gnuplot-datastrings/src/datafile.h gnuplot-eam/src/datafile.h
--- gnuplot-datastrings/src/datafile.h	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/datafile.h	2004-04-14 10:50:55.000000000 -0700
@@ -53,6 +53,10 @@
 #define DF_FOUND_KEY_TITLE   (-5)
 #define DF_KEY_TITLE_MISSING (-6)
 #endif
+#ifdef EAM_HISTOGRAMS
+/* should really be a parameter to df_readline rather than a global */
+extern struct curve_points *df_current_plot;
+#endif
 
 #ifndef MAXINT			/* should there be one already defined ? */
 # ifdef INT_MAX			/* in limits.h ? */
diff -urNP gnuplot-datastrings/src/gadgets.c gnuplot-eam/src/gadgets.c
--- gnuplot-datastrings/src/gadgets.c	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/gadgets.c	2004-04-14 10:50:55.000000000 -0700
@@ -143,6 +143,10 @@
 filledcurves_opts filledcurves_opts_func = EMPTY_FILLEDCURVES_OPTS;
 #endif
 
+#ifdef EAM_HISTOGRAMS
+histogram_style histogram_opts = DEFAULT_HISTOGRAM_STYLE;
+#endif
+
 /*****************************************************************/
 /* Routines that deal with global objects defined in this module */
 /*****************************************************************/
diff -urNP gnuplot-datastrings/src/gadgets.h gnuplot-eam/src/gadgets.h
--- gnuplot-datastrings/src/gadgets.h	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/gadgets.h	2004-04-14 10:50:55.000000000 -0700
@@ -177,6 +177,27 @@
 #define EMPTY_FILLEDCURVES_OPTS { 0, 0, 0.0, 0.0 }
 #endif
 
+#ifdef EAM_HISTOGRAMS
+typedef struct histogram_style {
+    int type;		/* enum t_histogram_type */
+    int gap;		/* set style hist gap <n> (space between clusters) */
+    int clustersize;	/* number of datasets in this histogram */
+    double start;	/* X-coord of first histogram entry */
+    double end;		/* X-coord of last histogram entry */
+    int startcolor;	/* LT_UNDEFINED or explicit color for first entry */
+    int startpattern;	/* LT_UNDEFINED or explicit pattern for first entry */
+    struct histogram_style *next;
+    struct text_label title;
+} histogram_style;
+typedef enum histogram_type {
+	HT_NONE,
+	HT_STACKED_IN_LAYERS,
+	HT_STACKED_IN_TOWERS,
+	HT_CLUSTERED
+} t_histogram_type;
+#define DEFAULT_HISTOGRAM_STYLE { HT_NONE, 2, 1, 0.0, 0.0, LT_UNDEFINED, LT_UNDEFINED, NULL, { 0 } }
+
+#endif
 
 /***********************************************************/
 /* Variables defined by gadgets.c needed by other modules. */
@@ -204,6 +224,7 @@
     double height_fix;
     keytitle_type auto_titles;	/* auto title curves unless plotted 'with notitle' */
     TBOOLEAN reverse;		/* key back to front */ 
+    TBOOLEAN invert;		/* key top to bottom */ 
     TBOOLEAN enhanced;		/* enable/disable enhanced text of key titles */ 
     struct lp_style_type default_keybox_lp; /* linetype of box around key:  */
     struct lp_style_type box;		    /*    default and current state */
@@ -226,7 +247,8 @@
 		DEFAULT_KEY_POSITION, \
 		TTOP, TRIGHT, JRIGHT,  \
 		4.0, 1.0, 0.0, 0.0, \
-		FILENAME_KEYTITLES, FALSE, TRUE,  \
+		FILENAME_KEYTITLES, \
+		FALSE, FALSE, TRUE, \
 		DEFAULT_KEYBOX_LP, \
 		DEFAULT_KEYBOX_LP, \
 		"" }
@@ -327,6 +349,10 @@
 extern filledcurves_opts filledcurves_opts_func;
 #endif
 
+#ifdef EAM_HISTOGRAMS
+extern histogram_style histogram_opts;
+#endif
+
 void default_arrow_style __PROTO((struct arrow_style_type *arrow));
 
 #ifdef EAM_DATASTRINGS
diff -urNP gnuplot-datastrings/src/gp_types.h gnuplot-eam/src/gp_types.h
--- gnuplot-datastrings/src/gp_types.h	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/gp_types.h	2004-04-14 10:50:55.000000000 -0700
@@ -102,6 +102,11 @@
 #ifdef EAM_DATASTRINGS
     , LABELPOINTS  = 23*PLOT_STYLE_BITS + 0
 #endif
+#ifdef USE_ULIG_FILLEDBOXES
+#ifdef EAM_HISTOGRAMS
+    , HISTOGRAMS   = 24*PLOT_STYLE_BITS + PLOT_STYLE_HAS_BOXES
+#endif
+#endif
 } PLOT_STYLE;
 
 typedef enum PLOT_SMOOTH { 
diff -urNP gnuplot-datastrings/src/graph3d.c gnuplot-eam/src/graph3d.c
--- gnuplot-datastrings/src/graph3d.c	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/graph3d.c	2004-04-14 10:50:55.000000000 -0700
@@ -1065,6 +1065,10 @@
 		    place_labels3d(this_plot->labels->next, 1);
 		break;
 #endif
+#ifdef EAM_HISTOGRAMS
+	    case HISTOGRAMS: /* Cannot happen */
+		break;
+#endif
 	    }			/* switch(plot-style) */
 
 		/* move key on a line */
@@ -1141,6 +1145,10 @@
 		    case PM3DSURFACE: /* ignored */
 			break;
 #endif
+#ifdef EAM_HISTOGRAMS
+		    case HISTOGRAMS: /* ignored */
+			break;
+#endif
 #ifdef EAM_DATASTRINGS
 		    case LABELPOINTS: /* Already handled above */
 			break;
@@ -1184,7 +1192,7 @@
 			    case XYERRORBARS:	/* ignored; treat like points */
 			    case BOXERROR:		/* HBB: treat these likewise */
 			    case BOXXYERROR:
-			    case CANDLESTICKS:	/* HBB: dito */
+			    case CANDLESTICKS:	/* HBB: ditto */
 			    case FINANCEBARS:
 			    case VECTOR:
 			    case POINTSTYLE:
@@ -1207,6 +1215,10 @@
 			    case PM3DSURFACE: /* ignored */
 				break;
 #endif
+#ifdef EAM_HISTOGRAMS
+			    case HISTOGRAMS: /* ignored */
+				break;
+#endif
 #ifdef EAM_DATASTRINGS
 			    case LABELPOINTS: /* Already handled above */
 				break;
@@ -1262,6 +1274,10 @@
 		    case PM3DSURFACE: /* ignored */
 			break;
 #endif
+#ifdef EAM_HISTOGRAMS 
+		    case HISTOGRAMS: /* ignored */
+			break;
+#endif
 #ifdef EAM_DATASTRINGS
 		    case LABELPOINTS: /* Already handled above */
 			break;
diff -urNP gnuplot-datastrings/src/graphics.c gnuplot-eam/src/graphics.c
--- gnuplot-datastrings/src/graphics.c	2004-04-16 17:37:12.000000000 -0700
+++ gnuplot-eam/src/graphics.c	2004-04-16 17:30:25.000000000 -0700
@@ -102,6 +102,13 @@
 static int ylabel_y, y2label_y, xtic_y, x2tic_y, ytic_x, y2tic_x;
 /*}}} */
 
+#ifdef EAM_HISTOGRAMS
+/* Status information for stacked histogram plots */
+static struct coordinate GPHUGE *stackheight = NULL;	/* top of previous row */
+static int stack_count;					/* points actually used */
+static void place_histogram_titles __PROTO((void));
+#endif
+
 /*{{{  static fns and local macros */
 static void plot_border __PROTO((void));
 static void plot_impulses __PROTO((struct curve_points * plot, int yaxis_x, int xaxis_y));
@@ -217,7 +224,7 @@
 
     mlen = cnt = 0;
     this_plot = plots;
-    for (curve = 0; curve < count; this_plot = this_plot->next, curve++)
+    for (curve = 0; curve < count; this_plot = this_plot->next, curve++) {
 	if (this_plot->title
 	    && ((len = /*assign */ strlen(this_plot->title)) != 0)	/* HBB 980308: quiet BCC warning */
 	    ) {
@@ -225,6 +232,25 @@
 	    if (len > mlen)
 		mlen = strlen(this_plot->title);
 	}
+#ifdef EAM_HISTOGRAMS
+	/* Check for new histogram here and save space for divider */
+	if (this_plot->plot_style == HISTOGRAMS 
+	&&  this_plot->histogram_sequence == 0 && cnt > 1)
+	    cnt++;
+	/* Check for column-stacked histogram with key entries */
+	if (this_plot->plot_style == HISTOGRAMS &&  this_plot->labels) {
+	    text_label *key_entry = this_plot->labels;
+	    for (; key_entry; key_entry=key_entry->next) {
+		cnt++;
+		len = key_entry->text ? strlen(key_entry->text) : 0;
+		if (len > mlen)
+		    mlen = len;
+	    }
+	}
+#endif
+    }
+
+
     if (kcnt != NULL)
 	*kcnt = cnt;
     return (mlen);
@@ -516,10 +542,6 @@
 	/* count max_len key and number keys with len > 0 */
 	max_ptitl_len = find_maxl_keys(plots, count, &ptitl_cnt);
 	ytlen = label_width(key->title, &ktitl_lines);
-#if (0)
-	/* This is wrong, as the title may span multiple key columns */
-	if (ytlen > max_ptitl_len) max_ptitl_len = ytlen;
-#endif
 
 	if (key->reverse) {
 	    key_sample_left = -key_sample_width;
@@ -560,7 +582,7 @@
 		/* now calculate actual no cols depending on no rows */
 		key_cols = (int) (ptitl_cnt + key_rows - 1) / key_rows;
 		KEY_PANIC(key_cols == 0);
-		key_col_wth = (int) (xright - xleft) / key_cols;
+
 		/* we divide into columns, then centre in column by considering
 		 * ratio of * key_left_size to key_right_size
 		 *
@@ -1373,6 +1395,38 @@
 
 	term_apply_lp_properties(&(this_plot->lp_properties));
 
+#ifdef EAM_HISTOGRAMS
+	/* Skip a line in the key between histogram clusters */
+	if (this_plot->plot_style == HISTOGRAMS 
+	&&  this_plot->histogram_sequence == 0 && yl != yl_ref) {
+	    if (++key_count >= key_rows) {
+		yl = yl_ref;
+		xl += key_col_wth;
+		key_count = 0;
+	    } else
+		yl = yl - key_entry_height;
+	}
+
+	/* Column-stacked histograms store their key titles internally */
+	if (this_plot->plot_style == HISTOGRAMS
+	&&  histogram_opts.type == HT_STACKED_IN_TOWERS) {
+	    text_label *key_entry;
+	    localkey = 0;
+	    if (this_plot->labels) {
+		for (key_entry = this_plot->labels; key_entry; key_entry = key_entry->next) {
+		    key_count++;
+		    this_plot->lp_properties.l_type = key_entry->tag;
+		    if (key_entry->text)
+			do_key_sample(this_plot, key, key_entry->text, t, xl, yl);
+		    yl = yl - key_entry_height;
+		}
+		/* EAM FIXME - where/when should this be freed again?  Here? */
+		free_labels(this_plot->labels);
+		this_plot->labels = NULL;
+	    }
+	} else
+#endif
+
 	if (this_plot->title && !*this_plot->title) {
 	    localkey = FALSE;
 	} else {
@@ -1380,6 +1434,8 @@
 		/* don't write filename or function enhanced */
 	    if (localkey && this_plot->title) {
 		key_count++;
+		if (key->invert)
+		    yl = keybox.yb + yl_ref + key_entry_height/2 - yl;
 		do_key_sample(this_plot, key, this_plot->title, t, xl, yl);
 	    }
 	ignore_enhanced_text = 0;
@@ -1486,13 +1542,21 @@
 	case BOXERROR:
 	    plot_bars(this_plot);
 	    /* no break */
-
 	    /*}}} */
 	    /*{{{  BOXES */
 	case BOXES:
-          plot_boxes(this_plot, Y_AXIS.term_zero);
+	    plot_boxes(this_plot, Y_AXIS.term_zero);
 	    break;
 	    /*}}} */
+
+#ifdef EAM_HISTOGRAMS
+	    /*{{{  HISTOGRAMS */
+	case HISTOGRAMS:
+	    plot_boxes(this_plot, Y_AXIS.term_zero);
+	    break;
+	    /*}}} */
+#endif
+
 #ifdef PM3D
 	    /*{{{  FILLEDCURVES */
 	case FILLEDCURVES:
@@ -1534,7 +1598,8 @@
 	    /* we deferred point sample until now */
 	    if (this_plot->plot_style & PLOT_STYLE_HAS_POINT)
 		(*t->point) (xl + key_point_offset, yl, this_plot->lp_properties.p_type);
-
+	    if (key->invert)
+		yl = keybox.yb + yl_ref + key_entry_height/2 - yl;
 	    if (key_count >= key_rows) {
 		yl = yl_ref;
 		xl += key_col_wth;
@@ -1555,6 +1620,11 @@
 /* PLACE LABELS */
     place_labels( first_label, 1 );
 
+#ifdef EAM_HISTOGRAMS
+/* PLACE HISTOGRAM TITLES */
+    place_histogram_titles();
+#endif
+
 /* PLACE ARROWS */
     place_arrows( 1 );
 
@@ -2515,12 +2585,40 @@
     int xaxis_y;
 {
     int i;			/* point index */
-    int xl, xr, yt;		/* point in terminal coordinates */
+    int xl, xr, yb, yt;		/* point in terminal coordinates */
     double dxl, dxr, dyt;
     struct termentry *t = term;
     enum coord_type prev = UNDEFINED;	/* type of previous point */
     TBOOLEAN boxxy = (plot->plot_style == BOXXYERROR);
 
+#ifdef EAM_HISTOGRAMS
+    double dyb = 0.0;
+    /* The stackheight[] array contains the y coord of the top   */
+    /* of the stack so far for each point.                       */
+    if (plot->plot_style == HISTOGRAMS) {
+	int newsize = plot->p_count;
+	if (histogram_opts.type == HT_STACKED_IN_TOWERS)
+	    stack_count = 0;
+	if (histogram_opts.type == HT_STACKED_IN_LAYERS && plot->histogram_sequence == 0)
+	    stack_count = 0;
+	if (!stackheight) {
+	    stackheight = gp_alloc( 
+				newsize * sizeof(struct coordinate GPHUGE),
+				"stackheight array");
+	    for (i = 0; i < newsize; i++)
+		stackheight[i].y = 0;
+	    stack_count = newsize;
+	} else if (stack_count < newsize) {
+	    stackheight = gp_realloc( stackheight, 
+				newsize * sizeof(struct coordinate GPHUGE),
+				"stackheight array");
+	    for (i = stack_count; i < newsize; i++)
+		stackheight[i].y = 0;
+	    stack_count = newsize;
+	}
+    }
+#endif
+
     for (i = 0; i < plot->p_count; i++) {
 
 	switch (plot->points[i].type) {
@@ -2574,6 +2672,56 @@
 		    dyt = plot->points[i].y;
 		}
 
+#ifdef EAM_HISTOGRAMS
+		if (plot->plot_style == HISTOGRAMS) {
+		    int ix = i;
+		    /* Shrink each cluster to fit within one unit along X axis,   */
+		    /* centered about the integer representing the cluster number */
+		    /* 'start' is reset to 0 at the top of eval_plots(), and then */
+		    /* incremented if 'plot new histogram' is encountered.        */
+		    if (histogram_opts.type == HT_CLUSTERED) {
+			int clustersize = plot->histogram->clustersize + histogram_opts.gap;
+			dxl  += (i-1) * (clustersize - 1) + plot->histogram_sequence;
+			dxr  += (i-1) * (clustersize - 1) + plot->histogram_sequence;
+			dxl  += histogram_opts.gap/2;
+			dxr  += histogram_opts.gap/2;
+			dxl  /= clustersize;
+			dxr  /= clustersize;
+			dxl  += plot->histogram->start + 0.5;
+			dxr  += plot->histogram->start + 0.5;
+		    } else if (histogram_opts.type == HT_STACKED_IN_TOWERS) {
+			dxl  = plot->histogram->start - boxwidth / 2.0;
+			dxr  = plot->histogram->start + boxwidth / 2.0;
+			dxl += plot->histogram_sequence;
+			dxr += plot->histogram_sequence;
+		    } else if (histogram_opts.type == HT_STACKED_IN_LAYERS) {
+			dxl += plot->histogram->start;
+			dxr += plot->histogram->start;
+		    }
+
+		    switch (histogram_opts.type) {
+		    case HT_STACKED_IN_TOWERS:
+			ix = 0;
+			/* Line type (color) must match row number */
+			(*t->linetype)(i);
+		    case HT_STACKED_IN_LAYERS:
+			dyb = stackheight[ix].y;
+			dyt += stackheight[ix].y;
+			stackheight[ix].y += plot->points[i].y;
+			if ((Y_AXIS.min < Y_AXIS.max && dyb < Y_AXIS.min)
+			||  (Y_AXIS.max < Y_AXIS.min && dyb > Y_AXIS.min))
+			    dyb = Y_AXIS.min;
+			if ((Y_AXIS.min < Y_AXIS.max && dyb > Y_AXIS.max)
+			||  (Y_AXIS.max < Y_AXIS.min && dyb < Y_AXIS.max))
+			    dyb = Y_AXIS.max;
+			break;
+		    case HT_CLUSTERED:
+			stackheight[i].y = plot->points[i].y;
+			break;
+		    }
+		}
+#endif
+
 		/* clip to border */
 		cliptorange(dyt, Y_AXIS.min, Y_AXIS.max);
 		cliptorange(dxr, X_AXIS.min, X_AXIS.max);
@@ -2582,16 +2730,23 @@
 		xl = map_x(dxl);
 		xr = map_x(dxr);
 		yt = map_y(dyt);
+		yb = xaxis_y;
 
 #if USE_ULIG_FILLEDBOXES
+#ifdef EAM_HISTOGRAMS
+		if (plot->plot_style == HISTOGRAMS
+		&& (  histogram_opts.type == HT_STACKED_IN_LAYERS
+		   || histogram_opts.type == HT_STACKED_IN_TOWERS))
+		    yb = map_y(dyb);
+#endif
 		if ((plot->fill_properties.fillstyle != FS_EMPTY) && t->fillbox) {
                     int x, y, w, h;
                     int fillpar, style;
 		    
                     x = xl;
-                    y = xaxis_y;
+		    y = yb;
                     w = xr - xl + 1;
-                    h = yt - xaxis_y + 1;
+		    h = yt - yb + 1;
                     /* avoid negative width/height */
                     if( w <= 0 ) { 
 			x = xr; 
@@ -2599,7 +2754,7 @@
 		    }
                     if( h <= 0 ) {
 			y = yt;
-			h = xaxis_y - yt + 1;
+			h = yb - yt + 1;
 		    }
 
                     /* squeeze all fill information into the old style
@@ -2618,11 +2773,14 @@
                         break;
                     case FS_PATTERN:
 			fillpar = plot->fill_properties.fillpattern;
+#ifdef EAM_HISTOGRAMS
+			if (plot->plot_style == HISTOGRAMS
+			&&  histogram_opts.type == HT_STACKED_IN_TOWERS)
+			    fillpar += i;
+#endif
 			style = ((fillpar & 0xfff) << 4) + FS_PATTERN;
                         break;
                     default:
-			/* style == 0 or unknown --> solid fill with
-                         * background color */
 			fillpar = 0;
 			style = FS_EMPTY;
                     }
@@ -2639,11 +2796,11 @@
 		}
 #endif /* USE_ULIG_FILLEDBOXES */
 
-		(*t->move) (xl, xaxis_y);
+		(*t->move) (xl, yb);
 		(*t->vector) (xl, yt);
 		(*t->vector) (xr, yt);
-		(*t->vector) (xr, xaxis_y);
-		(*t->vector) (xl, xaxis_y);
+		(*t->vector) (xr, yb);
+		(*t->vector) (xl, yb);
 #if USE_ULIG_FILLEDBOXES
                 if( t->fillbox && 
 		    plot->fill_properties.border_linetype != LT_UNDEFINED)
@@ -3973,6 +4130,61 @@
 	}
 }
 
+
+#ifdef EAM_HISTOGRAMS
+void
+init_histogram(struct histogram_style *histogram, char *title)
+{
+    if (stackheight)
+	free(stackheight);
+    stackheight = NULL;
+    if (histogram) {
+	memcpy(histogram,&histogram_opts,sizeof(histogram_opts));
+	/* Insert in linked list */
+	histogram_opts.next = histogram;
+	if (*title) {
+	    histogram->title.text = gp_alloc(strlen(title)+1, "histogram title");
+	    strcpy(histogram->title.text,title);
+	} else
+	    histogram->title.text = NULL;
+    }
+}
+
+void
+free_histlist(struct histogram_style *hist)
+{
+    if (!hist) 
+	return;
+    if (hist->title.text)
+	free(hist->title.text);
+    if (hist->next) {
+	free_histlist(hist->next);
+	free(hist->next);
+	hist->next = NULL;
+    }
+}
+
+void
+place_histogram_titles()
+{
+    histogram_style *hist = &histogram_opts;
+    unsigned int x, y;
+    while ((hist = hist->next)) {
+	if (hist->title.text && *(hist->title.text)) {
+	    x = map_x((hist->start + hist->end) / 2.);
+	    y = xlabel_y;
+	    x += (term->h_char * hist->title.hoffset);
+	    y += (term->v_char * (hist->title.voffset+0.25));
+	    apply_textcolor(&hist->title.textcolor,term);
+	    write_multiline(x, y, hist->title.text, 
+			    CENTRE, JUST_BOT, 0, hist->title.font);
+	    reset_textcolor(&hist->title.textcolor,term);
+	}
+    }
+}
+
+#endif
+
 /*
  * Make this code a subroutine, rather than in-line, so that it can
  * eventually be shared by other callers. It would be nice to share it
diff -urNP gnuplot-datastrings/src/graphics.h gnuplot-eam/src/graphics.h
--- gnuplot-datastrings/src/graphics.h	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/graphics.h	2004-04-14 10:50:55.000000000 -0700
@@ -71,6 +71,10 @@
 #ifdef EAM_DATASTRINGS
     struct text_label *labels;	/* Only used if plot_style == LABELPOINTS */
 #endif
+#ifdef EAM_HISTOGRAMS
+    struct histogram_style *histogram;	/* Only used if plot_style == HISTOGRAM */
+    int histogram_sequence;	/* Ordering of this dataset within the histogram */
+#endif
 } curve_points;
 
 /* From ESR's "Actual code patch" :) */
@@ -104,7 +108,11 @@
 #if defined(sun386) || defined(AMIGA_SC_6_1)
 double CheckLog __PROTO((TBOOLEAN, double, double));
 #endif
-
 void apply_head_properties __PROTO((struct arrow_style_type *arrow_properties));
 
+#ifdef EAM_HISTOGRAMS
+void init_histogram __PROTO((struct histogram_style *hist, char *title));
+void free_histlist __PROTO((struct histogram_style *hist));
+#endif
+
 #endif /* GNUPLOT_GRAPHICS_H */
diff -urNP gnuplot-datastrings/src/plot2d.c gnuplot-eam/src/plot2d.c
--- gnuplot-datastrings/src/plot2d.c	2004-04-16 17:37:12.000000000 -0700
+++ gnuplot-eam/src/plot2d.c	2004-04-16 17:23:31.000000000 -0700
@@ -68,7 +68,9 @@
 static void print_table __PROTO((struct curve_points * first_plot, int plot_num));
 static void eval_plots __PROTO((void));
 static void parametric_fixup __PROTO((struct curve_points * start_plot, int *plot_num));
-
+#ifdef EAM_HISTOGRAMS
+static void histogram_range_fiddling __PROTO((struct curve_points *plot));
+#endif
 
 /* internal and external variables */
 
@@ -83,6 +85,12 @@
 TBOOLEAN boxwidth_is_absolute  = TRUE;
 #endif
 
+#ifdef EAM_HISTOGRAMS
+static double histogram_rightmost = 0.0;	/* Highest x-coord of histogram so far */
+static char histogram_title[64] = { '\0' };	/* Subtitle for this histogram */
+static struct coordinate GPHUGE *stackheight = NULL; /* Scratch space for y autoscale */
+static int stack_count = 0;			/* counter for stackheight */
+#endif
 
 /* function implementations */
 
@@ -112,6 +120,10 @@
 #ifdef EAM_DATASTRINGS
     cp->labels = NULL;	/* Will be allocated later if plot_style == LABELPOINTS */
 #endif
+#ifdef EAM_HISTOGRAMS
+    cp->histogram = NULL; /* Will be allocated later if plot_style == HISTOGRAM */
+    cp->histogram_sequence = 0;
+#endif
     return (cp);
 }
 
@@ -299,8 +311,15 @@
 	max_cols = 4;
 	break;
 
+#ifdef EAM_HISTOGRAMS
+    case HISTOGRAMS:
+	min_cols = 1;
+	max_cols = 1;
+	break;
+#endif
+
     case BOXES:
-	min_cols = 2;
+	min_cols = 1;
 	max_cols = 4;
 	/* HBB 20010214: commented out. z_axis is abused to store a
 	 * flag here, not for the actual width, as I thought it
@@ -338,6 +357,15 @@
 	int_error(NO_CARET, "Not enough columns for this style");
 
     i = 0;
+
+#ifdef EAM_HISTOGRAMS
+    /* EAM FIXME - There are places in df_readline where it would be really */
+    /* nice to know what kind of plot we are making, so I think that        */
+    /* current_plot should be a parameter to df_readline. For now, however, */
+    /* I am using a global variable, and only for HISTOGRAMS.               */
+    df_current_plot = (current_plot->plot_style == HISTOGRAMS) ? current_plot : NULL;
+#endif
+
     while ((j = df_readline(v, max_cols)) != DF_EOF) {
 	/* j <= max_cols */
 
@@ -357,7 +385,15 @@
 		int_error(c_token, "internal error : df_readline returned %d : datafile line %d", j, df_line_number);
 	    }
 	case DF_UNDEFINED:
-	    /* bad result from extended using expression */
+	    /* bad result from extended using expression, */
+	    /* or data field contains missing-data symbol */
+#ifdef EAM_HISTOGRAMS
+	    /* HISTOGRAMS need to reserve a slot for this x-coord value even  */
+	    /* if the point is missing or undefined.                          */
+	    if (current_plot->plot_style == HISTOGRAMS)
+		store2d_point(current_plot, i, df_datum, 0, 
+			df_datum-boxwidth/2, df_datum+boxwidth/2, 0, 0, 0.0);
+#endif
 	    current_plot->points[i].type = UNDEFINED;
 	    i++;
 	    continue;
@@ -411,6 +447,29 @@
 		store2d_point(current_plot, i++, v[0], v[1],
 			      v[0] - boxwidth / 2, v[0] + boxwidth / 2,
 			      v[1], v[1], 0.0);
+#ifdef EAM_HISTOGRAMS
+	    } else if (current_plot->plot_style == HISTOGRAMS) {
+		if (histogram_opts.type == HT_STACKED_IN_TOWERS) {
+		    histogram_rightmost = current_plot->histogram_sequence
+		    			+ current_plot->histogram->start;
+		    current_plot->histogram->end = histogram_rightmost;
+		} else if (v[0] + current_plot->histogram->start > histogram_rightmost) {
+		    histogram_rightmost = v[0] + current_plot->histogram->start;
+		    current_plot->histogram->end = histogram_rightmost;
+		}
+		if (boxwidth > 0
+#if USE_ULIG_RELATIVE_BOXWIDTH
+		     && boxwidth_is_absolute
+#endif /* USE_ULIG_RELATIVE_BOXWIDTH */
+		)
+		    store2d_point(current_plot, i++, v[0], v[1],
+			      v[0] - boxwidth / 2, v[0] + boxwidth / 2,
+			      v[1], v[1], 0.0);
+		else
+		    store2d_point(current_plot, i++, v[0], v[1], 
+			      v[0], v[0], v[1],
+			      v[1], -1.0);
+#endif
 	    } else {
 		if (current_plot->plot_style == CANDLESTICKS
 		    || current_plot->plot_style == FINANCEBARS) {
@@ -581,6 +640,12 @@
     current_plot->p_count = i;
     cp_extend(current_plot, i);	/* shrink to fit */
 
+#ifdef EAM_HISTOGRAMS
+    /* Fiddle the auto-scaling data for histograms */
+    if (current_plot->plot_style == HISTOGRAMS)
+	histogram_range_fiddling(current_plot);
+#endif
+
     df_close();
 
     return i;			/* i==0 indicates an 'empty' file */
@@ -686,6 +751,75 @@
 	cp->z = width;
 }				/* store2d_point */
 
+#ifdef EAM_HISTOGRAMS
+/* Since the stored x values for histogrammed data do not correspond exactly */
+/* to the eventual x coordinates, we need to modify the x axis range bounds. */
+/* Also the two stacked histogram modes need adjustment of the y axis bounds.*/
+void
+histogram_range_fiddling(struct curve_points *plot)
+{
+    double xlow, xhigh, yhigh;
+    int i;
+    /*
+     * EAM FIXME - This is work in progress
+     * - HT_STACKED_IN_TOWERS forcibly resets xman, which is only
+     *   correct if no other plot came first.
+     */
+    switch (histogram_opts.type) {
+	case HT_STACKED_IN_LAYERS:
+	    if (axis_array[plot->y_axis].set_autoscale & AUTOSCALE_MAX) {
+		if (plot->histogram_sequence == 0) {
+		    if (stackheight)
+			free(stackheight);
+		    stackheight = gp_alloc( plot->p_count * sizeof(struct coordinate GPHUGE),
+			    		    "stackheight array");
+		    for (stack_count=0; stack_count < plot->p_count; stack_count++)
+			stackheight[stack_count].y = 0;
+		} else if (plot->p_count > stack_count) {
+		    stackheight = gp_realloc( stackheight,
+		    			    plot->p_count * sizeof(struct coordinate GPHUGE),
+			    		    "stackheight array");
+		    for ( ; stack_count < plot->p_count; stack_count++)
+			stackheight[stack_count].y = 0;
+		}
+		for (i=0; i<stack_count; i++) {
+		    stackheight[i].y += plot->points[i].y;
+		    if (axis_array[plot->y_axis].max < stackheight[i].y)
+			axis_array[plot->y_axis].max = stackheight[i].y;
+		}
+	    }
+		/* fall through to checks on x range */
+	case HT_CLUSTERED:	
+		if (!axis_array[plot->x_axis].set_autoscale)
+		    break;
+		xlow = -1.0;
+		xhigh = plot->points[plot->p_count-1].x;
+		xhigh += plot->histogram->start + 1.0;
+		if (axis_array[FIRST_X_AXIS].min > xlow)
+		    axis_array[FIRST_X_AXIS].min = xlow;
+		if (axis_array[FIRST_X_AXIS].max < xhigh)
+		    axis_array[FIRST_X_AXIS].max = xhigh;
+		break;
+	case HT_STACKED_IN_TOWERS:
+		if (!axis_array[plot->x_axis].set_autoscale)
+		    break;
+		xlow = 0.0;
+		xhigh = plot->histogram_sequence;
+		xhigh += plot->histogram->start + 1.0;
+		if (axis_array[FIRST_X_AXIS].min > xlow)
+		    axis_array[FIRST_X_AXIS].min = xlow;
+		if (axis_array[FIRST_X_AXIS].max != xhigh)
+		    axis_array[FIRST_X_AXIS].max  = xhigh;
+		for (i=0, yhigh=0.0; i<plot->p_count; i++)
+		    if (plot->points[i].type != UNDEFINED)
+			yhigh += plot->points[i].y;
+		if (axis_array[plot->y_axis].max < yhigh)
+		    axis_array[plot->y_axis].max = yhigh;
+		break;
+    }
+}
+#endif
+
 #ifdef EAM_DATASTRINGS
 /* store_label() is called by get_data for each point */
 /* This routine is exported so it can be shared by plot3d */
@@ -966,6 +1100,17 @@
     int begin_token = c_token;	/* so we can rewind for second pass */
     legend_key *key = &keyT;
 
+#ifdef EAM_HISTOGRAMS
+    double newhist_start = 0.0;
+    int histogram_sequence = -1;
+    int newhist_color = LT_UNDEFINED;
+    int newhist_pattern = LT_UNDEFINED;
+    histogram_rightmost = 0.0;
+    *histogram_title = '\0';
+    free_histlist(&histogram_opts);
+    init_histogram(NULL,"");
+#endif
+
     uses_axis[FIRST_X_AXIS] =
 	uses_axis[FIRST_Y_AXIS] =
 	uses_axis[SECOND_X_AXIS] =
@@ -994,10 +1137,43 @@
 	if (END_OF_COMMAND)
 	    int_error(c_token, "function to plot expected");
 
+#ifdef EAM_HISTOGRAMS
+	if (almost_equals(c_token,"newhist$ogram")) {
+	    struct lp_style_type lp;
+	    struct fill_style_type fs;
+	    int previous_token;
+	    c_token++;
+	    histogram_sequence = -1;
+
+	    if (histogram_rightmost > 0)
+		newhist_start = histogram_rightmost + 2;
+
+	    lp.l_type = LT_UNDEFINED;
+	    fs.fillpattern = LT_UNDEFINED;
+
+	    do {
+		previous_token = c_token;
+
+		/* Store title in temporary variable and then copy into the */
+		/* new histogram structure when it is allocated.            */
+		if (isstring(c_token)) {
+		    quote_str(&histogram_title[0], c_token++, sizeof(histogram_title));
+		} else
+		    histogram_title[0] = '\0';
+
+		/* Allow explicit starting color or pattern for this histogram */
+		lp_parse(&lp, TRUE, FALSE, lp.l_type, 0);
+		parse_fillstyle(&fs, FS_SOLID, 100, fs.fillpattern, -1); 
+
+		} while (c_token != previous_token);
+
+	    newhist_color = lp.l_type;
+	    newhist_pattern = fs.fillpattern;
+	} else
+#endif
 	if (is_definition(c_token)) {
 	    define();
 	} else {
-	    /* int x_axis = 0, y_axis = 0; */ /* HBB 20000520: have global in axis.c now */
 	    int specs = 0;
 
 	    /* for datafile plot, record datafile spec for title */
@@ -1353,6 +1525,41 @@
 	    this_plot->x_axis = x_axis;
 	    this_plot->y_axis = y_axis;
 
+#ifdef EAM_HISTOGRAMS
+	    /* Initialize histogram data structure */
+	    if (this_plot->plot_style == HISTOGRAMS) {
+		if ((histogram_opts.type == HT_STACKED_IN_LAYERS
+		||   histogram_opts.type == HT_STACKED_IN_TOWERS)
+		&&  axis_array[FIRST_Y_AXIS].log)
+		    int_error(c_token, "Log scale on Y is incompatible with stacked histogram plot\n");
+		this_plot->histogram_sequence = ++histogram_sequence;
+		/* Current histogram always goes at the front of the list */
+		if (this_plot->histogram_sequence == 0) {
+		    this_plot->histogram = gp_alloc(sizeof(struct histogram_style), "New histogram");
+		    init_histogram(this_plot->histogram,histogram_title);
+		    this_plot->histogram->start = newhist_start;
+		    this_plot->histogram->startcolor = newhist_color;
+		    this_plot->histogram->startpattern = newhist_pattern;
+		} else {
+		    this_plot->histogram = histogram_opts.next;
+		    this_plot->histogram->clustersize++;
+		}
+		/* Modify X and Y coordinate placement info so that xtic and */
+		/* title coords are handled correctly during get_data().     */
+		if (histogram_opts.type == HT_STACKED_IN_TOWERS)
+		    this_plot->histogram->start = 0.5;
+
+		/* Normally each histogram gets a new set of colors, but in */
+		/* 'newhistogram' you can force a starting color instead.   */
+		if (!set_lpstyle && this_plot->histogram->startcolor != LT_UNDEFINED)
+		    this_plot->lp_properties.l_type = this_plot->histogram_sequence
+						    + this_plot->histogram->startcolor;
+		if (this_plot->histogram->startpattern != LT_UNDEFINED)
+		    this_plot->fill_properties.fillpattern = this_plot->histogram_sequence
+		    				    + this_plot->histogram->startpattern;
+	    }
+#endif
+
 	    /* we can now do some checks that we deferred earlier */
 
 	    if (this_plot->plot_type == DATA) {
diff -urNP gnuplot-datastrings/src/save.c gnuplot-eam/src/save.c
--- gnuplot-datastrings/src/save.c	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/save.c	2004-04-14 10:50:55.000000000 -0700
@@ -366,9 +366,10 @@
 	    save_position(fp, &key->user_pos);
 	    break;
 	}
-	fprintf(fp, " %s %sreverse %senhanced box linetype %d linewidth %.3f samplen %g spacing %g width %g height %g %s\n",
+	fprintf(fp, " %s %sreverse %sinvert %senhanced box linetype %d linewidth %.3f samplen %g spacing %g width %g height %g %s\n",
 		key->just == JLEFT ? "Left" : "Right",
 		key->reverse ? "" : "no",
+		key->invert ? "" : "no",
 		key->enhanced ? "" : "no",
 		key->box.l_type + 1, key->box.l_width,
 		key->swidth, key->vert_factor, key->width_fix, key->height_fix,
@@ -477,6 +478,23 @@
 	}
 	fprintf(fp, "\n");
     }
+
+#ifdef EAM_HISTOGRAMS
+    fprintf(fp, "set style histogram ");
+    switch (histogram_opts.type) {
+	default:
+	case HT_CLUSTERED:
+	    fprintf(fp,"clustered gap %d ",histogram_opts.gap); break;
+	case HT_STACKED_IN_LAYERS:
+	    fprintf(fp,"rowstacked "); break;
+	case HT_STACKED_IN_TOWERS:
+	    fprintf(fp,"columnstacked "); break;
+    }
+    fprintf(fp,"title %g,%g ",histogram_opts.title.hoffset,histogram_opts.title.voffset);
+    save_textcolor(fp, &histogram_opts.title.textcolor);
+    fprintf(fp, "\n");
+#endif
+
     fputs("unset logscale\n", fp);
 #define SAVE_LOG(axis)							\
     if (axis_array[axis].log)						\
@@ -1047,6 +1065,11 @@
     case BOXES:
 	fputs("boxes\n", fp);
 	break;
+#ifdef EAM_HISTOGRAMS
+    case HISTOGRAMS:
+	fputs("histograms\n", fp);
+	break;
+#endif
 #ifdef PM3D
     case FILLEDCURVES:
 	fputs("filledcurves ", fp);
diff -urNP gnuplot-datastrings/src/set.c gnuplot-eam/src/set.c
--- gnuplot-datastrings/src/set.c	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/set.c	2004-04-14 10:50:55.000000000 -0700
@@ -165,6 +165,11 @@
 static void set_palette_file __PROTO((void));
 static void set_palette_function __PROTO((void));
 #endif
+#ifdef EAM_HISTOGRAMS
+static void parse_histogramstyle __PROTO((histogram_style *hs, 
+		t_histogram_type def_type, int def_gap));
+#endif
+  
 
 /* Backwards compatibility ... */
 static void set_nolinestyle __PROTO((void));
@@ -212,6 +217,10 @@
 	
 	    if (temp_style & PLOT_STYLE_HAS_ERRORBAR)
 		int_error(c_token, "style not usable for function plots, left unchanged");
+#ifdef EAM_HISTOGRAMS
+	    else if (temp_style == HISTOGRAMS)
+		int_error(c_token, "style not usable for function plots, left unchanged");
+#endif
 	    else
 		func_style = temp_style;
 	}
@@ -1528,6 +1537,12 @@
 	    case S_KEY_NOREVERSE:
 		key->reverse = FALSE;
 		break;
+	    case S_KEY_INVERT:
+		key->invert = TRUE;
+		break;
+	    case S_KEY_NOINVERT:
+		key->invert = FALSE;
+		break;
 	    case S_KEY_ENHANCED:
 		key->enhanced = TRUE;
 		break;
@@ -3047,6 +3062,9 @@
 #ifdef EAM_DATASTRINGS
 	       || (temp_style == LABELPOINTS)
 #endif
+#ifdef EAM_HISTOGRAMS
+		|| (temp_style == HISTOGRAMS)
+#endif
 	        )
 		int_error(c_token, "style not usable for function plots, left unchanged");
 	    else 
@@ -3073,6 +3091,11 @@
     case SHOW_STYLE_ARROW:
 	set_arrowstyle();
 	break;
+#ifdef EAM_HISTOGRAMS
+    case SHOW_STYLE_HISTOGRAM:
+	parse_histogramstyle(&histogram_opts,HT_CLUSTERED,histogram_opts.gap);
+	break;
+#endif
     default:
 	int_error(c_token,
 		  "expecting 'data', 'function', 'line', 'fill' or 'arrow'" );
@@ -4462,3 +4485,55 @@
 	this_label->textcolor.value = this_label->place.z;
 }
 
+
+#ifdef EAM_HISTOGRAMS
+/* <histogramstyle> = {clustered {gap <n>} | rowstacked | columnstacked} */
+/*                    {title <title_options>}                            */
+void
+parse_histogramstyle( histogram_style *hs, 
+		t_histogram_type def_type,
+		int def_gap)
+{
+    struct value a;
+    label_struct title_specs;
+
+    /* Set defaults */
+    hs->type  = def_type;
+    hs->gap   = def_gap;
+
+    if (END_OF_COMMAND)
+	return;
+    if (!equals(c_token,"hs") && !almost_equals(c_token,"hist$ogram"))
+	return;
+    c_token++;
+
+    while (!END_OF_COMMAND) {
+	if (almost_equals(c_token, "clust$ered")) {
+	    hs->type = HT_CLUSTERED;
+	    c_token++;
+	} else if (almost_equals(c_token, "rows$tacked")) {
+	    hs->type = HT_STACKED_IN_LAYERS;
+	    c_token++;
+	} else if (almost_equals(c_token, "columns$tacked")) {
+	    hs->type = HT_STACKED_IN_TOWERS;
+	    c_token++;
+	} else if (equals(c_token, "gap")) {
+	    if (isanumber(++c_token))
+		hs->gap = (int)real(const_express(&a));
+	    else
+		int_error(c_token,"expected gap value");
+	} else if (almost_equals(c_token, "ti$tle")) {
+	    title_specs.xoffset = hs->title.hoffset;
+	    title_specs.yoffset = hs->title.voffset;
+	    set_xyzlabel(&title_specs);
+	    memcpy(&hs->title.textcolor,&title_specs.textcolor,sizeof(t_colorspec));
+	    hs->title.hoffset = title_specs.xoffset;
+	    hs->title.voffset = title_specs.yoffset;
+	    /* EAM FIXME - could allocate space and copy parsed font instead */
+	    hs->title.font = &(axis_array[FIRST_X_AXIS].label.font[0]);
+	} else
+	    /* We hit something unexpected */
+	    break;
+    }
+}
+#endif /* EAM_HISTOGRAMS */
diff -urNP gnuplot-datastrings/src/show.c gnuplot-eam/src/show.c
--- gnuplot-datastrings/src/show.c	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/show.c	2004-04-14 10:50:55.000000000 -0700
@@ -128,6 +128,9 @@
 static void show_view __PROTO((void));
 static void show_surface __PROTO((void));
 static void show_hidden3d __PROTO((void));
+#ifdef EAM_HISTOGRAMS
+static void show_histogram __PROTO((void));
+#endif
 #if defined(HAVE_LIBREADLINE) && defined(GNUPLOT_HISTORY)
 static void show_historysize __PROTO((void));
 #endif
@@ -1394,6 +1397,12 @@
 	show_fillstyle();
 	c_token++;
 	break;
+#ifdef EAM_HISTOGRAMS
+    case SHOW_STYLE_HISTOGRAM:
+	show_histogram();
+	c_token++;
+	break;
+#endif
 #endif /* USE_ULIG_FILLEDBOXES */
     case SHOW_STYLE_ARROW:
 	c_token++;
@@ -1408,6 +1417,9 @@
 #if USE_ULIG_FILLEDBOXES
 	show_fillstyle();
 #endif /* USE_ULIG_FILLEDBOXES */
+#ifdef EAM_HISTOGRAMS
+	show_histogram();
+#endif
 	show_arrowstyle(0);
 	break;
     }
@@ -1698,9 +1710,10 @@
 	break;
     }
 
-	fprintf(stderr, "\tkey is %s justified, %sreversed, %senhanced and ",
+	fprintf(stderr, "\tkey is %s justified, %sreversed, %sinverted, %senhanced and ",
 		key->just == JLEFT ? "left" : "right",
 		key->reverse ? "" : "not ",
+		key->invert ? "" : "not ",
 		key->enhanced ? "" : "not ");
 	if (key->box.l_type > L_TYPE_NODRAW)
 	    fprintf(stderr, "boxed\n\twith linetype %d, linewidth %.3f\n",
@@ -2382,6 +2395,24 @@
 #endif /* LITE */
 }
 
+#ifdef EAM_HISTOGRAMS
+static void
+show_histogram()
+{
+    if (histogram_opts.type == HT_CLUSTERED)
+	fprintf(stderr, "\tHistogram style is clustered with gap %d ", 
+		histogram_opts.gap);
+    else if (histogram_opts.type == HT_STACKED_IN_LAYERS)
+	fprintf(stderr, "\tHistogram style is rowstacked ");
+    else if (histogram_opts.type == HT_STACKED_IN_TOWERS)
+	fprintf(stderr, "\tHistogram style is columnstacked ");
+    fprintf(stderr, " title offset %g,%g ",
+	histogram_opts.title.hoffset,histogram_opts.title.voffset);
+    if (histogram_opts.title.textcolor.type == TC_LT)
+	fprintf(stderr,"textcolor lt %d", histogram_opts.title.textcolor.lt+1); 
+    fprintf(stderr, "\n");
+}
+#endif
 
 #if defined(HAVE_LIBREADLINE) && defined(GNUPLOT_HISTORY)
 /* process 'show historysize' command */
diff -urNP gnuplot-datastrings/src/tables.c gnuplot-eam/src/tables.c
--- gnuplot-datastrings/src/tables.c	2004-04-14 10:49:27.000000000 -0700
+++ gnuplot-eam/src/tables.c	2004-04-14 10:50:55.000000000 -0700
@@ -367,6 +367,8 @@
     { "R$ight", S_KEY_RRIGHT },
     { "rev$erse", S_KEY_REVERSE },
     { "norev$erse", S_KEY_NOREVERSE },
+    { "inv$ert", S_KEY_INVERT },
+    { "noinv$ert", S_KEY_NOINVERT },
     { "enh$anced", S_KEY_ENHANCED },
     { "noenh$anced", S_KEY_NOENHANCED },
     { "b$ox", S_KEY_BOX },
@@ -560,6 +562,9 @@
     { "fill", SHOW_STYLE_FILLING },
     { "fs", SHOW_STYLE_FILLING },
     { "ar$row", SHOW_STYLE_ARROW },
+#ifdef EAM_HISTOGRAMS
+    { "hist$ogram", SHOW_STYLE_HISTOGRAM },
+#endif
     { NULL, SHOW_STYLE_INVALID }
 };
 
@@ -580,6 +585,9 @@
     { "xe$rrorbars", XERRORBARS },
     { "xye$rrorbars", XYERRORBARS },
     { "boxes", BOXES },
+#ifdef EAM_HISTOGRAMS
+    { "hist$ograms", HISTOGRAMS },
+#endif
 #ifdef PM3D
     { "filledc$urves", FILLEDCURVES },
 #endif
diff -urNP gnuplot-datastrings/src/tables.h gnuplot-eam/src/tables.h
--- gnuplot-datastrings/src/tables.h	2004-04-13 23:08:29.000000000 -0700
+++ gnuplot-eam/src/tables.h	2004-04-14 10:50:55.000000000 -0700
@@ -126,6 +126,7 @@
     S_KEY_INVALID,
     S_KEY_TOP, S_KEY_BOTTOM, S_KEY_LEFT, S_KEY_RIGHT, S_KEY_UNDER,
     S_KEY_OUTSIDE, S_KEY_LLEFT, S_KEY_RRIGHT, S_KEY_REVERSE, S_KEY_NOREVERSE,
+    S_KEY_INVERT, S_KEY_NOINVERT,
     S_KEY_ENHANCED, S_KEY_NOENHANCED,
     S_KEY_BOX, S_KEY_NOBOX, S_KEY_SAMPLEN, S_KEY_SPACING, S_KEY_WIDTH,
     S_KEY_HEIGHT, S_KEY_TITLE,
@@ -175,6 +176,9 @@
     SHOW_STYLE_INVALID,
     SHOW_STYLE_DATA, SHOW_STYLE_FUNCTION, SHOW_STYLE_LINE,
     SHOW_STYLE_FILLING, SHOW_STYLE_ARROW
+#ifdef EAM_HISTOGRAMS
+    , SHOW_STYLE_HISTOGRAM
+#endif
 };
 
 #ifdef PM3D
diff -urNP gnuplot-datastrings/src/unset.c gnuplot-eam/src/unset.c
--- gnuplot-datastrings/src/unset.c	2004-04-13 23:08:30.000000000 -0700
+++ gnuplot-eam/src/unset.c	2004-04-14 10:50:55.000000000 -0700
@@ -83,6 +83,9 @@
 static void unset_format __PROTO((void));
 static void unset_grid __PROTO((void));
 static void unset_hidden3d __PROTO((void));
+#ifdef EAM_HISTOGRAMS
+static void unset_histogram __PROTO((void));
+#endif
 #if defined(HAVE_LIBREADLINE) && defined(GNUPLOT_HISTORY)
 static void unset_historysize __PROTO((void));
 #endif
@@ -812,6 +815,14 @@
 #endif
 }
 
+#ifdef EAM_HISTOGRAMS
+static void
+unset_histogram()
+{
+    histogram_opts.type = HT_CLUSTERED;
+    histogram_opts.gap = 2;
+}
+#endif
 
 #if defined(HAVE_LIBREADLINE) && defined(GNUPLOT_HISTORY)
 /* process 'unset historysize' command */
@@ -1203,6 +1214,9 @@
 #if USE_ULIG_FILLEDBOXES
 	unset_fillstyle();
 #endif
+#ifdef EAM_HISTOGRAMS
+	unset_histogram();
+#endif
 	c_token++;
 	return;
     } 
@@ -1227,6 +1241,12 @@
 	c_token++;
 	break;
 #endif /* USE_ULIG_FILLEDBOXES */
+#ifdef EAM_HISTOGRAMS
+    case SHOW_STYLE_HISTOGRAM:
+	unset_histogram();
+	c_token++;
+	break;
+#endif
     case SHOW_STYLE_ARROW:
 	unset_arrowstyles();
 	c_token++;
@@ -1528,6 +1548,9 @@
 #if USE_ULIG_FILLEDBOXES
     unset_fillstyle();
 #endif
+#ifdef EAM_HISTOGRAMS
+    unset_histogram();
+#endif
 
     unset_missing();
     df_separator = '\0';
--- gnuplot/demo/histograms2.dem	1969-12-31 16:00:00.000000000 -0800
+++ gnuplot-eam/demo/histograms2.dem	2004-04-16 21:51:54.000000000 -0700
@@ -0,0 +1,66 @@
+#
+# Example of using histogram modes
+#
+reset
+set title "US immigration from Europe by decade"
+set missing "-"
+set xtics nomirror rotate by -45
+#
+# 'newhistogram' keyword to plot
+#
+set title "Default Histogram Colouring"
+set key under
+set style data histogram
+set style histogram clustered gap 1 title 2,0.25
+set style fill solid noborder
+set boxwidth 0.95
+unset xtics
+set xtics rotate by -45
+set xlabel "Immigration from different regions" 0,-3
+set ytics
+set grid y
+set auto y
+plot \
+newhistogram "Northern Europe", \
+'immigration.dat' using 6:xtic(1) t 6, '' u 13 t 13, '' u 14 t 14, \
+newhistogram "Southern Europe", \
+'' u 9:xtic(1) t 9, '' u 17 t 17, '' u 22 t 22, \
+newhistogram "British Isles", \
+'' u 10:xtic(1) t 10, '' u 21 t 21
+#
+pause -1 "Same plot using explicit histogram start colors"
+set title "Explicit start color in 'newhistogram' command"
+plot \
+newhistogram "Northern Europe" lt 4, \
+'immigration.dat' using 6:xtic(1) t 6, '' u 13 t 13, '' u 14 t 14, \
+newhistogram "Southern Europe" lt 4, \
+'' u 9:xtic(1) t 9, '' u 17 t 17, '' u 22 t 22, \
+newhistogram "British Isles" lt 4, \
+'' u 10:xtic(1) t 10, '' u 21 t 21
+#
+#
+pause -1 "Same plot using explicit histogram start pattern"
+set title "Explicit start pattern in 'newhistogram' command"
+set style fill pattern 1 border -1
+plot \
+newhistogram "Northern Europe" fs pattern 1, \
+'immigration.dat' using 6:xtic(1) t 6, '' u 13 t 13, '' u 14 t 14, \
+newhistogram "Southern Europe" fs pattern 1, \
+'' u 9:xtic(1) t 9, '' u 17 t 17, '' u 22 t 22, \
+newhistogram "British Isles" fs pattern 1, \
+'' u 10:xtic(1) t 10, '' u 21 t 21
+#
+#
+pause -1 "Same plot with both explicit color and pattern"
+set title "Explicit start pattern and linetype"
+set style fill pattern 1 border -1
+plot \
+newhistogram "Northern Europe" lt 2 fs pattern 1, \
+'immigration.dat' using 6:xtic(1) t 6, '' u 13 t 13, '' u 14 t 14, \
+newhistogram "Southern Europe" lt 2 fs pattern 1, \
+'' u 9:xtic(1) t 9, '' u 17 t 17, '' u 22 t 22, \
+newhistogram "British Isles" lt 2 fs pattern 1, \
+'' u 10:xtic(1) t 10, '' u 21 t 21
+#
+#
+pause -1
