/
psxyz.c
2440 lines (2269 loc) · 119 KB
/
psxyz.c
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
/*--------------------------------------------------------------------
*
* Copyright (c) 1991-2023 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
* See LICENSE.TXT file for copying and redistribution conditions.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3 or 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 Lesser General Public License for more details.
*
* Contact info: www.generic-mapping-tools.org
*--------------------------------------------------------------------*/
/*
* Author: Paul Wessel
* Date: 1-JAN-2010
* Version: 6 API
*
* Brief synopsis: psxyz will read <x,y,z> triplets and plot symbols, lines,
* or polygons in a 3-D perspective view.
*
* Note on KEYS: S?(=2 means if -S~|q then we may possibly take optional crossing line file, else the ? is set to ! for skipping it.
* The "2" means we must skip two characters (q|~ and f|x) before finding the dataset file name
*/
#include "gmt_dev.h"
#include "longopt/psxyz_inc.h"
#define THIS_MODULE_CLASSIC_NAME "psxyz"
#define THIS_MODULE_MODERN_NAME "plot3d"
#define THIS_MODULE_LIB "core"
#define THIS_MODULE_PURPOSE "Plot lines, polygons, and symbols in 3-D"
#define THIS_MODULE_KEYS "<D{,CC(,T-<,S?(=2,ZD(,>X}"
#define THIS_MODULE_NEEDS "Jd"
#define THIS_MODULE_OPTIONS "-:>BJKOPRUVXYabdefghilpqtwxy" GMT_OPT("EMmc")
/* Control structure for psxyz */
struct PSXYZ_CTRL {
struct PSXYZ_A { /* -A[m|y|p|x|r|t|step] */
bool active;
unsigned int mode;
double step;
} A;
struct PSXYZ_C { /* -C<cpt> or -C<color1>,<color2>[,<color3>,...] */
bool active;
char *file;
} C;
struct PSXYZ_D { /* -D<dx>/<dy>[/<dz>] */
bool active;
double dx, dy, dz;
} D;
struct PSXYZ_G { /* -G<fill>|+z */
bool active;
bool set_color;
unsigned int sequential;
struct GMT_FILL fill;
} G;
struct PSXYZ_H { /* -H read overall scaling factor for symbol size and pen width */
bool active;
unsigned int mode;
double value;
} H;
struct PSXYZ_I { /* -I[<intensity>] */
bool active;
unsigned int mode; /* 0 if constant, 1 if read from file (symbols only) */
double value;
} I;
struct PSXYZ_L { /* -L[+xl|r|x0][+yb|t|y0][+e|E][+p<pen>] */
bool active;
bool polygon; /* true when just -L is given */
int outline; /* 1 when +p<pen> is given */
unsigned int mode; /* Which side for the anchor */
unsigned int anchor; /* 0 not used, 1 = x anchors, 2 = y anchors, 3 = +/-dy, 4 = -dy1, +dy2 */
double value;
struct GMT_PEN pen;
} L;
struct PSXYZ_N { /* -N[r|c] */
bool active;
unsigned int mode;
} N;
struct PSXYZ_Q { /* -Q */
bool active;
} Q;
struct PSXYZ_S { /* -S */
bool active;
char *arg;
} S;
struct PSXYZ_T { /* -T */
bool active;
} T;
struct PSXYZ_W { /* -W<pen>[+c[l|f]][+o<offset>][+s][+v[b|e]<size><vecargs>][+z] */
bool active;
bool cpt_effect;
bool set_color;
unsigned int sequential;
struct GMT_PEN pen;
} W;
struct PSXYZ_Z { /* -Z<value>[+t|T] */
bool active;
unsigned set_transp;
double value;
char *file;
} Z;
};
enum Psxyz_poltype {
PSXYZ_POL_X = 1,
PSXYZ_POL_Y,
PSXYZ_POL_SYMM_DEV,
PSXYZ_POL_ASYMM_DEV,
PSXYZ_POL_ASYMM_ENV};
enum Psxyz_cliptype {
PSXYZ_CLIP_REPEAT = 0,
PSXYZ_CLIP_NO_REPEAT,
PSXYZ_NO_CLIP_REPEAT,
PSXYZ_NO_CLIP_NO_REPEAT};
enum Psxyz_scaletype {
PSXYZ_READ_SCALE = 0,
PSXYZ_CONST_SCALE = 1};
struct PSXYZ_DATA {
int symbol, outline;
unsigned int flag; /* 1 = convert azimuth, 2 = use geo-functions, 4 = x-base in units, 8 y-base in units */
double x, y, z, dim[PSL_MAX_DIMS], dist[2], transparency[2];
double *zz; /* For column symbol if +z<n> in effect */
struct GMT_FILL f;
struct GMT_PEN p, h;
struct GMT_VECT_ATTR v;
char *string;
struct GMT_CUSTOM_SYMBOL *custom;
};
GMT_LOCAL bool psxyz_is_stroke_symbol (int symbol) {
/* Return true if cross, x, y, - symbols */
if (symbol == PSL_CROSS) return true;
if (symbol == PSL_XDASH) return true;
if (symbol == PSL_YDASH) return true;
if (symbol == PSL_PLUS) return true;
return false;
}
static void *New_Ctrl (struct GMT_CTRL *GMT) { /* Allocate and initialize a new control structure */
struct PSXYZ_CTRL *C;
C = gmt_M_memory (GMT, NULL, 1, struct PSXYZ_CTRL);
/* Initialize values whose defaults are not 0/false/NULL */
C->W.pen = GMT->current.setting.map_default_pen;
gmt_init_fill (GMT, &C->G.fill, -1.0, -1.0, -1.0); /* Default is no fill */
C->A.step = GMT->current.setting.map_line_step;
C->N.mode = PSXYZ_CLIP_REPEAT;
return (C);
}
static void Free_Ctrl (struct GMT_CTRL *GMT, struct PSXYZ_CTRL *C) { /* Deallocate control structure */
if (!C) return;
gmt_M_str_free (C->C.file);
gmt_M_str_free (C->S.arg);
gmt_M_free (GMT, C);
}
static int usage (struct GMTAPI_CTRL *API, int level) {
/* This displays the psxyz synopsis and optionally full usage information */
const char *name = gmt_show_name_and_purpose (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_PURPOSE);
const char *mod_name = &name[4]; /* To skip the leading gmt for usage messages */
const char *T[2] = {" [-T]", ""};
if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR);
GMT_Usage (API, 0, "usage: %s [<table>] %s %s [%s] [%s] [-A[m|p|r|t|x|y]] [-C<cpt>] [-D<dx>/<dy>[/<dz>]] [-G<fill>] "
"[-H[<scale>]] [-I[<intens>]] %s [%s] [-N[c|r]] %s %s[-Q] [-S[<symbol>][<size>][/size_y]]%s [%s] [%s] [-W[<pen>][<attr>]] "
"[%s] [%s] [-Z<value>|<file>[+t|T]] [%s] [%s] %s[%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s]\n",
name, GMT_J_OPT, GMT_Rgeoz_OPT, GMT_B_OPT, GMT_Jz_OPT, API->K_OPT, PLOT_L_OPT, API->O_OPT, API->P_OPT,
T[API->GMT->current.setting.run_mode], GMT_U_OPT, GMT_V_OPT, GMT_X_OPT, GMT_Y_OPT, GMT_a_OPT, GMT_bi_OPT,
API->c_OPT, GMT_di_OPT, GMT_e_OPT, GMT_f_OPT, GMT_g_OPT, GMT_h_OPT, GMT_i_OPT, GMT_l_OPT, GMT_p_OPT,
GMT_qi_OPT, GMT_tv_OPT, GMT_w_OPT, GMT_colon_OPT, GMT_PAR_OPT);
if (level == GMT_SYNOPSIS) return (GMT_MODULE_SYNOPSIS);
GMT_Message (API, GMT_TIME_NONE, " REQUIRED ARGUMENTS:\n");
GMT_Option (API, "<,J-Z,R3");
GMT_Message (API, GMT_TIME_NONE, "\n OPTIONAL ARGUMENTS:\n");
GMT_Option (API, "B-");
GMT_Usage (API, 1, "\n-A[m|p|r|t|x|y]");
GMT_Usage (API, -2, "Suppress drawing geographic line segments as great circle arcs, i.e., draw "
"straight lines instead. Six optional directives instead convert paths to staircase curves:");
GMT_Usage (API, 3, "m: First follow meridians, then parallels when connecting geographic points.");
GMT_Usage (API, 3, "p: First follow parallels, then meridians when connecting geographic point.");
GMT_Usage (API, 3, "r: First follow radius, then theta for staircase curves for Polar projection.");
GMT_Usage (API, 3, "t: First follow theta, then radius for staircase curves for Polar projection.");
GMT_Usage (API, 3, "x: First follow x, then y for staircase curves for Cartesian projections.");
GMT_Usage (API, 3, "y: First follow y, then x for staircase curves for Cartesian projections.");
GMT_Usage (API, 1, "\n-C<cpt>|<color1>,<color2>[,<color3>,...]");
GMT_Usage (API, -2, "Assign symbol colors based on z-value in 3rd column. "
"Note: requires -S. Without -S, %s excepts lines/polygons "
"and looks for -Z<value> options in each segment header. Then, color is "
"applied for polygon fill (-L) or polygon pen (no -L).", mod_name);
GMT_Usage (API, 1, "\n-D<dx>/<dy>.");
GMT_Usage (API, -2, "Offset symbol or line positions by <dx>/<dy> [no offset].");
gmt_fill_syntax (API->GMT, 'G', NULL, "Specify color or pattern [Default is no fill].");
GMT_Usage (API, -2, "The -G option can be present in all segment headers (not with -S). "
"To assign fill color via -Z, give -G+z).");
GMT_Usage (API, 1, "\n-H[<scale>]");
GMT_Usage (API, -2, "Scale symbol sizes (set via -S or input column) by factors read from scale column. "
"The scale column follows the symbol size column. Alternatively, append a fixed <scale>.");
GMT_Usage (API, 1, "\n-I[<intens>]");
GMT_Usage (API, -2, "Use the intensity to modulate the fill color (requires -C or -G). "
"If no intensity is given we expect it to follow symbol size in the data record.");
GMT_Option (API, "K");
GMT_Usage (API, 1, "\n%s", PLOT_L_OPT);
GMT_Usage (API, -2, "Force closed polygons, or append modifiers to build polygon from a line:");
GMT_Usage (API, 3, "+d Symmetrical envelope around y(x) using deviations dy(x) from col 4.");
GMT_Usage (API, 3, "+D Asymmetrical envelope around y(x) using deviations dy1(x) and dy2(x) from cols 4-5.");
GMT_Usage (API, 3, "+b Asymmetrical envelope around y(x) using bounds yl(x) and yh(x) from cols 4-5.");
GMT_Usage (API, 3, "+x Connect 1st and last point to anchor points at l (xmin), r (xmax), or x0.");
GMT_Usage (API, 3, "+y Connect 1st and last point to anchor points at b (ymin), t (ymax), or y0.");
GMT_Usage (API, 3, "+p Draw polygon outline with <pen> [no outline].");
GMT_Usage (API, -2, "The polygon created may be painted via -G.");
GMT_Usage (API, 1, "\n-N[c|r]");
GMT_Usage (API, -2, "Do Not skip or clip symbols that fall outside the map border [clipping is on]:");
GMT_Usage (API, 3, "r: Turn off clipping and plot repeating symbols for periodic maps.");
GMT_Usage (API, 3, "c: Retain clipping but turn off plotting of repeating symbols for periodic maps.");
GMT_Usage (API, -2, "[Default will clip or skip symbols that fall outside and plot repeating symbols].");
GMT_Usage (API, -2, "Note: May also be used with lines or polygons but no periodicity will be honored.");
GMT_Option (API, "O,P");
GMT_Usage (API, 1, "\n-Q Do NOT sort symbols based on distance to viewer before plotting.");
GMT_Usage (API, 1, "\n-S[<symbol>][<size>]");
GMT_Usage (API, -2, "Select symbol type and symbol size (in %s). Choose from these symbols:",
API->GMT->session.unit_name[API->GMT->current.setting.proj_length_unit]);
GMT_Usage (API, 2, "\n%s Basic geometric symbol. Append one:", GMT_LINE_BULLET);
GMT_Usage (API, -3, "-(xdash), +(plus), st(a)r, (b|B)ar, (c)ircle, (d)iamond, (e)llipse, "
"(f)ront, octa(g)on, (h)exagon (i)nvtriangle, (j)rotated rectangle, "
"(k)ustom, (l)etter, (m)athangle, pe(n)tagon, c(o)lumn, (p)oint, "
"(q)uoted line, (r)ectangle, (R)ounded rectangle, (s)quare, (t)riangle, "
"c(u)be, (v)ector, (w)edge, (x)cross, (y)dash, (z)dash, or "
"=(geovector, i.e., great or small circle vectors).");
GMT_Usage (API, -3, "If no size is specified, then the 4th column must have sizes. "
"If no symbol is specified, then the last column must have symbol codes. "
"[Note: if -C is selected then 4th means 5th column, etc.]. "
"Both column and cube are true 3-D objects (give size as xsize/ysize); "
"all other symbols are shown in 2-D perspective only. "
"By default, the 3-D symbols column and cube are shaded; "
"use upper case O and U to disable this 3-D illumination. "
"Symbols A, C, D, F, H, I, N, S, T are adjusted to have same area "
"of a circle of given diameter.");
GMT_Usage (API, 2, "\n%s Bar: Append +b[<base>] to give the y- (or z-) value of the base [Default = 0 (1 for log-scales)]. "
"Use -SB for horizontal bars; then <base> value refers to the x location.", GMT_LINE_BULLET);
GMT_Usage (API, 3, "+B Heights are measured relative to <base> [relative to origin].");
GMT_Usage (API, 3, "+b Set <base>. Alternatively, leave <base> off to read it from file.");
GMT_Usage (API, 3, "+i Increments are given instead or values for multiband bars.");
GMT_Usage (API, 3, "+s Side-by-side placement of multiband bars [stacked multiband bars]. "
"Optionally, append <gap> between bars in fraction (or percent) of <size> [no gap].");
GMT_Usage (API, 3, "+v For multi-band bars, append <nbands>; then <nbands> values will "
"be read from file instead of just one.");
GMT_Usage (API, -3, "Multiband bars requires -C with one color per band (values 0, 1, ...). "
"For -SB the input band values are x (or dx) values instead of y (or dy). ");
GMT_Usage (API, 2, "\n%s 3-D Column: Append +b[<base>] to give the z-value of the base of the column "
"[Default = 0 (1 for log-scales)].", GMT_LINE_BULLET);
GMT_Usage (API, 3, "+B Heights are measured relative to <base> [relative to origin].");
GMT_Usage (API, 3, "+b Set <base>. Alternatively, leave <base> off to read it from file.");
GMT_Usage (API, 3, "+v For multi-band columns, append <nbands>; then <nbands> z-values will "
"be read from file instead of just one.");
GMT_Usage (API, 3, "+i Increments dz are given instead or values for multiband bars.");
GMT_Usage (API, -3, "Multiband columns requires -C with one color per band (values 0, 1, ...).");
GMT_Usage (API, 2, "\n%s 3-D Cube: Give <size> as the length of all sides; append q if <size> "
"is a quantity in x-units.", GMT_LINE_BULLET);
GMT_Usage (API, 2, "\n%s Ellipse: If not given, we read direction, major, and minor axis from columns 4-6. "
"If -SE rather than -Se is selected, %s will expect azimuth, and "
"axes [in km], and convert azimuths based on map projection. "
"Use -SE- for a degenerate ellipse (circle) with only diameter in km given. "
"in column 4, or append a fixed diameter in km to -SE instead. "
"Append any of the units in %s to the axes, and "
"if reading dimensions from file, just append the unit [Default is k]. "
"For a linear projection and -SE we scale the axes by the map scale.", GMT_LINE_BULLET, GMT_LEN_UNITS_DISPLAY, mod_name);
GMT_Usage (API, 2, "\n%s Rotatable Rectangle: If not given, we read direction, width and height from columns 4-6. "
"If -SJ rather than -Sj is selected, %s will expect azimuth, and "
"dimensions [in km] and convert azimuths based on map projection. "
"Use -SJ- for a degenerate rectangle (square w/no rotation) with only one dimension given "
"in column 4, or append a fixed dimension to -SJ instead. "
"Append any of the units in %s to the axes, and "
"if reading dimensions from file, just append the unit [Default is k]. "
"For a linear projection and -SJ we scale dimensions by the map scale.", GMT_LINE_BULLET, mod_name, GMT_LEN_UNITS_DISPLAY);
GMT_Usage (API, 2, "\n%s Front: -Sf<spacing>[/<ticklen>][+r+l][+f+t+s+c+b][+o<offset>][+p<pen>]", GMT_LINE_BULLET);
GMT_Usage (API, -3, "If <spacing> is negative it means the number of gaps instead. "
"If <spacing> has a leading + then <spacing> is used exactly [adjusted to fit line length]. "
"If not given, <ticklen> defaults to 15%% of <spacing>. Append various modifiers:");
GMT_Usage (API, 3, "+l Plot symbol to the left of the front [centered].");
GMT_Usage (API, 3, "+r Plot symbol to the right of the front [centered].");
GMT_Usage (API, 3, "+i Make main front line invisible [drawn using pen settings from -W].");
GMT_Usage (API, 3, "+b Plot square when centered, half-square otherwise.");
GMT_Usage (API, 3, "+c Plot full circle when centered, half-circle otherwise.");
GMT_Usage (API, 3, "+f Plot centered cross-tick or tick only in specified direction [Default].");
GMT_Usage (API, 3, "+s Plot left-or right-lateral strike-slip arrows. Optionally append the arrow angle [20].");
GMT_Usage (API, 3, "+S Same as +s but with curved arrow-heads.");
GMT_Usage (API, 3, "+t diagonal square when centered, directed triangle otherwise.");
GMT_Usage (API, 3, "+o Plot first symbol when along-front distance is <offset> [0].");
GMT_Usage (API, 3, "+p Append <pen> for front symbol outline; if no <pen> then no outline [Outline with -W pen].");
GMT_Usage (API, -3, "Only one of +b|c|f|i|s|S|t may be selected.");
GMT_Usage (API, 2, "\n%s Kustom: -Sk|K<symbolname>[/<size>]", GMT_LINE_BULLET);
GMT_Usage (API, -3, "Append <symbolname> immediately after 'k|K'; this will look for "
"<symbolname>.def or <symbolname>.eps in the current directory, in $GMT_USERDIR, "
"or in $GMT_SHAREDIR (searched in that order). Give full path if located elsewhere. "
"Use upper case 'K' if your custom symbol refers a variable symbol, ?.");
gmt_list_custom_symbols (API->GMT);
GMT_Usage (API, 2, "\n%s Letter: -Sl[<size>]+t<string>[a|A<angle>][+f<font>][+j<justify]", GMT_LINE_BULLET);
GMT_Usage (API, -3, "Specify <size> of letter; append required and optional modifiers:");
GMT_Usage (API, 3, "+t Specify <string> to use (required).");
GMT_Usage (API, 3, "+a Set text angle relative to horizontal [0]. Use +A if map azimuth.");
GMT_Usage (API, 3, "+f Set specific <font> for text placement [FONT_ANNOT_PRIMARY].");
GMT_Usage (API, 3, "+j Change the text justification via <justify> [CM].");
GMT_Usage (API, 2, "\n%s Mathangle: radius, start, and stop directions of math angle must be in columns 4-5. "
"If -SM rather than -Sm is used, we draw straight angle symbol if 90 degrees.", GMT_LINE_BULLET);
gmt_vector_syntax (API->GMT, 0, 3);
GMT_Usage (API, 2, "\n%s Quoted line (z must be constant): -Sq[d|n|l|s|x]<info>[:<labelinfo>]" ,GMT_LINE_BULLET);
GMT_Usage (API, -3, "The <code><info> settings control placement of labels along lines. Select from these codes:");
gmt_cont_syntax (API->GMT, 3, 1);
GMT_Usage (API, 3, "<labelinfo> controls the label attributes. Choose from these choices:");
gmt_label_syntax (API->GMT, 2, 1);
GMT_Usage (API, 2, "\n%s Rectangle: If not given, the x- and y-dimensions must be in columns 4-5. "
"Append +s if instead the diagonal corner coordinates are given in columns 4-5.", GMT_LINE_BULLET);
GMT_Usage (API, 2, "\n%s Rounded rectangle: If not given, the x- and y-dimensions and corner radius must be in columns 4-6.", GMT_LINE_BULLET);
GMT_Usage (API, 2, "\n%s Vector: -Sv|V<size>[+a<angle>][+b][+e][+h<shape>][+j<just>][+l][+m][+n[<norm>[/<min>]]][+o<lon>/<lat>][+q][+r][+s][+t[b|e]<trim>][+z]", GMT_LINE_BULLET);
GMT_Usage (API, -3, "Direction and length must be in columns 4-5. "
"If -SV rather than -Sv is selected, %s will expect azimuth and "
"length and convert azimuths based on the chosen map projection.", mod_name);
gmt_vector_syntax (API->GMT, 19, 3);
GMT_Usage (API, 2, "\n%s Wedge: -Sw|W[<outerdiameter>[/<startdir>/<stopdir>]][+a[<dr>][+i<inner_diameter>][+r[<da>]]]", GMT_LINE_BULLET);
GMT_Usage (API, -3, "Append [<outerdiameter>[<startdir><stopdir>]] or we read these parameters from file from column 4. "
"If -SW rather than -Sw is selected, specify two azimuths instead of directions. "
"-SW: Specify <outerdiameter><unit> with units either from %s or %s [Default is k]. "
"-Sw: Specify <outerdiameter><unit> with units from %s [Default is %s].", GMT_LEN_UNITS_DISPLAY, GMT_DIM_UNITS_DISPLAY, GMT_DIM_UNITS_DISPLAY,
API->GMT->session.unit_name[API->GMT->current.setting.proj_length_unit]);
GMT_Usage (API, 3, "+a Just draw arc(s), optionally specify <dr> increment [wedge].");
GMT_Usage (API, 3, "+i Append nonzero <innerdiameter>; we read it from file if not appended.");
GMT_Usage (API, 3, "+r Just draw radial lines, optionally specify <da> increment [wedge].");
GMT_Usage (API, 2, "\n%s Geovector: -S=<size>[+a<angle>][+b][+e][+h<shape>][+j<just>][+l][+m][+n[<norm>[/<min>]]][+o<lon>/<lat>][+q][+r][+s][+t[b|e]<trim>][+z]", GMT_LINE_BULLET);
GMT_Usage (API, -3, "Azimuth and length must be in columns 4-5. "
"Append any of the units in %s to length [k].", GMT_LEN_UNITS_DISPLAY);
gmt_vector_syntax (API->GMT, 3+32, 3);
if (API->GMT->current.setting.run_mode == GMT_CLASSIC) /* -T has no purpose in modern mode */
GMT_Usage (API, 1, "\n-T Ignore all input files.");
GMT_Option (API, "U,V");
gmt_pen_syntax (API->GMT, 'W', NULL, "Set pen attributes [Default pen is %s].", NULL, 8);
GMT_Usage (API, 2, "To assign pen outline color via -Z, append +z.");
GMT_Option (API, "X");
GMT_Usage (API, 1, "\n-Z<value>|<file>[+t|T]");
GMT_Usage (API, -2, "Use <value> with -C<cpt> to determine <color> instead of via -G<color> or -W<pen>. "
"Use <file> to get per-line or polygon <values>. Two modifiers can also be used: ");
GMT_Usage (API, 3, "+t Expect transparency (0-100%%) instead of z-value in the last column of <file>.");
GMT_Usage (API, 3, "+T Expect both transparency (0-100%%) and z-value in last two columns of <file>.");
GMT_Usage (API, -2, "Control if the outline or fill (for polygons only) are affected: ");
GMT_Usage (API, 3, "%s To use <color> for fill, also select -G+z. ", GMT_LINE_BULLET);
GMT_Usage (API, 3, "%s To use <color> for an outline pen, also select -W<pen>+z.", GMT_LINE_BULLET);
GMT_Option (API, "a,bi");
if (gmt_M_showusage (API)) GMT_Usage (API, -2, "Default <ncols> is the required number of columns.");
GMT_Option (API, "c,di,e,f,g,h,i,l,p,qi,T,w,:,.");
return (GMT_MODULE_USAGE);
}
GMT_LOCAL unsigned int gmt_get_z_bands (struct GMTAPI_CTRL *API, struct PSXYZ_CTRL *Ctrl, char *text) {
unsigned int j = 0, n_errors = 0;
if (text[j] == '-') {Ctrl->W.pen.cptmode = 1; j++;}
if (text[j] == '+') {Ctrl->W.pen.cptmode = 3; j++;}
if (text[j] && gmt_getpen (API->GMT, &text[j], &Ctrl->W.pen)) {
gmt_pen_syntax (API->GMT, 'W', NULL, "sets pen attributes [Default pen is %s]:", NULL, 3);
GMT_Usage (API, 3, "+c Append l to apply cpt color (-C) to the pen only.");
GMT_Usage (API, 3, "+c Append f to apply cpt color (-C) to symbol fill.");
GMT_Usage (API, -2, "Give +c with no arguments for both effects [none].");
n_errors++;
}
return n_errors;
}
static int parse (struct GMT_CTRL *GMT, struct PSXYZ_CTRL *Ctrl, struct GMT_OPTION *options, struct GMT_SYMBOL *S) {
/* This parses the options provided to psxyz and sets parameters in Ctrl.
* Note Ctrl has already been initialized and non-zero default values set.
* Any GMT common options will override values set previously by other commands.
* It also replaces any file names specified as input or output with the data ID
* returned when registering these sources/destinations with the API.
*/
unsigned int n_errors = 0, ztype;
int n;
char txt_a[GMT_LEN256] = {""}, txt_b[GMT_LEN256] = {""}, txt_c[GMT_LEN256] = {""}, *c = NULL;
struct GMT_OPTION *opt = NULL;
struct GMTAPI_CTRL *API = GMT->parent;
for (opt = options; opt; opt = opt->next) { /* Process all the options given */
switch (opt->option) {
case '<': /* Skip input files after checking they exist */
if (GMT_Get_FilePath (API, GMT_IS_DATASET, GMT_IN, GMT_FILE_REMOTE, &(opt->arg))) n_errors++;
break;
/* Processes program-specific parameters */
case 'A': /* Turn off draw_arc mode */
n_errors += gmt_M_repeated_module_option (API, Ctrl->A.active);
switch (opt->arg[0]) {
case 'm': case 'y': case 'r': Ctrl->A.mode = GMT_STAIRS_Y; break;
case 'p': case 'x': case 't': Ctrl->A.mode = GMT_STAIRS_X; break;
#ifdef DEBUG
default: Ctrl->A.step = atof (opt->arg); break; /* Undocumented test feature */
#endif
}
break;
case 'C': /* Vary symbol color with z */
n_errors += gmt_M_repeated_module_option (API, Ctrl->C.active);
gmt_M_str_free (Ctrl->C.file);
if (opt->arg[0]) Ctrl->C.file = strdup (opt->arg);
break;
case 'D':
n_errors += gmt_M_repeated_module_option (API, Ctrl->D.active);
if ((n = sscanf (opt->arg, "%[^/]/%[^/]/%s", txt_a, txt_b, txt_c)) < 2) {
GMT_Report (API, GMT_MSG_ERROR, "Option -D: Give x and y [and z] offsets\n");
n_errors++;
}
else {
Ctrl->D.dx = gmt_M_to_inch (GMT, txt_a);
Ctrl->D.dy = gmt_M_to_inch (GMT, txt_b);
if (n == 3) Ctrl->D.dz = gmt_M_to_inch (GMT, txt_c);
}
break;
case 'G': /* Set color for symbol or polygon */
n_errors += gmt_M_repeated_module_option (API, Ctrl->G.active);
if (strncmp (opt->arg, "+z", 2U) == 0)
Ctrl->G.set_color = true;
else if (!opt->arg[0] || gmt_getfill (GMT, opt->arg, &Ctrl->G.fill)) {
gmt_fill_syntax (GMT, 'G', NULL, " ");
n_errors++;
}
if (Ctrl->G.fill.rgb[0] < -4.0) Ctrl->G.sequential = irint (Ctrl->G.fill.rgb[0] + 7.0);
break;
case 'H': /* Overall symbol/pen scale column provided */
n_errors += gmt_M_repeated_module_option (API, Ctrl->H.active);
if (opt->arg[0]) { /* Gave a fixed scale - no reading from file */
Ctrl->H.value = atof (opt->arg);
Ctrl->H.mode = PSXYZ_CONST_SCALE;
}
break;
case 'I': /* Adjust symbol color via intensity */
n_errors += gmt_M_repeated_module_option (API, Ctrl->I.active);
if (opt->arg[0])
Ctrl->I.value = atof (opt->arg);
else
Ctrl->I.mode = 1;
break;
case 'L': /* Force closed polygons */
n_errors += gmt_M_repeated_module_option (API, Ctrl->L.active);
if ((c = strstr (opt->arg, "+b")) != NULL) /* Build asymmetric polygon from lower and upper bounds */
Ctrl->L.anchor = PSXYZ_POL_ASYMM_ENV;
else if ((c = strstr (opt->arg, "+d")) != NULL) /* Build symmetric polygon from deviations about y(x) */
Ctrl->L.anchor = PSXYZ_POL_SYMM_DEV;
else if ((c = strstr (opt->arg, "+D")) != NULL) /* Build asymmetric polygon from deviations about y(x) */
Ctrl->L.anchor = PSXYZ_POL_ASYMM_DEV;
else if ((c = strstr (opt->arg, "+x")) != NULL) { /* Parse x anchors for a polygon */
switch (c[2]) {
case 'l': Ctrl->L.mode = XLO; break; /* Left side anchors */
case 'r': Ctrl->L.mode = XHI; break; /* Right side anchors */
default: Ctrl->L.mode = ZLO; Ctrl->L.value = atof (&c[2]); break; /* Arbitrary x anchor */
}
Ctrl->L.anchor = PSXYZ_POL_X;
}
else if ((c = strstr (opt->arg, "+y")) != NULL) { /* Parse y anchors for a polygon */
switch (c[2]) {
case 'b': Ctrl->L.mode = YLO; break; /* Bottom side anchors */
case 't': Ctrl->L.mode = YHI; break; /* Top side anchors */
default: Ctrl->L.mode = ZHI; Ctrl->L.value = atof (&c[2]); break; /* Arbitrary y anchor */
}
Ctrl->L.anchor = PSXYZ_POL_Y;
}
else /* Just force a closed polygon */
Ctrl->L.polygon = true;
if ((c = strstr (opt->arg, "+p")) != NULL) { /* Want outline */
if (c[2] && gmt_getpen (GMT, &c[2], &Ctrl->L.pen)) {
gmt_pen_syntax (GMT, 'W', NULL, "sets pen attributes [no outline]", NULL, 0);
n_errors++;
}
Ctrl->L.outline = 1;
}
break;
case 'N': /* Do not clip to map */
n_errors += gmt_M_repeated_module_option (API, Ctrl->N.active);
if (opt->arg[0] == 'r') Ctrl->N.mode = PSXYZ_NO_CLIP_REPEAT;
else if (opt->arg[0] == 'c') Ctrl->N.mode = PSXYZ_CLIP_NO_REPEAT;
else if (opt->arg[0] == '\0') Ctrl->N.mode = PSXYZ_NO_CLIP_NO_REPEAT;
else {
GMT_Report (API, GMT_MSG_ERROR, "Option -N: Unrecognized argument %s\n", opt->arg);
n_errors++;
}
break;
case 'Q': /* Do not sort symbols based on distance */
n_errors += gmt_M_repeated_module_option (API, Ctrl->Q.active);
n_errors += gmt_get_no_argument (GMT, opt->arg, opt->option, 0);
break;
case 'S': /* Get symbol [and size] */
n_errors += gmt_M_repeated_module_option (API, Ctrl->S.active);
Ctrl->S.arg = strdup (opt->arg);
break;
case 'T': /* Skip all input files */
n_errors += gmt_M_repeated_module_option (API, Ctrl->T.active);
n_errors += gmt_get_no_argument (GMT, opt->arg, opt->option, 0);
break;
case 'W': /* Set line attributes */
n_errors += gmt_M_repeated_module_option (API, Ctrl->W.active);
if ((c = strstr (opt->arg, "+z"))) {
Ctrl->W.set_color = true;
c[0] = '\0'; /* Chop off this modifier */
}
if (opt->arg[0] == '-' || (opt->arg[0] == '+' && opt->arg[1] != 'c')) { /* Definitively old-style args */
if (gmt_M_compat_check (API->GMT, 5)) { /* Sorry */
GMT_Report (API, GMT_MSG_ERROR, "Your -W syntax is obsolete; see program usage.\n");
n_errors++;
}
else {
GMT_Report (API, GMT_MSG_ERROR, "Your -W syntax is obsolete; see program usage.\n");
n_errors += gmt_get_z_bands (API, Ctrl, opt->arg);
}
}
else if (opt->arg[0] && gmt_getpen (GMT, opt->arg, &Ctrl->W.pen)) {
gmt_pen_syntax (GMT, 'W', NULL, "sets pen attributes [Default pen is %s]:", NULL, 11);
n_errors++;
}
if (Ctrl->W.pen.cptmode) Ctrl->W.cpt_effect = true;
if (c) c[0] = '+'; /* Restore */
if (Ctrl->W.pen.rgb[0] < -4.0) Ctrl->W.sequential = irint (Ctrl->W.pen.rgb[0] + 7.0);
break;
case 'Z': /* Get value for CPT lookup */
n_errors += gmt_M_repeated_module_option (API, Ctrl->Z.active);
if ((c = strstr (opt->arg, "+t"))) {
Ctrl->Z.set_transp = 1;
c[0] = '\0'; /* Chop off this modifier */
}
else if ((c = strstr (opt->arg, "+T"))) {
Ctrl->Z.set_transp = 2;
c[0] = '\0'; /* Chop off this modifier */
}
if (gmt_not_numeric (GMT, opt->arg) && !gmt_access (GMT, opt->arg, R_OK)) { /* Got a file */
Ctrl->Z.file = strdup (opt->arg);
n_errors += gmt_M_check_condition (GMT, Ctrl->Z.file && gmt_access (GMT, Ctrl->Z.file, R_OK),
"Option -Z: Cannot read file %s!\n", Ctrl->Z.file);
}
else { /* Got a value */
ztype = (strchr (opt->arg, 'T')) ? GMT_IS_ABSTIME : gmt_M_type (GMT, GMT_IN, GMT_Z);
n_errors += gmt_verify_expectations (GMT, ztype, gmt_scanf_arg (GMT, opt->arg, ztype, false, &Ctrl->Z.value), opt->arg);
}
break;
default: /* Report bad options */
n_errors += gmt_default_option_error (GMT, opt);
break;
}
}
gmt_consider_current_cpt (API, &Ctrl->C.active, &(Ctrl->C.file));
if (Ctrl->T.active) GMT_Report (API, GMT_MSG_WARNING, "Option -T ignores all input files\n");
n_errors += gmt_M_check_condition (GMT, Ctrl->Z.active && Ctrl->Z.set_transp != 1 && !Ctrl->C.active, "Option -Z: No CPT given via -C\n");
n_errors += gmt_M_check_condition (GMT, Ctrl->C.active && (Ctrl->C.file == NULL || Ctrl->C.file[0] == '\0'), "Option -C: No CPT given\n");
n_errors += gmt_M_check_condition (GMT, !GMT->common.R.active[RSET], "Must specify -R option\n");
n_errors += gmt_M_check_condition (GMT, !GMT->common.J.active, "Must specify a map projection with the -J option\n");
n_errors += gmt_M_check_condition (GMT, Ctrl->S.active && gmt_parse_symbol_option (GMT, Ctrl->S.arg, S, 1, true), "Option -S: Parsing failure\n");
n_errors += gmt_M_check_condition (GMT, GMT->common.b.active[GMT_IN] && S->symbol == GMT_SYMBOL_NOT_SET, "Binary input data cannot have symbol information\n");
n_errors += gmt_M_check_condition (GMT, Ctrl->W.active && Ctrl->W.pen.cptmode && !Ctrl->C.active, "Option -W modifier +c requires the -C option\n");
n_errors += gmt_M_check_condition (GMT, Ctrl->L.anchor && (!Ctrl->G.active && !Ctrl->Z.active) && !Ctrl->L.outline, "Option -L<modifiers> must include +p<pen> if -G not given\n");
if (Ctrl->S.active && gmt_is_barcolumn (GMT, S)) {
n = gmt_get_columbar_bands (GMT, S);
n_errors += gmt_M_check_condition (GMT, n > 1 && !Ctrl->C.active, "Options -Sb|B|o|O with multiple layers require -C\n");
}
return (n_errors ? GMT_PARSE_ERROR : GMT_NOERROR);
}
GMT_LOCAL void psxyz_column3D (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x, double y, double z, double *dim, double rgb[3][4], int outline) {
int i, k;
double x_size, y_size, z_size, sign;
x_size = 0.5 * dim[0];
y_size = 0.5 * dim[1];
z_size = 0.5 * dim[2];
for (i = 0; i < 3; i++) {
sign = -1.0;
k = GMT->current.proj.z_project.face[i] / 2;
PSL_setfill (PSL, rgb[k], outline);
switch (GMT->current.proj.z_project.face[i]) {
case 0: /* yz plane positive side */
sign = 1.0;
/* Intentionally fall through - after flipping the sign */
case 1: /* negative side */
gmt_plane_perspective (GMT, GMT_X, x + sign * x_size);
PSL_plotbox (PSL, y - y_size, z - z_size, y + y_size, z + z_size);
break;
case 2: /* xz plane positive side */
sign = 1.0;
/* Intentionally fall through - after flipping the sign */
case 3: /* negative side */
gmt_plane_perspective (GMT, GMT_Y, y + sign * y_size);
PSL_plotbox (PSL, x - x_size, z - z_size, x + x_size, z + z_size);
break;
case 4: /* xy plane positive side */
sign = 1.0;
/* Intentionally fall through - after flipping the sign */
case 5: /* negative side */
gmt_plane_perspective (GMT, GMT_Z, z + sign * z_size);
PSL_plotbox (PSL, x - x_size, y - y_size, x + x_size, y + y_size);
break;
}
}
}
GMT_LOCAL int psxyz_dist_compare (const void *a, const void *b) {
if (((struct PSXYZ_DATA *)a)->dist[0] < ((struct PSXYZ_DATA *)b)->dist[0]) return (-1);
if (((struct PSXYZ_DATA *)a)->dist[0] > ((struct PSXYZ_DATA *)b)->dist[0]) return (1);
if (((struct PSXYZ_DATA *)a)->dist[1] < ((struct PSXYZ_DATA *)b)->dist[1]) return (-1);
if (((struct PSXYZ_DATA *)a)->dist[1] > ((struct PSXYZ_DATA *)b)->dist[1]) return (1);
#if defined(WIN32) || defined(__MINGW32__)
/* MSVC qsort call a quick sorting function when number of elements to sort is small. e.g.
* below a certain size, it is faster to use a O(n^2) sorting method *
if (size <= CUTOFF) {
__SHORTSORT(lo, hi, width, comp, context);
}
and that function damn looks bugged as it imposes
if (__COMPARE(context, p, max) > 0) { ...
as condition to NOT change order (instead of >= 0). Se we force the hand here and
return 1 to circumvent that bad behavior
Note: Since it uses MSVCRT.DLL MinGW GCC suffers from the same bug
*/
return (1);
#else
return (0);
#endif
}
GMT_LOCAL bool psxyz_no_z_variation (struct GMT_CTRL *GMT, struct GMT_DATASEGMENT *L) {
/* Determine if we are on a constant z-level plane */
unsigned int row;
gmt_M_unused (GMT);
for (row = 1; row < L->n_rows; row++) {
if (!doubleAlmostEqualZero (L->data[GMT_Z][row], L->data[GMT_Z][row-1])) return false;
}
return (true);
}
GMT_LOCAL bool psxyz_load_bands (struct GMT_CTRL *GMT, double *in, double *out, unsigned int n, uint64_t rec, struct GMT_SYMBOL *S) {
/* Accumulate and project to projected values */
unsigned int k, kk, col;
double xx, yy;
for (col = GMT_Z, k = 0; k < n; k++, col++ ) { /* Place the x, y, z OR dx, dy, or dz increments in the out array */
if (S->symbol == GMT_SYMBOL_BARX) /* Must pick first x, then what follows z */
kk = (k == 0) ? GMT_X : col;
else if (S->symbol == GMT_SYMBOL_BARY) /* Must pick first y, then what follows z */
kk = (k == 0) ? GMT_Y : col;
else /* just pick z columns */
kk = col;
out[k] = in[kk];
}
if (S->accumulate) { /* Do the accumulation of increments into absolute values */
for (k = 1; k < n; k++)
out[k] += out[k-1];
}
if (S->base_set & GMT_BASE_ORIGIN) { /* Add the new origin offset */
for (k = 0; k < n; k++)
out[k] += S->base;
}
/* Now we have final x1, x2, x3... or y1, y2, y3..., or z1, z2, z3... in the data array in user units */
for (k = 1; k < n; k++) { /* Check things are monotonically increasing for single bars or columns */
if (!S->sidebyside && out[k] < out[k-1]) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "The -Sb|B|o|O options require monotonically increasing band-values - not true near line %d\n", rec);
return true;
}
}
/* Now project the data values to projected units */
for (k = 0; k < n; k++) {
if (S->symbol == GMT_SYMBOL_BARX) { /* Project and keep the projected x values */
gmt_geo_to_xy (GMT, out[k], in[GMT_Y], &xx, &yy);
out[k] = xx;
}
else if (S->symbol == GMT_SYMBOL_BARY) { /* Project and keep the projected y values */
gmt_geo_to_xy (GMT, in[GMT_X], out[k], &xx, &yy);
out[k] = yy;
}
else /* Just get the projected z values */
out[k] = gmt_z_to_zz (GMT, out[k]);
}
return false;
}
#define bailout(code) {gmt_M_free_options (mode); return (code);}
#define Return(code) {Free_Ctrl (GMT, Ctrl); gmt_end_module (GMT, GMT_cpy); bailout (code);}
EXTERN_MSC int GMT_psxyz (void *V_API, int mode, void *args) {
/* High-level function that implements the psxyz task */
bool polygon = false, penset_OK = true, not_line = false, old_is_world = false, seq_legend = false, use_z_table = false;
bool get_rgb = false, read_symbol = false, clip_set = false, fill_active = false, rgb_from_z = false, QR_symbol = false;
bool default_outline = false, outline_active = false, save_u = false, geovector = false, can_update_headpen = true;
unsigned int k, j, geometry, tbl, pos2x, pos2y, xcol = 0, icol = 0, tcol_f = 0, tcol_s = 0, grid_order, frame_order, n_z = 0;
unsigned int n_cols_start = 3, justify, v4_outline = 0, v4_status = 0, bcol, ex1, ex2, ex3, change = 0, n_needed = 0;
int error = GMT_NOERROR, seq_n_legends = 0, seq_frequency = 0;
uint64_t i, n, n_total_read = 0, n_z_for_cpt = 0;
size_t n_alloc = 0;
char s_args[GMT_BUFSIZ] = {""};
double dim[PSL_MAX_DIMS], rgb[3][4] = {{-1.0, -1.0, -1.0, 0.0}, {-1.0, -1.0, -1.0, 0.0}, {-1.0, -1.0, -1.0, 0.0}};
double DX = 0, DY = 0, *xp = NULL, *yp = NULL, *in = NULL, *v4_rgb = NULL, *z_for_cpt = NULL;
double lux[3] = {0.0, 0.0, 0.0}, tmp, x_1, x_2, y_1, y_2, dx, dy, s, c, zz, zb, length, base;
double bar_gap, bar_width, bar_step, nominal_size_x, nominal_size_y, *t_for_cpt = NULL;
double axes[2] = {0.0, 0.0}, Az = 0.0, factor = 1.0;
struct GMT_PEN default_pen, current_pen, last_headpen, last_spiderpen;
struct GMT_FILL default_fill, current_fill, black, no_fill;
struct GMT_SYMBOL S;
struct GMT_PALETTE *P = NULL;
struct GMT_PALETTE_HIDDEN *PH = NULL;
struct GMT_DATASEGMENT *L = NULL;
struct PSXYZ_DATA *data = NULL;
struct PSXYZ_CTRL *Ctrl = NULL;
struct GMT_CTRL *GMT = NULL, *GMT_cpy = NULL; /* General GMT internal parameters */
struct GMT_OPTION *options = NULL;
struct PSL_CTRL *PSL = NULL; /* General PSL internal parameters */
struct GMTAPI_CTRL *API = gmt_get_api_ptr (V_API); /* Cast from void to GMTAPI_CTRL pointer */
/*----------------------- Standard module initialization and parsing ----------------------*/
if (API == NULL) return (GMT_NOT_A_SESSION);
if (mode == GMT_MODULE_PURPOSE) return (usage (API, GMT_MODULE_PURPOSE)); /* Return the purpose of program */
options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */
if (API->GMT->current.setting.run_mode == GMT_CLASSIC) { /* Classic requires options, while modern does not */
if ((error = gmt_report_usage (API, options, 0, usage)) != GMT_NOERROR) bailout (error); /* Give usage if requested */
}
else {
if (options && options->option == GMT_OPT_SYNOPSIS) bailout (usage (API, GMT_SYNOPSIS)); /* Return the synopsis */
if (API->usage || (options && options->option == GMT_OPT_USAGE)) bailout (usage (API, GMT_USAGE)); /* Return the usage message */
}
/* Parse the command-line arguments; return if errors are encountered */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, module_kw, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error);
/* Initialize GMT_SYMBOL structure */
gmt_M_memset (&S, 1, struct GMT_SYMBOL);
gmt_M_memset (&last_headpen, 1, struct GMT_PEN);
gmt_M_memset (&last_spiderpen, 1, struct GMT_PEN);
gmt_contlabel_init (GMT, &S.G, 0);
S.base = GMT->session.d_NaN;
S.font = GMT->current.setting.font_annot[GMT_PRIMARY];
S.u = GMT->current.setting.proj_length_unit;
S.justify = PSL_MC;
Ctrl = New_Ctrl (GMT); /* Allocate and initialize a new control structure */
if ((error = parse (GMT, Ctrl, options, &S)) != 0) Return (error);
/*---------------------------- This is the psxyz main code ----------------------------*/
if (!Ctrl->T.active) GMT_Report (API, GMT_MSG_INFORMATION, "Processing input table data\n");
GMT->current.plot.mode_3D = 1; /* Only do background axis first; do foreground at end */
nominal_size_x = S.size_x;
nominal_size_y = S.size_y;
/* Do we plot actual symbols, or lines */
not_line = (S.symbol != GMT_SYMBOL_FRONT && S.symbol != GMT_SYMBOL_QUOTED_LINE && S.symbol != GMT_SYMBOL_LINE);
read_symbol = (S.symbol == GMT_SYMBOL_NOT_SET);
gmt_init_fill (GMT, &black, 0.0, 0.0, 0.0); /* Default fill for points, if needed */
gmt_init_fill (GMT, &no_fill, -1.0, -1.0, -1.0);
if (Ctrl->C.active || Ctrl->Z.file) {
if (Ctrl->C.active ) {
if ((P = GMT_Read_Data (API, GMT_IS_PALETTE, GMT_IS_FILE, GMT_IS_NONE, GMT_READ_NORMAL, NULL, Ctrl->C.file, NULL)) == NULL) {
Return (API->error);
}
get_rgb = not_line; /* Need to assign color from either z or text from input data file */
}
if (Ctrl->Z.active) { /* Get color from cpt -Z and store in -G */
if (Ctrl->Z.file) {
/* Must temporarily let the x-column contain datavalues for the CPT lookup */
struct GMT_DATASET *Zin = NULL;
enum gmt_col_enum x_col_type = gmt_get_column_type (GMT, GMT_IN, GMT_X);
enum gmt_col_enum v_col_type = gmt_get_column_type (GMT, GMT_IN, 3);
gmt_disable_bghio_opts (GMT); /* Do not want any -b -g -h -i -o to affect the reading from -Z file */
gmt_set_column_type (GMT, GMT_IN, GMT_X, v_col_type);
if ((Zin = GMT_Read_Data (API, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_POINT, GMT_IO_ASCII, NULL, Ctrl->Z.file, NULL)) == NULL) {
Return (API->error);
}
gmt_set_column_type (GMT, GMT_IN, GMT_X, x_col_type);
gmt_reenable_bghio_opts (GMT); /* Recover settings provided by user (if -b -g -h -i were used at all) */
if (Zin->n_segments > 1) {
GMT_Report (API, GMT_MSG_ERROR, "The file given via -Z must have a single segment with one z-value for each polygon in the input file\n");
Return (API->error);
}
if (Zin->n_columns == 0) {
GMT_Report (API, GMT_MSG_ERROR, "The file given via -Z must have a at least one data column and we will choose the last column\n");
Return (API->error);
}
n_z_for_cpt = Zin->table[0]->segment[0]->n_rows; /* Remember length of segment */
if (Ctrl->Z.set_transp == 2) { /* This needs two columns */
if (Zin->n_columns < 2) {
GMT_Report (API, GMT_MSG_ERROR, "Option -Z: The file must have two columns (transparency and z-value) when modifier +T is used\n");
Return (API->error);
}
}
if (Ctrl->Z.set_transp == 2) { /* Got z and transp */
t_for_cpt = gmt_M_memory (GMT, NULL, n_z_for_cpt, double);
z_for_cpt = gmt_M_memory (GMT, NULL, n_z_for_cpt, double);
gmt_M_memcpy (z_for_cpt, Zin->table[0]->segment[0]->data[Zin->n_columns-1], n_z_for_cpt, double);
gmt_M_memcpy (t_for_cpt, Zin->table[0]->segment[0]->data[Zin->n_columns-2], n_z_for_cpt, double);
}
else if (Ctrl->Z.set_transp == 1) { /* Got just transp */
t_for_cpt = gmt_M_memory (GMT, NULL, n_z_for_cpt, double);
gmt_M_memcpy (t_for_cpt, Zin->table[0]->segment[0]->data[Zin->n_columns-1], n_z_for_cpt, double);
}
else { /* Just z-column */
z_for_cpt = gmt_M_memory (GMT, NULL, n_z_for_cpt, double);
gmt_M_memcpy (z_for_cpt, Zin->table[0]->segment[0]->data[Zin->n_columns-1], n_z_for_cpt, double);
}
use_z_table = (z_for_cpt || t_for_cpt);
if (GMT_Destroy_Data (API, &Zin) != GMT_NOERROR) { /* Finished with this file */
Return (API->error);
}
}
else {
double rgb[4];
(void)gmt_get_rgb_from_z (GMT, P, Ctrl->Z.value, rgb);
if (Ctrl->W.set_color) /* To be used in polygon or symbol outline */
gmt_M_rgb_copy (Ctrl->W.pen.rgb, rgb);
if (Ctrl->G.set_color) /* To be used in polygon or symbol fill */
gmt_M_rgb_copy (Ctrl->G.fill.rgb, rgb);
}
get_rgb = false; /* Not reading z from data */
}
else if ((P->categorical & GMT_CPT_CATEGORICAL_KEY)) /* Get rgb from trailing text, so read no extra z columns */
rgb_from_z = false;
else if (S.v.status & PSL_VEC_MAGCPT) /* Get rgb via user data magnitude and handle it per symbol */
rgb_from_z = false;
else { /* Read extra z column for symbols only */
rgb_from_z = not_line;
if (rgb_from_z && (P->categorical & GMT_CPT_CATEGORICAL_KEY) == 0) n_cols_start++;
}
}
polygon = (S.symbol == GMT_SYMBOL_LINE && (Ctrl->G.active || Ctrl->L.polygon) && !Ctrl->L.anchor);
if (Ctrl->W.cpt_effect && Ctrl->W.pen.cptmode & 2) polygon = true;
if (Ctrl->G.set_color) polygon = true;
default_pen = current_pen = Ctrl->W.pen;
current_fill = default_fill = (S.symbol == PSL_DOT && !Ctrl->G.active) ? black : Ctrl->G.fill;
default_outline = Ctrl->W.active;
if (Ctrl->I.active && Ctrl->I.mode == 0) {
gmt_illuminate (GMT, Ctrl->I.value, current_fill.rgb);
gmt_illuminate (GMT, Ctrl->I.value, default_fill.rgb);
}
if (get_rgb && gmt_is_barcolumn (GMT, &S) && (n_z = gmt_get_columbar_bands (GMT, &S)) > 1) get_rgb = rgb_from_z = false; /* Not used in the same way here */
if (Ctrl->L.anchor == PSXYZ_POL_SYMM_DEV) n_cols_start += 1;
if (Ctrl->L.anchor == PSXYZ_POL_ASYMM_DEV || Ctrl->L.anchor == PSXYZ_POL_ASYMM_ENV) n_cols_start += 2;
/* Extra columns 1, 2, and 3 */
ex1 = (rgb_from_z) ? 4 : 3;
ex2 = (rgb_from_z) ? 5 : 4;
ex3 = (rgb_from_z) ? 6 : 5;
pos2x = ex1 + GMT->current.setting.io_lonlat_toggle[GMT_IN]; /* Column with a 2nd longitude (for VECTORS with two sets of coordinates) */
pos2y = ex2 - GMT->current.setting.io_lonlat_toggle[GMT_IN]; /* Column with a 2nd latitude (for VECTORS with two sets of coordinates) */
if (gmt_is_barcolumn (GMT, &S)) {
n_z = gmt_get_columbar_bands (GMT, &S); /* > 0 for multiband, else 0 */
n_needed = n_cols_start + ((n_z > 1) ? n_z - 2 : S.n_required);
}
else
n_needed = n_cols_start + S.n_required;
if (not_line)
gmt_set_column_types (GMT, n_cols_start, rgb_from_z, 7, &S); /* Handle the dimensional vs non-dimensional column types including if -i is used */
if (Ctrl->H.active && Ctrl->H.mode == PSXYZ_READ_SCALE) {
xcol = n_needed;
n_needed++; /* Read scaling from data file */
gmt_set_column_type (GMT, GMT_IN, xcol, GMT_IS_FLOAT);
}
if (Ctrl->I.mode) {
icol = n_needed;
n_needed++; /* Read intensity from data file */
gmt_set_column_type (GMT, GMT_IN, icol, GMT_IS_FLOAT);
}
if (GMT->common.t.variable) { /* Need one or two transparencies from file */
if (GMT->common.t.mode & GMT_SET_FILL_TRANSP) {
tcol_f = n_needed;
n_needed++; /* Read fill transparencies from data file */
gmt_set_column_type (GMT, GMT_IN, tcol_f, GMT_IS_FLOAT);
}
if (GMT->common.t.mode & GMT_SET_PEN_TRANSP) {
tcol_s = n_needed;
n_needed++; /* Read stroke transparencies from data file */
gmt_set_column_type (GMT, GMT_IN, tcol_s, GMT_IS_FLOAT);
}
}
if (gmt_check_binary_io (GMT, n_needed))
Return (GMT_RUNTIME_ERROR);
if (S.symbol == GMT_SYMBOL_QUOTED_LINE) {
if (gmt_contlabel_prep (GMT, &S.G, NULL))
Return (GMT_RUNTIME_ERROR);
penset_OK = false; /* Since it is set in PSL */
}
if (gmt_map_setup (GMT, GMT->common.R.wesn))
Return (GMT_PROJECTION_ERROR);
if (S.u_set) { /* When -Sc<unit> is given we temporarily reset the system unit to these units so conversions will work */
save_u = GMT->current.setting.proj_length_unit;
GMT->current.setting.proj_length_unit = S.u;
}
lux[0] = fabs (GMT->current.proj.z_project.sin_az * GMT->current.proj.z_project.cos_el);
lux[1] = fabs (GMT->current.proj.z_project.cos_az * GMT->current.proj.z_project.cos_el);
lux[2] = fabs (GMT->current.proj.z_project.sin_el);
tmp = MAX (lux[0], MAX (lux[1], lux[2]));
for (k = 0; k < 3; k++) lux[k] = (lux[k] / tmp) - 0.5;
if ((S.symbol == GMT_SYMBOL_COLUMN || S.symbol == GMT_SYMBOL_CUBE) && (!Ctrl->C.active || current_fill.rgb[0] >= 0)) { /* Modify the color for each facet */
for (k = 0; k < 3; k++) {
gmt_M_rgb_copy (rgb[k], current_fill.rgb);
if (S.shade3D) {
GMT_Report (API, GMT_MSG_DEBUG, "3-D shading illusion: lux[k] = %g\n", k, lux[k]);
gmt_illuminate (GMT, lux[k], rgb[k]);
}
}
}
if (GMT->current.proj.z_pars[0] == 0.0) { /* Only consider clipping if there is no z scaling */
if ((gmt_M_is_conical(GMT) && gmt_M_360_range (GMT->common.R.wesn[XLO], GMT->common.R.wesn[XHI]))) { /* Must turn clipping on for 360-range conical */
/* Special case of 360-range conical (which is periodic but do not touch at w=e) so we must clip to ensure nothing is plotted in the gap between west and east border */
clip_set = true;
frame_order = (Ctrl->N.active) ? GMT_BASEMAP_FRAME_BEFORE : GMT_BASEMAP_FRAME_AFTER;
}
else if (Ctrl->N.mode == PSXYZ_CLIP_REPEAT || Ctrl->N.mode == PSXYZ_CLIP_NO_REPEAT) { /* Only set clip if plotting symbols and -N not used */
clip_set = true;
frame_order = GMT_BASEMAP_FRAME_AFTER;
}
else
frame_order = (Ctrl->N.active) ? GMT_BASEMAP_FRAME_BEFORE : GMT_BASEMAP_FRAME_AFTER;
}
else
frame_order = GMT_BASEMAP_FRAME_BEFORE;
if ((PSL = gmt_plotinit (GMT, options)) == NULL) Return (GMT_RUNTIME_ERROR);
if (Ctrl->T.active) {
gmt_plotend (GMT);
Return (GMT_NOERROR);
}
gmt_plane_perspective (GMT, GMT_Z + GMT_ZW, GMT->current.proj.z_level);
grid_order = (polygon) ? GMT_BASEMAP_GRID_AFTER : GMT_BASEMAP_GRID_BEFORE;
gmt_set_basemap_orders (GMT, frame_order, grid_order, GMT_BASEMAP_ANNOT_BEFORE);
gmt_plotcanvas (GMT); /* Fill canvas if requested */
gmt_map_basemap (GMT); /* Lay down gridlines */
gmt_set_line_resampling (GMT, Ctrl->A.active, Ctrl->A.mode); /* Possibly change line resampling mode */
#ifdef DEBUG
/* Change default step size (in degrees) used for interpolation of line segments along great circles (if requested) */
if (Ctrl->A.active) Ctrl->A.step = Ctrl->A.step / GMT->current.proj.scale[GMT_X] / GMT->current.proj.M_PR_DEG;
#endif
if (clip_set) gmt_map_clip_on (GMT, GMT->session.no_rgb, 3);
gmt_plane_perspective (GMT, -1, 0.0);