summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgfplots/pgfplots.errorbars.code.tex
blob: 42d6c9f4b65455c7d125bf189f7419a410fa1550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
%--------------------------------------------
%
% Package pgfplots
%
% Provides a user-friendly interface to create function plots (normal
% plots, semi-logplots and double-logplots).
% 
% It is based on Till Tantau's PGF package.
%
% Copyright 2007-2013 by Christian Feuersänger.
%
% 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 3 of the License, 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.
% 
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.
%
%--------------------------------------------


% the \addplot commands assign
%   \pgfplots@current@point@error@x@plus
%   \pgfplots@current@point@error@x@minus
%   \pgfplots@current@point@error@y@plus
%   \pgfplots@current@point@error@y@minus
%   \pgfplots@current@point@error@z@plus
%   \pgfplots@current@point@error@z@minus
%
% the error bar processing takes these values as input, adds them to
% the current coordinates where applicable and according the the error
% bar configuration and overwrites these macros.
%   
% Then, these values are registered as "visualization depends on",
% i.e. they will be available for every visualization phase.
%
% The visualization phase, in turn, expects these values. More
% precisely, a separate visualization phase called
% \pgfplotsaxis@visphase@name@errorbars is started. This installs the
% plot handler \pgfplots@errorbars@plot@handler and does the same job
% as it would for normal plot handlers.
%
\def\pgfplots@errorbars@survey@begin{%
	%
	\pgfplots@errorbars@prepare@value@serialization
	%
	% Now, prepare the coordinate processing for errorbars:
	\pgfplots@PREPARE@errorbar@processing@in@dir x%
	\pgfplots@PREPARE@errorbar@processing@in@dir y%
	\ifpgfplots@curplot@threedim
		\pgfplots@PREPARE@errorbar@processing@in@dir z%
	\else
		\let\pgfplots@PREPARE@errorbar@process@z=\relax
	\fi
}

\def\pgfplots@errorbars@survey@end{%
	\pgfplots@streamerrorbarend
}%

\def\pgfplots@errorbars@survey@point{%
	% This thing gets the 'current@point@...' context,
	% that means 
	% \pgfplots@current@point@[xy]
	% \pgfplots@current@point@[xy]@error
	% \pgfplots@current@point@[xy]@unfiltered
	\pgfplots@PREPARE@errorbar@process@x%
	\pgfplots@PREPARE@errorbar@process@y%
	\pgfplots@PREPARE@errorbar@process@z%
}

\def\pgfplots@errorbars@visphase@begin{%
	\pgfplots@errorbars@prepare@value@serialization
}

\def\pgfplots@errorbars@visphase@end{%
}%

\def\pgfplots@errorbars@visphase@point{%
}%

\def\pgfplots@errorbars@prepare@value@serialization{%
	\if0\pgfplots@errorbars@xdirection
	\else
		\pgfplotsset{%
			visualization depends on=value \pgfplots@current@point@error@x@plus\as\pgfplots@current@point@error@x@plus,
			visualization depends on=value \pgfplots@current@point@error@x@minus\as\pgfplots@current@point@error@x@minus,
		}%
	\fi
	\if0\pgfplots@errorbars@ydirection
	\else
		\pgfplotsset{%
			visualization depends on=value \pgfplots@current@point@error@y@plus\as\pgfplots@current@point@error@y@plus,
			visualization depends on=value \pgfplots@current@point@error@y@minus\as\pgfplots@current@point@error@y@minus,
		}%
	\fi
	\ifpgfplots@curplot@threedim
		\if0\pgfplots@errorbars@zdirection
		\else
			\pgfplotsset{%
				visualization depends on=value \pgfplots@current@point@error@z@plus\as\pgfplots@current@point@error@z@plus,
				visualization depends on=value \pgfplots@current@point@error@z@minus\as\pgfplots@current@point@error@z@minus,
			}%
		\fi
	\fi
}%

% Prepares a macro \pgfplots@PREPARE@process@errorbar@for@dir##1
% which can then be used to process error bars. The macro will be
% \relax if error bars are disabled for #1.
%
% #1: either x, y or z.
%
% POSTCONDITION:
%   the macro \pgfplots@PREPARE@errorbar@process@#1 will be defined.
%   It is supposed to be used inside of the pgfplots streaming methods
%   and depends on the arguments
% 		\pgfplots@current@point@[xyz]
%		\pgfplots@current@point@[xyz]@unfiltered
%		\pgfplots@current@point@[xyz]@error
%	The '@unfilterered' arguments are needed for log plots. I do not
%	want to compute exp(current@point@[xyz]) again.
\def\pgfplots@PREPARE@errorbar@processing@in@dir#1{%
	\pgfplots@PREPARE@errorbar@processing@in@dir@reset#1%
	%
	\if0\csname pgfplots@errorbars@#1direction\endcsname
		% no error bars. Ok. Do nothing here.
		\expandafter\let\csname pgfplots@PREPARE@errorbar@process@#1\endcsname=\relax
	\else
		%
		% The routine which is invoked for every reported input
		% coordinate is \pgfplots@process@errorbar@for.
		%
		% This here prepares its helper macros for direction '#1':
		%
		% More precisely, it prepared 
		%
		% ##1 is either '+' or '-':
		% \pgfplots@PREPARE@errorbar@process@x@##1
		% \pgfplots@PREPARE@errorbar@process@y@##1
		% \pgfplots@PREPARE@errorbar@process@z@##1
		%
		\pgfplots@if{pgfplots@#1islinear}{%
			\ifcase\csname pgfplots@errorbars@#1mode\endcsname\relax
				% fixed absolute error.
				\pgfplotscoordmath{#1}{parsenumber}{\csname pgfplots@errorbars@#1fixed\endcsname}%
				\expandafter\let\csname pgfplots@error@coord@#1\endcsname=\pgfmathresult
				\expandafter\def\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname##1{%
					\if +##1%
						\def\pgfplots@loc@TMPb{add}%
					\else
						\def\pgfplots@loc@TMPb{subtract}%
					\fi
					\pgfplotscoordmath{#1}{op}{\pgfplots@loc@TMPb}{%
						{\csname pgfplots@current@point@#1\endcsname}%
						{\csname pgfplots@error@coord@#1\endcsname}%
					}%
					\let\pgfplots@error@coord=\pgfmathresult
					\pgfplots@PREPARE@errorbar@stream@it@#1##1%
				}%
			\or% fixed relative error:
				\pgfplotscoordmath{#1}{parsenumber}{\csname pgfplots@errorbars@#1rel\endcsname}%
				\let\pgfplots@loc@TMPb=\pgfmathresult
				%
				% +1:
				\pgfplotscoordmath{#1}{parsenumber}{1}%
				\let\pgfplots@loc@TMPa=\pgfmathresult
				%
				% Prepare '1 + err':
				\pgfplotscoordmath{#1}{op}{add}{%
					{\pgfplots@loc@TMPa}%
					{\pgfplots@loc@TMPb}%
				}%
				\expandafter\let\csname pgfplots@error@coord@#1@+\endcsname=\pgfmathresult
				%
				% Prepare '1 - err':
				\pgfplotscoordmath{#1}{op}{subtract}{%
					{\pgfplots@loc@TMPa}%
					{\pgfplots@loc@TMPb}%
				}%
				\expandafter\let\csname pgfplots@error@coord@#1@-\endcsname=\pgfmathresult
				%
				\expandafter\def\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname##1{%
					\pgfplotscoordmath{#1}{op}{multiply}{%
						{\csname pgfplots@current@point@#1\endcsname}
						{\csname pgfplots@error@coord@#1@##1\endcsname}%
					}%
					\let\pgfplots@error@coord=\pgfmathresult
					\pgfplots@PREPARE@errorbar@stream@it@#1##1%
				}%
			\or% explicit absolute:
				\expandafter\def\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname##1{%
					\edef\pgfplots@error@coord{\csname pgfplots@current@point@error@#1@\pgfplots@errorbars@plusminus##1\endcsname}%
					\ifx\pgfplots@error@coord\pgfutil@empty
						\pgfplots@PREPARE@errorbar@stream@it@empty#1##1%
					\else
						\pgfplotscoordmath{#1}{parsenumber}{\pgfplots@error@coord}%
						\pgfplotscoordmath{#1}{if is bounded}{\pgfmathresult}{%
							\let\pgfplots@error@coord=\pgfmathresult
							% remember result here - will be used in case
							% of '+' AND '-' error bars:
							%\expandafter\let\csname pgfplots@current@point@error@#1@\pgfplots@errorbars@plusminus##1\endcsname=\pgfmathresult
							\if +##1%
								\def\pgfplots@loc@TMPb{add}%
							\else
								\def\pgfplots@loc@TMPb{subtract}%
							\fi
							\pgfplotscoordmath{#1}{op}{\pgfplots@loc@TMPb}{%
								{\csname pgfplots@current@point@#1\endcsname}%
								{\pgfplots@error@coord}%
							}%
							\let\pgfplots@error@coord=\pgfmathresult
							\pgfplots@PREPARE@errorbar@stream@it@#1##1%
						}{%
							% input is unbounded. Skip it.
							\pgfplots@PREPARE@errorbar@stream@it@empty#1##1%
						}%
					\fi
				}%
			\or% explicit relative:
				\expandafter\def\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname##1{%
					\edef\pgfplots@error@coord{\csname pgfplots@current@point@error@#1@\pgfplots@errorbars@plusminus##1\endcsname}%
					\ifx\pgfplots@error@coord\pgfutil@empty
						\pgfplots@PREPARE@errorbar@stream@it@empty#1##1%
					\else
						\pgfplotscoordmath{#1}{parsenumber}{\pgfplots@error@coord}%
						\pgfplotscoordmath{#1}{if is bounded}{\pgfmathresult}{%
							\let\pgfplots@error@coord=\pgfmathresult
							% compute ' 1 + value' or '1-value':
							\pgfplotscoordmath{#1}{one}%
							\if +##1%
								\def\pgfplots@loc@TMPb{add}%
							\else
								\def\pgfplots@loc@TMPb{subtract}%
							\fi
							\pgfplotscoordmath{#1}{op}{\pgfplots@loc@TMPb}{%
								{\pgfmathresult}%
								{\pgfplots@error@coord}%
							}%
							\let\pgfplots@error@coord=\pgfmathresult
							\pgfplotscoordmath{#1}{op}{multiply}{%
								{\csname pgfplots@current@point@#1\endcsname}
								{\pgfplots@error@coord}%
							}%
							\let\pgfplots@error@coord=\pgfmathresult
							\pgfplots@PREPARE@errorbar@stream@it@#1##1%
						}{%
							% input is unbounded. Skip it.
							\pgfplots@PREPARE@errorbar@stream@it@empty#1##1%
						}%
					\fi
				}%
			\fi
		}{%
			% LOGARITHMIC scaling. All errors are interpreted as 
			%   log(x +- e_x)
			% or
			%   log( x*(1+-e_x) )
			%
			% That means any input argument is
			% given in log base e and in fixed point.
			% Furthermore, we expect the '@unfiltered' keys to be
			% present (I don't want to apply 'exp' again!).
			%
			\ifcase\csname pgfplots@errorbars@#1mode\endcsname
				% fixed absolute, log( x +- e_x )
				%
				\pgfplotscoordmath{default}{parsenumber}{\csname pgfplots@errorbars@#1fixed\endcsname}%
				\expandafter\let\csname pgfplots@error@coord@#1\endcsname=\pgfmathresult
				\expandafter\def\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname##1{%
					\pgfplotscoordmath{default}{parsenumber}{\csname pgfplots@current@point@#1@unfiltered\endcsname}%
					\let\pgfplots@loc@TMPa=\pgfmathresult
					\if +##1%
						\def\pgfplots@loc@op{add}%
					\else
						\def\pgfplots@loc@op{subtract}%
					\fi
					\pgfplotscoordmath{default}{op}{\pgfplots@loc@op}{%
						{\pgfplots@loc@TMPa}%
						{\csname pgfplots@error@coord@#1\endcsname}%
					}%
					\pgfplotscoordmath{default}{tostring}{\pgfmathresult}%
					\pgfplotscoordmath{#1}{log}{\pgfmathresult}%
					\let\pgfplots@error@coord=\pgfmathresult
					\pgfplots@PREPARE@errorbar@stream@it@#1##1%
				}%
			\or% fixed relative, log( x ( 1+-e_x ) ) = log(x) + log(1+-e_x)
				\pgfplotscoordmath{default}{parsenumber}{\csname pgfplots@errorbars@#1rel\endcsname}%
				\let\pgfplots@loc@TMPb=\pgfmathresult
				%
				% +1:
				\pgfplotscoordmath{default}{one}%
				\let\pgfplots@loc@TMPa=\pgfmathresult
				%
				% Prepare '1 + err':
				\pgfplotscoordmath{default}{op}{add}{{\pgfplots@loc@TMPa}{\pgfplots@loc@TMPb}}%
				\pgfplotscoordmath{default}{tostring}{\pgfmathresult}%
				\pgfplotscoordmath{#1}{log}{\pgfmathresult}%
				\pgfplotscoordmath{#1}{if is bounded}{\pgfmathresult}{%
				}{%
					% 1 + err <= 0  and log(1+err) is undefined:
					\pgfplotscoordmath{default}{tostring}{\pgfplots@loc@TMPb}%
					\pgfplots@error{Sorry, log(1 + \pgfmathresult) is undefined. Please provide a different argument for '/pgfplots/error bar/#1 fixed relative'.}%
					\let\pgfmathresult=\pgfutil@empty
				}%
				\expandafter\let\csname pgfplots@error@coord@#1@+\endcsname=\pgfmathresult
				%
				% Prepare '1 - err':
				\pgfplotscoordmath{default}{op}{subtract}{{\pgfplots@loc@TMPa}{\pgfplots@loc@TMPb}}%
				\pgfplotscoordmath{default}{tostring}{\pgfmathresult}%
				\pgfplotscoordmath{#1}{log}{\pgfmathresult}%
				\pgfplotscoordmath{#1}{if is bounded}{\pgfmathresult}{%
				}{%
					% 1 - err <= 0  and log(1+err) is undefined:
					\pgfplotscoordmath{default}{tostring}{\pgfplots@loc@TMPb}%
					\pgfplots@error{Sorry, log(1 - \pgfmathresult) (\pgfplots@loc@TMPa - \pgfplots@loc@TMPb) is undefined. Please provide a different argument for '/pgfplots/error bar/#1 fixed relative'.}%
					\let\pgfmathresult=\pgfutil@empty
				}%
				\expandafter\let\csname pgfplots@error@coord@#1@-\endcsname=\pgfmathresult
				%
				\expandafter\def\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname##1{%
					\expandafter\ifx\csname pgfplots@current@point@#1@##1\endcsname\pgfutil@empty
						\pgfplots@PREPARE@errorbar@stream@it@empty#1##1%
					\else
						\pgfmath@basic@add@
							{\csname pgfplots@current@point@#1\endcsname}
							{\csname pgfplots@error@coord@#1@##1\endcsname}%
						\let\pgfplots@error@coord=\pgfmathresult
						\pgfplots@PREPARE@errorbar@stream@it@#1##1%
					\fi
				}%
			\or% explicit absolute
				% log( x +- e_x )
				\expandafter\def\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname##1{%
					\edef\pgfplots@error@coord{\csname pgfplots@current@point@error@#1@\pgfplots@errorbars@plusminus##1\endcsname}%
					\ifx\pgfplots@error@coord\pgfutil@empty
						\pgfplots@PREPARE@errorbar@stream@it@empty#1##1%
					\else
						\pgfplotscoordmath{default}{parsenumber}{\pgfplots@error@coord}%
						\pgfplotscoordmath{default}{if is bounded}{\pgfmathresult}{%
							\let\pgfplots@error@coord=\pgfmathresult
							% remember result here - will be used in case
							% of '+' AND '-' error bars:
							%\expandafter\let\csname pgfplots@current@point@error@#1@\pgfplots@errorbars@plusminus##1\endcsname=\pgfmathresult
							\pgfplotscoordmath{default}{parsenumber}{\csname pgfplots@current@point@#1@unfiltered\endcsname}%
							\let\pgfplots@loc@TMPa=\pgfmathresult
							\if +##1%
								\def\pgfplots@loc@op{add}%
							\else
								\def\pgfplots@loc@op{subtract}%
							\fi
							\pgfplotscoordmath{default}{op}{\pgfplots@loc@op}{%
								{\pgfplots@loc@TMPa}%
								{\pgfplots@error@coord}%
							}%
							\pgfplotscoordmath{default}{tostring}{\pgfmathresult}%
							\pgfplotscoordmath{#1}{log}{\pgfmathresult}%
							\let\pgfplots@error@coord=\pgfmathresult
							\pgfplots@PREPARE@errorbar@stream@it@#1##1%
						}{%
							% input is unbounded. Skip it.
							\pgfplots@PREPARE@errorbar@stream@it@empty#1##1%
						}%
					\fi
				}%
				%
			\or% explicit relative:
				% log( x ( 1+-e_x ) ) = log(x) + log(1+-e_x)
				\expandafter\def\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname##1{%
					\edef\pgfplots@error@coord{\csname pgfplots@current@point@error@#1@\pgfplots@errorbars@plusminus##1\endcsname}%
					\ifx\pgfplots@error@coord\pgfutil@empty
						\pgfplots@PREPARE@errorbar@stream@it@empty#1##1%
					\else
						\pgfplotscoordmath{default}{parsenumber}{\pgfplots@error@coord}%
						\pgfplotscoordmath{default}{if is bounded}{\pgfmathresult}{%
							\let\pgfplots@error@coord=\pgfmathresult
							% remember result here - will be used in case
							% of '+' AND '-' error bars:
							%\expandafter\let\csname pgfplots@current@point@error@#1@\pgfplots@errorbars@plusminus##1\endcsname=\pgfmathresult
							%
							\pgfplotscoordmath{default}{one}%
							\let\pgfplots@loc@TMPa=\pgfmathresult
							\if +##1%
								\def\pgfplots@loc@op{add}%
							\else
								\def\pgfplots@loc@op{subtract}%
							\fi
							\pgfplotscoordmath{default}{op}{\pgfplots@loc@op}{%
								{\pgfplots@loc@TMPa}%
								{\pgfplots@error@coord}%
							}%
							\pgfplotscoordmath{default}{tostring}{\pgfmathresult}%
							\pgfplotscoordmath{#1}{log}{\pgfmathresult}%
							\let\pgfplots@error@coord=\pgfmathresult
							\pgfplotscoordmath{#1}{if is bounded}{\pgfmathresult}{%
								\pgfplotscoordmath{#1}{op}{add}{%
									{\csname pgfplots@current@point@#1\endcsname}
									{\pgfplots@error@coord}%
								}%
								\let\pgfplots@error@coord=\pgfmathresult
								\pgfplots@PREPARE@errorbar@stream@it@#1##1%
							}{%
								% -> log( <= 0 ) -> do nothing.
								\pgfplots@PREPARE@errorbar@stream@it@empty#1##1%
							}%
						}{%
							% input is unbounded - do nothing.
							\pgfplots@PREPARE@errorbar@stream@it@empty#1##1%
						}%
					\fi
				}%
				%
			\fi
		}%
		\ifcase\csname pgfplots@errorbars@#1direction\endcsname
			% none
		\or
			% plus
			\expandafter\edef\csname pgfplots@PREPARE@errorbar@process@#1\endcsname{%
				\expandafter\noexpand\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname+%
			}%
		\or
			% minus
			\expandafter\edef\csname pgfplots@PREPARE@errorbar@process@#1\endcsname{%
				\expandafter\noexpand\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname-%
			}%
		\or
			% both
			\expandafter\edef\csname pgfplots@PREPARE@errorbar@process@#1\endcsname{%
				\expandafter\noexpand\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname+%
				\expandafter\noexpand\csname pgfplots@PREPARE@errorbar@process@#1@\endcsname-%
			}%
		\fi
	\fi
}

\def\pgfplots@PREPARE@errorbar@processing@in@dir@reset#1{%
	\expandafter\let\csname pgfplots@current@point@error@#1@plus\endcsname=\pgfutil@empty
	\expandafter\let\csname pgfplots@current@point@error@#1@minus\endcsname=\pgfutil@empty
}%

% #1: one of x,y, or z
% #2: either '+' or '-', denotes the direction of the error
% bar
%
% PRECONDITION: \pgfplots@error@coord contains the value which is to
% be stored as \pgfplots@current@point@error@#1@plus or
% \pgfplots@current@point@error@#1@minus
%
% POSTCONDITION: limits updated and
% \pgfplots@current@point@error@#1@plus or
% \pgfplots@current@point@error@#1@minus
% is defined.
\def\pgfplots@PREPARE@errorbar@stream@it@#1#2{%
	\ifx\pgfplots@error@coord\pgfutil@empty
	\else
		\expandafter\let\expandafter\pgfplots@current@point@@old\csname pgfplots@current@point@#1\endcsname
		\expandafter\let\csname pgfplots@current@point@#1\endcsname=\pgfplots@error@coord
		\pgfplotsaxisupdatelimitsforcoordinate\pgfplots@current@point@x\pgfplots@current@point@y\pgfplots@current@point@z
		\expandafter\let\csname pgfplots@current@point@#1\endcsname=\pgfplots@current@point@@old
	\fi
	%
	% ... and remember what we need! This value will be stored as
	% "visualization depends on"
	\expandafter\let\csname pgfplots@current@point@error@#1@\pgfplots@errorbars@plusminus#2\endcsname=\pgfplots@error@coord
}%

\def\pgfplots@PREPARE@errorbar@stream@it@empty#1#2{%
	% ... and remember what we need! This value will be stored as
	% "visualization depends on"
	\expandafter\let\csname pgfplots@current@point@error@#1@\pgfplots@errorbars@plusminus#2\endcsname=\pgfutil@empty
}

\def\pgfplots@errorbars@plusminus#1{%
	\if#1+%
		plus%
	\else
		minus%
	\fi
}%

% A dummy plot handler which is used in a special visualization phase
% for error bars.
\def\pgfplots@errorbars@plot@handler{%
	\gdef\pgf@plotstreamstart{%
		\pgfplots@streamerrorbar@directdraw
		\global\let\pgf@plotstreampoint=\pgfplots@errorbars@plot@handler@point
		\global\let\pgf@plotstreamspecial=\relax
		\global\let\pgf@plotstreamend=\pgfplots@streamerrorbarend
		\pgfplots@streamerrorbarstart
	}%
}%

\def\pgfplots@errorbars@plot@handler@point#1{%
	\pgf@process{#1}%
	\edef\pgfplots@errorbars@src{(\the\pgf@x,\the\pgf@y)}%
	%
	% we want to allow scatter plots to vary depending on 'point
	% meta'. This here does not hurt:
	\pgfplotsaxisvisphasetransformpointmetaifany
	%
	\pgfplots@errorbars@plot@handler@point@dir x%
	\pgfplots@errorbars@plot@handler@point@dir y%
	\ifpgfplots@curplot@threedim
		\pgfplots@errorbars@plot@handler@point@dir z%
	\fi
}

% #1: one of x,y, or z
% #2: the error bar value in dir #1
% output: \pgfplots@errorbars@trg in the form (<x>,<y>,<z>)
\def\pgfplots@errorbars@to@pt#1#2{%
	\begingroup
	\expandafter\let\csname pgfplots@current@point@#1\endcsname=#2%
	\ifpgfplots@curplot@threedim
		\edef\pgfplotsretval{(\pgfplots@current@point@x,\pgfplots@current@point@y,\pgfplots@current@point@z)}%
	\else
		\edef\pgfplotsretval{(\pgfplots@current@point@x,\pgfplots@current@point@y)}%
	\fi
	\global\let\pgfplots@errorbars@trg=\pgfplotsretval
	\endgroup
}%

% #1: a <\macro> containing the value 
% #2: either x,y, or z
\def\pgfplots@errorbars@plot@handler@point@dir@@#1#2{%
	\ifx#1\pgfutil@empty
	\else
		\pgfplotsaxisvisphasetransformcoordinateentry{#2}{#1}%
		\pgfplots@errorbars@to@pt{#2}{\pgfmathresult}%
		\pgfplots@streamerrorbarcoords{\pgfplots@errorbars@src}{\pgfplots@errorbars@trg}%
	\fi
}%

\def\pgfplots@errorbars@plot@handler@point@dir#1{%
	\ifcase\csname pgfplots@errorbars@#1direction\endcsname
		% none
	\or
		% plus
		\expandafter\pgfplots@errorbars@plot@handler@point@dir@@\csname pgfplots@current@point@error@#1@plus\endcsname#1%
	\or
		% minus
		\expandafter\pgfplots@errorbars@plot@handler@point@dir@@\csname pgfplots@current@point@error@#1@minus\endcsname#1%
	\or
		% both
		\expandafter\pgfplots@errorbars@plot@handler@point@dir@@\csname pgfplots@current@point@error@#1@plus\endcsname#1%
		\expandafter\pgfplots@errorbars@plot@handler@point@dir@@\csname pgfplots@current@point@error@#1@minus\endcsname#1%
	\fi
}%

\def\pgfplots@streamerrorbarstart{%
}%
\def\pgfplots@streamerrorbarend{%
}%
\def\pgfplots@streamerrorbarcoords#1#2{%
}%

\def\pgfplots@streamerrorbar@directdraw{%
	\def\pgfplots@streamerrorbarstart{}%
	\def\pgfplots@streamerrorbarend{}%
	\def\pgfplots@streamerrorbarcoords##1##2{%
		\pgfplots@errorbar@draw{##1}{##2}%
	}%
}
	
% This thing here shall draw all error bar commands listed in '#2'.
%
% It will be invoked when any plotting commands take effect (that
% means all limits are computed; the axis has been drawn,
% transformations are set up...)
\def\pgfplots@errorbars@finishwithstyleoptions[#1]#2{%
	\scope[/pgfplots/.cd,#1,/pgfplots/every error bar]% it uses the /pgfplots/.unknown handler
	#2%
	\endscope
}

\def\pgfplots@errorbar@draw#1#2{%
	\begingroup
	\pgfplots@restorepgfpoint
	\pgfkeysvalueof{/pgfplots/error bars/draw error bar/.@cmd}{#1}{#2}\pgfeov%
	\endgroup
}%

\def\pgfplotsaxis@visphase@name@errorbars{errorbars}

\expandafter\def\csname pgfplots@visphase@\pgfplotsaxis@visphase@name@errorbars\endcsname{%
	\pgfplots@errorbars@finishwithstyleoptions[]{%
		\let\tikz@plot@handler=\pgfplots@errorbars@plot@handler
		\expandafter\pgfplots@coord@stream@finalize@storedcoords@START\pgfplots@stored@current@data\pgfplots@EOI
	}%
}%

\endinput