This file is indexed.

/usr/share/doc/libplplot12/examples/ada/xthick33a.adb is in libplplot-ada1-dev 5.10.0+dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
-- -*- coding: utf-8; -*-
--
-- $Id: xthick33a.adb 12523 2013-09-24 10:27:16Z jbauck $
--
-- Demonstrate most Create_Legend capability including unicode symbols.
--
-- Copyright (C) 2011-2013 Jerry Bauck
--
-- This file is part of PLplot.
--
-- PLplot is free software; you can redistribute it and/or modify
-- it under the terms of the GNU Library General Public License as published
-- by the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- PLplot 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 Library General Public License for more details.
--
-- You should have received a copy of the GNU Library General Public License
-- along with PLplot; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
--

-- This example designed just for devices (e.g., the cairo-related and
-- qt-related devices) where the best choice of glyph is automatically
-- selected by the related libraries (pango/cairo or Qt4) for each
-- unicode character depending on what system fonts are installed.  Of
-- course, you must have the appropriate TrueType fonts installed to
-- have access to all the required glyphs.

-- Ada note: The function TUB is Ada.Strings.Unbounded.To_Unbounded_String
-- renamed. See PLplot.ads or PLplot.ads.

with
    Ada.Strings.Unbounded,
    Ada.Strings,
    Ada.Strings.Fixed,
    PLplot_Auxiliary,
    PLplot;
use
    Ada.Strings.Unbounded,
    Ada.Strings,
    Ada.Strings.Fixed,
    PLplot_Auxiliary,
    PLplot;

----------------------------------------------------------------------------
-- Demonstrate most Create_Legend capability including unicode symbols.
----------------------------------------------------------------------------

procedure xthick33a is
    position_options : Integer_Array_1D(0 .. 15) := 
       (Pl_Position_Left + Pl_Position_Top + Pl_Position_Outside,
        Pl_Position_Top + Pl_Position_Outside,
        Pl_Position_Right + Pl_Position_Top + Pl_Position_Outside,
        Pl_Position_Right + Pl_Position_Outside,
        Pl_Position_Right + Pl_Position_Bottom + Pl_Position_Outside,
        Pl_Position_Bottom + Pl_Position_Outside,
        Pl_Position_Left + Pl_Position_Bottom + Pl_Position_Outside,
        Pl_Position_Left + Pl_Position_Outside,
        Pl_Position_Left + Pl_Position_Top + Pl_Position_Inside,
        Pl_Position_Top + Pl_Position_Inside,
        Pl_Position_Right + Pl_Position_Top + Pl_Position_Inside,
        Pl_Position_Right + Pl_Position_Inside,
        Pl_Position_Right + Pl_Position_Bottom + Pl_Position_Inside,
        Pl_Position_Bottom + Pl_Position_Inside,
        Pl_Position_Left + Pl_Position_Bottom + Pl_Position_Inside,
        Pl_Position_Left + Pl_Position_Inside);

    -- Pick 5 arbitrary UTF-8 symbols useful for plotting points (✠✚✱✪✽✺✰✴✦).
    special_symbols : Legend_String_Array_Type(0 .. 4) := 
       (TUB("✰"), TUB("✴"), TUB("✱"), TUB("✽"), TUB("✦")); -- TUB is renamed To_Unbounded_String.

    -- Create_Colorbar options

    -- Colorbar type options
    Colorbar_Kinds : constant Integer := 4;
    colorbar_option_kinds : Integer_Array_1D(0 .. Colorbar_Kinds - 1) := (
        Pl_Colorbar_Shade,
        Pl_Colorbar_Shade + Pl_Colorbar_Shade_Label,
        Pl_Colorbar_Image,
        Pl_Colorbar_Gradient);
    colorbar_option_kind_labels : Legend_String_Array_Type(0 .. Colorbar_Kinds - 1) :=
       (TUB("Shade colorbars"),
        TUB("Shade colorbars with custom labels"),
        TUB("Image colorbars"),
        TUB("Gradient colorbars"));

    -- Which side of the page are we positioned relative to?
    Colorbar_Positions :constant Integer := 4;
    colorbar_position_options : Integer_Array_1D(0 .. Colorbar_Positions - 1) :=
       (Pl_Position_Left,
        Pl_Position_Right,
        Pl_Position_Top,
        Pl_Position_Bottom);
    
    colorbar_position_option_labels : Legend_String_Array_Type(0 .. Colorbar_Positions - 1) :=
       (TUB("Left"),
        TUB("Right"),
        TUB("Top"),
        TUB("Bottom"));
    
    -- Colorbar label positioning options
    Colorbar_Labels : constant Integer := 4;
    colorbar_label_options : Integer_Array_1D(0 .. Colorbar_Labels - 1) :=
       (Pl_Colorbar_Label_Left,
        Pl_Colorbar_Label_Right,
        Pl_Colorbar_Label_Top,
        Pl_Colorbar_Label_Bottom);

    colorbar_label_option_labels : Legend_String_Array_Type(0 .. Colorbar_Labels - 1) :=
       (TUB("Label left"),
        TUB("Label right"),
        TUB("Label top"),
        TUB("Label bottom"));
    
    -- Colorbar cap options
    Colorbar_Caps : constant Integer := 4;
    colorbar_cap_options : Integer_Array_1D(0 .. Colorbar_Caps - 1) :=
       (Pl_Colorbar_Cap_None,
        Pl_Colorbar_Cap_Low,
        Pl_Colorbar_Cap_High,
        Pl_Colorbar_Cap_Low + Pl_Colorbar_Cap_High);
    colorbar_cap_option_labels : Legend_String_Array_Type(0 .. Colorbar_Caps - 1) :=
       (TUB("No caps"),
        TUB("Low cap"),
        TUB("High cap"),
        TUB("Low and high caps"));


    procedure Create_Colorbar_example_page(kind_i : Integer; label_i : Integer; cap_i : Integer;
        cont_color : Integer; cont_width : Long_Float; n_values : Integer; values : Real_Vector) 
    is
        -- Parameters for the colorbars on this page
        position, opt : Integer;
        x, y, x_length, y_length : Long_Float;
        ticks : Real_Vector(0 .. 0) := (others => 0.0);
        sub_ticks : Integer_Array_1D(0 .. 0) := (others => 0);
        low_cap_color, high_cap_color : Long_Float;
        vertical, ifn : Boolean;
        n_axes : Integer := 1;
        axis_opts : Legend_String_Array_Type(0 .. 0);
        n_labels : Integer := 1;
        label_opts : Integer_Array_1D(0 .. 0) := (others => 0);
        label : Legend_String_Array_Type(0 .. 0);
        title : Unbounded_String;
        colorbar_width, colorbar_height : Long_Float;
        n_values_array : Integer_Array_1D(0 .. 0);
        values_array : Real_Matrix(0 .. 0, values'first .. values'last);
        type Stupid is mod 2**7; -- To cover Legend_Colorbar_Position_Type in plplot_thin.ads.
    begin
        n_values_array(0) := n_values;
        for i in values'range loop
           values_array(0, i) := values(i);
        end loop;

        low_cap_color := 0.0;
        high_cap_color := 1.0;

        -- Start a new page.
        Advance_To_Subpage(Next_Subpage);

        -- Draw one colorbar relative to each side of the page.
        for position_i in 0 .. Colorbar_Positions - 1 loop
            position := colorbar_position_options(position_i);
            opt := colorbar_option_kinds(kind_i) + 
                colorbar_label_options(label_i) + colorbar_cap_options(cap_i);

            -- We have to convert these integers to modular type Stupid before and-ing the bits.
            -- That's because manipulating bits of non-modular types is nonsense but other
            -- languages seem to not care about stuff like this.
            vertical := ((Stupid(position) and Stupid(Pl_Position_Left)) > 0) or 
                        ((Stupid(position) and Stupid(Pl_Position_Right)) > 0);
            
            ifn := ((Stupid(position) and Stupid(Pl_Position_Left)) > 0) or 
                ((Stupid(position) and Stupid(Pl_Position_Bottom)) > 0);

            -- Set the offset position on the page.
            if vertical then
                x        := 0.0;
                y        := 0.0;
                x_length := 0.05;
                y_length := 0.5;
            else
                x        := 0.0;
                y        := 0.0;
                x_length := 0.5;
                y_length := 0.05;
            end if;
            
            -- Set appropriate labelling options.
            if ifn then
                if cont_color = 0 or cont_width = 0.0 then
                    axis_opts(0) := TUB("uwtivn"); -- TUB is renamed To_Unbounded_String.
                else
                    axis_opts(0) := TUB("uwxvn");
                end if;
            else
                if cont_color = 0 or cont_width = 0.0 then
                    axis_opts(0) := TUB("uwtivm");
                else
                    axis_opts(0) := TUB("uwxvm");
                end if;
            end if;
            
            label(0) := colorbar_position_option_labels(position_i) & ", " 
                & colorbar_label_option_labels(label_i);
                
            -- Smaller text
            Set_Character_Height(0.0, 0.75);
            -- Small ticks on the vertical axis
            Set_Major_Tick_Length(0.0, 0.5);
            Set_Minor_Tick_Length(0.0, 0.5);
            
            Set_Viewport_Normalized(0.20, 0.80, 0.20, 0.80);
            Set_Viewport_World(0.0, 1.0, 0.0, 1.0);
            -- Set interesting background colour.
            Set_One_Color_Map_0_And_Alpha(White, 0, 0, 0, 0.20);
            Create_Colorbar(colorbar_width, colorbar_height,
                opt + Pl_Colorbar_Bounding_Box + Pl_Colorbar_Background, position,
                x, y, x_length, y_length,
                White, Red, 1,
                low_cap_color, high_cap_color,
                cont_color, cont_width,
                label_opts, label,
                axis_opts,
                ticks, sub_ticks,
                n_values_array, values_array);
            
            -- Reset text and tick sizes
            Set_Character_Height(0.0, 1.0);
            Set_Major_Tick_Length(0.0, 1.0);
            Set_Minor_Tick_Length(0.0, 1.0);
        end loop;

        -- Draw a page title
        title := colorbar_option_kind_labels(kind_i) & " - " 
            & colorbar_cap_option_labels(cap_i);
        Set_Viewport_Normalized(0.0, 1.0, 0.0, 1.0);
        Set_Viewport_World(0.0, 1.0, 0.0, 1.0);
        Write_Text_World(0.5, 0.5, 0.0, 0.0, 0.5, To_String(title));
    end Create_Colorbar_example_page;


    procedure Create_Colorbar_example(palette : String; kind_i : Integer; cont_color : Integer;
        cont_width : Long_Float; n_values : Integer; values : Real_Vector) is
    begin
        -- Load the color palette
        Set_Color_Map_1_From_File(palette, True);

        for label_i in 0 .. Colorbar_Labels - 1 loop
            for cap_i in 0 .. Colorbar_Caps - 1 loop
                Create_Colorbar_example_page(kind_i, label_i, cap_i, cont_color, cont_width,
                    n_values, values );
            end loop;
        end loop;
    end Create_Colorbar_example;


    colorbar : Boolean := True; -- By default do not plot Create_Colorbar pages
                                -- for now while we are working out the API.
    opt : Integer;
    nlegend : Integer;
    nturn : Integer;
    legend_width, legend_height, x, y, xstart, ystart : Long_Float;
    max_height, text_scale : Long_Float;
    position, opt_base, nrow, ncolumn : Integer;

begin -- main
    Parse_Command_Line_Arguments(Pl_Parse_Full); 

    -- Initialize plplot
    Initialize_PLplot;

    -- First page illustrating the 16 standard positions.
    declare
        nlegend : constant Integer := 1;
        opt_array       :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        text_colors     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        box_colors      :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        box_patterns    :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        box_scales      :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        box_line_widths :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        line_colors     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        line_styles     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        line_widths     :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        symbol_numbers  :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        symbol_colors   :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        symbol_scales   :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        text            : Legend_String_Array_Type(0 .. nlegend - 1) := (others => TUB(" "));
        symbols         : Legend_String_Array_Type(0 .. nlegend - 1) := (others => TUB(" "));
    begin
        Advance_To_Subpage(Next_Subpage);
        Set_Viewport_Normalized(0.25, 0.75, 0.25, 0.75);
        Set_Viewport_World(0.0, 1.0, 0.0, 1.0);
        Box_Around_Viewport("bc", 0.0, 0, "bc", 0.0, 0);
        Set_Font(PL_FCI_SANS, -1, -1);
        Write_Text_Viewport("t", 8.0, 0.5, 0.5, "The 16 standard legend positions with");
        Write_Text_Viewport("t", 6.0, 0.5, 0.5, "the same (0.05) offset in x and y");

        -- Only specify legend data that are required according to the
        -- value of opt_array for that entry.
        opt_base          := Pl_Legend_Background + Pl_Legend_Bounding_Box;
        opt_array(0)      := Pl_Legend_Line + Pl_Legend_Symbol;
        line_styles(0)    := 1;
        line_widths(0)    := 1.0;
        symbol_scales(0)  := 1.0;
        symbol_numbers(0) := 4;
        symbols(0)        := TUB("*");

        -- Use monotype fonts so that all legends are the same size.
        Set_Font(PL_FCI_MONO, -1, -1);
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        for k in 0 .. 15 loop
            position := position_options(k);
            opt      := opt_base;
            -- Make a 2-digit string with leading 0 for 0 .. 9.
            if k >= 10 then
                text(0) := To_Unbounded_String(Trim(Integer'image(k), Left));
            else
                text(0) := To_Unbounded_String("0" & Trim(Integer'image(k), Left));
            end if;
            text_colors(0)   := 1 + (k mod 8);
            line_colors(0)   := 1 + (k mod 8);
            symbol_colors(0) := 1 + (k mod 8);

            Create_Legend(legend_width, legend_height, opt, position, 0.05, 0.05,
                0.1, White, Red, 1, 0, 0,
                opt_array, 1.0, 1.0, 2.0,
                1.0, text_colors, text,
                Box_Colors, Box_Patterns, 
                Box_Scales, Box_Line_Widths,
                line_colors, line_styles, line_widths,
                symbol_colors, symbol_scales, symbol_numbers, symbols);
        end loop;
    end; -- declare

    -- Second page illustrating effect of nrow, ncolumn for the same legend data.
    declare
        nlegend : constant Integer := 7;
        opt_array       :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        text_colors     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        box_colors      :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        box_patterns    :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        box_scales      :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        box_line_widths :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        line_colors     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        line_styles     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        line_widths     :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        symbol_numbers  :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        symbol_colors   :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        symbol_scales   :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        text            : Legend_String_Array_Type(0 .. nlegend - 1) := (others => TUB(" "));
        symbols         : Legend_String_Array_Type(0 .. nlegend - 1) := (others => TUB(" "));
    begin
        Advance_To_Subpage(Next_Subpage);
        Set_Viewport_Normalized(0.25, 0.75, 0.25, 0.75);
        Set_Viewport_World(0.0, 1.0, 0.0, 1.0);
        Box_Around_Viewport("bc", 0.0, 0, "bc", 0.0, 0);
        Set_Font(PL_FCI_SANS, -1, -1);
        Write_Text_Viewport("t", 8.0, 0.5, 0.5, "The effect of nrow, ncolumn, PL_LEGEND_ROW_MAJOR,");
        Write_Text_Viewport("t", 6.0, 0.5, 0.5, "and position for the same legend data");

        -- Only specify legend data that are required according to the
        -- value of opt_array for that entry.
        opt_base := Pl_Legend_Background + Pl_Legend_Bounding_Box;
        for k in 0 .. nlegend - 1 loop
            opt_array(k)      := Pl_Legend_Line + Pl_Legend_Symbol;
            line_styles(k)    := 1;
            line_widths(k)    := 1.0;
            symbol_scales(k)  := 1.0;
            symbol_numbers(k) := 2;
            symbols(k)        := TUB("*");
            -- Make 2-digit strings with leading 0 for 0 .. 9.
            if k >= 10 then
                text(k) := To_Unbounded_String(Trim(Integer'image(k), Left));
            else
                text(k) := To_Unbounded_String("0" & Trim(Integer'image(k), Left));
            end if;
            text_colors(k)   := 1 + (k mod 8);
            line_colors(k)   := 1 + (k mod 8);
            symbol_colors(k) := 1 + (k mod 8);
        end loop;

        -- Use monotype fonts so that all legends are the same size.
        Set_Font(PL_FCI_MONO, -1, -1);
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        position := Pl_Position_Top + Pl_Position_Outside;
        opt      := opt_base;
        x        := 0.0;
        y        := 0.1;
        nrow     := 1;
        ncolumn  := nlegend;
        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.05, White, Red, 1, nrow, ncolumn,
            opt_array, 1.0, 1.0, 2.0,
            1.0, text_colors, text,
            Box_Colors, Box_Patterns, 
            Box_Scales, Box_Line_Widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);

        position := Pl_Position_Bottom + Pl_Position_Outside;
        opt      := opt_base;
        x        := 0.0;
        y        := 0.1;
        nrow     := 1;
        ncolumn  := nlegend;
        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.05, White, Red, 1, nrow, ncolumn,
            opt_array, 1.0, 1.0, 2.0,
            1.0, text_colors, text,
            Box_Colors, Box_Patterns, 
            Box_Scales, Box_Line_Widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);

        position := Pl_Position_Left + Pl_Position_Outside;
        opt      := opt_base;
        x        := 0.1;
        y        := 0.0;
        nrow     := nlegend;
        ncolumn  := 1;
        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.05, White, Red, 1, nrow, ncolumn,
            opt_array, 1.0, 1.0, 2.0,
            1.0, text_colors, text,
            Box_Colors, Box_Patterns, 
            Box_Scales, Box_Line_Widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);

        position := Pl_Position_Right + Pl_Position_Outside;
        opt      := opt_base;
        x        := 0.1;
        y        := 0.0;
        nrow     := nlegend;
        ncolumn  := 1;
        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.05, White, Red, 1, nrow, ncolumn,
            opt_array, 1.0, 1.0, 2.0,
            1.0, text_colors, text,
            Box_Colors, Box_Patterns, 
            Box_Scales, Box_Line_Widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);

        position := Pl_Position_Left + Pl_Position_Top + Pl_Position_Inside;
        opt      := opt_base;
        x        := 0.0;
        y        := 0.0;
        nrow     := 6;
        ncolumn  := 2;
        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.05, White, Red, 1, nrow, ncolumn,
            opt_array, 1.0, 1.0, 2.0,
            1.0, text_colors, text,
            Box_Colors, Box_Patterns, 
            Box_Scales, Box_Line_Widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);

        position := Pl_Position_Right + Pl_Position_Top + Pl_Position_Inside;
        opt      := opt_base + Pl_Legend_Row_Major;
        x        := 0.0;
        y        := 0.0;
        nrow     := 6;
        ncolumn  := 2;
        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.05, White, Red, 1, nrow, ncolumn,
            opt_array, 1.0, 1.0, 2.0,
            1.0, text_colors, text,
            Box_Colors, Box_Patterns, 
            Box_Scales, Box_Line_Widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);

        position := Pl_Position_Bottom + Pl_Position_Inside;
        opt      := opt_base + Pl_Legend_Row_Major;
        x        := 0.0;
        y        := 0.0;
        nrow     := 3;
        ncolumn  := 3;
        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.05, White, Red, 1, nrow, ncolumn,
            opt_array, 1.0, 1.0, 2.0,
            1.0, text_colors, text,
            Box_Colors, Box_Patterns, 
            Box_Scales, Box_Line_Widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);
    end; -- declare

    -- Third page demonstrating legend alignment
    Advance_To_Subpage(Next_Subpage);
    Set_Viewport_Normalized(0.0, 1.0, 0.0, 0.9);
    Set_Viewport_World(0.0, 1.0, 0.0, 1.0);
    Set_Font(Pl_Fci_Sans, -1, -1);
    Write_Text_Viewport("t", 2.0, 0.5, 0.5, "Demonstrate legend alignment");

    x        := 0.1;
    y        := 0.1;
    nturn    := 4;
    nlegend  := 0;
    position := Pl_Position_Top + Pl_Position_Left + Pl_Position_Subpage;
    opt_base := Pl_Legend_Background + Pl_Legend_Bounding_Box;
    opt      := opt_base;
    for i in 0 .. 8 loop

        -- Set up legend arrays with the correct size, type.
        if i <= nturn then
            nlegend := nlegend + 1;
        else
            nlegend := nlegend - 1;
        end if;
        nlegend := Integer'max(1, nlegend);
        declare
            opt_array       :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
            text_colors     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
            box_colors      :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
            box_patterns    :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
            box_scales      :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
            box_line_widths :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
            line_colors     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
            line_styles     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
            line_widths     :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
            symbol_numbers  :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
            symbol_colors   :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
            symbol_scales   :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
            text            : Legend_String_Array_Type(0 .. nlegend - 1) := (others => TUB(" "));
            symbols         : Legend_String_Array_Type(0 .. nlegend - 1) := (others => TUB(" "));
        begin
            -- Only specify legend data that are required according to the
            -- value of opt_array for that entry.
            for k in 0 .. nlegend - 1 loop
                opt_array(k)      := Pl_Legend_Line + Pl_Legend_Symbol;
                line_styles(k)    := 1;
                line_widths(k)    := 1.0;
                symbol_scales(k)  := 1.0;
                symbol_numbers(k) := 2;
                symbols(k)        := TUB("*");
                -- Make 2-digit strings with leading 0 for 0 .. 9.
                if k >= 10 then
                    text(k) := To_Unbounded_String(Trim(Integer'image(k), Left));
                else
                    text(k) := To_Unbounded_String("0" & Trim(Integer'image(k), Left));
                end if;
                text_colors(k)   := 1 + (k mod 8);
                line_colors(k)   := 1 + (k mod 8);
                symbol_colors(k) := 1 + (k mod 8);
            end loop; -- k

            -- Use monotype fonts so that all legends are the same size.
            Set_Font(Pl_Fci_Mono, -1, -1);
            Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

            nrow    := Integer'min(3, nlegend);
            ncolumn := 0;

            Create_Legend(legend_width, legend_height, opt, position, x, y,
                0.025, White, Red, 1, nrow, ncolumn,
                opt_array, 1.0, 1.0, 1.5,
                1.0, text_colors, text,
                Box_Colors, Box_Patterns, 
                Box_Scales, Box_Line_Widths,
                line_colors, line_styles, line_widths,
                symbol_colors, symbol_scales, symbol_numbers, symbols);

            if i = nturn then
                position := Pl_Position_Top + Pl_Position_Right + Pl_Position_Subpage;
                opt      := opt_base;
                x        := 1.0 - x;
                y        := y + legend_height;
            else
                x := x + legend_width;
                y := y + legend_height;
            end if;
        end; -- declare
    end loop; -- i

    -- Fourth page illustrating various kinds of legends
    declare
        nlegend : constant Integer := 5;
        opt_array       :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        text_colors     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        box_colors      :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        box_patterns    :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        box_scales      :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        box_line_widths :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        line_colors     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        line_styles     :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        line_widths     :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        symbol_numbers  :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        symbol_colors   :         Integer_Array_1D(0 .. nlegend - 1) := (others => 0);
        symbol_scales   :         Real_Vector     (0 .. nlegend - 1) := (others => 0.0);
        text            : Legend_String_Array_Type(0 .. nlegend - 1) := (others => TUB(" "));
        symbols         : Legend_String_Array_Type(0 .. nlegend - 1) := (others => TUB(" "));
    begin
        max_height := 0.0;
        xstart     := 0.0;
        ystart     := 0.1;
        x          := xstart;
        y          := ystart;
        text_scale := 0.90;
        Advance_To_Subpage(Next_Subpage);
        Set_Viewport_Normalized(0.0, 1.0, 0.0, 0.90);
        Set_Viewport_World(0.0, 1.0, 0.0, 1.0);
        Set_Font(Pl_Fci_Sans, -1, -1);
        Write_Text_Viewport("t", 2.0, 0.5, 0.5, "Demonstrate Various Kinds of Legends");

        -- Only specify legend data that are required according to the
        -- value of opt_array for that entry.
        position := Pl_Position_Left + Pl_Position_Top;
        opt_base := Pl_Legend_Background + Pl_Legend_Bounding_Box + Pl_Legend_Text_Left;

        -- Set up None, Box, Line, Symbol, and Line & Symbol legend entries.
        opt_array(0) := Pl_Legend_None;
        text(0) := TUB("None");
        text_colors(0) := 1;

        opt_array(1) := Pl_Legend_Color_Box;
        text(1) := TUB("Box");
        text_colors(1)     := 2;
        box_colors(1)      := 2;
        box_patterns(1)    := 0;
        box_scales(1)      := 0.8;
        box_line_widths(1) := 1.0;

        opt_array(2) := Pl_Legend_Line;
        text(2) := TUB("Line");
        text_colors(2) := 3;
        line_colors(2) := 3;
        line_styles(2) := 1;
        line_widths(2) := 1.0;

        opt_array(3) := Pl_Legend_Symbol;
        text(3) := TUB("Symbol");
        text_colors(3)    := 4;
        symbol_colors(3)  := 4;
        symbol_scales(3)  := text_scale;
        symbol_numbers(3) := 4;
        symbols(3)        := special_symbols(2);

        opt_array(4) := Pl_Legend_Symbol + Pl_Legend_Line;
        text(4) := TUB("L & S");
        text_colors(4)    := 5;
        line_colors(4)    := 5;
        line_styles(4)    := 1;
        line_widths(4)    := 1.0;
        symbol_colors(4)  := 5;
        symbol_scales(4)  := text_scale;
        symbol_numbers(4) := 4;
        symbols(4)        := special_symbols(2);

        opt := opt_base;
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.1, White, Red, 1, 0, 0,
            opt_array, 1.0, text_scale, 2.0,
            0.0, text_colors, text,
            box_colors, box_patterns, box_scales, box_line_widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);
        max_height := Long_Float'max(max_height, legend_height);

        -- Set up symbol legend entries with various symbols.
        for i in 0 .. nlegend - 1 loop
            opt_array(i) := Pl_Legend_Symbol;
            text(i) := TUB("Symbol ") & special_symbols(i);
            text_colors(i)    := i + 1;
            symbol_colors(i)  := i + 1;
            symbol_scales(i)  := text_scale;
            symbol_numbers(i) := 4;
            symbols(i)        := special_symbols(i);
        end loop;

        opt := opt_base;
        x  := x + legend_width;
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.1, White, Red, 1, 0, 0,
            opt_array, 1.0, text_scale, 2.0,
            0.0, text_colors, text,
            Box_Colors, Box_Patterns, 
            Box_Scales, Box_Line_Widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);
        max_height := Long_Float'max(max_height, legend_height);

        -- Set up symbol legend entries with various numbers of symbols.
        for i in 0 .. nlegend - 1 loop
            opt_array(i) := Pl_Legend_Symbol;
            text(i) := TUB("Symbol Number" & Integer'image(i + 2));
            text_colors(i)    := i + 1;
            symbol_colors(i)  := i + 1;
            symbol_scales(i)  := text_scale;
            symbol_numbers(i) := i + 2;
            symbols(i)        := special_symbols(2);
        end loop;

        opt := opt_base;
        x  := x + legend_width;
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.1, White, Red, 1, 0, 0,
            opt_array, 1.0, text_scale, 2.0,
            0.0, text_colors, text,
            Box_Colors, Box_Patterns, 
            Box_Scales, Box_Line_Widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);
        max_height := Long_Float'max(max_height, legend_height);

        -- Set up box legend entries with various colours.
        for i in 0 .. nlegend - 1 loop
            opt_array(i) := Pl_Legend_Color_Box;
            text(i) := TUB("Box Color" & Integer'image(i + 1));
            text_colors(i)     := i + 1;
            box_colors(i)      := i + 1;
            box_patterns(i)    := 0;
            box_scales(i)      := 0.8;
            box_line_widths(i) := 1.0;
        end loop;

        opt := opt_base;
        -- Use new origin
        x          := xstart;
        y         := y + max_height;
        max_height := 0.0;
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.1, White, Red, 1, 0, 0,
            opt_array, 1.0, text_scale, 2.0,
            0.0, text_colors, text,
            box_colors, box_patterns, box_scales, box_line_widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);
        max_height := Long_Float'max(max_height, legend_height);

        -- Set up box legend entries with various patterns.
        for i in 0 .. nlegend - 1 loop
            opt_array(i) := Pl_Legend_Color_Box;
            text(i) := TUB("Box Pattern" & Integer'image(i));
            text_colors(i)     := 2;
            box_colors(i)      := 2;
            box_patterns(i)    := i;
            box_scales(i)      := 0.8;
            box_line_widths(i) := 1.0;
        end loop;

        opt := opt_base;
        x  := x + legend_width;
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.1, White, Red, 1, 0, 0,
            opt_array, 1.0, text_scale, 2.0,
            0.0, text_colors, text,
            box_colors, box_patterns, box_scales, box_line_widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);
        max_height := Long_Float'max(max_height, legend_height);

        -- Set up box legend entries with various box pattern line widths.
        for i in 0 .. nlegend - 1 loop
            opt_array(i) := Pl_Legend_Color_Box;
            text(i) := TUB("Box Line Width" & Integer'image(i + 1));
            text_colors(i)     := 2;
            box_colors(i)      := 2;
            box_patterns(i)    := 3;
            box_scales(i)      := 0.8;
            box_line_widths(i) := Long_Float(i) + 1.0;
        end loop;

        opt := opt_base;
        x  := x + legend_width;
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.1,White, Red, 1, 0, 0,
            opt_array, 1.0, text_scale, 2.0,
            0.0, text_colors, text,
            box_colors, box_patterns, box_scales, box_line_widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);
        max_height := Long_Float'max(max_height, legend_height);

        -- Set up line legend entries with various colours.
        for i in 0 .. nlegend - 1 loop
            opt_array(i) := Pl_Legend_Line;
            text(i) := TUB("Line Color" & Integer'image(i + 1));
            text_colors(i) := i + 1;
            line_colors(i) := i + 1;
            line_styles(i) := 1;
            line_widths(i) := 1.0;
        end loop;

        opt := opt_base;
        -- Use new origin
        x := xstart;
        y := y + max_height;
        max_height := 0.0;
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.1, White, Red, 1, 0, 0,
            opt_array, 1.0, text_scale, 2.0,
            0.0, text_colors, text,
            box_colors, box_patterns, box_scales, box_line_widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);
        max_height := Long_Float'max(max_height, legend_height);

        -- Set up line legend entries with various styles.
        for i in 0 .. nlegend - 1 loop
            opt_array(i) := Pl_Legend_Line;
            text(i) := TUB("Line Style" & Integer'image(i + 1));
            text_colors(i) := 2;
            line_colors(i) := 2;
            line_styles(i) := i + 1;
            line_widths(i) := 1.0;
        end loop;

        opt := opt_base;
        x  := x + legend_width;
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.1, White, Red, 1, 0, 0,
            opt_array, 1.0, text_scale, 2.0,
            0.0, text_colors, text,
            box_colors, box_patterns, box_scales, box_line_widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);
        max_height := Long_Float'max(max_height, legend_height);

        -- Set up line legend entries with various widths.
        for i in 0 .. nlegend - 1 loop
            opt_array(i) := Pl_Legend_Line;
            text(i) := TUB("Line Width" & Integer'image(i + 1));
            text_colors(i) := 2;
            line_colors(i) := 2;
            line_styles(i) := 1;
            line_widths(i) := Long_Float(i) + 1.0;
        end loop;

        opt := opt_base;
        x  := x + legend_width;
        Set_One_Color_Map_0_And_Alpha(White, 32, 32, 32, 0.70);

        Create_Legend(legend_width, legend_height, opt, position, x, y,
            0.1, White, Red, 1, 0, 0,
            opt_array, 1.0, text_scale, 2.0,
            0.0, text_colors, text,
            box_colors, box_patterns, box_scales, box_line_widths,
            line_colors, line_styles, line_widths,
            symbol_colors, symbol_scales, symbol_numbers, symbols);
        max_height := Long_Float'max(max_height, legend_height);
    end; -- declare

    if colorbar then
        -- Color bar examples
        declare
            values_small : Real_Vector(0 .. 1)  := (-1.0e-200, 1.0e-200);
            values_uneven : Real_Vector(0 .. 8) := (-1.0e-200, 2.0e-200, 2.6e-200, 3.4e-200, 
                6.0e-200, 7.0e-200, 8.0e-200, 9.0e-200, 10.0e-200);
            values_even : Real_Vector(0 .. 8)   := (-2.0e-200, -1.0e-200, 0.0e-200, 1.0e-200, 
                2.0e-200, 3.0e-200, 4.0e-200, 5.0e-200, 6.0e-200);
        begin
            -- Use unsaturated green background colour to contrast with black caps.
            Set_Background_Color_RGB(70, 185, 70);
            -- Cut out the greatest and smallest bits of the color spectrum to
            -- leave colors for the end caps.
            Set_Color_Map_1_Range(0.01, 0.99);

            -- We can only test image and gradient colorbars with two element arrays
            for i in 2 .. COLORBAR_KINDS - 1 loop
                Create_Colorbar_example("cmap1_blue_yellow.pal", i, 0, 0.0, 2, values_small);
            end loop;
            -- Test shade colorbars with larger arrays
            for i in 0 .. 1 loop
                Create_Colorbar_example("cmap1_blue_yellow.pal", i, 4, 2.0, 9, values_even);
            end loop;
            for i in 0 .. 1 loop
                Create_Colorbar_example("cmap1_blue_yellow.pal", i, 0, 0.0, 9, values_uneven);
            end loop;
        end;
    end if;
    End_PLplot;
end xthick33a;