forked from GenericMappingTools/gmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmt_plot.c
11337 lines (10316 loc) · 568 KB
/
gmt_plot.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-2024 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
*--------------------------------------------------------------------*/
/*
*
* G M T _ P L O T . C
*
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* GMT_plot.c contains code related to plotting maps. These functions requires
* we pass both the GMT and PSL control structure pointers.
*
* Author: Paul Wessel
* Date: 1-JAN-2010
* Version: 5
*
* A) List of exported gmt_* functions available to modules and libraries via gmt_dev.h:
*
* gmt_BB_clip_on
* gmt_add_label_record
* gmt_contlabel_plot
* gmt_contlabel_save_begin
* gmt_contlabel_save_end
* gmt_draw_custom_symbol
* gmt_draw_front
* gmt_draw_map_inset
* gmt_draw_map_panel
* gmt_draw_map_rose
* gmt_draw_map_scale
* gmt_draw_vertical_scale
* gmt_draw_vertical_scale_old
* gmt_export2proj4
* gmt_geo_line
* gmt_geo_polarcap_segment
* gmt_geo_polygons
* gmt_geo_rectangle
* gmt_geo_vector
* gmt_geo_wedge
* gmt_get_postscript
* gmt_importproj4
* gmt_inch_to_degree_scale
* gmt_linearx_grid
* gmt_map_basemap
* gmt_map_clip_off
* gmt_map_clip_on
* gmt_map_text
* gmt_map_title
* gmt_plane_perspective
* gmt_plot_geo_ellipse
* gmt_plot_grid_graticules
* gmt_plot_line
* gmt_plot_timex_grid
* gmt_plotcanvas
* gmt_plotend
* gmt_plotinit
* gmt_ps_append
* gmt_set_basemap_orders
* gmt_set_psfilename
* gmt_setfill
* gmt_setfont
* gmt_setpen
* gmt_strip_layer
* gmt_text_is_latex
* gmt_textpath_init
* gmt_vertical_axis
* gmt_xy_axis
* gmt_xy_axis2
*
* B) List of exported gmtlib_* functions available to libraries via gmt_internals.h:
*
* gmtlib_create_ps
* gmtlib_duplicate_ps
* gmtlib_ellipsoid_name_convert
* gmtlib_free_ps
* gmtlib_free_ps_ptr
* gmtlib_read_ps
* gmtlib_set_do_seconds
* gmtlib_write_ps
*
*/
#include "gmt_dev.h"
#include "gmt_internals.h"
#ifdef _WIN32
#include <windows.h>
#include <tlhelp32.h>
#endif
#define gmt_M_axis_is_geo_strict(C,axis) (((axis) == GMT_X && gmt_M_type (C, GMT_IN, axis) & GMT_IS_LON) || ((axis) == GMT_Y && gmt_M_type (C, GMT_IN, axis) & GMT_IS_LAT))
#define PSL_IZ(PSL,z) ((int)lrint ((z) * PSL->internal.dpu))
/* Local variables to this file */
static unsigned int GMT_n_annotations_skip[4] = {0, 0, 0, 0};
static size_t GMT_n_annotations[4] = {0, 0, 0, 0};
static size_t GMT_alloc_annotations[4] = {0, 0, 0, 0};
static double *GMT_x_annotation[4] = {NULL, NULL, NULL, NULL}, *GMT_y_annotation[4] = {NULL, NULL, NULL, NULL};
/* THese functions are public but used in a static function so declared here to avoid resorting */
void gmt_linearx_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, double dval);
/* Get bitmapped 600 dpi GMT glyph for timestamp. The glyph is a 90 x 220 pixel 1-bit image
and it is here represented as ceil (220 / 8) * 90 = 2520 bytes */
#define GMT_TIMESTAMP_DATESIZE 8.0 /* Fixed font size for date-clock timestamp portion */
#define GMT_TIMESTAMP_LABELSIZE 7.0 /* Fixed font size for optional user label timestamp portion */
#define GMT_TIMESTAMP_GLYPH_WIDTH 220 /* Fixed pixel width of glyph image */
#define GMT_TIMESTAMP_GLYPH_HEIGHT 90 /* Fixed pixel height of glyph image */
static unsigned char GMT_glyph[2520] = { /* The GMT glyph bitmap */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0x80, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f,
0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
0xc0, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xfc, 0x00, 0x00, 0x01,
0xff, 0xc0, 0x00, 0x00, 0x01, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0xff, 0xe0, 0x00, 0x00,
0x01, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x00, 0x00, 0xff, 0xf8, 0x7f,
0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff,
0xff, 0xc0, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xe0, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x03,
0xff, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x07, 0xff, 0xf8, 0x00, 0x00,
0x00, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xff, 0xfc, 0x3f, 0xff, 0xe0, 0x00, 0x07, 0xff, 0xf8, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0x80, 0x07,
0xff, 0xf0, 0x00, 0x07, 0xff, 0xfc, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0x80, 0x00, 0xff, 0xfc,
0x00, 0x0f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x01, 0xff, 0xfc, 0x00, 0x01, 0xff, 0xf8, 0x00, 0x07,
0xff, 0xfc, 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x07, 0xff, 0xe0, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x07, 0xff, 0xfc, 0x00, 0x00,
0x00, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x1f,
0xff, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x00, 0x0f, 0xff, 0xfe, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc0,
0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x00, 0x00, 0x00,
0x3f, 0xf8, 0x00, 0x0f, 0xff, 0xfe, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x03, 0xff,
0x80, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x0f,
0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x0f, 0xff, 0xff, 0x00, 0x00,
0x00, 0xff, 0xbf, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x07, 0xff,
0x80, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x0f, 0xfd, 0xff, 0x80, 0x00, 0x01, 0xff, 0xbf, 0xf0,
0x00, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xf8, 0x00, 0x0f, 0xfd, 0xff, 0x80, 0x00, 0x01, 0xff, 0x9f, 0xf8, 0x00, 0x00, 0x00, 0x7f,
0xf0, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x0f,
0xfd, 0xff, 0x80, 0x00, 0x01, 0xff, 0x9f, 0xf8, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x1f, 0xfc, 0xff, 0xc0, 0x00,
0x01, 0xff, 0x9f, 0xf8, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x7f, 0xf0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0xff, 0xc0, 0x00, 0x01, 0xff, 0x8f, 0xfc,
0x00, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0x0f, 0x00, 0x00, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0xf8, 0xff, 0xe0, 0x00, 0x01, 0xff, 0x8f, 0xfc, 0x00, 0x00, 0x00, 0x0f,
0xfc, 0x00, 0x00, 0x0f, 0x00, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
0xf8, 0x7f, 0xe0, 0x00, 0x03, 0xff, 0x8f, 0xfc, 0x00, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x00, 0x0f,
0x00, 0x01, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x7f, 0xe0, 0x00,
0x03, 0xff, 0x8f, 0xfc, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x0f, 0x00, 0x03, 0xff, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x7f, 0xf0, 0x00, 0x03, 0xff, 0x0f, 0xfe,
0x00, 0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x0f, 0x00, 0x07, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0xf8, 0x3f, 0xf0, 0x00, 0x03, 0xff, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x07,
0xff, 0x00, 0x00, 0x0f, 0x00, 0x07, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
0xf8, 0x3f, 0xf8, 0x00, 0x07, 0xff, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x0f,
0x00, 0x07, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x3f, 0xf8, 0x00,
0x07, 0xff, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x0f, 0x00, 0x07, 0xff, 0x00,
0x00, 0x03, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x1f, 0xf8, 0x1f, 0xf8, 0x00, 0x07, 0xfe, 0x07, 0xfe,
0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x0f, 0x00, 0x07, 0xff, 0x00, 0x00, 0x03, 0xff, 0xff,
0xff, 0xf8, 0x00, 0x1f, 0xf8, 0x1f, 0xfc, 0x00, 0x0f, 0xfe, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x03,
0xff, 0x00, 0x00, 0x0f, 0x00, 0x07, 0xff, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x1f,
0xf8, 0x1f, 0xfc, 0x00, 0x0f, 0xfe, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x0f,
0x00, 0x07, 0xff, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x1f, 0xf8, 0x0f, 0xfc, 0x00,
0x1f, 0xfc, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x0f, 0x00, 0x07, 0xff, 0x00,
0x00, 0x03, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x1f, 0xf8, 0x0f, 0xfe, 0x00, 0x1f, 0xfc, 0x07, 0xfe,
0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x0f, 0x00, 0x07, 0xff, 0x00, 0x00, 0x03, 0xff, 0xff,
0xff, 0xfc, 0x00, 0x1f, 0xf8, 0x0f, 0xfe, 0x00, 0x1f, 0xf8, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x07,
0xff, 0x00, 0x00, 0x0f, 0x00, 0x03, 0xff, 0x80, 0x00, 0x03, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x1f,
0xf8, 0x07, 0xfe, 0x00, 0x3f, 0xf8, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x0f,
0x00, 0x03, 0xff, 0x80, 0x00, 0x00, 0x03, 0xf8, 0x0f, 0xfc, 0x00, 0x1f, 0xf8, 0x07, 0xff, 0x00,
0x3f, 0xf0, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x0f, 0x00, 0x03, 0xff, 0x80,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x00, 0x1f, 0xf8, 0x07, 0xff, 0x00, 0x7f, 0xf0, 0x0f, 0xfc,
0x00, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x00, 0x0f, 0x00, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x0f, 0xfc, 0x00, 0x1f, 0xf8, 0x03, 0xff, 0x00, 0x7f, 0xe0, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x0f,
0xfe, 0x00, 0x00, 0x0f, 0x00, 0x00, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x00, 0x1f,
0xf8, 0x03, 0xff, 0x80, 0xff, 0xe0, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x1f, 0xfc, 0x03, 0xff, 0x80,
0xff, 0xc0, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x3f, 0xf0,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x1f, 0xfc, 0x01, 0xff, 0x81, 0xff, 0xc0, 0x1f, 0xf8,
0x00, 0x00, 0x00, 0x3f, 0xf8, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x07, 0xfe, 0x00, 0x0f, 0xfc, 0x01, 0xff, 0x81, 0xff, 0x80, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x3f,
0xf0, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x00, 0x0f,
0xfc, 0x00, 0xff, 0xc3, 0xff, 0x80, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x7f, 0xf0, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x00, 0x0f, 0xfc, 0x00, 0xff, 0xc3,
0xff, 0x00, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xe0, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x03, 0xff,
0xc0, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x00, 0x0f, 0xfc, 0x00, 0xff, 0xc7, 0xfe, 0x00, 0x3f, 0xe0,
0x00, 0x00, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x01, 0xff, 0xe0, 0x00, 0x00, 0x00,
0x0f, 0xff, 0x00, 0x0f, 0xfc, 0x00, 0x7f, 0xcf, 0xfe, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x03, 0xff,
0x80, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x80, 0x0f,
0xfc, 0x00, 0x7f, 0xef, 0xfc, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x1f, 0xfe, 0x00, 0x00, 0x00, 0x1f, 0xff, 0x80, 0x07, 0xfc, 0x00, 0x7f, 0xff,
0xf8, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x0f,
0xff, 0x80, 0x00, 0x00, 0x1f, 0xff, 0x80, 0x07, 0xfc, 0x00, 0x7f, 0xff, 0xf0, 0x00, 0xff, 0x80,
0x00, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00,
0x3f, 0xff, 0xc0, 0x07, 0xfc, 0x00, 0x3f, 0xff, 0xf0, 0x01, 0xff, 0x80, 0x00, 0x00, 0x3f, 0xf8,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xff, 0xff, 0xc0, 0x07,
0xfc, 0x00, 0x3f, 0xff, 0xe0, 0x01, 0xff, 0x00, 0x00, 0x00, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xe0, 0x03, 0xff, 0xff, 0xe0, 0x07, 0xfc, 0x00, 0x3f, 0xff,
0xc0, 0x03, 0xfe, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x0f, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xe0, 0x03, 0xfe, 0x00, 0x1f, 0xff, 0x80, 0x07, 0xfe, 0x00,
0x00, 0x01, 0xff, 0x80, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff,
0xff, 0xcf, 0xf0, 0x03, 0xfe, 0x00, 0x1f, 0xff, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x03, 0xff, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xc7, 0xf0, 0x03,
0xfe, 0x00, 0x1f, 0xff, 0x00, 0x0f, 0xf8, 0x00, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x83, 0xf0, 0x03, 0xfe, 0x00, 0x0f, 0xfe,
0x00, 0x1f, 0xf0, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xff, 0xff, 0xff, 0x81, 0xf8, 0x01, 0xfe, 0x00, 0x0f, 0xfc, 0x00, 0x1f, 0xe0, 0x00,
0x00, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff,
0xff, 0x00, 0xf8, 0x01, 0xfe, 0x00, 0x0f, 0xf8, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0x7f, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
};
struct GMT_CIRCLE { /* Helper variables needed to draw great or small circle heads */
double lon[2], lat[2]; /* Coordinates of arc end points */
double A[3], B[3]; /* Cartesian vector of arc end points */
double P[3]; /* Cartesian vector of the pole */
bool longway; /* True if the arc > 180 degrees */
double r0; /* Arc length in degrees */
double r; /* Will be 180 less if longway is true, otherwise r == r0 */
double colat; /* Colatitude of circle relative to pole */
double rot; /* Full opening angle of vector arc */
};
/* Local functions */
/* Converting LaTeX strings to EPS files. This is based on the discussion we had at
* https://github.com/GenericMappingTools/gmt/issues/4563#issuecomment-743374160.
* As long as the user has latex, dvips and required fonts installed this should work
* for everybody. P. Wessel, Dec 11, 2020.
*/
bool gmt_text_is_latex (struct GMT_CTRL *GMT, const char *string) {
/* Detect if string contains LaTeX commands, i.e., "....@[LaTeX...@[ ..." or "....<math>LaTeX...</math> ..." */
char *p;
gmt_M_unused (GMT);
if (string == NULL || string[0] == '\0') return false;
if ((p = strstr (string, "@[")) && strstr (&p[1], "@[")) return true;
if ((p = strstr (string, "<math>")) && strstr (&p[1], "</math>")) return true;
return false;
}
GMT_LOCAL bool gmtplot_has_title_breaks (struct GMT_CTRL *GMT, const char *string) {
/* Returns true if string has line-break escape sequences in it */
gmt_M_unused (GMT);
if (string == NULL || string[0] == '\0') return false;
return ((strstr (string, "<break>") || strstr (string, "@^")) ? true : false);
}
GMT_LOCAL unsigned char * gmtplot_latex_eps (struct GMT_CTRL *GMT, struct GMT_FONT *F, const char *string, struct imageinfo *h) {
/* Convert a string containing LaTeX syntax to an EPS image */
unsigned int i, o;
int error = 0;
char *text = NULL, *font, *code;
char tmpdir[PATH_MAX] = {""}, here[PATH_MAX] = {""}, file[PATH_MAX] = {""}, cmd[PATH_MAX] = {""};
unsigned char *picture = NULL;
FILE *fp = NULL;
struct GMTAPI_CTRL *API = GMT->parent;
if (gmtplot_has_title_breaks (GMT, string)) {
GMT_Report (API, GMT_MSG_ERROR, "LaTeX expressions are only allowed in single-line strings\n");
return NULL;
}
if (gmt_check_executable (GMT, "latex", "--version", NULL, NULL)) {
GMT_Report (API, GMT_MSG_DEBUG, "latex found.\n");
}
else {
GMT_Report (API, GMT_MSG_ERROR, "latex is not installed or not in your executable path - cannot process LaTeX to DVI.\n");
return NULL;
}
if (gmt_check_executable (GMT, "dvips", "--version", NULL, NULL)) {
GMT_Report (API, GMT_MSG_DEBUG, "dvips found.\n");
}
else {
GMT_Report (API, GMT_MSG_ERROR, "dvips is not installed or not in your executable path - cannot convert DVI to EPS.\n");
return NULL;
}
/* Create unique directory for outputs, stored in tmpdir */
if (gmt_create_tempdir (API, "gmt_latex", tmpdir))
return NULL;
/* Remember where we are */
if (getcwd (here, PATH_MAX) == NULL) {
GMT_Report (API, GMT_MSG_ERROR, "Unable to determine current working directory - exiting.\n");
return NULL;
}
gmt_replace_backslash_in_path (here);
/* Use tmpdir as the current directory */
if (chdir (tmpdir)) {
GMT_Report (API, GMT_MSG_ERROR, "Unable to change directory to %s - exiting.\n", tmpdir);
return NULL;
}
/* Create LaTeX file */
sprintf (file, "gmt_eq.tex");
if ((fp = fopen (file, "w")) == NULL) {
GMT_Report (API, GMT_MSG_ERROR, "gmtplot_latex_eps: Could not create LaTeX file %s.\n", file);
return NULL;
}
/* Replace any @[ or <math> ... </math> with $ */
text = strdup (string);
for (i = o = 0; i < strlen (string); i++) {
if (string[i] == '@' && string[i+1] == '[')
text[o++] = '$', i++;
else if (!strncmp (&string[i], "<math>", 6U))
text[o++] = '$', i += 5;
else if (!strncmp (&string[i], "</math>", 7U))
text[o++] = '$', i += 6;
else
text[o++] = string[i];
}
text[o] = '\0'; /* Terminate the now shortened string */
/* Check title font selection and pick corresponding fontpackagename and fontcode, if possible */
switch (F->id) {
case 0: case 1: case 2: case 3: font = "helvet"; code = "phv"; break;
case 4: case 5: case 6: case 7: font = "mathptmx"; code = "ptm"; break;
case 8: case 9: case 10: case 11: font = "courier"; code = "pcr"; break;
case 12: font = "symbol"; code = "psy"; break;
case 13: case 14: case 15: case 16: font = "avantgar"; code = "pag"; break;
case 17: case 18: case 19: case 20: font = "bookman"; code = "pbk"; break;
case 21: case 22: case 23: case 24: font = "helvet"; code = "phv"; break;
case 25: case 26: case 27: case 28: font = "newcent"; code = "pnc"; break;
case 29: case 30: case 31: case 32: font = "mathpazo"; code = "ppl"; break;
case 33: font = "zapfchan"; code = "pzc"; break;
case 34: font = "zapfding"; code = "pzd"; break;
default: font = code = NULL; /* Go with default */
}
/* Write LaTeX file content */
fprintf (fp, "\\documentclass{article}\n"); /* Default to 10p font size */
if (font) { /* Impose a selected font family, otherwise take default Computer Modern */
GMT_Report (API, GMT_MSG_DEBUG, "gmtplot_latex_eps: Selecting font %s [%s].\n", font, code);
fprintf (fp, "\\usepackage[T1]{fontenc}\\usepackage[utf8]{inputenc}\\usepackage{%s}\n", font);
}
fprintf (fp, "\\begin{document}\n\\thispagestyle{empty}\n"); /* No page number */
if (code) /* Select font */
fprintf (fp, "\\fontfamily{%s}\\selectfont\n", code);
fprintf (fp, "%s\n\\end{document}\n", text);
fclose (fp);
gmt_M_str_free (text);
/* Make script file for running latex and dvips */
#ifdef WIN32
sprintf (file, "gmt_eq.bat");
sprintf (cmd, "cmd /C gmt_eq.bat");
#else
sprintf (file, "gmt_eq.sh");
sprintf (cmd, "sh gmt_eq.sh");
#endif
if ((fp = fopen (file, "w")) == NULL) {
GMT_Report (API, GMT_MSG_ERROR, "gmtplot_latex_eps: Could not create script file %s.\n", file);
return NULL;
}
#ifdef WIN32
fprintf (fp, "latex -interaction=nonstopmode gmt_eq.tex > NUL\ndvips -q -E gmt_eq.dvi -o equation.eps\n");
#else
fprintf (fp, "latex -interaction=nonstopmode gmt_eq.tex > /dev/null\ndvips -q -E gmt_eq.dvi -o equation.eps\n");
#endif
fclose (fp);
/* Run the script via a system call */
if ((error = system (cmd))) {
GMT_Report (API, GMT_MSG_ERROR, "gmtplot_latex_eps: Running \"%s\" returned error %d.\n", cmd, error);
GMT_Report (API, GMT_MSG_ERROR, "gmtplot_latex_eps: Please run it manually to learn what LaTeX packages you are missing.\n", cmd, error);
GMT_Report (API, GMT_MSG_ERROR, "gmtplot_latex_eps: The script and logs can be found here: %s\n", tmpdir);
return NULL;
}
else { /* Success, now remove the temp files but not worry about the return code here */
#ifdef WIN32
system ("del gmt_eq.*");
#else
system ("rm -f gmt_eq.*");
#endif
}
/* Retrieve the EPS code */
gmt_M_memset (h, 1U, struct imageinfo); /* Initialize information struct */
if (PSL_loadeps (GMT->PSL, "equation.eps", h, &picture)) {
GMT_Report (API, GMT_MSG_ERROR, "gmtplot_latex_eps: Unable to load EPS file equation.eps\n");
return NULL;
}
/* Change back to original directory */
if (chdir (here)) {
GMT_Report (API, GMT_MSG_ERROR, "gmtplot_latex_eps: Unable to change directory back to %s - exiting.\n", here);
PSL_free (picture);
return NULL;
}
/* Clean up */
if (gmt_remove_dir (API, tmpdir, false)) {
GMT_Report (API, GMT_MSG_ERROR, "gmtplot_latex_eps: Unable to remove temporary directory %s!\n", tmpdir);
PSL_free (picture);
return NULL;
}
/* Return the EPS data and size information via header */
return picture;
}
/* GMT_LINEAR PROJECTION MAP BOUNDARY */
GMT_LOCAL void gmtplot_linear_map_boundary (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n) {
unsigned int cap = PSL->internal.line_cap;
double x_length, y_length;
x_length = GMT->current.proj.rect[XHI] - GMT->current.proj.rect[XLO];
y_length = GMT->current.proj.rect[YHI] - GMT->current.proj.rect[YLO];
if (GMT->current.setting.map_frame_type == GMT_IS_GRAPH && GMT->current.setting.map_graph_origin_txt[0]) {
if (strchr (GMT->current.setting.map_graph_origin_txt, '/')) { /* Gave a coordinate pair */
/* Convert the graph origin string coordinates to internal values */
char txt_a[GMT_LEN128] = {""}, txt_b[GMT_LEN128] = {""};
unsigned int n_errors = 0;
sscanf (&GMT->current.setting.map_graph_origin_txt[2], "%[^/]/%s", txt_a, txt_b);
n_errors += gmt_verify_expectations (GMT, gmt_M_type (GMT, GMT_IN, GMT_X),
gmt_scanf_arg (GMT, txt_a, gmt_M_type (GMT, GMT_IN, GMT_X), false,
&GMT->current.setting.map_graph_origin[GMT_X]), txt_a);
n_errors += gmt_verify_expectations (GMT, gmt_M_type (GMT, GMT_IN, GMT_Y),
gmt_scanf_arg (GMT, txt_b, gmt_M_type (GMT, GMT_IN, GMT_Y), false,
&GMT->current.setting.map_graph_origin[GMT_Y]), txt_b);
if (n_errors) {
GMT_Report (GMT->parent, GMT_MSG_WARNING, "Graph origin modifier set with MAP_FRAME_TYPE could not be parsed (%s) - origin remains at (0,0)\n",
GMT->current.setting.map_graph_origin_txt);
gmt_M_memset (GMT->current.setting.map_graph_origin, 2, double);
}
}
else { /* Gave +oc for centered on current user domain */
GMT->current.setting.map_graph_origin[GMT_X] = 0.5 * (GMT->common.R.wesn[XLO] + GMT->common.R.wesn[XHI]);
GMT->current.setting.map_graph_origin[GMT_Y] = 0.5 * (GMT->common.R.wesn[YLO] + GMT->common.R.wesn[YHI]);
}
GMT->current.setting.map_graph_shift = 0.0;
}
PSL_command (PSL, "/PSL_slant_y 0 def /PSL_slant_x 0 def\n"); /* Unless x-annotations are slanted there is no adjustment. PSL_slant_y may be revised in gmt_xy_axis */
if (GMT->current.map.frame.draw) {
/* Temporarily change to square cap so rectangular frames have neat corners */
PSL_setlinecap (PSL, PSL_SQUARE_CAP);
if (GMT->current.map.frame.side[W_SIDE]) gmt_xy_axis (GMT, GMT->current.proj.rect[XLO], GMT->current.proj.rect[YLO], y_length, s, n,
&GMT->current.map.frame.axis[GMT_Y], true, GMT->current.map.frame.side[W_SIDE]); /* West or left y-axis */
if (GMT->current.map.frame.side[E_SIDE]) gmt_xy_axis (GMT, GMT->current.proj.rect[XHI], GMT->current.proj.rect[YLO], y_length, s, n,
&GMT->current.map.frame.axis[GMT_Y], false, GMT->current.map.frame.side[E_SIDE]); /* East or right y-axis */
if (GMT->current.map.frame.side[S_SIDE]) gmt_xy_axis (GMT, GMT->current.proj.rect[XLO], GMT->current.proj.rect[YLO], x_length, w, e,
&GMT->current.map.frame.axis[GMT_X], true, GMT->current.map.frame.side[S_SIDE]); /* South or lower x-axis */
if (GMT->current.map.frame.side[N_SIDE]) gmt_xy_axis (GMT, GMT->current.proj.rect[XLO], GMT->current.proj.rect[YHI], x_length, w, e,
&GMT->current.map.frame.axis[GMT_X], false, GMT->current.map.frame.side[N_SIDE]); /* North or upper x-axis */
PSL_setlinecap (PSL, cap); /* Reset back to default */
}
if (!GMT->current.map.frame.header[0] || GMT->current.map.frame.plotted_header) return; /* No title (and optional subtitle) today */
PSL_comment (PSL, "Placing plot title\n");
y_length += GMT->current.setting.map_graph_shift; /* Extra shift (set in gmt_xy_axis) for map title when we have a centered y-axis with vector */
if (!GMT->current.map.frame.draw || GMT->current.map.frame.side[N_SIDE] <= GMT_AXIS_DRAW || GMT->current.setting.map_frame_type == GMT_IS_INSIDE)
PSL_defunits (PSL, "PSL_H_y", GMT->current.setting.map_title_offset); /* No ticks or annotations, offset by map_title_offset only */
else
PSL_command (PSL, "/PSL_H_y PSL_L_y PSL_LH add %d add def\n", PSL_IZ (PSL, GMT->current.setting.map_title_offset)); /* For title adjustment */
PSL_command (PSL, "%d %d PSL_H_y add PSL_slant_y add M\n", PSL_IZ (PSL, 0.5 * x_length), PSL_IZ (PSL, y_length));
gmt_map_title (GMT, 0.0, 0.0);
}
GMT_LOCAL unsigned int gmtplot_get_primary_annot (struct GMT_PLOT_AXIS *A) {
/* Return the primary annotation item number [== GMT_ANNOT_UPPER if there are no unit set]*/
unsigned int i, no[2] = {GMT_ANNOT_UPPER, GMT_ANNOT_LOWER};
double val[2], s;
for (i = 0; i < 2; i++) {
val[i] = 0.0;
if (!A->item[no[i]].active || A->item[no[i]].type == 'i' || A->item[no[i]].type == 'I') continue;
switch (A->item[no[i]].unit) {
case 'Y': case 'y':
s = GMT_DAY2SEC_F * 365.25;
break;
case 'O': case 'o':
s = GMT_DAY2SEC_F * 30.5;
break;
case 'U': case 'u':
s = GMT_DAY2SEC_F * 7.0;
break;
case 'K': case 'k':
case 'D': case 'd':
s = GMT_DAY2SEC_F;
break;
case 'H': case 'h':
s = GMT_HR2SEC_F;
break;
case 'M': case 'm':
s = GMT_MIN2SEC_F;
break;
case 'C': case 'c':
s = 1.0;
break;
default: /* No unit specified - probably not a time axis */
s = 1.0;
break;
}
val[i] = A->item[no[i]].interval * s;
}
if (A->item[GMT_ANNOT_UPPER].special) return GMT_ANNOT_UPPER;
return ((val[0] > val[1]) ? GMT_ANNOT_UPPER : GMT_ANNOT_LOWER);
}
GMT_LOCAL bool gmtplot_skip_second_annot (unsigned int item, double x, double x2[], unsigned int n, unsigned int primary) {
unsigned int i;
bool found;
double small;
if (n < 2) return (false); /* Need at least two points so no need to skip */
if (item == primary) return (false); /* Not working on secondary annotation */
if (!x2) return (false); /* None given */
small = (x2[1] - x2[0]) * GMT_CONV4_LIMIT;
for (i = 0, found = false; !found && i < n; i++)
found = (fabs (x2[i] - x) < small);
return (found);
}
GMT_LOCAL void gmtplot_map_latline (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double lat, double west, double east) /* Draws a line of constant latitude */ {
uint64_t nn;
double *llon = NULL, *llat = NULL;
#ifdef DEBUG
uint64_t k;
FILE *fp = NULL;
char name[GMT_LEN64] = {""};
if (GMT->hidden.gridline_debug && (GMT->hidden.gridline_kind == 'x' || GMT->hidden.gridline_val != lat)) return;
#endif
nn = gmtlib_latpath (GMT, lat, west, east, &llon, &llat);
#ifdef DEBUG
if (GMT->hidden.gridline_debug) {
snprintf (name, GMT_LEN64, "gridline_y_%g_ll.txt", lat);
fp = fopen (name, "w");
for (k = 0; k < nn; k++) fprintf (fp, "%g\t%g\n", llon[k], llat[k]);
fclose (fp);
}
#endif
GMT->current.plot.n = gmt_geo_to_xy_line (GMT, llon, llat, nn);
#ifdef DEBUG
if (GMT->hidden.gridline_debug) {
snprintf (name, GMT_LEN64, "gridline_y_%g_xy.txt", lat);
fp = fopen (name, "w");
for (k = 0; k < GMT->current.plot.n; k++) fprintf (fp, "%g\t%g\t%d\n", GMT->current.plot.x[k], GMT->current.plot.y[k], GMT->current.plot.pen[k]);
fclose (fp);
}
#endif
if (GMT->current.plot.n > 1) { /* Need at least 2 points for a line */
PSL_comment (PSL, "Lat = %g\n", lat);
if (GMT->current.map.parallel_straight) { /* Simplify to a 2-point straight line */
GMT->current.plot.x[1] = GMT->current.plot.x[GMT->current.plot.n-1];
GMT->current.plot.y[1] = GMT->current.plot.y[GMT->current.plot.n-1];
GMT->current.plot.pen[1] = GMT->current.plot.pen[GMT->current.plot.n-1];
GMT->current.plot.n = 2;
}
gmt_plot_line (GMT, GMT->current.plot.x, GMT->current.plot.y, GMT->current.plot.pen, GMT->current.plot.n, PSL_LINEAR);
}
gmt_M_free (GMT, llon);
gmt_M_free (GMT, llat);
}
GMT_LOCAL void gmtplot_map_lonline (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double lon, double south, double north) /* Draws a line of constant longitude */ {
uint64_t nn;
double *llon = NULL, *llat = NULL;
#ifdef DEBUG
uint64_t k;
FILE *fp = NULL;
char name[GMT_LEN64] = {""};
if (GMT->hidden.gridline_debug && (GMT->hidden.gridline_kind == 'y' || GMT->hidden.gridline_val != lon)) return;
#endif
nn = gmtlib_lonpath (GMT, lon, south, north, &llon, &llat);
#ifdef DEBUG
if (GMT->hidden.gridline_debug) {
snprintf (name, GMT_LEN64, "gridline_x_%g_ll.txt", lon);
fp = fopen (name, "w");
for (k = 0; k < nn; k++) fprintf (fp, "%g\t%g\n", llon[k], llat[k]);
fclose (fp);
}
#endif
GMT->current.plot.n = gmt_geo_to_xy_line (GMT, llon, llat, nn);
#ifdef DEBUG
if (GMT->hidden.gridline_debug) {
snprintf (name, GMT_LEN64, "gridline_x_%g_xy.txt", lon);
fp = fopen (name, "w");
for (k = 0; k < GMT->current.plot.n; k++) fprintf (fp, "%g\t%g\t%d\n", GMT->current.plot.x[k], GMT->current.plot.y[k], GMT->current.plot.pen[k]);
fclose (fp);
}
#endif
if (GMT->current.plot.n > 1) { /* Need at least 2 points for a line */
PSL_comment (PSL, "Lon = %g\n", lon);
if (GMT->current.map.meridian_straight) { /* Simplify to a 2-point straight line */
GMT->current.plot.x[1] = GMT->current.plot.x[GMT->current.plot.n-1];
GMT->current.plot.y[1] = GMT->current.plot.y[GMT->current.plot.n-1];
GMT->current.plot.pen[1] = GMT->current.plot.pen[GMT->current.plot.n-1];
GMT->current.plot.n = 2;
}
gmt_plot_line (GMT, GMT->current.plot.x, GMT->current.plot.y, GMT->current.plot.pen, GMT->current.plot.n, PSL_LINEAR);
}
gmt_M_free (GMT, llon);
gmt_M_free (GMT, llat);
}
GMT_LOCAL void gmtplot_linearx_oblgrid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, double dval) {
/* x gridlines in oblique coordinates for all but the Oblique Mercator projection [which already is oblique] */
double *x = NULL, *lon = NULL, *lat = NULL, *lat_obl = NULL, tval, p_cap, s_cap;
unsigned int idup = 0, i, j, k, nx, np, nc1 = 0, nc2, npc, np1;
bool cap = false;
gmt_M_unused(PSL); gmt_M_unused(w); gmt_M_unused(e);
/* Ideally we should determine the w/e/s/n of the oblique coordinates but here we will simply
* create oblique coordinates for the full 0/360/-90/90, convert to regular coordinates and
* then truncate points outside the actual w/e/s/n */
/* Do we have duplicate e and w boundaries ? */
p_cap = fabs (GMT->current.setting.map_polar_cap[0]);
s_cap = -p_cap;
idup = (gmt_M_is_azimuthal(GMT)) ? 1 : 0;
cap = !doubleAlmostEqual (p_cap, 90.0); /* true if we have a polar cap specified */
tval = (n - s) * GMT->current.setting.map_line_step / GMT->current.map.height;
nx = gmtlib_linear_array (GMT, 0.0, TWO_PI, D2R * dval, D2R * GMT->current.map.frame.axis[GMT_X].phase, &x);
np = gmtlib_linear_array (GMT, -90.0, 90.0, tval, 0.0, &lat_obl);
np1 = nc2 = np - 1; /* Nominal number of points in path */
lon = gmt_M_memory (GMT, NULL, np+2, double); /* Allow 2 more slots for possibly inserted cap-latitudes */
lat = gmt_M_memory (GMT, NULL, np+2, double);
for (i = 0; i < nx - idup; i++) { /* For each oblique meridian to draw */
/* Create lon,lat arrays of oblique coordinates for this meridian */
for (k = j = 0; k < np; k++, j++) {
gmtlib_iobl (GMT, &lon[j], &lat[j], x[i], D2R * lat_obl[k]); /* Get regular coordinates of this point */
lon[j] *= R2D; lat[j] *= R2D; /* Convert back to degrees */
if (lat_obl[k] < s_cap && k < np1 && lat_obl[k+1] > s_cap) { /* Must insert S pole cap latitude point */
j++; gmtlib_iobl (GMT, &lon[j], &lat[j], x[i], D2R * s_cap);
lon[j] *= R2D; lat[j] *= R2D; /* Back to degrees */
nc1 = j;
}
else if (lat_obl[k] < p_cap && k < np1 && lat_obl[k+1] > p_cap) { /* Must insert N pole cap latitude point */
j++; gmtlib_iobl (GMT, &lon[j], &lat[j], x[i], D2R * p_cap);
lon[j] *= R2D; lat[j] *= R2D; /* Back to degrees */
nc2 = j;
}
}
if (cap) { /* Only plot the line between the two polar caps */
npc = nc2 - nc1 + 1; /* Number of points along meridian bounded by caps */
if ((GMT->current.plot.n = gmt_geo_to_xy_line (GMT, &lon[nc1], &lat[nc1], npc)) == 0) continue;
}
else { /* No polar cap in effect, plot entire meridian */
if ((GMT->current.plot.n = gmt_geo_to_xy_line (GMT, lon, lat, j)) == 0) continue;
}
gmt_plot_line (GMT, GMT->current.plot.x, GMT->current.plot.y, GMT->current.plot.pen, GMT->current.plot.n, PSL_LINEAR);
}
if (nx) gmt_M_free (GMT, x);
if (cap) { /* Draw the polar cap(s) meridians with a separate lon spacing */
nx = gmtlib_linear_array (GMT, 0.0, TWO_PI, D2R * GMT->current.setting.map_polar_cap[1], D2R * GMT->current.map.frame.axis[GMT_X].phase, &x);
for (i = 0; i < nx - idup; i++) {
for (k = j = 0; k < np; k++, j++) {
gmtlib_iobl (GMT, &lon[j], &lat[j], x[i], D2R * lat_obl[k]); /* Get regular coordinates of this point */
lon[j] *= R2D; lat[j] *= R2D; /* Back to degrees */
if (lat_obl[k] < s_cap && k < np1 && lat_obl[k+1] > s_cap) { /* Must insert S pole cap latitude point */
j++; gmtlib_iobl (GMT, &lon[j], &lat[j], x[i], D2R * s_cap);
lon[j] *= R2D; lat[j] *= R2D; /* Back to degrees */
nc1 = j;
}
else if (lat_obl[k] < p_cap && k < np1 && lat_obl[k+1] > p_cap) { /* Must insert N pole cap latitude point */
j++; gmtlib_iobl (GMT, &lon[j], &lat[j], x[i], D2R * p_cap);
lon[j] *= R2D; lat[j] *= R2D; /* Back to degrees */
nc2 = j;
}
}
if ((GMT->current.plot.n = gmt_geo_to_xy_line (GMT, lon, lat, nc1+1)) > 0)
gmt_plot_line (GMT, GMT->current.plot.x, GMT->current.plot.y, GMT->current.plot.pen, GMT->current.plot.n, PSL_LINEAR);
if ((GMT->current.plot.n = gmt_geo_to_xy_line (GMT, &lon[nc2], &lat[nc2], j-nc2)) > 0)
gmt_plot_line (GMT, GMT->current.plot.x, GMT->current.plot.y, GMT->current.plot.pen, GMT->current.plot.n, PSL_LINEAR);
}
if (nx) gmt_M_free (GMT, x);
}
gmt_M_free (GMT, lat_obl);
gmt_M_free (GMT, lon);
gmt_M_free (GMT, lat);
}
GMT_LOCAL void gmtplot_lineary_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, double dval) {
double *y = NULL;
char *type = (gmt_M_y_is_lat (GMT, GMT_IN)) ? "parallel" : "y";
unsigned int i, ny = 0;
if (GMT->current.proj.z_down) {
if (GMT->current.proj.z_down == GMT_ZDOWN_Z) /* z = n - r */
ny = gmtlib_linear_array (GMT, 0.0, GMT->current.proj.z_radius-s, dval, GMT->current.map.frame.axis[GMT_Y].phase, &y);
else if (GMT->current.proj.z_down == GMT_ZDOWN_ZP) /* z = n - r */
ny = gmtlib_linear_array (GMT, GMT->current.proj.z_radius-n, GMT->current.proj.z_radius-s, dval, GMT->current.map.frame.axis[GMT_Y].phase, &y);
for (i = 0; i < ny; i++) {
if (GMT->current.proj.z_down == GMT_ZDOWN_ZP)
y[i] = GMT->current.proj.z_radius - y[i]; /* These are the z values needed for positioning */
else
y[i] = GMT->common.R.wesn[YHI] - y[i]; /* These are the radial values needed for positioning */
}
}
else
ny = gmtlib_linear_array (GMT, s, n, dval, GMT->current.map.frame.axis[GMT_Y].phase, &y);
for (i = 0; i < ny; i++) {
GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Draw %s = %g from %g to %g\n", type, y[i], w, e);
gmtplot_map_latline (GMT, PSL, y[i], w, e);
}
if (ny) gmt_M_free (GMT, y);
}
GMT_LOCAL void gmtplot_x_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double s, double n, double *x, unsigned int nx) {
unsigned int i;
double x1, y1, x2, y2;
for (i = 0; i < nx; i++) {
if (gmt_M_x_is_lon (GMT, GMT_IN))
gmtplot_map_lonline (GMT, PSL, x[i], s, n);
else {
gmt_geo_to_xy (GMT, x[i], s, &x1, &y1);
gmt_geo_to_xy (GMT, x[i], n, &x2, &y2);
PSL_plotsegment (PSL, x1, y1, x2, y2);
}
}
}
GMT_LOCAL void gmtplot_lineary_oblgrid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, double dval) {
/* y gridlines in oblique coordinates for all but the Oblique Mercator projection [which already is oblique] */
double *y = NULL, *lon = NULL, *lon_obl = NULL, *lat = NULL, tval, p_cap;
bool cap;
unsigned int i, k, ny, np;
gmt_M_unused(PSL); gmt_M_unused(s); gmt_M_unused(n);
/* Ideally we should determine the w/e/s/n of the oblique coordinates but here we will simply
* create oblique coordinates for the full 0/360/-90/90, convert to regular coordinates and
* then truncate points outside the actual w/e/s/n */
ny = gmtlib_linear_array (GMT, -M_PI_2, M_PI_2, D2R * dval, D2R * GMT->current.map.frame.axis[GMT_Y].phase, &y);
tval = (e - w) * GMT->current.setting.map_line_step / GMT->current.map.width;
np = gmtlib_linear_array (GMT, 0.0, TWO_PI, D2R * tval, 0.0, &lon_obl);
lon = gmt_M_memory (GMT, NULL, np+2, double); /* Allow 2 more slots for possibly inserted cap-latitudes */
lat = gmt_M_memory (GMT, NULL, np+2, double);
for (i = 0; i < ny; i++) {
for (k = 0; k < np; k++) {
gmtlib_iobl (GMT, &lon[k], &lat[k], lon_obl[k], y[i]); /* Get regular coordinates of this point */
lon[k] *= R2D; lat[k] *= R2D; /* Convert to degrees */
}
if ((GMT->current.plot.n = gmt_geo_to_xy_line (GMT, lon, lat, np)) == 0) continue;
gmt_plot_line (GMT, GMT->current.plot.x, GMT->current.plot.y, GMT->current.plot.pen, GMT->current.plot.n, PSL_LINEAR);
}
if (ny) gmt_M_free (GMT, y);
p_cap = fabs (GMT->current.setting.map_polar_cap[0]);
cap = !doubleAlmostEqual (p_cap, 90.0); /* true if we have a polar cap specified */
if (cap) { /* Draw the polar cap(s) with a separate spacing */
p_cap = D2R * GMT->current.setting.map_polar_cap[0];
for (k = 0; k < np; k++) { /* S polar cap */
gmtlib_iobl (GMT, &lon[k], &lat[k], lon_obl[k], -p_cap); /* Get regular coordinates of this point */
lon[k] *= R2D; lat[k] *= R2D; /* Convert to degrees */
}
if ((GMT->current.plot.n = gmt_geo_to_xy_line (GMT, lon, lat, np)) > 0)
gmt_plot_line (GMT, GMT->current.plot.x, GMT->current.plot.y, GMT->current.plot.pen, GMT->current.plot.n, PSL_LINEAR);
for (k = 0; k < np; k++) { /* N polar cap */
gmtlib_iobl (GMT, &lon[k], &lat[k], lon_obl[k], p_cap); /* Get regular coordinates of this point */
lon[k] *= R2D; lat[k] *= R2D; /* Convert to degrees */
}
if ((GMT->current.plot.n = gmt_geo_to_xy_line (GMT, lon, lat, np)) > 0)
gmt_plot_line (GMT, GMT->current.plot.x, GMT->current.plot.y, GMT->current.plot.pen, GMT->current.plot.n, PSL_LINEAR);
}
gmt_M_free (GMT, lon_obl);
gmt_M_free (GMT, lon);
gmt_M_free (GMT, lat);
}
GMT_LOCAL void gmtplot_y_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double *y, unsigned int ny) {
unsigned int i;
double x1, y1, x2, y2;
for (i = 0; i < ny; i++) {
if (gmt_M_y_is_lat (GMT, GMT_IN))
gmtplot_map_latline (GMT, PSL, y[i], w, e);
else {
gmt_geo_to_xy (GMT, w, y[i], &x1, &y1);
gmt_geo_to_xy (GMT, e, y[i], &x2, &y2);
PSL_plotsegment (PSL, x1, y1, x2, y2);
}
}
}
void gmt_plot_timex_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, unsigned int item) {
unsigned int nx;
double *x = NULL;
nx = gmtlib_time_array (GMT, w, e, &GMT->current.map.frame.axis[GMT_X].item[item], &x);
gmtplot_x_grid (GMT, PSL, s, n, x, nx);
if (x) gmt_M_free (GMT, x);
}
GMT_LOCAL void gmtplot_timey_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, unsigned int item) {
unsigned int ny;
double *y = NULL;
ny = gmtlib_time_array (GMT, s, n, &GMT->current.map.frame.axis[GMT_Y].item[item], &y);
gmtplot_y_grid (GMT, PSL, w, e, y, ny);
if (y) gmt_M_free (GMT, y);
}
GMT_LOCAL void gmtplot_logx_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, double dval) {
unsigned int nx;
double *x = NULL;
nx = gmtlib_log_array (GMT, w, e, dval, &x);
gmtplot_x_grid (GMT, PSL, s, n, x, nx);
if (x) gmt_M_free (GMT, x);
}
GMT_LOCAL void gmtplot_logy_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, double dval) {
unsigned int ny;
double *y = NULL;
ny = gmtlib_log_array (GMT, s, n, dval, &y);
gmtplot_y_grid (GMT, PSL, w, e, y, ny);
if (y) gmt_M_free (GMT, y);
}
GMT_LOCAL void gmtplot_powx_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, double dval) {
unsigned int nx;
double *x = NULL;
nx = gmtlib_pow_array (GMT, w, e, dval, 0, &x);
gmtplot_x_grid (GMT, PSL, s, n, x, nx);
if (x) gmt_M_free (GMT, x);
}
GMT_LOCAL void gmtplot_powy_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, double dval) {
unsigned int ny;
double *y = NULL;
ny = gmtlib_pow_array (GMT, s, n, dval, 1, &y);
gmtplot_y_grid (GMT, PSL, w, e, y, ny);
if (y) gmt_M_free (GMT, y);
}
GMT_LOCAL double gmtplot_shift_gridline (struct GMT_CTRL *GMT, double val, unsigned int type) {
/* Only for oblique projections: If any of the corners are exactly multiples of annotation
* or tick intervals then the gridline intersection may fail (tangent or slightly outside
* due to round-off). We determine which gridlines go through the corners and shift them
* a tiny bit to the inside to ensure crossings */
double shift = 0.0;
if (!GMT->common.R.oblique) return shift; /* Return zero if not an oblique projection */
if (type == GMT_X) {
if (gmt_M_360_range (val, GMT->common.R.wesn_orig[XLO])) val = GMT->common.R.wesn_orig[XLO];
else if (gmt_M_360_range (val, GMT->common.R.wesn_orig[XHI])) val = GMT->common.R.wesn_orig[XHI];
if (doubleAlmostEqualZero (val, GMT->common.R.wesn_orig[XLO])) shift = +GMT_CONV4_LIMIT * fabs (GMT->common.R.wesn_orig[XHI] - GMT->common.R.wesn_orig[XLO]); /* Add this to lon to get a slightly larger longitude to ensure crossing */
else if (doubleAlmostEqualZero (val, GMT->common.R.wesn_orig[XHI])) shift = -GMT_CONV4_LIMIT * fabs (GMT->common.R.wesn_orig[XHI] - GMT->common.R.wesn_orig[XLO]); /* Add this to lon to get a slightly smaller longitude to ensure crossing */
}
else {
if (doubleAlmostEqualZero (val, GMT->common.R.wesn_orig[YLO])) shift = +GMT_CONV4_LIMIT * fabs (GMT->common.R.wesn_orig[YHI] - GMT->common.R.wesn_orig[YLO]); /* Add this to lon to get a slightly larger longitude to ensure crossing */
else if (doubleAlmostEqualZero (val, GMT->common.R.wesn_orig[YHI])) shift = -GMT_CONV4_LIMIT * fabs (GMT->common.R.wesn_orig[YHI] - GMT->common.R.wesn_orig[YLO]); /* Add this to lon to get a slightly smaller longitude to ensure crossing */
}
if (shift != 0.0) GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Adjusted argument %g by %g\n", val, shift);
return shift;
}
/* FANCY RECTANGULAR PROJECTION MAP BOUNDARY */
GMT_LOCAL void gmtplot_fancy_frame_offset (struct GMT_CTRL *GMT, double angle, double shift[2]) {
/* Given the angle of the axis, return the coordinate adjustments needed to
* shift in order to plot the outer 1-2 parallel frame lines (shift[0|1] */
double s, c;
sincos (angle, &s, &c);
shift[0] = GMT->current.setting.map_frame_width * s;
shift[1] = -GMT->current.setting.map_frame_width * c;
}
GMT_LOCAL void gmtplot_fancy_frame_straightlon_checkers (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, bool secondary_too) {
/* Plot checkers along straight longitude boundaries */
int i, k, nx;
unsigned int shade, item[2] = {GMT_TICK_UPPER, GMT_TICK_LOWER};
double dx, w1, val, v1, v2, x1, x2, y1, y2, shift_s[2], shift_n[2], scale[2];
struct GMT_PLOT_AXIS_ITEM *T = NULL;
scale[0] = (secondary_too) ? 0.5 : 1.0;
scale[1] = 1.5;
gmt_geo_to_xy (GMT, e, s, &x1, &y1);
gmt_geo_to_xy (GMT, w, s, &x2, &y2);
gmtplot_fancy_frame_offset (GMT, d_atan2 (y2 - y1, x2 - x1), shift_s);
gmt_geo_to_xy (GMT, w, n, &x1, &y1);
gmt_geo_to_xy (GMT, e, n, &x2, &y2);
gmtplot_fancy_frame_offset (GMT, d_atan2 (y2 - y1, x2 - x1), shift_n);
for (k = 0; k < 1 + secondary_too; k++) {
T = &GMT->current.map.frame.axis[GMT_X].item[item[k]];
if (T->active) {
dx = gmtlib_get_map_interval (GMT, GMT->current.map.frame.axis[GMT_X].type, T);
shade = (urint (floor ((w - GMT->current.map.frame.axis[GMT_X].phase)/ dx))) % 2;
w1 = floor ((w - GMT->current.map.frame.axis[GMT_X].phase)/ dx) * dx + GMT->current.map.frame.axis[GMT_X].phase;
nx = (w1 > e) ? -1 : irint (((e - w1) / dx + GMT_CONV4_LIMIT));
for (i = 0; i <= nx; i++) {
shade = !shade;
val = w1 + i * dx;
v1 = MAX (val, w);
v2 = MIN (val + dx, e);
if (v2 - v1 < GMT_CONV8_LIMIT) continue;
PSL_setcolor (PSL, shade ? GMT->current.setting.map_frame_pen.rgb : GMT->PSL->init.page_rgb, PSL_IS_STROKE);
if (GMT->current.map.frame.side[S_SIDE] & GMT_AXIS_TICK) {
gmt_geo_to_xy (GMT, v1, s, &x1, &y1);
gmt_geo_to_xy (GMT, v2, s, &x2, &y2);
PSL_plotsegment (PSL, x1-0.5*scale[k]*shift_s[0], y1-0.5*scale[k]*shift_s[1], x2-0.5*scale[k]*shift_s[0], y2-0.5*scale[k]*shift_s[1]);
}
if (GMT->current.map.frame.side[N_SIDE] & GMT_AXIS_TICK) {
gmt_geo_to_xy (GMT, v1, n, &x1, &y1);
gmt_geo_to_xy (GMT, v2, n, &x2, &y2);
PSL_plotsegment (PSL, x1-0.5*scale[k]*shift_n[0], y1-0.5*scale[k]*shift_n[1], x2-0.5*scale[k]*shift_n[0], y2-0.5*scale[k]*shift_n[1]);
}
}
}
}
}
GMT_LOCAL void gmtplot_fancy_frame_curvedlon_checkers (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, bool secondary_too) {
/* Plot checkers along curved longitude boundaries */