summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/makeplot/makeplot.dtx
blob: c7b4874172d44d3a689ba32448f043b78141a43f (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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
% \iffalse (meta-comment)
%
% Doc-Source file to use with LaTeX2e
%
% Copyright 2005-2009 by Jose-Emilio Vila-Forcen (jemilio@gmail.com)
%                   
% All rights reserved.
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 of this license
% or (at your option) any later version. The latest version of the
% license is in
%
%     http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
% The Current Maintainer of this work is Tobias Oetiker (oetiker@ee.ethz.ch).
%
% I N S T A L L A T I O N
%
% makeplot.sty:
% run: latex makeplot.ins
%
% makeplot.dvi and pdf:
% run: latex makeplot.dtx
%      makeindex -s gind.ist -o makeplot.ind makeplot.idx
%			 makeindex -s gglo.ist -o makeplot.gls makeplot.glo
%      latex makeplot.dtx 
%      pdflatex makeplot.dtx

%<*driver>
\documentclass{ltxdoc}
\usepackage{makeplot}   % to get file info
\EnableCrossrefs
%\DisableCrossrefs     % say \DisableCrossrefs if index is ready
\CodelineIndex
\RecordChanges         % gather update information
%\OnlyDescription      % comment out for implementation details
%\OldMakeindex         % use if your MakeIndex is pre-v2.9
%\setlength\hfuzz{15pt} % dont make so many
%\hbadness=7000         % over and under full box warnings
\begin{document}
  \DocInput{makeplot.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{1234}
%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%
% \DoNotIndex{\@ifnextchar,\@legend}
% \DoNotIndex{\@legendA,\@legendB,\@legendC,\@legendD,\@legendE,\@legendF,\@legendG,%
%     \@legendAf,\@legendBf,\@legendCf,\@legendDf,\@legendEf,\@legendFf,\@legendGf}
% \DoNotIndex{\@legendDL,\@legendDR,\@legendUL,\@legendUR,\@legendXY,\@legendf,\@legendText}
% \DoNotIndex{\@makeplot,\@plotFile,\@plotFileA,\@plotFileB,\@plotFileC,\@plotFileD,%
%     \@plotFileE,\@plotFileF,\@plotFileG,\@whiteBG}
% \DoNotIndex{\begin,\CurrentOption,\data,\dataplot,\def,\define@choicekey, \define@key,\dif,\factorX,\factorXmakeplot,\factorY,\factorYmakeplot, \drawmargins,\drawmarginsmakeplot,\ff,\fi,\fillcolorWhiteBG, \fillstyleWhiteBG,\footnotesize,\FPadd,\FPdiv,\FPmul,\heightPlotFactor, \heightPlotFactormakeplot,\highY,\hspace,\ifMP@color,\ifMP@drawmargins, \ifnum,\l,\leftX,\linecolorWhiteBG,\linestyleWhiteBG,\linewidthWhiteBG, \llegendXY,\lowY,\makeatletter,\makeatother,\makebox,\MP@colorfalse, \MP@colortrue,\MP@drawmarginsfalse,\MP@drawmarginstrue,\n,\NeedsTeXFormat, \newcommand,\newenvironment,\newif\normalsize,\nr,\nrr,\orgX,\orgXmakeplot, \orgY,\orgYmakeplot,\posx,\posy,\ProvidesPackage,\psframe,\pshlabel, \psline,\psset,\pst@addfams,\psvlabel,\readdata,\relax,\RequirePackage, \rightX,\rotateleft,\rput,\s,\sep,\sepTx,\sepTxlegendXY,\sepY,\sepYleendXY, \sepYy,\slegendXY,\tickHerex,\tickHerey,\ticky,\tickymakeplot,\typeout, \unitX,\unitY,\val,\vall,\var,\w,widthPlot,\widthPlotmakeplot,\ww,\www, \x,\xa,\xaa,\xaaa,\xaDL,\xaDR,\xamakeplot,\xaOrigin,\xaXY,\xb,\xbb,\xc, \xDiff,\xinc,\xmid,\xp,\xUL,\xUR,\xx,\xz,\xzDL,\xzDR,\xzmakeplot,\xzz, \y,\ya,\yaa,\yaaa,\yaDL,\yaDR,\yamakeplot,\yaOrigin,\yDiff,\yinc,\ymid, \yUL,\yUR,\yz,\yzDL,\yzDR,\yzmakeplot,\yzXY,\factorBOUNDARYx, \factorBOUNDARYxmakeplot,\factorBOUNDARYy,\factorBOUNDARYymakeplot, \framearcWhiteBG,\newif,\gridDx,\gridDxmakeplot,\gridDy,\gridDymakeplot, \widthPlot,\sepYlegendXY,\sepTy,\ProcessOptions,\definecolor}
%
% \changes{v1.0.7}{2009/08/26}{minor bugs corrected thanks to Herbert Voss}
% \changes{v1.0.6}{2008/01/18}{minor bugs corrected due to other packages updates and improved slightly documentation}
% \changes{v1.0.5}{2005/12/20}{added option big}
% \changes{v1.0.4}{2005/11/23}{corrected small problem that made labels appear twice in the 'ticky' part}
% \changes{v1.0.3}{2005/10/24}{added optional parameters to readdata, changed fileplot to listplot command (allows more options from pstricks-add) and corrected a bug related to the option tickyplot}
% \changes{v1.0.2}{2005/10/04}{rounded some calculated parameters to avoid overflow (tickherex and tickherey)}
% \changes{v1.0.1}{2005/09/24}{data1.mat and data2.mat files are now generated automatically, thanks to Dan}
% \changes{v1.0}{2005/09/22}{Initial version by Jose-Emilio Vila-Forcen}
%
%
%
%
% \GetFileInfo{makeplot.sty}
%
% \title{A plot package for \LaTeXe\thanks{^^A
%        This file has version number \fileversion,
%        last revised \filedate.}}
% \author{Jose-Emilio Vila-Forcen \\ \texttt{jemilio@gmail.com}}
% \date{\filedate}
% \maketitle
%
% \PrintChanges
%
% \section{Introduction}
%
% The functions described in the present document have been created 
% to help in the drawing of plots from Matlab to \LaTeX. The overall
% objective is to create a easy and fast framework to create plots with
% the same style, proper fonts, and just enough parameters.
%
% \section{Known problems}
% \begin{itemize}
%  \item Sometimes a combination of numbers in the dimensions of the plot might cause an error in latex. That is because the combination of numbers has caused some kind of overflow. The source of the problem might be in the makeplot package or in the pstricks family (supposed to be solved in v2.64 of pstricks-add). Send an email to the package author with all the data and hopefully you will receive an answer with an update of the package: the workaround solution is to use a different number, a close one to the original numbe might work.
%
% \end{itemize}
%
%
% \section{Description}
% The package Startplot is composed of several functions. Due to the 
% author's limited knowledge of \TeX, it is done following \LaTeX\ macros 
% and the robustness of the package is not fully demonstrated.
%
% All positions, total size of the figure and so on are calcul%ated 
% automatically using package FP.
%
%
% \subsection{Definition of an especific style}
% Some functions are provided to change the style of the plots:
% \DescribeMacro{\MPbg}
%  Execute |\MPbg| it in order to use black lines with different styles already predefined.
%  It is by default
%
% \DescribeMacro{\MPcolor}
%  Execute |\MPcolor| it in order to use solid color lines already predefined.
%  It can be selected using the |color| package option or executing the command.
%
% \DescribeMacro{colorLine[ABCDEFG]}
%  If you want to change the colors of the lines, you may change one by one redefining the colors.
%  For example:
%  \begin{quote}
%       |\definecolor{colorLineA}{rgb}{1,1,1}|
%  \end{quote}
%
% \DescribeMacro{\styleofLine[ABCDEFG]}
% It is possible to modify the seven predefined styles one by one: simply recreate a new definition
% for the desired one(s).
%
% \DescribeMacro{Font commands}
% The commands |\fontaxeX|, |\fontaxeY|, |\fonttitleX|, |\fonttitleY| and |\fontlegend| contains
% the definitions of the fonts used in different parts of the legend: axes, labels (or titles) and legend.
% You may change them as, for example:
%  \begin{quote}
%       |\def\fontaxeY{\small}|
%  \end{quote}
%
% \DescribeMacro{\defaultOptionsMakeplot}
% The |\defaultOptionsMakeplot| command is executed at the beginning of the definition of the plot.
% redefine it to your desired code if you need to execute something more for each picture.
%
%
%\subsection{Create the plot}
% The plot is composed of several orders consecutive. Besides the order 
% described here, a lot of them exist in the file which obtain the same 
% result, but using more input parameters. The ones that I describe here 
% are enough for the most of the cases.
%
% \DescribeEnv{makeplot}
% The |makeplot| environment is the starting point to create the plot. The 
% command line is as follows:
%  \begin{quote}
%        |\begin{makeplot}|\oarg{keys}\marg{label in Y}\marg{label in X}
%        .....
%        |\end{makeplot}|
%   \end{quote}
% The optional arguments are the keys from PsTricks, including the ones for |\psaxes| function. Also,
% some new keys are added:
%\begin{description}
%	\item[Dx] Distance between labels in X
%	\item[Dy] Distance between labels in Y
%	\item[width] Width of the plot in mm
%	\item[heightFactor] Factor of height length respect to the width
%	\item[startX] Minimum value in the axis X
%	\item[startY] Minimum value in the axis Y
%	\item[endX] Maximum value in the axis X
%	\item[endY] Maximum value in the axis Y
%	\item[factorBoundaryX] Separation to the border
%	\item[factorBoundaryY] Separation to the border
%	\item[captionX] Separation to the caption in X, over 100
%	\item[captionY] Separation to the caption in Y, over 100
%	\item[changeEndXpos] If it is needed to change the end of the axis X, because of external legend (yes or no)
%	\item[changeEndXsize] How many mm more than the estandard
%	\item[tickyplot] Special ticks (all, x, y, none)
%	\item[drawmargins] Draw margins in this figure (there exist an option in the package to do it globally)
% \item[orgX and orgY] Not working properly, intended to change the origin of the graphic
%\end{description}
% For example, a typical configuration for semilog case it is to use the options:
%\begin{quote}
%     ylogBase=10, logLines=y, subticks=10, xsubticks=1
%\end{quote}
% and LogLines can take the values x, y or all.
%
% \DescribeMacro{\makeplot}
% The |\makeplot| macro works as the environment, but once the plot is finished it is needed to write |\end{pspicture}|
%
% \subsection{Plotting the data from files}
%
% \DescribeMacro{\plotFile}
% The |\plotFile|\oarg{keys}\marg{file} macro takes the data from a file and plot it using the existing
% properties for lines in PsTricks taking into account the optional keys given to the command.
%
% \DescribeMacro{\plotFile[ABCDEFG]}
% These macros have the same configuration as |\plotFile|, but each one uses the line style predefined. It accept the optinal arguments plotNoMax and PlotNo to say how many different plots are in the file and which one is intented to be plot, and nStep, xStart, xEnd, yStart and yEnd in order to select which values of the file should be plot.
%
% \subsection{The legend}
% The |makeplot| package can do very nice legends and without effort. There exists the next keys to control the apearance of the legend:
%\begin{description}
%	\item[fillcolorWhiteBG] Select the color name for the background of the legend
% \item[fillstyleWhiteBG] Select the fillstyle for the background of the legend
% \item[framearcWhiteBG] dimension of the arc of the legend box
% \item[linewidthWhiteBG] linewidth of the legend box
% \item[linestyleWhiteBG] linestyle of the legend box
% \item[linecolorWhiteBG] color of the line of the legend box
%\end{description}
% and
%\begin{description}
%	\item[legendSep] Separation between legends in vertical
% \item[lineLength] Length of the line in the legend area
% \item[lineTextSep] Separation between the line and the text
% \item[borderlineSep] Separation from the border of the box to the line
%\end{description}
%
% The main commands are as follows:
%
%
% \DescribeMacro{\legendXY}
% The |\legendXY| macro usage is as follows:
% \begin{quote}
%    |\legendXY|\oarg{keys}\parg{coordinate X,coordinateY}\marg{number of lines to be in the legend}%
%         \marg{width in mm}
% \end{quote}
%
% \DescribeMacro{\legend[DL,DR,UL,UR]}
% These macros avoid the needed to specify a coordinate and draw the legend in the 
% position down-left, down-right, up-left or up-right of the plot. Therefore, the syntax is:
% \begin{quote}
%    |\legendDL|\oarg{keys}\marg{number of lines to be in the legend}%
%         \marg{width in mm}
% \end{quote}
%
% There exist some different ways to write the legends into the box. The easiest one is to use the
% next commands:
%
% \DescribeMacro{\legend[ABCDEFG]f}
% These macros write the legends into the box in the order of the tex source. Each one has a different
% line style as it was for the plot. The syntax is:
% \begin{quote}
%    |\legendCf|\oarg{keys}\marg{text}%
% \end{quote}
% where the keys might modify the line style.
%
%
% \DescribeMacro{\legendText}
% The |\legendText| macro includes some text in the legend without a line: 
% \begin{quote}
%    |\legendText|\oarg{keys}\marg{text}%
% \end{quote}
% where the keys are not used, but kept in the definition of the macro for paralelism.
%
% \section{Record proper Matlab data}
% \index{Matlab}
% Matlab is one of the most famous data processing software in the 
% research community. Because of its simplicity, the generation of the 
% needed files can be done easily after their generation.
%
% Each plot should be saved in a separate file in ASCII format. Thus, 
%follow the next process for each one of the lines to plot:
% \begin{enumerate}
%	\item Create a matrix Nx2, where N denotes the dimensionality of the 
%    data. Put in the first column the data of the X-axis, and in the  
%    second one the values in the Y-axis corresponding to the previous X 
%    one, let's call this matrix \emph{values};
% \item Save \emph{values} in a file as follows: \verb+ save file.mat values -ascii+.
% \end{enumerate}
%
%\paragraph{Remarks}
%\begin{itemize}
%  \item Editing in a text editor should be possible, and numbers should be visible in ASCII format;
%	\item The data should be real;
%  \item It is possible to comment values in the file with \verb+%+;
%  \item It is possible to modify manually the values in the file.
%\end{itemize}
%
%
%
% \section{Create EPS files}
% \index{EPS}
% It is possible to create EPS files and use them directly in latex. The %
% benefits are faster compilation and it is always good to have them in%
% separate files, for example for distribution.
%
% In order to create EPS files, follow the procedure:
% \begin{enumerate}
% \item Install perl from www.perl.com; \index{perl}
% \item Copy bbox.exe from ps2eps.zip file to \verb+c:\texmf\miktex\bin+. \index{ps2eps}%
%    ps2eps.zip can be found at \\ { \verb+www.telematik.informatik.uni-karlsruhe.de/~bless/ps2eps.html+};
% \item \verb+SET PATHEXT=.pl;%PATHEXT%+ or use the start, settings, control panel,%
%    system, advanced tab, environment variables and edit the PATHEXT entry accordingly;
% \item Rename ps2eps to ps2eps.pl and copy it to \verb+c:\texmf\miktex\bin+.
% \end{enumerate}
%
% Now, we create a batch file to help in the compilation of each time:%
%   Create a bat file something like: \verb+makefigure.bat+, \index{makefigure.bat} save it%
%   in \verb+c:\texmf\miktex\bin+. It should contain the following lines:
% \begin{verbatim}
% echo off
% del figures/%1.eps
% latex %1eps.tex
% dvips -t a4 -P pdf %1eps.dvi
% ps2eps.pl %1eps.ps %1eps.eps
% del %1eps.ps 
% del %1eps.eps
% mkdir figures
% rename %1eps.eps.eps %1.eps
% move %1.eps figures
% \end{verbatim}
% It is possible to change the contain above for different file names.%
%   In my case, I am creating files are follows:
%
% \begin{verbatim}
% \input{headers.tex}
% \begin{document}
% \pagestyle{empty}
% \input{fig1.tex}
% \end{document}
% \end{verbatim}
% with the name \verb+NAMEeps.tex+ where \verb+NAME+ can be changed%
%  to the desired name. The file \verb+headers.tex+ contains all%
%  the headers of my report and therefore all proper fonts and so on%
%  will be used in this file and in the general one.
%
% To create this file, it is possible to make another batch file called \verb+fileForEPS.bat+ such that:
%
% \begin{verbatim}
% echo off
% echo \input{headers.tex} \begin{document} \emph{(continue in the same line)}
%      \pagestyle{empty} \input{%1.tex} \end{document} > %1eps.tex
% \end{verbatim}
%
% Execute \verb+makefigure NAME+ in the proper directory, and the EPS picture file%
%  will be created in the directory \verb+figures/+. If you need to create the%
%  additional tex file, execute \verb+fileForEPS NAME+ and it will be done.
%
%
% The procedure described above allows to use the following code in the main file:
% \begin{verbatim}
% \begin{figure}
% \centering
% %\input{fig.tex}
% \includegraphics{figure/fig.eps}
% \caption{Caption of the figure}
% \label{fig:fig}
% \end{figure}
% \end{verbatim}
%where the commented line will describe which file is used: it is possible%
% to choose between the tex file or (once picture is fixed and in order to%
% improve speed) the eps one.
%
% 
% \clearpage
% \section{An example file}
%    \begin{macrocode}
%<*mptest>
\documentclass[]{article}
\usepackage[color]{makeplot}
\begin{document}
\begin{figure}
\centering

\begin{makeplot}[startX=-10, endX=5, startY=-1, endY=0, Dx = 5,%
   width=40, heightFactor=1, %
   ylogBase=10, logLines=y, subticks=10, xsubticks=1]%
   {$P_e$}{WNR, [dB]}
\plotFileA{data1.mat}
\plotFileB{data2.mat}
\legendDL{24.5}{2}
\legendAf{UDQ-QIM}
\legendBf{UQ-QIM}
\end{makeplot}

\caption{Performance analysis result.}
\label{fig:results}
\end{figure}

\end{document}
%</mptest>
%    \end{macrocode}
% \subsection{Data files:}
% \paragraph{data1.mat}
%    \begin{macrocode}
%<*data1>
 -1.0000000e+001 -3.1186120e-001
 -9.5000000e+000 -3.1382220e-001
 -9.0000000e+000 -3.1610308e-001
 -8.5000000e+000 -3.1874224e-001
 -8.0000000e+000 -3.2177814e-001
 -7.5000000e+000 -3.2524775e-001
 -7.0000000e+000 -3.2918480e-001
 -6.5000000e+000 -3.3361772e-001
 -6.0000000e+000 -3.3856759e-001
 -5.5000000e+000 -3.4404614e-001
 -5.0000000e+000 -3.5005399e-001
 -4.5000000e+000 -3.5657933e-001
 -4.0000000e+000 -3.6359717e-001
 -3.5000000e+000 -3.7106902e-001
 -3.0000000e+000 -3.7894319e-001
 -2.5000000e+000 -3.8715537e-001
 -2.0000000e+000 -3.9562939e-001
 -1.5000000e+000 -4.0427825e-001
 -1.0000000e+000 -4.1300527e-001
 -5.0000000e-001 -4.2170561e-001
  0.0000000e+000 -4.3026847e-001
  5.0000000e-001 -4.5284882e-001
  1.0000000e+000 -4.8524584e-001
  1.5000000e+000 -5.2154969e-001
  2.0000000e+000 -5.6193985e-001
  2.5000000e+000 -6.0664420e-001
  3.0000000e+000 -6.5595407e-001
  3.5000000e+000 -7.1023618e-001
  4.0000000e+000 -7.6994081e-001
  4.5000000e+000 -8.3560655e-001
  5.0000000e+000 -9.0786295e-001
%</data1>
%    \end{macrocode}
% \paragraph{data2.mat}
%    \begin{macrocode}
%<*data2>
 -1.0000000e+001 -3.0170171e-001
 -9.5000000e+000 -3.0182275e-001
 -9.0000000e+000 -3.0197731e-001
 -8.5000000e+000 -3.0217679e-001
 -8.0000000e+000 -3.0243768e-001
 -7.5000000e+000 -3.0278484e-001
 -7.0000000e+000 -3.0325664e-001
 -6.5000000e+000 -3.0391260e-001
 -6.0000000e+000 -3.0484295e-001
 -5.5000000e+000 -3.0617875e-001
 -5.0000000e+000 -3.0809964e-001
 -4.5000000e+000 -3.1083660e-001
 -4.0000000e+000 -3.1466753e-001
 -3.5000000e+000 -3.1990577e-001
 -3.0000000e+000 -3.2688343e-001
 -2.5000000e+000 -3.3593295e-001
 -2.0000000e+000 -3.4737023e-001
 -1.5000000e+000 -3.6148225e-001
 -1.0000000e+000 -3.7852034e-001
 -5.0000000e-001 -3.9869936e-001
  0.0000000e+000 -4.2220206e-001
  5.0000000e-001 -4.4918738e-001
  1.0000000e+000 -4.7980138e-001
  1.5000000e+000 -5.1418989e-001
  2.0000000e+000 -5.5251165e-001
  2.5000000e+000 -5.9495142e-001
  3.0000000e+000 -6.4173231e-001
  3.5000000e+000 -6.9312654e-001
  4.0000000e+000 -7.4946429e-001
  4.5000000e+000 -8.1114012e-001
  5.0000000e+000 -8.7861718e-001
%</data2>
%    \end{macrocode}
%
% \StopEventually{}
% \clearpage
%
% \section{The implementation}
%    \begin{macrocode}
%<*makeplot>
%    \end{macrocode}
%
%
%    \subsection{Headers}
%
%    First we test that we got the right format and name the package, and load external packages.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}%
\ProvidesPackage{makeplot}[2009/08/26 %
                           v1.0.7 %
                           Plots utility from Jose-Emilio Vila-Forcen]%
\RequirePackage[nomessages]{fp}%
\RequirePackage{pst-plot}%
\RequirePackage{pstricks-add}%
\RequirePackage{xkeyval}%
%    \end{macrocode}
%
%    \begin{macro}{color}
%    The option |color| leads to a redefinition of the line styles
% of the plot and uses colors with solid lines. Otherwise, black lines
% with different line styles are used
%    \begin{macrocode}
\newif\ifMP@color%
\MP@colorfalse%
\DeclareOption{color}{%
  \MP@colortrue%
  \typeout{ ------}%
  \typeout{ ------   makePlot package working in color}%
  \typeout{ ------}}%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{drawmargins}
% The option | drawmargins | draw the margins of the figues. This option
% is useful in order to check if something is going out of the margins,
% since there is not internal checking for that.
%    \begin{macrocode}
\newif\ifMP@drawmargins%
\MP@drawmarginsfalse%
\DeclareOption{drawmargins}{%
  \MP@drawmarginstrue%
  \typeout{ ------}%
  \typeout{ ------   makePlot package drawing the margins}%
  \typeout{ ------}}%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{big}
% The option | big | put the lines of the plot larger
%    \begin{macrocode}
\newif\ifMP@big%
\MP@bigfalse%
\DeclareOption{big}{%
	\MP@bigtrue
  \typeout{ ------}%
  \typeout{ ------   makePlot package in big size}%
  \typeout{ ------}}%
%    \end{macrocode}
%    \end{macro}
%
% If an unknown option is used, a warning will be displayed.
%    \begin{macrocode}
\DeclareOption*{%
  \PackageWarning{startPlot}{%
    Unknown option '\CurrentOption'}}%
%    \end{macrocode}
%
%    Now we process the options.
%    \begin{macrocode}
\ProcessOptions\relax%
%    \end{macrocode}
%
% \subsection{Commands to fix the style}
%
%    \begin{macro}{\MPbg}
% Command to use the styles of the lines in black and white, by default:
%    \begin{macrocode}
\newcommand{\MPbg}{%
 \def\styleoflineA{%
 		\psset{linestyle=solid, dash=1pt 0pt 0pt 0pt, dotsep=0pt,%
 		   linecolor=black}}%
 \def\styleoflineB{%
 		\psset{linestyle=dashed, dash=5pt 5pt 0pt 0pt, dotsep=0pt,%
 		   linecolor=black}}%
 \def\styleoflineC{%
 		\psset{linestyle=dotted, dash=3pt 2pt 0pt 0pt, dotsep=1pt,%
 		   linecolor=black}}%
 \def\styleoflineD{%
 		\psset{linestyle=dashed, dash=4pt 1.5pt 1pt 1.5pt, dotsep=3pt,%
 		   linecolor=black}}%
 \def\styleoflineE{%
 		\psset{linestyle=dotted, dash=1pt 4pt 0pt 0pt, dotsep=3pt,%
 		   linecolor=black}}%
 \def\styleoflineF{%
 		\psset{linestyle=dashed, dash=6pt 1.5pt 3pt 1.5pt, dotsep=3pt,%
 		   linecolor=black}}%
 \def\styleoflineG{%
 		\psset{linestyle=dashed, dash=2pt 6pt 0pt 0pt, dotsep=0pt,%
 		   linecolor=black}}}%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{MPcolor}
% Definition of the standard colors for the lines, using the
% color option of the package. They might be changed by the user:
%    \begin{macrocode}
\definecolor{colorLineA}{rgb}{0,0,1}%
\definecolor{colorLineB}{rgb}{1,0,0}%
\definecolor{colorLineC}{rgb}{0,1,0}%
\definecolor{colorLineD}{rgb}{0,1,1}%
\definecolor{colorLineE}{rgb}{1,0,1}%
\definecolor{colorLineF}{rgb}{1,1,0}%
\definecolor{colorLineG}{rgb}{0.5,0.5,0.5}%
%    \end{macrocode}
%
% Command to set the styles of the lines using colors:
%    \begin{macrocode}
\newcommand{\MPcolor}{%
 \def\styleoflineA{\psset{linestyle=solid, linecolor=colorLineA}}%
 \def\styleoflineB{\psset{linestyle=solid, linecolor=colorLineB}}%
 \def\styleoflineC{\psset{linestyle=solid, linecolor=colorLineC}}%
 \def\styleoflineD{\psset{linestyle=solid, linecolor=colorLineD}}%
 \def\styleoflineE{\psset{linestyle=solid, linecolor=colorLineE}}%
 \def\styleoflineF{\psset{linestyle=solid, linecolor=colorLineF}}%
 \def\styleoflineG{\psset{linestyle=solid, linecolor=colorLineG}}}%
%    \end{macrocode}
%    \end{macro}
%
% According to the package option, one of the styles will be loaded:
%    \begin{macrocode}
\ifMP@color%
 \MPcolor%
\else%
 \MPbg%
\fi%
%    \end{macrocode}
%
%    \begin{macrocode}
\makeatletter%
%    \end{macrocode}
%
%    \begin{macro}{Font sizes}
% Definition of the standard font sizes in the plot. It is possible to redefine them.
%    \begin{macrocode}
\def\fontaxeY{\normalsize}%
\def\fontaxeX{\normalsize}%
\def\fonttitleY{\normalsize}%
\def\fonttitleX{\normalsize}%
\def\fontlegend{\footnotesize}%
%    \end{macrocode}
%    \end{macro}
%
% \subsection{Main macros: makeplot}
% Options for the command |makeplot| and the addition of the family of keys. 
%
%    \begin{macrocode}
\define@key[psset]{makeplot}{Dx}[1]%
   {\def\gridDxmakeplot{#1}}%
\define@key[psset]{makeplot}{Dy}[1]%
   {\def\gridDymakeplot{#1}}%
\define@key[psset]{makeplot}{width}[50]%
   {\def\widthPlotmakeplot{#1}}%
\define@key[psset]{makeplot}{heightFactor}[1]%
   {\def\heightPlotFactormakeplot{#1}}%
\define@key[psset]{makeplot}{startX}[0]%
   {\def\xamakeplot{#1}}%
\define@key[psset]{makeplot}{startY}[0]%
   {\def\yamakeplot{#1}}%
\define@key[psset]{makeplot}{endX}[1]%
   {\def\xzmakeplot{#1}}%
\define@key[psset]{makeplot}{endY}[1]%
   {\FPmul\yzmakeplot{#1}{1.0001}}%
\define@key[psset]{makeplot}{factorBoundaryX}%
   {\FPdiv\factorBOUNDARYxmakeplot{#1}{1.5}}%
\define@key[psset]{makeplot}{factorBoundaryY}%
   {\FPdiv\factorBOUNDARYymakeplot{#1}{1.5}}% 
\define@key[psset]{makeplot}{captionY}%
   {\FPdiv\factorXmakeplot{#1}{8}}% 
\define@key[psset]{makeplot}{captionX}%
   {\FPdiv\factorYmakeplot{#1}{11}}%
\define@choicekey[psset]{makeplot}{changeEndXpos}[\var\nr]{no,yes}%
   {\def\endXamakeplot{\nr}}% 
\define@key[psset]{makeplot}{changeEndXsize}%
   {\def\endXbmakeplot{#1}}% 
\define@choicekey[psset]{makeplot}{tickyplot}[\val\nr]{all,x,y,none}%
   {\def\tickymakeplot{\nr}} % 
\define@choicekey[psset]{makeplot}{drawmargins}[\vall\nrr]{yes,no}%
   {\def\drawmarginsmakeplot{\nrr}} % 
\define@key[psset]{makeplot}{orgX}%
   {\def\orgXmakeplot{#1}} % 
\define@key[psset]{makeplot}{orgY}%
   {\def\orgYmakeplot{#1}} % 
\pst@addfams{makeplot}%
%    \end{macrocode}
%
% Default values for the above parameters
%    \begin{macrocode}
\psset{Dx=1, Dy=1, 
	width=50, heightFactor=1, startX=0, endX=1, startY=0, endY=1,
	showorigin=true, axesstyle=frame, ticks=all, labels=all,
	factorBoundaryX=1, factorBoundaryY=1, captionY=100, captionX=100,
	xsubticks=0, subticksize=1, subtickcolor=black}%
\ifMP@big%
 \psset{tickwidth=0.5pt, subtickwidth=0.5pt, linewidth=1pt}%
\else%
 \psset{tickwidth=0.2pt, subtickwidth=0.2pt, linewidth=0.5pt}%
\fi%
\psset{tickyplot=all}%
\psset{changeEndXsize=0, changeEndXpos=no}%
\ifMP@drawmargins%
 \psset{drawmargins=yes}%
\else%
 \psset{drawmargins=no}%
\fi%
\psset{orgX=314, orgY=314}%
%    \end{macrocode}
%
% \begin{environment}{makeplot}
% The |makeplot| environemnt perfoms most of the tasks needed for the plot. The
% axes are drawn, the legends and everything related with the background of the plot
% besides the legend, that will arrive later.
%    \begin{macrocode}
\newenvironment{makeplot}[3][]%
  {\makeplot[#1]{#2}{#3}}%
  {\end{pspicture}}%
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\defaultOptionsMakeplot}
% Default values, it is possible to change this command as desired
% to include some source to be executed in each |makeplot| command
% or enviroment call
%    \begin{macrocode}
	\def\defaultOptionsMakeplot{}%
%    \end{macrocode}
% \end{macro}
%	
% \begin{macro}{\makeplot}
% This is the most important macro, it can be used instead of the 
% makeplot enviroment just adding |\end{pspicture}| at the end of the
% plot.
%    \begin{macrocode}
\def\makeplot{\@ifnextchar[\@makeplot{\@makeplot[]}}%
\def\@makeplot[#1]#2#3{%
  % Use the default options command and process
  % the options of the command line
  \defaultOptionsMakeplot%
  \psset{#1}%
  % Calculate the dimensions of the plot
  \def\gridDx{\gridDxmakeplot}%
  \def\gridDy{\gridDymakeplot}%
  \def\widthPlot{\widthPlotmakeplot}%
  \def\heightPlotFactor{\heightPlotFactormakeplot}%
  \def\xa{\xamakeplot}%
  \def\ya{\yamakeplot}%
  \def\xz{\xzmakeplot}%
  \def\yz{\yzmakeplot}%
  \def\factorBOUNDARYx{\factorBOUNDARYxmakeplot}%
  \def\factorBOUNDARYy{\factorBOUNDARYymakeplot}%
  \def\factorX{\factorXmakeplot}%
  \def\factorY{\factorYmakeplot}%
  \def\endXa{\endXamakeplot}%
  \def\endXb{\endXbmakeplot}%
  \def\ticky{\tickymakeplot}%
  \def\drawmargins{\drawmarginsmakeplot}%
  \def\orgX{\orgXmakeplot}%
  \def\orgY{\orgYmakeplot}%
  %
  % Use the fonts established
  \def\pshlabel{\fontaxeX}%
  \def\psvlabel{\fontaxeY}%
  \def\pshlabel{\fontaxeX}%
  \def\psvlabel{\fontaxeY}%
  %	
  % Calculate the proper units for the plot
  \FPadd\xDiff\xz{-\xa}%
  \FPdiv\unitX\widthPlot\xDiff%
  \FPadd\yDiff\yz{-\ya}%
  \FPmul\ff\widthPlot\heightPlotFactor%
  \FPdiv\unitY\ff\yDiff%
  \psset{xunit=\unitX mm,yunit=\unitY mm}%
  %
  \FPadd\yinc\yz{-\ya}%
  \FPdiv\ymid\yinc{2}%
  \FPadd\ymid\ymid\ya%
  \FPadd\xinc\xz{-\xa}%
  \FPdiv\xmid\xinc{2}%
  \FPadd\xmid\xmid\xa%
  \FPadd\xzz\xz{0}%
  %
  % Related to the position of the legends
  \FPdiv\factorX\factorX\unitX%
  \FPadd\xaa\xa{-\factorX}%
  \FPdiv\factorY\factorY\unitY%
  \FPadd\yaa\ya{-\factorY}%
  %
  % Related to the size of the plot
  \FPdiv\factorBOUNDARYx\factorBOUNDARYx\unitX%
  \FPadd\xaaa\xaa{-\factorBOUNDARYx}%
  \FPdiv\factorBOUNDARYy\factorBOUNDARYy\unitY%
  \FPadd\yaaa\yaa{-\factorBOUNDARYy}%
  %
  % Change of the size of the plot
  % if it is asked in the options,
  % like putting the legend at the right
  \ifnum \endXb>0
    \FPdiv\w{\endXb}\unitX%
    \ifnum \endXa=0
      \def\endXa{\xz}%
    \fi%
    \FPadd\ww{\endXa}{-\xz}%
    \def\sep{0.5}%
    \FPdiv\www\sep\unitX%
    \FPadd\xzz\xz\w%
    \FPadd\xzz\xzz\ww%
    \FPadd\xzz\xzz\www	%
  \fi%
  %
  % Starting the pspicture environment
  \begin{pspicture}(\xaaa,\yaaa)(\xzz,\yz)%
  %
  % Draw a box with the margins if requested
  \ifnum \drawmargins=0
    \psframe(\xaaa,\yaaa)(\xzz,\yz)%
  \fi%
  %
  \FPadd\tickHerex{\yz}{-\ya}%
  \FPmul\tickHerex\tickHerex\unitY%
  \FPadd\tickHerey{\xz}{-\xa}%
  \FPmul\tickHerey\tickHerey\unitX%
  %
  % To change the origin of the plot
  % not working yet
  \def\xaOrigin{\xa}%
  \def\yaOrigin{\ya}%
  \ifnum \orgX=314
  \else%
    \def\xaOrigin{\orgX}%
  \fi%
  \ifnum \orgY=314
  \else%
    \def\yaOrigin{\orgY}%
  \fi	%
  %
  % Put the ticks as given in the options
  \ifnum \ticky=0
    \psaxes[Ox=\xa,Oy=\ya,Dx=\gridDx,Dy=\gridDy, #1,%
        ticksize=-4pt 4pt, subticks=0, subticksize=0,%
        tickwidth=0.5pt, linewidth=0pt,%
        axesstyle=axes, linecolor=white, #1, ticks=all, labels=none]%
        {-}(\xa,\ya)(\xa,\ya)(\xz,\yz)%
  \fi%
  \ifnum \ticky=1
    \psaxes[Ox=\xa,Oy=\ya,Dx=\gridDx,Dy=\gridDy, #1,%
        ticksize=-4pt 4pt, subticks=0, subticksize=0,%
        tickwidth=0.5pt, linewidth=0pt,%
        axesstyle=axes, linecolor=white, #1, ticks=x, labels=none]%
        {-}(\xa,\ya)(\xa,\ya)(\xz,\yz)%
  \fi%
  \ifnum \ticky=2
    \psaxes[Ox=\xa,Oy=\ya,Dx=\gridDx,Dy=\gridDy, #1,%
        ticksize=-4pt 4pt, subticks=0, subticksize=0,%
        tickwidth=0.5pt, linewidth=0pt,%
        axesstyle=axes, linecolor=white, #1, ticks=y, labels=none]%
        {-}(\xa,\ya)(\xa,\ya)(\xz,\yz)%
  \fi%
  \ifnum \ticky=3
  \fi%
  %	
  % Put the main axes and the grid
  \FPround\tickHerex{\tickHerex}{10}%
  \FPround\tickHerey{\tickHerey}{10}%
  \psaxes[xticksize=0mm \tickHerex mm, yticksize=0mm \tickHerey mm,%
	    Ox=\xa,Oy=\ya,Dx=\gridDx,Dy=\gridDy, #1]%
	    {-}(\xaOrigin,\yaOrigin)(\xa,\ya)(\xz,\yz)%
	\def\MP@xa{\xaOrigin}%
	\def\MP@ya{\yaOrigin}%
	\def\MP@xz{\xz}%
	\def\MP@yz{\yz}%
  %
  % Write the legend of the plot
  \rput(\xaa,\ymid){\rotateleft{\fonttitleY #2}}%
  \rput(\xmid,\yaa){\fonttitleX #3}%
  \ifMP@big%
   \psset{linewidth=2pt}%
  \else%
   \psset{linewidth=1pt}%
  \fi%
}%
%    \end{macrocode}
% \end{macro}
%
% \subsection{How to plot the data of a file}
% \begin{macro}{\plotFile}
% Function to plot a file with the linestyle given
%    \begin{macrocode}
\def\plotFile{\@ifnextchar[\@plotFile{\@plotFile[]}}%
\def\@plotFile[#1]#2{%
  \readdata[#1]{\data}{#2}\listplot[#1]{\data}}%
%    \end{macrocode}
% \end{macro}
% And now, a specific function for each linestyle predefined:
% \begin{macro}{\plotFileA}
%    \begin{macrocode}
\def\plotFileA{\@ifnextchar[\@plotFileA{\@plotFileA[]}}%
\def\@plotFileA[#1]#2{%
  \styleoflineA%
  \plotFile[#1]{#2}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\plotFileB}
%    \begin{macrocode}
\def\plotFileB{\@ifnextchar[\@plotFileB{\@plotFileB[]}}%
\def\@plotFileB[#1]#2{%
  \styleoflineB%
  \plotFile[#1]{#2}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\plotFileC}
%    \begin{macrocode}
\def\plotFileC{\@ifnextchar[\@plotFileC{\@plotFileC[]}}%
\def\@plotFileC[#1]#2{%
  \styleoflineC%
  \plotFile[#1]{#2}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\plotFileD}
%    \begin{macrocode}
\def\plotFileD{\@ifnextchar[\@plotFileD{\@plotFileD[]}}%
\def\@plotFileD[#1]#2{%
  \styleoflineD%
  \plotFile[#1]{#2}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\plotFileE}
%    \begin{macrocode}
\def\plotFileE{\@ifnextchar[\@plotFileE{\@plotFileE[]}}%
\def\@plotFileE[#1]#2{%
  \styleoflineE%
  \plotFile[#1]{#2}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\plotFileF}
%    \begin{macrocode}
\def\plotFileF{\@ifnextchar[\@plotFileF{\@plotFileF[]}}%
\def\@plotFileF[#1]#2{%
  \styleoflineF%
  \plotFile[#1]{#2}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\plotFileG}
%    \begin{macrocode}
\def\plotFileG{\@ifnextchar[\@plotFileG{\@plotFileG[]}}%
\def\@plotFileG[#1]#2{%
  \styleoflineG%
  \plotFile[#1]{#2}}%
%    \end{macrocode}
% \end{macro}
%
% \subsection{Legends code}
%
% \begin{macro}{\legend}
% Defines the general |\legend| command, the inputs are:
% the optional parameter with PSTricks keys, the position in X,
% the length of the line, the separation between line and text,
% the position in Y and the text of the legend.
%    \begin{macrocode}
\def\legend{\@ifnextchar[\@legend{\@legendf[]}}%
\def\@legend[#1]#2#3#4#5#6{%
  \def\xb{#2}%
  \def\x{#3}%
  \FPdiv\x\x\unitX%
  \FPadd\xbb\xb\x%
  \def\x{#4}%
  \FPdiv\x\x\unitX%
  \FPadd\xc\xbb\x%
  %
  \def\y{#5}%
  \psline[#1]{-}(\xb,\y)(\xbb,\y)%
  \rput(\xc,\y){\makebox[0 cm][l]{{\fontlegend #6}}}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\legend[ABCDEFG]}
% One command for each line style: as the previous command, but
% now using the predefined styles
%    \begin{macrocode}
\def\legendA{\@ifnextchar[\@legendA{\@legendA[]}}%
\def\@legendA[#1]#2#3#4#5{%
  \styleoflineA%
  \legend[#1]{#2}{#3}{#4}{#5}}%
\def\legendB{\@ifnextchar[\@legendB{\@legendB[]}}%
\def\@legendB[#1]#2#3#4#5{%
  \styleoflineB%
  \legend[#1]{#2}{#3}{#4}{#5}}%
\def\legendC{\@ifnextchar[\@legendC{\@legendC[]}}%
\def\@legendC[#1]#2#3#4#5{%
  \styleoflineC%
  \legend[#1]{#2}{#3}{#4}{#5}}%
\def\legendD{\@ifnextchar[\@legendD{\@legendD[]}}%
\def\@legendD[#1]#2#3#4#5{%
  \styleoflineD%
  \legend[#1]{#2}{#3}{#4}{#5}}%
\def\legendE{\@ifnextchar[\@legendE{\@legendE[]}}%
\def\@legendE[#1]#2#3#4#5{%
  \styleoflineE%
  \legend[#1]{#2}{#3}{#4}{#5}}%
\def\legendF{\@ifnextchar[\@legendF{\@legendF[]}}%
\def\@legendF[#1]#2#3#4#5{%
  \styleoflineF%
  \legend[#1]{#2}{#3}{#4}{#5}}%
\def\legendG{\@ifnextchar[\@legendG{\@legendG[]}}%
\def\@legendG[#1]#2#3#4#5{%
  \styleoflineG%
  \legend[#1]{#2}{#3}{#4}{#5}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\legend[ABCDEFG]f}
% An automatic legend mode, where the position is automatically
% calculated for each one in consecutive order
%    \begin{macrocode}
\def\legendAf{\@ifnextchar[\@legendAf{\@legendAf[]}}%
\def\@legendAf[#1]#2{%
  \legendA[#1]{\posx}{\l}{\s}{\posy}{#2}%
  \FPadd\posy\posy{-\dif}}%
\def\legendBf{\@ifnextchar[\@legendBf{\@legendBf[]}}%
\def\@legendBf[#1]#2{%
  \legendB[#1]{\posx}{\l}{\s}{\posy}{#2}%
  \FPadd\posy\posy{-\dif}}%
\def\legendCf{\@ifnextchar[\@legendCf{\@legendCf[]}}%
\def\@legendCf[#1]#2{%
  \legendC[#1]{\posx}{\l}{\s}{\posy}{#2}%
  \FPadd\posy\posy{-\dif}}%
\def\legendDf{\@ifnextchar[\@legendDf{\@legendDf[]}}%
\def\@legendDf[#1]#2{%
  \legendD[#1]{\posx}{\l}{\s}{\posy}{#2}%
  \FPadd\posy\posy{-\dif}}%
\def\legendEf{\@ifnextchar[\@legendEf{\@legendEf[]}}%
\def\@legendEf[#1]#2{%
  \legendE[#1]{\posx}{\l}{\s}{\posy}{#2}%
  \FPadd\posy\posy{-\dif}}%
\def\legendFf{\@ifnextchar[\@legendFf{\@legendFf[]}}%
\def\@legendFf[#1]#2{%
  \legendF[#1]{\posx}{\l}{\s}{\posy}{#2}%
  \FPadd\posy\posy{-\dif}}%
\def\legendGf{\@ifnextchar[\@legendGf{\@legendGf[]}}%
\def\@legendGf[#1]#2{%
  \legendG[#1]{\posx}{\l}{\s}{\posy}{#2}%
  \FPadd\posy\posy{-\dif}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\legendText}
% A legend without a line: to include some text in the legend box
%    \begin{macrocode}
\def\legendText{\@ifnextchar[\@legendText{\@legendText[]}}%
\def\@legendText[#1]#2{%
  \rput(\posx,\posy){%
    \makebox[0 cm][l]{%
    \hspace{-0.1cm}{\footnotesize #2}}}%
  \FPadd\posy\posy{-\dif}}%
%    \end{macrocode}
% \end{macro}
%
% Keys to be used in the legend environment:
%    \begin{macrocode}
\define@key[psset]{whiteBG}{fillcolorWhiteBG}{\def\fillcolorWhiteBG{#1}}%
\define@key[psset]{whiteBG}{fillstyleWhiteBG}{\def\fillstyleWhiteBG{#1}}%
\define@key[psset]{whiteBG}{framearcWhiteBG}{\def\framearcWhiteBG{#1}}%
\define@key[psset]{whiteBG}{linewidthWhiteBG}{\def\linewidthWhiteBG{#1}}%
\define@key[psset]{whiteBG}{linestyleWhiteBG}{\def\linestyleWhiteBG{#1}}%
\define@key[psset]{whiteBG}{linecolorWhiteBG}{\def\linecolorWhiteBG{#1}}%
\pst@addfams{whiteBG}%
%    \end{macrocode}
% Default values for the above keys:
%    \begin{macrocode}
\psset{fillcolorWhiteBG=white, fillstyleWhiteBG=solid,
   framearcWhiteBG=0.3, linewidthWhiteBG=0.01, 
   linestyleWhiteBG=solid, linecolorWhiteBG=black}%
%    \end{macrocode}
%
% \begin{macro}{\whiteBG}
% Create the box of the legend in the given position
%    \begin{macrocode}
\def\whiteBG{\@ifnextchar[\@whiteBG{\@whiteBG[]}}%
\def\@whiteBG[#1]#2#3#4#5{%
  \psframe[framearc=\framearcWhiteBG, fillcolor=\fillcolorWhiteBG,%
    fillstyle=\fillstyleWhiteBG, linewidth=\linewidthWhiteBG cm,%
    linestyle=\linestyleWhiteBG, linecolor=\linecolorWhiteBG, #1]%
    (#2,#3)(#4,#5)}%
%    \end{macrocode}
% \end{macro}
%
% Keys to control the line length and separation with the text
% in the legend:
%    \begin{macrocode}
\define@key[psset]{legendXY}{legendSep}{\def\sepYlegendXY{#1}} % 
\define@key[psset]{legendXY}{lineLength}{\def\llegendXY{#1}} % 
\define@key[psset]{legendXY}{lineTextSep}{\def\slegendXY{#1}} % 
\define@key[psset]{legendXY}{borderlineSep}{\FPmul\sepTxlegendXY{#1}{2}} % 
\pst@addfams{legendXY}%
%    \end{macrocode}
%
% Default values:
%    \begin{macrocode}
\psset{legendSep=4, lineLength=5, lineTextSep=1, borderlineSep=1}%
%    \end{macrocode}
%
% \begin{macro}{\legendXY}
% Plot a legend box and calculate the parameters of the legend
% in the position given in round brackets, for |#4| different legends
% and with a width of |#5|.
%    \begin{macrocode}
\def\legendXY{\@ifnextchar[\@legendXY{\@legendXY[]}}%
\def\@legendXY[#1](#2,#3)#4#5{%
  \psset{#1}%
  \def\sepY{\sepYlegendXY}%
  \def\l{\llegendXY}%
  \def\s{\slegendXY}%
  \def\sepTx{\sepTxlegendXY}%
  \def\xaXY{#2}%
  \def\yzXY{#3}%
  \FPdiv\sep\sepY{8}% 
  \FPdiv\sepYy\sepY{1.33} % 
  \FPdiv\x\sep\unitX% To separate \sep mm the legend from the axe
  \FPdiv\y\sep\unitY% To separate \sep mm the legend from the axe
  \FPadd\leftX\xaXY{\x}%
  \FPadd\highY\yzXY{-\y}%
  \FPdiv\w{#4}\unitX%
  \FPadd\rightX\leftX{\w}%
  \FPdiv\sepTx\sepTx\unitX%
  \FPadd\posx\leftX\sepTx%
  \FPdiv\sepTy\sepYy\unitY%
  \FPadd\posy\highY{-\sepTy}%
  \FPdiv\dif{\sepY}\unitY% Separation of the legends
  \FPadd\n{#5}{-1}%
  \FPmul\lowY\dif\n%
  \FPadd\lowY\lowY\sepTy%
  \FPadd\lowY\posy{-\lowY}%
  \whiteBG[#1]{\leftX}{\lowY}{\rightX}{\highY}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\legend[UL,UR,DL,DR]}
% Put the legend box in the positions upper-left, upper-right,
% down-left and down-right. The input parameters are the optional keys,
% the number of legends and the width.
%    \begin{macrocode}
\def\legendUL{\@ifnextchar[\@legendUL{\@legendUL[]}}%
\def\@legendUL[#1]#2#3{%
  \FPmul\xUL\MP@xa{1}%
  \FPmul\yUL\MP@yz{1}%
  \legendXY[#1](\xUL,\yUL){#2}{#3}}%
  %
  \def\legendUR{\@ifnextchar[\@legendUR{\@legendUR[]}}%
  \def\@legendUR[#1]#2#3{%
  \FPmul\xUR\MP@xz{1}%
  \FPmul\yUR\MP@yz{1}%
  \def\sep{0.5}%
  \FPdiv\xp\sep\unitX% To separate \sep mm the legend from the axe
  \FPmul\xp\xp{2}%
  \FPadd\xp\xUR{-\xp}%
  \FPdiv\xx{#2}\unitX%
  \FPadd\xp\xp{-\xx}%
  \legendXY[#1](\xp,\yUR){#2}{#3}}%
  %
\def\legendDL{\@ifnextchar[\@legendDL{\@legendDL[]}}%
\def\@legendDL[#1]#2#3{%
  \psset{#1}%
  \def\sepY{\sepYlegendXY}%
  \def\sepTx{\sepTxlegendXY}%
  \FPmul\xzDL\MP@xz{1}%
  \FPmul\xaDL\MP@xa{1}%
  \FPmul\yzDL\MP@yz{1}%
  \FPmul\yaDL\MP@ya{1}%
  \FPdiv\sep\sepY{8}%
  \FPdiv\sep\sepY{8}%
  \FPdiv\sepYy\sepY{1.33} % 
  \FPdiv\x\sep\unitX% To separate \sep mm the legend from the axe
  \FPdiv\y\sep\unitY% To separate \sep mm the legend from the axe
  \FPadd\leftX\xaDL{0}%
  \FPdiv\w{#2}\unitX%
  \FPadd\rightX\leftX{\w}%
  \FPdiv\sepTx\sepTx\unitX%
  \FPadd\posx\leftX\sepTx%
  \FPadd\lowY\yaDL{\y}%
  \FPadd\lowY\lowY{\y}%
  \FPdiv\sepTy\sepYy\unitY%
  \FPadd\posy\lowY{\sepTy}%
  \FPdiv\dif\sepY\unitY% Separation of the legends
  \FPadd\n{#3}{-1}%
  \FPmul\highY\dif\n%
  \FPadd\highY\highY\sepTy%
  \FPadd\highY\posy{\highY}%
  \FPadd\posy\highY{-\sepTy}%
  \legendXY[#1](\leftX,\highY){#2}{#3}}%
  %
\def\legendDR{\@ifnextchar[\@legendDR{\@legendDR[]}}%
\def\@legendDR[#1]#2#3{%
  \psset{#1}%
  \def\sepY{\sepYlegendXY}%
  \def\sepTx{\sepTxlegendXY}%
  \FPmul\xzDR\MP@xz{1}%
  \FPmul\xaDR\MP@xa{1}%
  \FPmul\yzDR\MP@yz{1}%
  \FPmul\yaDR\MP@ya{1}%
  \FPdiv\sep\sepY{8}%
  \FPdiv\sepYy\sepY{1.33} % 
  \FPdiv\x\sep\unitX% To separate \sep mm the legend from the axe
  \FPdiv\y\sep\unitY% To separate \sep mm the legend from the axe
  \FPadd\rightX\xzDR{-\x}%
  \FPdiv\w{#2}\unitX%
  \FPadd\leftX\rightX{-\w}%
  \FPadd\leftX\leftX{-\x}%
  \FPdiv\sepTx\sepTx\unitX%
  \FPadd\posx\leftX\sepTx%
  \FPadd\lowY\yaDR{\y}%
  \FPadd\lowY\lowY{\y}%
  \FPdiv\sepTy\sepYy\unitY%
  \FPadd\posy\lowY{\sepTy}%
  \FPdiv\dif{\sepY}\unitY% Separation of the legends
  \FPadd\n{#3}{-1}%
  \FPmul\highY\dif\n%
  \FPadd\highY\highY\sepTy%
  \FPadd\highY\posy{\highY}%
  \FPadd\posy\highY{-\sepTy}%
  \legendXY[#1](\leftX,\highY){#2}{#3}}%
%    \end{macrocode}
% \end{macro}
%
% This is the end
%    \begin{macrocode}
\makeatother%
%</makeplot>
%    \end{macrocode}
% \clearpage
% \PrintIndex
% \Finale
\endinput